Exemplo n.º 1
0
        public FtpJob(
            FtpLoader ftpLoader,
            FileNameMatcher fileNameMatcher,
            IFtpJobRepository ftpJobRepository)
        {
            var fromDateSetting = ConfigurationManager.AppSettings["startDate"];

            if (string.IsNullOrEmpty(fromDateSetting))
            {
                throw new ConfigurationErrorsException("Please add 'startDate' settigns to .config file.");
            }

            var jobInterval = ConfigurationManager.AppSettings["job:FtpJobInterval"];

            if (string.IsNullOrEmpty(jobInterval))
            {
                throw new ConfigurationErrorsException("Please add 'job:FtpJobInterval' settigns to .config file.");
            }

            _fromDate   = DateTime.ParseExact(fromDateSetting, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            JobInterval = int.Parse(jobInterval);

            _ftpJobRepository = ftpJobRepository;
            _ftpLoader        = ftpLoader;
            _fileNameMatcher  = fileNameMatcher;
        }
Exemplo n.º 2
0
        public bool SyncChannelsByPeriod(VideoReg video, DateInterval interval)
        {
            var cts  = new CancellationTokenSource();
            var task = new Task(() =>
            {
                using (var ftp = FtpLoader.Start(video.FtpSettings))
                {
                    try
                    {
                        // Загружаем данные за необходимый интревал
                        // video.BrigadeCode, video.ChannelFolder, channelFolder
                        string localRoot = Path.Combine(channelFolder, video.BrigadeCode.ToString());
                        ftp.DownloadFilesByInterval(interval, video.ChannelFolder, localRoot, cts);
                    }
                    catch (OperationCanceledException e)
                    {
                        logger.Info(e, $"{video.BrigadeCode}  [{interval}] operation canseled");
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                    }
                }

                // Сннимаем задачу из списка задач
                lock (tasksLock)
                {
                    tasks.RemoveAll(t =>
                                    t.BrigadeCode == video.BrigadeCode &&
                                    t.Interval == interval);
                }
            }, cts.Token);

            ChannelTask newTask = new ChannelTask
            {
                BrigadeCode = video.BrigadeCode,
                Interval    = interval,
                Task        = task,
                Cts         = cts
            };

            lock (tasksLock)
            {
                // Проверем выполняется ли в данный момент аналогичная задача если да то не надо ее дублировать
                ChannelTask oldTask = tasks.FirstOrDefault(x =>
                                                           x.BrigadeCode == video.BrigadeCode &&
                                                           x.Interval == interval);
                if (oldTask != null)
                {
                    logger.Warn($"SyncChannelsByPeriod({video.BrigadeCode}, {interval}) [EXECUTION-MISS]");
                    return(false);
                }
                // Ставим задачу на выполнение
                tasks.Add(newTask);
                newTask.Task.Start();
            }

            logger.Info($"SyncChannelsByPeriod({video.BrigadeCode}, {interval}) [EXECUTION]");
            return(true);
        }
Exemplo n.º 3
0
 public AzureBlobStorageProvider(FtpLoader ftpLoader)
 {
     _ftpLoader = ftpLoader;
     FolderName = ConfigurationManager.AppSettings["historyFolder"];
     if (string.IsNullOrEmpty(FolderName))
     {
         throw new ConfigurationErrorsException("Please add 'historyFolder' settigns to .config file.");
     }
 }
Exemplo n.º 4
0
        public FileSystemProvider(FtpLoader ftpLoader)
        {
            _ftpLoader = ftpLoader;
            FolderName = ConfigurationManager.AppSettings["historyFolder"];
            if (string.IsNullOrEmpty(FolderName))
            {
                throw new ConfigurationErrorsException("Please add 'historyFolder' settigns to .config file.");
            }

            if (!Directory.Exists(FolderName))
            {
                Directory.CreateDirectory(FolderName);
            }
        }
Exemplo n.º 5
0
 public FtpJob(
     FtpLoader ftpLoader,
     InMemoryCache <TradeMasterAccountModel> tradeMasterAccountModel,
     IContract wcf,
     FileNameMatcher fileNameMatcher,
     IFtpJobRepository ftpJobRepository,
     IImportRepository importRepository) : base(wcf)
 {
     _job       = Job.Ftp;
     _ftpLoader = ftpLoader;
     _tradeMasterAccountModel = tradeMasterAccountModel;
     _ftpJobRepository        = ftpJobRepository;
     _importRepository        = importRepository;
     _fileNameMatcher         = fileNameMatcher;
     //using (_ftpJobRepository.BeginOperation())
     //{
     //    foreach (var ftpFile in ftpJobRepository.ImportedFilesQuery())
     //    {
     //        _existingFiles.Add(ftpFile.OriginalFileName);
     //    }
     //}
 }
Exemplo n.º 6
0
 public AzureBlobStorageProvider(FtpLoader ftpLoader)
 {
     _ftpLoader = ftpLoader;
 }
Exemplo n.º 7
0
 public FileSystemProvider(FtpLoader ftpLoader)
 {
     _ftpLoader = ftpLoader;
 }
Exemplo n.º 8
0
        public bool SetOn(VideoReg reg)
        {
            var cts = new CancellationTokenSource();
            // Задача постоянного обновления кеша данных с приборов
            var task = new Task(() =>
            {
                logger.Info($"Task [{reg.BrigadeCode}] autoupdate device values was started");
                if (string.IsNullOrEmpty(reg.ValuesFile))
                {
                    logger.Info($"Task [{reg.BrigadeCode}] autoupdate device values. File name is uncorrect.");
                    DeleteTask(reg.BrigadeCode);
                    return;
                }
                using (var ftp = FtpLoader.Start(reg.FtpSettings))
                {
                    while (!cts.IsCancellationRequested)
                    {
                        string strJson = "";
                        try
                        {
                            strJson = ftp.DownloadFile(reg.ValuesFile);
                        }
                        catch (Exception e)
                        {
                            logger.Error(e, $"Task [{reg.BrigadeCode}] autoupdate device values. Faild load file {reg.ValuesFile} [ERROR]");
                        }
                        BrigadeChannelValue obj = null;
                        try
                        {
                            obj = JsonConvert.DeserializeObject <BrigadeChannelValue>(strJson);
                        }
                        catch (Exception e)
                        {
                            logger.Error(e, $"Task [{reg.BrigadeCode}] autoupdate device values. Faild load file {reg.ValuesFile} [ERROR]");
                            return;
                        }

                        if (obj.BrigadeCode != reg.BrigadeCode)
                        {
                            logger.Error($"[IMPORTANT] Task [{reg.BrigadeCode}]  Database data not equals device brigadeCode [ERROR]");
                        }

                        DeviceDataCash.Instance.Set(obj);
                    }
                }
                // Если задача была отменена убераем ее с выполнения
                DeleteTask(reg.BrigadeCode);
                logger.Info($"Task [{reg.BrigadeCode}] autoupdate device values was canceled");
            }, cts.Token);

            DeviceDataTask newTask = new DeviceDataTask
            {
                BrigadeCode = reg.BrigadeCode,
                Task        = task,
                Cts         = cts
            };

            newTask.Task.Start();
            AddTask(newTask);
            logger.Info($"OnAutoUpdateChannelValue({reg.BrigadeCode}) [EXECUTION]");
            return(true);
        }