/// <summary> /// 停止执行动作 ,进行停止 /// </summary> public void Stop() { if (!m_TaskWaitTokenSource.IsCancellationRequested) { m_TaskWaitTokenSource.Cancel(); } foreach (PlanActionProvider action in m_actionProviders) { Task.Run(new System.Action(() => action.Stop())); } //停止声光报警动作 Task.Run(new System.Action(() => SoundLightAction.Stop(PlanTask.Plan))); //同事更新预案的下一执行时间 //PlanTask.Plan.Running = false; }
private async void Run(Plan plan) { if ((plan.Actions != null && plan.Actions.Count > 0) || plan.TvVideoRoundSceneId != null) { //预案动作分类 _logger.LogInformation("开始执行预案{0},按动作分类Begin..", plan.PlanId); IEnumerable <IGrouping <string, PlanActionArgument> > actionGroup = GroupPlanAction(plan); SoundLightAction.RemoveActionArgument(plan.PlanId); foreach (var action in actionGroup) { if (GlobalSetting.PlanActionOptions.ContainsKey(action.Key)) { string actionName = GlobalSetting.PlanActionOptions[action.Key]; PlanActionProvider executor = GetPlanActionExecutor("TaskServer.Action." + actionName); executor.PlanTrigger = plan.PlanTrigger; executor.PlanId = plan.PlanId; action.ToList().ForEach(t => { try { executor.AddPlanActionItem(t); } catch (Exception ex) { _logger.LogError("预案动作分类异常:Message:{0}\r\nStackTrace:{1}", ex.Message, ex.StackTrace); } }); } else { _logger.LogInformation("Not define action:{0}", action.Key); } } //上墙动作 if (plan.TvVideoRoundSceneId != null) { TvAction tvAction = new TvAction(); tvAction.PlanTrigger = plan.PlanTrigger; tvAction.PlanId = plan.PlanId; tvAction.AddPlanActionItem(new TvVideoPlayArgument() { VideoRoundSceneId = plan.TvVideoRoundSceneId.Value }); m_actionProviders.Add(tvAction); } _logger.LogInformation("预案{0},按动作分类End..", plan.PlanId); //执行,动作异步执行 m_actionProviders.ForEach(t => Task.Run(new System.Action(() => t.Execute()))); Task.Run(() => SoundLightAction.Execute(plan)); //等待停止 bool result = await Wait(); if (OnPlanExecutedEnd != null) { OnPlanExecutedEnd(this, new EventArgs()); } //正常停止 if (result) { Stop(); } } }