Exemplo n.º 1
0
        public async void ConnectBDAsync(Action <Exception> callback, BDSettings bds)
        {
            Exception error = null;
            await Task.Factory.StartNew(() =>
            {
                _bdService.ConnectBD(e =>
                {
                    error = e;
                }, new BDService.ConnectionSettings()
                {
                    Server   = bds.Server,
                    BDName   = bds.BDName,
                    Port     = bds.Port,
                    Login    = bds.Login,
                    Password = bds.Password
                });

                callback(error);
            });
        }
Exemplo n.º 2
0
        public async void GetDataFromBDAsync(Action <IEnumerable <EntityGeoCod>, Exception> callback, BDSettings bds, string query)
        {
            Exception           error = null;
            List <EntityGeoCod> data  = new List <EntityGeoCod>();

            await Task.Factory.StartNew(() =>
            {
                _bdService.ExecuteUserQuery((d, e) =>
                {
                    if (e == null)
                    {
                        foreach (var item in d)
                        {
                            var a = new EntityGeoCod();

                            if (item.OrponId == 0)
                            {
                                SetError(a, _errorIsFormatIDWrong);
                            }
                            else
                            {
                                a.GlobalID = item.OrponId;
                            }

                            if (string.IsNullOrEmpty(item.Address))
                            {
                                SetError(a, _errorIsAddressEmpty);
                            }
                            else
                            {
                                a.Address = item.Address;
                            }

                            data.Add(a);
                        }
                    }
                    else
                    {
                        error = e;
                    }
                }, new BDService.ConnectionSettings()
                {
                    Server   = bds.Server,
                    BDName   = bds.BDName,
                    Port     = bds.Port,
                    Login    = bds.Login,
                    Password = bds.Password
                }, query);

                callback(data, error);
            });
        }
Exemplo n.º 3
0
        /// <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);
        }
Exemplo n.º 4
0
        /// <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);
        }
Exemplo n.º 5
0
        public void GetSettingsFromFile(Action <Exception> callback, string file, FTPSettings ftp, BDSettings bd)
        {
            Exception     error = null;
            List <string> data  = null;

            _fileService.GetData((d, e) =>
            {
                error = e;
                if (e == null && d != null)
                {
                    data = d.ToList();
                }
            }, file);

            foreach (var str in data)
            {
                if (str[0] == '#')
                {
                    continue;
                }
                var s = str.Split('=');
                switch (s[0])
                {
                case "FtpServer":
                    ftp.Server = s[1];
                    break;

                case "FtpPort":
                    int.TryParse(s[1], out int i);
                    ftp.Port = i;
                    break;

                case "FtpOutput":
                    ftp.FolderOutput = s[1];
                    break;

                case "FtpInput":
                    ftp.FolderInput = s[1];
                    break;

                case "BdServer":
                    bd.Server = s[1];
                    break;

                case "BdName":
                    bd.BDName = s[1];
                    break;

                case "BdPort":
                    int.TryParse(s[1], out int k);
                    bd.Port = k;
                    break;

                default:
                    break;
                }
            }

            callback(error);
        }