/// <summary> /// 通过模式2提交到web接口 /// 通过HTTP协议Post消息到ScheduleActionServiceWebUrl的web接口,提交的对象类型为SMessagePostData /// 其中Signature为CurrentTime的字符串格式(yyyy-MM-dd hh:mm:ss)通过WebSignature签名后的字符串 /// 接收方需要对此进行校验 /// </summary> /// <param name="action"></param> /// <returns></returns> private async Task <IScheduleActionResult> ExecuteByMode2(ScheduleAction action) { ScheduleActionResultDefault result = new ScheduleActionResultDefault(); var currentTime = DateTime.UtcNow; var strContent = $"{currentTime.ToString("yyyy-MM-dd hh:mm:ss")}"; var strSignature = _securityService.SignByKey(strContent, action.WebSignature); await HttpClinetHelper.PostAsync(strSignature, action.ScheduleActionServiceWebUrl); return(result); }
public async Task <IScheduleActionResult> Execute(ScheduleAction action) { //检查调度动作模式 //不同的模式执行不同的处理 if (action.Mode == 0) { return(await ExecuteByMode1(action)); } else { return(await ExecuteByMode2(action)); } }
/// <summary> /// 通过模式1直接调用由工厂类创建的调度作业服务 /// </summary> /// <param name="action"></param> /// <returns></returns> private async Task <IScheduleActionResult> ExecuteByMode1(ScheduleAction action) { if (!_actionServiceFactories.TryGetValue(action.ScheduleActionServiceFactoryType, out IFactory <IScheduleActionService> actionFactory)) { lock (_actionServiceFactories) { Type actionFactoryType = Type.GetType(action.ScheduleActionServiceFactoryType); if (!_actionServiceFactories.TryGetValue(action.ScheduleActionServiceFactoryType, out actionFactory)) { object objActionFactory; if (action.ScheduleActionServiceFactoryTypeUseDI == true) { //通过DI容器创建 //objActionFactory = DIContainerContainer.Get(actionFactoryType); objActionFactory = DIContainerGetHelper.Get().Get(actionFactoryType); } else { //通过反射创建 objActionFactory = actionFactoryType.Assembly.CreateInstance(actionFactoryType.FullName); } if (!(objActionFactory is IFactory <IScheduleActionService>)) { var fragment = new TextFragment() { Code = TextCodes.ScheduleActionServiceTypeError, DefaultFormatting = "调度作业{0}中,调度动作服务工厂的类型{1}未实现接口IFactory<IScheduleActionService>", ReplaceParameters = new List <object>() { action.Name, action.ScheduleActionServiceFactoryType } }; throw new UtilityException((int)Errors.ScheduleActionServiceTypeError, fragment); } actionFactory = (IFactory <IScheduleActionService>)objActionFactory; _actionServiceFactories.Add(action.ScheduleActionServiceFactoryType, actionFactory); } } } var actionObj = actionFactory.Create(); return(await actionObj.Execute(action.Configuration)); }
public async Task Update(ScheduleAction action) { await _scheduleActionStore.Update(action); }
public async Task Delete(ScheduleAction action) { await _scheduleActionStore.Delete(action.ID); }
public async Task Add(ScheduleAction action) { await _scheduleActionStore.Add(action); }