Exemplo n.º 1
0
        public static TasksList AddTask(TasksList state, TvAction action)
        {
            if (action.Name == "ADD_TASK")
            {
                var num      = state.Count;
                var newState = new TasksList();
                newState.AddRange(state);
                newState.Add(new TaskData()
                {
                    Message = $"I am task #{num + 1}"
                });
                return(newState);
            }

            return(state);
        }
Exemplo n.º 2
0
        public static FileList RefreshFolder(FileList state, TvAction action)
        {
            if (action.Name == "FETCH_DIR")
            {
                var folderName = action.WithData <string>().Value;
                var folder     = new DirectoryInfo(folderName);

                var items = folder.GetFileSystemInfos().Select(f => new FileItem
                {
                    FileAttributes = f.Attributes,
                    Name           = f.Name,
                    IsDirectory    = (f.Attributes & FileAttributes.Directory) != 0,
                    FullName       = f.FullName
                });

                return(new FileList(folder.FullName, items.ToArray()));
            }
            if (action.Name == "FETCH_INFO")
            {
                return(state);
            }

            if (action.Name == "FETCH_BACK")
            {
                var folderName = $"{state.CurrentFolder}{Path.DirectorySeparatorChar}..";
                var folder     = new DirectoryInfo(folderName);

                var items = folder.GetFileSystemInfos().Select(f => new FileItem
                {
                    FileAttributes = f.Attributes,
                    Name           = f.Name,
                    IsDirectory    = (f.Attributes & FileAttributes.Directory) != 0,
                    FullName       = f.FullName
                });

                return(new FileList(folder.FullName, items.ToArray()));
            }

            return(state);
        }
Exemplo n.º 3
0
        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();
                }
            }
        }