/// <summary> /// Метод для сохранения настроек /// </summary> /// <param name="callback">Функция обратного вызова, с параметром: ошибка</param> /// <param name="filesSettings">Настройки файлов</param> /// <param name="ftpSettings">Настройки фтп-сервера</param> /// <param name="geoCodSettings">Настройки геокодирования</param> public void SaveSettings(Action <Exception> callback, FilesSettings filesSettings, FTPSettings ftpSettings, GeoCodSettings geoCodSettings, BDSettings bdSettings, NotificationSettings ns, string color, bool comp) { Exception error = null; var p = Properties.Settings.Default; p.CanBreakFileOutput = filesSettings.CanBreakFileOutput; p.CanCopyFileOutputToFtp = filesSettings.CanCopyFileOutputToFtp; p.CanGeoCodGetAll = geoCodSettings.CanGeoCodGetAll; p.CanGeoCodGetError = geoCodSettings.CanGeoCodGetError; p.CanGeoCodGetNotGeo = geoCodSettings.CanGeoCodGetNotGeo; p.CanGetDataOnce = filesSettings.CanGetDataOnce; p.CanOpenFolderAfter = geoCodSettings.CanOpenFolderAfter; p.CanSaveDataAsFinished = geoCodSettings.CanSaveDataAsFinished; p.CanSaveDataAsTemp = geoCodSettings.CanSaveDataAsTemp; p.GeoService = geoCodSettings.GeoService; p.FtpFolderInput = ftpSettings.FolderInput; p.FtpFolderOutput = ftpSettings.FolderOutput; p.IsFileInputOnFTP = filesSettings.IsFileInputOnFTP; p.MaxSizePart = filesSettings.MaxSizePart; p.CanStartCompact = comp; // ФТП-сервер пароль шифруем Helpers.ProtectedDataDPAPI.EncryptData((d, e) => { if (e == null) { p.FtpPassword = d; } }, ftpSettings.Password); // ФТП-сервер шифруем Helpers.ProtectedDataDPAPI.EncryptData((d, e) => { if (e == null) { p.FtpServer = d; } }, ftpSettings.Server); p.FtpPort = ftpSettings.Port; p.FtpUser = ftpSettings.User; p.CanGeoCodAfterGetFile = geoCodSettings.CanGeoCodAfterGetFile; p.CanSaveStatistics = geoCodSettings.CanSaveStatistics; p.ColorTheme = color; p.BDPort = bdSettings.Port; p.BDName = bdSettings.BDName; p.BDLogin = bdSettings.Login; // БД сервер шифруем Helpers.ProtectedDataDPAPI.EncryptData((d, e) => { if (e == null) { p.BDServer = d; } }, bdSettings.Server); // БД пароль шифруем Helpers.ProtectedDataDPAPI.EncryptData((d, e) => { if (e == null) { p.BDPassword = d; } }, bdSettings.Password); p.CanNotificationProcessCancel = ns.CanNotificationProcessCancel; p.CanNotificationDataEmpty = ns.CanNotificationDataEmpty; p.CanNotificationDataProcessed = ns.CanNotificationDataProcessed; p.CanNotificationSaveData = ns.CanNotificationSaveData; p.CanNotificationSaveSettings = ns.CanNotificationSaveSettings; p.CanNotificationStatAlreadySave = ns.CanNotificationStatAlreadySave; p.CanNotificationOnlyError = ns.CanNotificationOnlyError; p.CanNotificationExit = ns.CanNotificationExit; try { p.Save(); } catch (Exception ex) { error = ex; } callback(error); }
/// <summary> /// Метод для получения настроек приложения /// </summary> /// <param name="callback">Функция обратного вызова, с параметрами: ошибка, настройки файлов, настройки геокодирования, настройки фтп-сервера</param> public void GetSettings(Action <Exception, FilesSettings, GeoCodSettings, FTPSettings, BDSettings, NotificationSettings, string, bool> callback) { Exception error = null; var p = Properties.Settings.Default; var curDir = Environment.CurrentDirectory; string color = p.ColorTheme; bool canStartCompact = p.CanStartCompact; FilesSettings f = new FilesSettings() { CanBreakFileOutput = p.CanBreakFileOutput, CanCopyFileOutputToFtp = p.CanCopyFileOutputToFtp, FolderInput = $"{curDir}\\{p.FolderInput}", FolderOutput = $"{curDir}\\{p.FolderOutput}", FolderTemp = $"{curDir}\\{p.FolderTemp}", FolderStatistics = $"{curDir}\\{p.FolderStatistics}", FolderErrors = $"{curDir}\\{p.FolderErrors}", IsFileInputOnFTP = p.IsFileInputOnFTP, MaxSizePart = p.MaxSizePart, CanGetDataOnce = p.CanGetDataOnce }; GeoCodSettings g = new GeoCodSettings() { CanGeoCodGetAll = p.CanGeoCodGetAll, CanGeoCodGetError = p.CanGeoCodGetError, CanGeoCodGetNotGeo = p.CanGeoCodGetNotGeo, CanSaveDataAsFinished = p.CanSaveDataAsFinished, CanSaveDataAsTemp = p.CanSaveDataAsTemp, CanOpenFolderAfter = p.CanOpenFolderAfter, CanGeoCodAfterGetFile = p.CanGeoCodAfterGetFile, CanSaveStatistics = p.CanSaveStatistics, GeoService = p.GeoService }; FTPSettings ftp = new FTPSettings() { Port = p.FtpPort, User = p.FtpUser, FolderInput = p.FtpFolderInput, FolderOutput = p.FtpFolderOutput }; Helpers.ProtectedDataDPAPI.DecryptData((d, e) => { if (e == null) { ftp.Server = d; } }, p.FtpServer); Helpers.ProtectedDataDPAPI.DecryptData((d, e) => { if (e == null) { ftp.Password = d; } }, p.FtpPassword); BDSettings bds = new BDSettings() { BDName = p.BDName, Port = p.BDPort, Login = p.BDLogin, Password = p.BDPassword }; Helpers.ProtectedDataDPAPI.DecryptData((d, e) => { if (e == null) { bds.Server = d; } }, p.BDServer); Helpers.ProtectedDataDPAPI.DecryptData((d, e) => { if (e == null) { bds.Password = d; } }, p.BDPassword); NotificationSettings ns = new NotificationSettings() { CanNotificationDataEmpty = p.CanNotificationDataEmpty, CanNotificationDataProcessed = p.CanNotificationDataProcessed, CanNotificationOnlyError = p.CanNotificationOnlyError, CanNotificationProcessCancel = p.CanNotificationProcessCancel, CanNotificationSaveData = p.CanNotificationSaveData, CanNotificationSaveSettings = p.CanNotificationSaveSettings, CanNotificationStatAlreadySave = p.CanNotificationStatAlreadySave, CanNotificationExit = p.CanNotificationExit }; callback(error, f, g, ftp, bds, ns, color, canStartCompact); }