352 lines
15 KiB
C#
352 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GestoreTrimestrale
|
|
{
|
|
class configModel
|
|
{
|
|
private int _zipInterval;
|
|
private int _countersUpdateInterval;
|
|
private int _loggingInterval;
|
|
private int _maxGestoreThreads;
|
|
private int _numeroCfPerZip;
|
|
private string _fTPServer;
|
|
private string _fTPLogin;
|
|
private string _fTPPassword;
|
|
private string _fTPPath;
|
|
private string _queryContratti;
|
|
private int _savePDFtoDISK;
|
|
private string _pDFProcessFolder;
|
|
private string _pDFOutputFolder;
|
|
private string _zipFolder;
|
|
private string _zipBackupFolder;
|
|
private string _workFolder;
|
|
private string _connectionString;
|
|
private string _connectionStringReportManager;
|
|
private int _sqlCommandTimeout;
|
|
public Configuration _config;
|
|
|
|
/// <summary>
|
|
/// We decided to save all the changes to default app.config, as it was impossible to
|
|
/// change connection strings entries without applying changes to file on hard drive.
|
|
/// </summary>
|
|
private void saveDefaultConfigFile()
|
|
{
|
|
Configuration defaultAppConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
defaultAppConfig.AppSettings.Settings["pathFolder"].Value = PDFProcessFolder;
|
|
defaultAppConfig.AppSettings.Settings["pathPDFToDB_PERIODICO"].Value = PDFOutputFolder;
|
|
defaultAppConfig.AppSettings.Settings["path_OUTPUT_ZIP_PERIODICO"].Value = ZipFolder;
|
|
defaultAppConfig.AppSettings.Settings["path_ZIP_BACKUP_FOLDER"].Value = ZipBackupFolder;
|
|
defaultAppConfig.AppSettings.Settings["pathZIPTemp"].Value = WorkFolder;
|
|
defaultAppConfig.AppSettings.Settings["zipInterval"].Value = zipInterval.ToString();
|
|
defaultAppConfig.AppSettings.Settings["loggingInterval"].Value = loggingInterval.ToString();
|
|
defaultAppConfig.AppSettings.Settings["statisticsUpdateInterval"].Value = countersUpdateInterval.ToString();
|
|
defaultAppConfig.AppSettings.Settings["maxGestoreThreads"].Value = maxGestoreThreads.ToString();
|
|
defaultAppConfig.AppSettings.Settings["numeroCfPerZip"].Value = numeroCfPerZip.ToString();
|
|
defaultAppConfig.AppSettings.Settings["QueryContratti"].Value = QueryContratti;
|
|
defaultAppConfig.AppSettings.Settings["SavePDFtoDISK"].Value = SavePDFtoDISK.ToString();
|
|
defaultAppConfig.AppSettings.Settings["FTPServer"].Value = FTPServer;
|
|
defaultAppConfig.AppSettings.Settings["FTPUser"].Value = FTPLogin;
|
|
defaultAppConfig.AppSettings.Settings["FTPPassword"].Value = FTPPassword;
|
|
defaultAppConfig.AppSettings.Settings["FTPPath"].Value = FTPPath;
|
|
defaultAppConfig.AppSettings.Settings["sqlCommandTimeout"].Value = SqlCommandTimeout.ToString();
|
|
// connection strings
|
|
_connectionString = _config.ConnectionStrings.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString;
|
|
_connectionStringReportManager = _config.ConnectionStrings.ConnectionStrings["SqlServerConnection"].ConnectionString;
|
|
defaultAppConfig.ConnectionStrings.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString = _connectionString;
|
|
defaultAppConfig.ConnectionStrings.ConnectionStrings["SqlServerConnection"].ConnectionString = _connectionStringReportManager;
|
|
// connection strings end
|
|
|
|
defaultAppConfig.Save(ConfigurationSaveMode.Minimal, true);
|
|
}
|
|
public configModel(string configPath = null)
|
|
{
|
|
if (configPath == null)
|
|
{
|
|
_config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
}
|
|
else
|
|
{
|
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
|
configMap.ExeConfigFilename = configPath;
|
|
Properties.Settings.Default.Reload();
|
|
_config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
|
}
|
|
|
|
|
|
PDFProcessFolder = _config.AppSettings.Settings["pathFolder"].Value; // pathFolder
|
|
ConfigurationManager.AppSettings["pathFolder"] = PDFProcessFolder;
|
|
|
|
PDFOutputFolder = _config.AppSettings.Settings["pathPDFToDB_PERIODICO"].Value; // pathPDFToDB_PERIODICO
|
|
ConfigurationManager.AppSettings["pathPDFToDB_PERIODICO"] = PDFOutputFolder;
|
|
|
|
ZipFolder = _config.AppSettings.Settings["path_OUTPUT_ZIP_PERIODICO"].Value; // path_OUTPUT_ZIP_PERIODICO
|
|
ConfigurationManager.AppSettings["path_OUTPUT_ZIP_PERIODICO"] = ZipFolder;
|
|
|
|
ZipBackupFolder = _config.AppSettings.Settings["path_ZIP_BACKUP_FOLDER"].Value; // path_ZIP_BACKUP_FOLDER
|
|
ConfigurationManager.AppSettings["path_ZIP_BACKUP_FOLDER"] = ZipBackupFolder;
|
|
|
|
WorkFolder = _config.AppSettings.Settings["pathZIPTemp"].Value; // pathZIPTemp
|
|
ConfigurationManager.AppSettings["pathZIPTemp"] = WorkFolder;
|
|
|
|
zipInterval = Int32.Parse(_config.AppSettings.Settings["zipInterval"].Value);
|
|
ConfigurationManager.AppSettings["zipInterval"] = zipInterval.ToString();
|
|
|
|
loggingInterval = Int32.Parse(_config.AppSettings.Settings["loggingInterval"].Value);
|
|
ConfigurationManager.AppSettings["loggingInterval"] = loggingInterval.ToString();
|
|
|
|
countersUpdateInterval = Int32.Parse(_config.AppSettings.Settings["statisticsUpdateInterval"].Value);
|
|
ConfigurationManager.AppSettings["statisticsUpdateInterval"] = countersUpdateInterval.ToString();
|
|
|
|
maxGestoreThreads = Int32.Parse(_config.AppSettings.Settings["maxGestoreThreads"].Value);
|
|
ConfigurationManager.AppSettings["maxGestoreThreads"] = maxGestoreThreads.ToString();
|
|
|
|
numeroCfPerZip = Int32.Parse(_config.AppSettings.Settings["numeroCfPerZip"].Value);
|
|
ConfigurationManager.AppSettings["numeroCfPerZip"] = numeroCfPerZip.ToString();
|
|
|
|
QueryContratti = _config.AppSettings.Settings["QueryContratti"].Value;
|
|
ConfigurationManager.AppSettings["QueryContratti"] = QueryContratti;
|
|
|
|
SavePDFtoDISK = Int32.Parse(_config.AppSettings.Settings["SavePDFtoDISK"].Value);
|
|
ConfigurationManager.AppSettings["SavePDFtoDISK"] = SavePDFtoDISK.ToString();
|
|
|
|
FTPServer = _config.AppSettings.Settings["FTPServer"].Value;
|
|
ConfigurationManager.AppSettings["FTPServer"] = FTPServer;
|
|
|
|
FTPLogin = _config.AppSettings.Settings["FTPUser"].Value;
|
|
ConfigurationManager.AppSettings["FTPUser"] = FTPLogin;
|
|
|
|
FTPPassword = _config.AppSettings.Settings["FTPPassword"].Value;
|
|
ConfigurationManager.AppSettings["FTPPassword"] = FTPPassword;
|
|
|
|
FTPPath = _config.AppSettings.Settings["FTPPath"].Value;
|
|
ConfigurationManager.AppSettings["FTPPath"] = FTPPath;
|
|
|
|
SqlCommandTimeout = Int32.Parse(_config.AppSettings.Settings["sqlCommandTimeout"].Value);
|
|
ConfigurationManager.AppSettings["sqlCommandTimeout"] = SqlCommandTimeout.ToString();
|
|
|
|
saveDefaultConfigFile();
|
|
|
|
ConfigurationManager.RefreshSection("appConfig");
|
|
ConfigurationManager.RefreshSection("connectionStrings");
|
|
ConfigurationManager.RefreshSection("appSettings");
|
|
Properties.Settings.Default.Reload();
|
|
}
|
|
public void SaveConfig(string configPath = null)
|
|
{
|
|
if (configPath == null)
|
|
{
|
|
_config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
}
|
|
else
|
|
{
|
|
ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
|
|
configMap.ExeConfigFilename = configPath;
|
|
Properties.Settings.Default.Reload();
|
|
_config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);
|
|
}
|
|
|
|
ConfigurationManager.AppSettings["sqlCommandTimeout"] = _sqlCommandTimeout.ToString();
|
|
_config.AppSettings.Settings["sqlCommandTimeout"].Value = _sqlCommandTimeout.ToString();
|
|
ConfigurationManager.AppSettings["statisticsUpdateInterval"] = _countersUpdateInterval.ToString();
|
|
_config.AppSettings.Settings["statisticsUpdateInterval"].Value = _countersUpdateInterval.ToString();
|
|
ConfigurationManager.AppSettings["loggingInterval"] = _loggingInterval.ToString();
|
|
_config.AppSettings.Settings["loggingInterval"].Value = _loggingInterval.ToString();
|
|
ConfigurationManager.AppSettings["zipInterval"] = _zipInterval.ToString();
|
|
_config.AppSettings.Settings["zipInterval"].Value = _zipInterval.ToString();
|
|
ConfigurationManager.AppSettings["maxGestoreThreads"] = _maxGestoreThreads.ToString();
|
|
_config.AppSettings.Settings["maxGestoreThreads"].Value = _maxGestoreThreads.ToString();
|
|
ConfigurationManager.AppSettings["numeroCfPerZip"] = _numeroCfPerZip.ToString();
|
|
_config.AppSettings.Settings["numeroCfPerZip"].Value = _numeroCfPerZip.ToString();
|
|
ConfigurationManager.AppSettings["FTPServer"] = _fTPServer.ToString();
|
|
_config.AppSettings.Settings["FTPServer"].Value = _fTPServer.ToString();
|
|
ConfigurationManager.AppSettings["FTPUser"] = _fTPLogin.ToString();
|
|
_config.AppSettings.Settings["FTPUser"].Value = _fTPLogin.ToString();
|
|
ConfigurationManager.AppSettings["FTPPassword"] = _fTPPassword.ToString();
|
|
_config.AppSettings.Settings["FTPPassword"].Value = _fTPPassword.ToString();
|
|
|
|
ConfigurationManager.AppSettings["FTPPath"] = _fTPPath.ToString();
|
|
_config.AppSettings.Settings["FTPPath"].Value = _fTPPath.ToString();
|
|
|
|
|
|
ConfigurationManager.AppSettings["QueryContratti"] = _queryContratti.ToString();
|
|
_config.AppSettings.Settings["QueryContratti"].Value = _queryContratti.ToString();
|
|
ConfigurationManager.AppSettings["SavePDFtoDISK"] = _savePDFtoDISK.ToString();
|
|
_config.AppSettings.Settings["SavePDFtoDISK"].Value = _savePDFtoDISK.ToString();
|
|
ConfigurationManager.AppSettings["pathFolder"] = _pDFProcessFolder.ToString();
|
|
_config.AppSettings.Settings["pathFolder"].Value = _pDFProcessFolder.ToString();
|
|
ConfigurationManager.AppSettings["pathPDFToDB_PERIODICO"] = _pDFOutputFolder.ToString();
|
|
_config.AppSettings.Settings["pathPDFToDB_PERIODICO"].Value = _pDFOutputFolder.ToString();
|
|
ConfigurationManager.AppSettings["path_OUTPUT_ZIP_PERIODICO"] = _zipFolder.ToString();
|
|
_config.AppSettings.Settings["path_OUTPUT_ZIP_PERIODICO"].Value = _zipFolder.ToString();
|
|
ConfigurationManager.AppSettings["path_ZIP_BACKUP_FOLDER"] = _zipBackupFolder.ToString();
|
|
_config.AppSettings.Settings["path_ZIP_BACKUP_FOLDER"].Value = _zipBackupFolder.ToString();
|
|
ConfigurationManager.AppSettings["pathZIPTemp"] = _workFolder.ToString();
|
|
_config.AppSettings.Settings["pathZIPTemp"].Value = _workFolder.ToString();
|
|
_config.ConnectionStrings.ConnectionStrings["SqlServerStampeC6Connection"].ConnectionString = _connectionString.ToString();
|
|
_config.ConnectionStrings.ConnectionStrings["SqlServerConnection"].ConnectionString = _connectionStringReportManager.ToString();
|
|
_config.Save(ConfigurationSaveMode.Modified);
|
|
saveDefaultConfigFile();
|
|
ConfigurationManager.RefreshSection("appConfig");
|
|
ConfigurationManager.RefreshSection("connectionStrings");
|
|
Properties.Settings.Default.Reload();
|
|
}
|
|
public int countersUpdateInterval
|
|
{
|
|
get { return _countersUpdateInterval; }
|
|
set
|
|
{
|
|
_countersUpdateInterval = value;
|
|
}
|
|
}
|
|
public int loggingInterval
|
|
{
|
|
get { return _loggingInterval; }
|
|
set
|
|
{
|
|
_loggingInterval = value;
|
|
}
|
|
}
|
|
public int zipInterval
|
|
{
|
|
get { return _zipInterval; }
|
|
set
|
|
{
|
|
_zipInterval = value;
|
|
}
|
|
}
|
|
public int SqlCommandTimeout
|
|
{
|
|
get { return _sqlCommandTimeout; }
|
|
set
|
|
{
|
|
_sqlCommandTimeout = value;
|
|
}
|
|
}
|
|
public int maxGestoreThreads
|
|
{
|
|
get { return _maxGestoreThreads; }
|
|
set
|
|
{
|
|
_maxGestoreThreads = value;
|
|
}
|
|
}
|
|
public int numeroCfPerZip
|
|
{
|
|
get { return _numeroCfPerZip; }
|
|
set
|
|
{
|
|
_numeroCfPerZip = value;
|
|
}
|
|
}
|
|
public string FTPServer
|
|
{
|
|
get { return _fTPServer; }
|
|
set
|
|
{
|
|
_fTPServer = value;
|
|
}
|
|
}
|
|
public string FTPLogin
|
|
{
|
|
get { return _fTPLogin; }
|
|
set
|
|
{
|
|
_fTPLogin = value;
|
|
}
|
|
}
|
|
public string FTPPassword
|
|
{
|
|
get { return _fTPPassword; }
|
|
set
|
|
{
|
|
_fTPPassword = value;
|
|
}
|
|
}
|
|
public string FTPPath
|
|
{
|
|
get { return _fTPPath; }
|
|
set
|
|
{
|
|
_fTPPath = value;
|
|
}
|
|
}
|
|
public string QueryContratti
|
|
{
|
|
get { return _queryContratti; }
|
|
set
|
|
{
|
|
_queryContratti = value;
|
|
}
|
|
}
|
|
public int SavePDFtoDISK
|
|
{
|
|
get { return _savePDFtoDISK; }
|
|
set
|
|
{
|
|
_savePDFtoDISK = value;
|
|
}
|
|
}
|
|
public string PDFProcessFolder
|
|
{
|
|
get { return _pDFProcessFolder; }
|
|
set
|
|
{
|
|
_pDFProcessFolder = value;
|
|
}
|
|
}
|
|
public string PDFOutputFolder
|
|
{
|
|
get { return _pDFOutputFolder; }
|
|
set
|
|
{
|
|
_pDFOutputFolder = value;
|
|
}
|
|
}
|
|
public string ZipFolder
|
|
{
|
|
get { return _zipFolder; }
|
|
set
|
|
{
|
|
_zipFolder = value;
|
|
}
|
|
}
|
|
public string ZipBackupFolder
|
|
{
|
|
get { return _zipBackupFolder; }
|
|
set
|
|
{
|
|
_zipBackupFolder = value;
|
|
}
|
|
}
|
|
public string WorkFolder
|
|
{
|
|
get { return _workFolder; }
|
|
set
|
|
{
|
|
_workFolder = value;
|
|
}
|
|
}
|
|
public string ConnectionString
|
|
{
|
|
get { return _connectionString; }
|
|
set
|
|
{
|
|
_connectionString = value;
|
|
}
|
|
}
|
|
public string ConnectionStringReportManager
|
|
{
|
|
get { return _connectionStringReportManager; }
|
|
set
|
|
{
|
|
_connectionStringReportManager = value;
|
|
}
|
|
}
|
|
}
|
|
}
|