Пример #1
0
        /// <summary>
        /// 迭代T8配置项
        /// </summary>
        private void IteratonT8TaskItems()
        {
            int intervaltime = 1000 * 60 * 5;//迭代完毕间隔5分钟再重新迭代

            while (!cts.IsCancellationRequested)
            {
                foreach (KeyValuePair <string, T8ConfigItemEntity> item in T8ConfigItemDic)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }

                    T8ConfigItemEntity      t8ConfigItem   = item.Value;
                    TimingQueryTimeStragety timingStragety = new BuildInstanceObject().GetTimingQueryTimeStragety(t8ConfigItem.DateType);
                    DateTime TimingStartTime = timingStragety.GetStartTime(DateTime.Now);
                    DateTime TimingEndTime   = timingStragety.GetStartTime(DateTime.Now);

                    if (DateTime.Now >= TimingStartTime && DateTime.Now <= TimingEndTime)
                    {
                        Task.Factory.StartNew(() => BuildServiceTask(t8ConfigItem, cts.Token));
                    }
                }

                for (int i = 0; i < intervaltime; i++)
                {
                    if (cts.IsCancellationRequested)
                    {
                        break;
                    }
                    Thread.Sleep(1000);
                }
            }
        }
Пример #2
0
        public override void BuildUploadFile()
        {
            Action <T8TaskEntity> action = t8Task =>
            {
                try
                {
                    if (!File.Exists(t8Task.T8FileEntity.CompressFileInfo.FilePath))
                    {
                        throw new Exception($"开始上传FTP服务器,发现数据库文件:{t8Task.T8FileEntity.CompressFileInfo.FilePath}不存在");
                    }

                    GenerateFileNameStragety fileStragety   = new BuildInstanceObject().GetGenerateFileNameStragety(3);
                    T8FileInfoEntity         fileInfoEntity = new T8FileInfoEntity();
                    fileInfoEntity.FileGenerateTime = DateTime.Now;
                    fileInfoEntity.FileName         = fileStragety.FileName(t8Task.T8FileEntity);
                    fileInfoEntity.FilePath         = fileStragety.FileFullName(t8Task.T8FileEntity);

                    //FileHelper.ZipFile(t8Task.T8FileEntity.GeneralFileInfo.FilePath, fileInfoEntity.FilePath);
                    FtpHelper.UploadFile(t8Task.T8FileEntity.FtpInfo, fileInfoEntity);

                    t8Task.T8FileEntity.StepStatus = StepStatus.UploadFile;

                    LogUtil.WriteLog($"压缩数据库文件[{fileInfoEntity.FilePath}]完成");
                }
                catch (Exception ex)
                {
                    Common.SetTaskErrorStatus(t8Task, $"BuildUploadFile()[{ex.Message}]");
                    LogUtil.WriteLog(ex);
                    throw new Exception(ex.Message);
                }
            };

            product.AddPart(action);
        }
Пример #3
0
        public override void BuildDbFile()
        {
            Action <T8TaskEntity> action = t8Task =>
            {
                try
                {
                    t8Task.T8TaskStatus = T8TaskStatus.Executing;

                    //1得到数据库文件路径
                    GenerateFileNameStragety fileStragety   = new BuildInstanceObject().GetGenerateFileNameStragety(1);
                    T8FileInfoEntity         fileInfoEntity = new T8FileInfoEntity();
                    fileInfoEntity.FileName             = fileStragety.FileName(t8Task.T8FileEntity);
                    fileInfoEntity.FilePath             = fileStragety.FileName(t8Task.T8FileEntity);
                    fileInfoEntity.FileGenerateTime     = DateTime.Now;
                    t8Task.T8FileEntity.GeneralFileInfo = fileInfoEntity;


                    //2创建数据库文件并添加数据
                    IDatabase databaseService = DatabaseFactory.CreateDatabase(t8Task.T8FileEntity.DataBaseInfo);
                    databaseService.ExecuteDataToDBFile(t8Task.T8FileEntity.DbFileType, fileInfoEntity.FilePath, t8Task.T8FileEntity.SqlString, t8Task.T8FileEntity.SqlStartTime, t8Task.T8FileEntity.SqlEndTime);


                    t8Task.T8FileEntity.StepStatus = StepStatus.GenerateFile;
                    LogUtil.WriteLog($"数据库文件[{fileInfoEntity.FilePath}]创建并添加数据完成");
                }
                catch (Exception ex)
                {
                    Common.SetTaskErrorStatus(t8Task, $"BuildDbFile()[{ex.Message}]");
                    LogUtil.WriteLog(ex);
                    throw new Exception(ex.Message);
                }
            };

            product.AddPart(action);
        }
Пример #4
0
        public override void BackupDbFile()
        {
            //备份文件异常不影响程序功能,所以出现异常也会默认任务成功,只是在任务中做个备注
            Action <T8TaskEntity> action = t8Task =>
            {
                try
                {
                    if (!File.Exists(t8Task.T8FileEntity.CompressFileInfo.FilePath))
                    {
                        throw new FileNotFoundException($"上传文件:{t8Task.T8FileEntity.CompressFileInfo.FilePath}不存在");
                    }

                    GenerateFileNameStragety fileStragety   = new BuildInstanceObject().GetGenerateFileNameStragety(3);
                    T8FileInfoEntity         fileInfoEntity = new T8FileInfoEntity();
                    fileInfoEntity.FileGenerateTime        = DateTime.Now;
                    fileInfoEntity.FileName                = fileStragety.FileName(t8Task.T8FileEntity);
                    fileInfoEntity.FilePath                = fileStragety.FileFullName(t8Task.T8FileEntity);
                    t8Task.T8FileEntity.UploadBackFileInfo = fileInfoEntity;

                    bool isMoveSucess = FileHelper.MoveFile(t8Task.T8FileEntity.CompressFileInfo.FilePath, fileInfoEntity.FilePath);
                    if (!isMoveSucess)
                    {
                        throw new Exception($"压缩文件{t8Task.T8FileEntity.CompressFileInfo.FilePath}备份失败");
                    }

                    t8Task.T8FileEntity.StepStatus = StepStatus.BackupUploadFile;
                    t8Task.CompleteTime            = DateTime.Now;
                    t8Task.T8TaskStatus            = T8TaskStatus.Complete;
                }
                catch (Exception ex)
                {
                    t8Task.T8FileEntity.StepStatus = StepStatus.BackupUploadFile;


                    t8Task.CompleteTime = DateTime.Now;
                    t8Task.T8TaskStatus = T8TaskStatus.Complete;
                    t8Task.Content      = t8Task.Content + (!string.IsNullOrEmpty(t8Task.Content) ? $"\r\n{ex.Message}" : ex.Message);
                    LogUtil.WriteLog(ex.Message);
                }
            };

            product.AddPart(action);
        }