示例#1
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);
        }
示例#2
0
        /// <summary>
        /// Метод для копирования файла на фтп-сервер
        /// </summary>
        /// <param name="callback">Функция обратного вызова, с параметром ошибка</param>
        /// <param name="ftps">Настройки фтп-сервера</param>
        /// <param name="path">Путь к файлу</param>
        public void CopyFileOnFtp(Action <Exception> callback, FTPSettings ftps, string path)
        {
            Exception error = null;

            _ftpService.CopyFileOnFtp(e =>
            {
                error = e;
            }, GetConSettings(ftps), path);

            callback(error);
        }
示例#3
0
 /// <summary>
 /// Метод для формирования фтп-настроек в формате
 /// </summary>
 /// <param name="ftps">Настройки фтп-сервера</param>
 /// <returns>Возвращает настройки фтп-сервера в формате</returns>
 private FTPService.ConnectionSettings GetConSettings(FTPSettings ftps)
 {
     return(new FTPService.ConnectionSettings()
     {
         Server = ftps.Server,
         Port = ftps.Port,
         Login = ftps.User,
         Password = ftps.Password,
         FolderInput = ftps.FolderInput,
         FolderOutput = ftps.FolderOutput
     });
 }
示例#4
0
        /// <summary>
        /// Метод для тестового подключения к фтп-серверу
        /// </summary>
        /// <param name="callback">Функция обратного вызова, с параметром ошибка</param>
        /// <param name="ftps">Настройки фтп-сервера</param>
        public async void ConnectFTPAsync(Action <Exception> callback, FTPSettings ftps)
        {
            Exception error = null;
            await Task.Factory.StartNew(() =>
            {
                _ftpService.ConnectFtp(e =>
                {
                    error = e;
                }, GetConSettings(ftps));

                callback(error);
            });
        }
示例#5
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);
        }
示例#6
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);
        }
示例#7
0
        /// <summary>
        /// Метод для сохранения данных в файл
        /// </summary>
        /// <param name="callback">Функция обратного вызова, с параметром ошибка</param>
        /// <param name="data">Множество данных для записи</param>
        /// <param name="file">Файл куда записывать</param>
        public void SaveData(Action <Exception> callback, IEnumerable <EntityGeoCod> data, string file, int maxSizePart, bool canCopyToFtp, FTPSettings ftps)
        {
            Exception     error = null;
            List <string> list  = new List <string>();

            if (maxSizePart == 0)
            {
                list.Add(_nameColumnOutputFile);

                list.AddRange(data.Where(y => y.Status == StatusType.OK).Select(x =>
                {
                    return($"{x.GlobalID}{_charSplit}{x.MainGeoCod?.Latitude}{_charSplit}{x.MainGeoCod?.Longitude}{_charSplit}{x.MainGeoCod?.Qcode}");
                }));

                _fileService.SaveData(er =>
                {
                    error = er;
                }, list, file);

                if (error == null && canCopyToFtp)
                {
                    CopyFileOnFtp(e =>
                    {
                        error = e;
                    }, ftps, file);
                }
            }
            else
            {
                var i = 1;

                var a = data.Partition(maxSizePart);
                try
                {
                    foreach (var item in a)
                    {
                        string nameFile    = System.IO.Path.GetFileNameWithoutExtension(file);
                        string nameFolder  = System.IO.Path.GetDirectoryName(file);
                        string ex          = System.IO.Path.GetExtension(file);
                        string newNameFile = $"{nameFolder}\\{nameFile}_{i}{ex}";

                        list = new List <string>()
                        {
                            _nameColumnOutputFile
                        };

                        list.AddRange(item.Where(y => y.Status == StatusType.OK).Select(x =>
                        {
                            return($"{x.GlobalID}{_charSplit}{x.MainGeoCod?.Latitude}{_charSplit}{x.MainGeoCod?.Longitude}{_charSplit}{x.MainGeoCod?.Qcode}");
                        }));

                        _fileService.SaveData(er =>
                        {
                            error = er;
                        }, list, newNameFile);

                        if (error == null && canCopyToFtp)
                        {
                            CopyFileOnFtp(e =>
                            {
                                error = e;
                            }, ftps, newNameFile);
                        }

                        i++;
                    }
                }
                catch (Exception ex)
                {
                    error = ex;
                }
            }

            callback(error);
        }