Exemplo n.º 1
0
        /// <summary>
        /// Сохраняем backup файлов
        /// </summary>
        /// <param name="files"></param>
        private static void BackUpFiles(FileInfo[] files, ReceiverParamsHelper receiverParams)
        {
            string        backupPath = $@"{receiverParams.DirName}backup\";
            DirectoryInfo dir        = new DirectoryInfo(backupPath);

            if (!dir.Exists)
            {
                Directory.CreateDirectory(backupPath);
            }
            else
            {
                var filesToDrop = dir.GetFiles();
                if (filesToDrop != null)
                {
                    foreach (var file in filesToDrop)
                    {
                        file.Delete();
                    }
                }
            }

            foreach (var file in files)
            {
                file.CopyTo($"{backupPath}{file.Name}");
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Работа с файлами импорта
        /// </summary>
        /// <param name="file"></param>
        private static bool FileProcessing(FileInfo file, dbModel db, ReceiverParamsHelper receiverParams)
        {
            try
            {
                SrvcLogger.Info("{preparing}", $"импорт данных из: '{file.Name}'");
                Log.Insert(0, $"Чтение данных: {file.Name}");

                using (FileStream fileStream = new FileStream(file.FullName, FileMode.Open))
                {
                    SrvcLogger.Info("{preparing}", $"данные прочитаны из файла: {file.Name}");
                    Log.Insert(0, "Данные прочитаны");

                    var helper = new InsertHelper
                    {
                        FileStream = fileStream,
                        Db         = db,
                        Entity     = Entity.Catalogs
                    };

                    if (file.Name.StartsWith("cat"))
                    {
                        InsertWithLogging(helper);
                    }
                    else if (file.Name.StartsWith("prod"))
                    {
                        foreach (Entity entity in Enum.GetValues(typeof(Entity)))
                        {
                            if (!entity.Equals(Entity.Catalogs))
                            {
                                helper.Entity = entity;
                                InsertWithLogging(helper);
                            }
                        }
                        Step++;

                        SrvcLogger.Info("{work}", "перенос данных из буферных таблиц");
                        Log.Insert(0, "Перенос данных из буферных таблиц");
                        Finalizer(db);
                        Step++;
                    }
                    else if (file.Name.Contains(".zip"))
                    {
                        ImageService imageService = new ImageService(receiverParams);
                        imageService.Execute(file);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                SrvcLogger.Error("{error}", e.ToString());
                return(false);
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            ReceiverParamsHelper helperParams = new ReceiverParamsHelper();

            DirectoryInfo info = new DirectoryInfo(helperParams.DirName);

            FileInfo[] files = info.GetFiles("*.zip")
                               .OrderByDescending(p => p.LastWriteTime)
                               .Take(3)
                               .ToArray();

            Importer.DoImport(files);

            //XmlSerializer writer = new XmlSerializer(typeof(OrdersXMLModel));
            //var path = $"{helperParams.DirName}order.xml";
            //using (FileStream file = File.Create(path))
            //{
            //    var order = OrdersCreator()[0];
            //    writer.Serialize(file, order);
            //}
        }
Exemplo n.º 4
0
        /// <summary>
        /// Основной метод
        /// </summary>
        public static void DoImport(FileInfo[] files)
        {
            ReceiverParamsHelper receiverParams = new ReceiverParamsHelper();
            Stopwatch            stopwatch      = new Stopwatch();

            stopwatch.Start();
            Preparing();
            BackUpFiles(files, receiverParams);

            if (files != null && files.Any(a => a != null))
            {
                Step++;
                files = files.Where(w => w != null).ToArray();
                var _files = FilesOrdering(files);
                SrvcLogger.Info("{preparing}", $"кол-во файлов: {_files.Count()}");
                string ff = String.Empty;
                foreach (var f in _files)
                {
                    ff += f.ToString() + "; ";
                }

                SrvcLogger.Info("{preparing}", $"файлы: {ff}");

                try
                {
                    if (_files.Any(a => a.Name.Contains(".xml")))
                    {
                        if (_files.Any(a => a.Name.Contains(".zip")))
                        {
                            SetSteps(3);
                        }
                        else
                        {
                            SetSteps(1);
                        }
                    }
                    else if (_files.Any(a => a.Name.Contains(".zip")))
                    {
                        SetSteps(2);
                    }

                    UpdateCurrentStep();
                    using (var db = new dbModel(CONNECTION))
                    {
                        foreach (var file in _files)
                        {
                            try
                            {
                                if (file != null)
                                {
                                    bool resultEx = false;
                                    resultEx = FileProcessing(file, db, receiverParams);
                                    if (!resultEx)
                                    {
                                        Thread.Sleep(1000 * 60 * 5);
                                        FileProcessing(file, db, receiverParams);
                                    }
                                }
                            }
                            catch (Exception e)
                            {
                                SrvcLogger.Error("{error}", e.ToString());
                            }
                        }

                        stopwatch.Stop();
                        EmailBody += ResultLogging(stopwatch);
                        SendEmail(EmailBody, db);
                        CreateXmlExport(receiverParams.DirName);
                        DropImportFiles(_files);
                    }
                }
                catch (Exception e)
                {
                    SrvcLogger.Error("{error}", e.ToString());
                }
            }
            else
            {
                SrvcLogger.Info("{work}", "файлов для импорта не найдено");
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Конструктор
 /// </summary>
 public ImageService(ReceiverParamsHelper helper)
 {
     ParamsHelper = helper;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Запуск интеграции
        /// </summary>
        /// <param name="data"></param>
        private void DoIntegration(object data)
        {
            SrvcLogger.Info("{preparing}", "I work!");
            ReceiverParamsHelper helperParams = new ReceiverParamsHelper();
            string times = String.Join(";", helperParams.StartTime);

            SrvcLogger.Info("{preparing}", $"время запуска интеграции {times}");
            SrvcLogger.Info("{preparing}", $"директория с файлами {helperParams.DirName}");

            while (enableIntegration)
            {
                int[] executeWaitArray = MilisecondsToWait(helperParams.StartTime);
                int   executeWait      = executeWaitArray.Min();
                int   hoursWait        = executeWait / 1000 / 60 / 60;
                int   minutesWait      = (executeWait - (hoursWait * 60 * 60 * 1000)) / 1000 / 60;
                int   secWait          = (executeWait - (hoursWait * 60 * 60 * 1000) - (minutesWait * 60 * 1000)) / 1000;
                SrvcLogger.Info("{preparing}", $"импорт будет выполнен через: " +
                                $"{hoursWait} час. {minutesWait} мин. {secWait} сек.");
                Thread.Sleep(executeWait);

                DirectoryInfo info  = new DirectoryInfo(helperParams.DirName);
                FileInfo[]    files = info.GetFiles("*.zip")
                                      .OrderByDescending(p => p.LastWriteTime)
                                      .Take(3)
                                      .ToArray();

                //FileInfo[] filesToDrop = info.GetFiles("*.xml");
                //DropFiles(filesToDrop);

                SrvcLogger.Info("{preparing}", "запуск ядра импорта");
                SrvcLogger.Info("{work}", $"директория: {helperParams.DirName}");
                if (files != null && files.Any(a => a != null))
                {
                    string listFiles = "список найденных файлов: ";
                    foreach (var file in files)
                    {
                        if (file != null)
                        {
                            listFiles += $"{file.Name}; ";
                        }
                    }
                    SrvcLogger.Info("{work}", $"{listFiles}");
                    Importer.DoImport(files);

                    foreach (var file in files)
                    {
                        if (file != null && file.Exists)
                        {
                            try
                            {
                                SrvcLogger.Info("{work}", $"удаление файла: {file}");
                                file.Delete();
                            }
                            catch (Exception e)
                            {
                                SrvcLogger.Error("{error}", $"{e.ToString()}");
                            }
                        }
                    }
                }
                else
                {
                    SrvcLogger.Info("{work}", "файлов для импорта не найдено");
                }
            }
        }