Пример #1
0
        /// <summary>
        /// 获取文件名信息 1一般文件 2压缩文件 3上传备份文件
        /// </summary>
        /// <param name="type">1一般文件 2压缩文件 3上传备份文件</param>
        /// <returns></returns>
        public virtual GenerateFileNameStragety GetGenerateFileNameStragety(int type)
        {
            AFileName aFileName = null;

            switch (type)
            {
            case 1:
                aFileName = AutoFacContainer.ResolveNamed <AFileName>(typeof(GeneralFileName).Name);
                break;

            case 2:
                aFileName = AutoFacContainer.ResolveNamed <AFileName>(typeof(CompressFileName).Name);
                break;

            case 3:
                aFileName = AutoFacContainer.ResolveNamed <AFileName>(typeof(UploadBackFileName).Name);
                break;
            }
            GenerateFileNameStragety service = new GenerateFileNameStragety(aFileName);

            return(service);
        }
Пример #2
0
        /// <summary>
        /// 构建T8任务
        /// </summary>
        private void BuildServiceTask(T8ConfigItemEntity t8ConfigItem, CancellationToken ct)
        {
            try
            {
                ct.ThrowIfCancellationRequested();

                ACreateTask  createTaskService = AutoFacContainer.ResolveNamed <ACreateTask>(typeof(ServiceCreateTask).Name);
                T8TaskEntity t8Task            = createTaskService.CreateTask();
                if (t8Task != null)
                {
                    //获取文件名
                    AFileName aFileNameService = AutoFacContainer.ResolveNamed <AFileName>(typeof(GeneralFileName).Name);
                    t8Task.T8FileEntity.GeneralFileInfo = new T8FileInfoEntity
                    {
                        FileName = aFileNameService.FileName(t8Task.T8FileEntity),
                        FilePath = aFileNameService.FileFullName(t8Task.T8FileEntity)
                    };

                    T8TaskEntity taskEntityQueueItem;
                    if (Completed_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem))
                    {
                        return;
                    }

                    if (Processing_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem))
                    {
                        return;
                    }

                    if (Error_TaskQueue.TryGetValue(t8Task.GenerateTaskQueueKey, out taskEntityQueueItem))
                    {
                        return;
                    }

                    //添加到执行中队列
                    if (!Common.AddTaskToQueue(Processing_TaskQueue, t8Task, TaskQueueType.Processing))
                    {
                        LogUtil.WriteLog($"任务队列[{t8Task.TaskTitle}]添加失败");

                        Common.SetTaskErrorStatus(t8Task, "添加Processing_TaskQueue失败");
                        Common.AddTaskToQueue(Error_TaskQueue, t8Task, TaskQueueType.Error);
                        return;
                    }

                    //构造数据文件产品并执行
                    DbFileProductDirector director       = new DbFileProductDirector();
                    ADbFileProductBuilder productBuilder = new DbFileProductBuilder();
                    director.ConstructProduct(productBuilder);
                    DbFileProduct product = productBuilder.GetDbFileProduct();
                    product.Execute(t8Task, cts.Token);

                    //任务结束 1从Processing_TaskQueue队列移走 2任务完成,移入Completed_TaskQueue队列 3任务失败,移入
                    if (Common.RemoveTaskFromQueue(Processing_TaskQueue, t8Task, TaskQueueType.Processing))
                    {
                        if (t8Task.T8TaskStatus == T8TaskStatus.Complete)
                        {
                            Common.AddTaskToQueue(Completed_TaskQueue, t8Task, TaskQueueType.Completed);
                            LogUtil.WriteLog($"T8任务[{t8Task.TaskTitle}]执行完成,转移到Completed_TaskQueue队列");
                        }
                        else
                        {
                            Common.AddTaskToQueue(Error_TaskQueue, t8Task, TaskQueueType.Error);
                            LogUtil.WriteLog($"T8任务[{t8Task.TaskTitle}]执行失败,转移到Error_TaskQueue队列,等待下次重试");
                        }
                    }
                }
                else
                {
                    LogUtil.WriteLog("创建任务实体失败");
                }
            }
            catch (Exception ex)
            {
                LogUtil.WriteLog(ex);
            }
        }
Пример #3
0
 public GenerateFileNameStragety(AFileName aFileName)
 {
     _AFileName = aFileName;
 }