Exemple #1
0
        public async Task <ResponseMessage <TaskContentResponse> > AddTaskWithoutPolicy([FromBody, BindRequired] TaskInfoRequest task)
        {
            var Response = new ResponseMessage <TaskContentResponse>();

            if (task == null)
            {
                Response.Code = ResponseCodeDefines.ModelStateInvalid;
                Response.Msg  = "请求参数不正确";
            }
            try
            {
                Response.Ext = await _taskManage.AddTaskWithoutPolicy(task, string.Empty, string.Empty, string.Empty, string.Empty);

                //添加后如果开始时间在2分钟以内,需要调度一次
                if ((DateTimeFormat.DateTimeFromString(task.TaskContent.Begin) - DateTime.Now).TotalSeconds < 120)
                {
                    await _taskManage.UpdateComingTasks();
                }

                var _globalinterface = ApplicationContext.Current.ServiceProvider.GetRequiredService <IIngestGlobalInterface>();
                if (_globalinterface != null)
                {
                    GlobalInternals re = new GlobalInternals()
                    {
                        funtype = IngestDBCore.GlobalInternals.FunctionType.SetGlobalState, State = GlobalStateName.ADDTASK
                    };
                    var response1 = await _globalinterface.SubmitGlobalCallBack(re);

                    if (response1.Code != ResponseCodeDefines.SuccessCode)
                    {
                        Logger.Error("SetGlobalState modtask error");
                    }
                }

                //SetGTMTaskInfo
                //添加后如果开始时间在2分钟以内,需要调度一次
                //这玩意我完全不知道有啥,放弃,后面改
                //if ((GlobalFun.DateTimeFromString(pIn.taskAdd.strBegin) - DateTime.Now).TotalSeconds < 120)
                //    TASKSERVICE.UpdateComingTasks();
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(SobeyRecException))//sobeyexcep会自动打印错误
                {
                    SobeyRecException se = e as SobeyRecException;
                    Response.Code = se.ErrorCode.ToString();
                    Response.Msg  = se.Message;
                }
                else
                {
                    Response.Code = ResponseCodeDefines.ServiceError;
                    Response.Msg  = "AddTaskWithoutPolicy error info:" + e.ToString();
                    Logger.Error(Response.Msg);
                }
            }
            return(Response);
        }
Exemple #2
0
        public TaskParam CreateTaskParam(TaskContent contentinfo)
        {
            var param = new TaskParam();

            param.taskID   = contentinfo.TaskId;
            param.taskName = contentinfo.TaskName;
            param.tmBeg    = DateTimeFormat.DateTimeFromString(contentinfo.Begin);
            return(param);
        }
        public override async ValueTask<int> StopTaskAsync(TaskFullInfo task, ChannelInfo channel)
        {
            DateTime end = (task.RetryTimes > 0 && task.NewEndTime != DateTime.MinValue) ? task.NewEndTime
                : DateTimeFormat.DateTimeFromString(task.TaskContent.End).AddSeconds(taskStopBehind);

            while (true)
            {
                if (DateTime.Now >= end)
                {
                    var msvtaskinfo = await msvClient.QueryTaskInfoAsync(channel.ChannelIndex, channel.Ip, Logger);

                    if (msvtaskinfo != null)
                    {
                        if (msvtaskinfo.ulID == task.TaskContent.TaskId)
                        {
                            var stopback = await msvClient.StopAsync(channel.ChannelIndex, channel.Ip, task.TaskContent.TaskId, Logger);

                            if (stopback > 0)
                            {
                                await restClient.SetTaskStateAsync(task.TaskContent.TaskId, taskState.tsComplete);
                                await UnlockTaskAsync(task.TaskContent.TaskId, taskState.tsNo, dispatchState.dpsDispatched, syncState.ssSync);
                                return task.TaskContent.TaskId;
                            }
                            else
                            {
                                return IsNeedRedispatchask(task);
                            }
                        }
                        else
                        {
                            if (msvtaskinfo.ulID >0)
                            {
                                // 停止的任务不是MSV当前正在采集的任务
                                // 需要将该任务标记为无效任务
                                await UnlockTaskAsync(task.TaskContent.TaskId, taskState.tsInvaild,
                                    dispatchState.dpsDispatched, syncState.ssSync);
                            }
                            
                            Logger.Error($"stop task not same {msvtaskinfo.ulID} {task.TaskContent.TaskId}");
                            return task.TaskContent.TaskId;
                        }

                    }
                    else
                    {
                        return IsNeedRedispatchask(task);
                    }

                }
                else
                    await Task.Delay(end - DateTime.Now);
            }
        }
Exemple #4
0
        public async Task <ResponseMessage <TaskContentResponse> > ModifyTask([FromQuery, BindRequired] int taskid, [FromBody, BindRequired] TaskContentRequest req)
        {
            var Response = new ResponseMessage <TaskContentResponse>();

            if (req == null)
            {
                Response.Code = ResponseCodeDefines.ModelStateInvalid;
                Response.Msg  = "请求参数不正确";
            }

            try
            {
                Response.Ext = await _taskManage.ModifyTask <TaskContentResponse>(req, string.Empty, string.Empty, string.Empty, string.Empty);

                //添加后如果开始时间在2分钟以内,需要调度一次
                if ((DateTimeFormat.DateTimeFromString(req.Begin) - DateTime.Now).TotalSeconds < 120)
                {
                    await _taskManage.UpdateComingTasks();
                }

                var _globalinterface = ApplicationContext.Current.ServiceProvider.GetRequiredService <IIngestGlobalInterface>();
                if (_globalinterface != null)
                {
                    GlobalInternals re = new GlobalInternals()
                    {
                        funtype = IngestDBCore.GlobalInternals.FunctionType.SetGlobalState, State = GlobalStateName.MODTASK
                    };
                    var response1 = await _globalinterface.SubmitGlobalCallBack(re);

                    if (response1.Code != ResponseCodeDefines.SuccessCode)
                    {
                        Logger.Error("SetGlobalState modtask error");
                    }
                }
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(SobeyRecException))//sobeyexcep会自动打印错误
                {
                    SobeyRecException se = e as SobeyRecException;
                    Response.Code = se.ErrorCode.ToString();
                    Response.Msg  = se.Message;
                }
                else
                {
                    Response.Code = ResponseCodeDefines.ServiceError;
                    Response.Msg  = "TaskIDByTaskGUID error info:" + e.ToString();
                    Logger.Error(Response.Msg);
                }
            }
            return(Response);
        }
Exemple #5
0
        public async Task <PostModifyTaskDb_OUT> PostModifyTaskDb([FromBody] PostModifyTaskDb_IN pIn)
        {
            var Response = new PostModifyTaskDb_OUT
            {
                bRet   = true,
                errStr = "OK"
            };

            try
            {
                await _taskManage.ModifyTask <TaskContent>(pIn.taskModify, string.Empty, pIn.TaskMetaData, pIn.MaterialMetaData, string.Empty);

                //添加后如果开始时间在2分钟以内,需要调度一次
                if ((DateTimeFormat.DateTimeFromString(pIn.taskModify.strBegin) - DateTime.Now).TotalSeconds < 120)
                {
                    await _taskManage.UpdateComingTasks();
                }

                var _globalinterface = ApplicationContext.Current.ServiceProvider.GetRequiredService <IIngestGlobalInterface>();
                if (_globalinterface != null)
                {
                    GlobalInternals re = new GlobalInternals()
                    {
                        funtype = IngestDBCore.GlobalInternals.FunctionType.SetGlobalState, State = GlobalStateName.MODTASK
                    };
                    var response1 = await _globalinterface.SubmitGlobalCallBack(re);

                    if (response1.Code != ResponseCodeDefines.SuccessCode)
                    {
                        Logger.Error("SetGlobalState modtask error");
                    }
                }

                return(Response);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(SobeyRecException))//sobeyexcep会自动打印错误
                {
                    SobeyRecException se = e as SobeyRecException;
                    Response.errStr = se.ErrorCode.ToString();
                }
                else
                {
                    Response.errStr = "error info:" + e.ToString();
                    Logger.Error("GetAllChannelCapturingTask" + e.ToString());
                }
                return(Response);
            }
            return(Response);
        }
        public override int IsNeedRedispatchask(TaskFullInfo taskinfo)
        {
            if (taskinfo.StartOrStop)
            {
                if (DateTime.Now.AddSeconds(5) <=
                DateTimeFormat.DateTimeFromString(taskinfo.TaskContent.End))
                {
                    Logger.Error($"IsNeedRedispatchaskAsync start over {taskinfo.TaskContent.TaskId}");
                    return 0;
                }

                return taskinfo.TaskContent.TaskId;
            }
            else
            {
                if (DateTime.Now <=
                DateTimeFormat.DateTimeFromString(taskinfo.TaskContent.End).AddSeconds(2))
                {
                    Logger.Error($"IsNeedRedispatchaskAsync stop over {taskinfo.TaskContent.TaskId}");
                    return 0;
                }
                return taskinfo.TaskContent.TaskId;
            }
        }
        //修改状态对象之外,TransitionState方法不应该有任何副作用,并且应该是确定性的
        public void Apply(TaskEvent @event)
        {
            //我认为无论任务重复不,都不需要筛选,无非一系列工作交给执行器做而已。后面引入cancletoken保证及时终止就可以了
            switch (@event.OpType)
            {
            case opType.otAdd:
            {
                var info = TaskLists.Find(x => x.TaskContent.TaskId == @event.TaskContentInfo.TaskId);
                if (info == null)
                {
                    TaskLists.Add(new TaskFullInfo()
                        {
                            TaskContent = @event.TaskContentInfo, StartOrStop = true, HandleTask = false
                        });
                }
            }
            break;

            case opType.otDel:
            {
                TaskLists.RemoveAll(a => a.TaskContent.TaskId == @event.TaskContentInfo.TaskId);
            }
            break;

            case opType.otMove:
                break;

            case opType.otModify:
                break;

            case opType.otStop:
            {
                //if (DateTimeFormat.DateTimeFromString(@event.TaskContentInfo.End) < DateTime.Now.AddSeconds(10))
                TaskLists.Add(new TaskFullInfo()
                    {
                        TaskContent = @event.TaskContentInfo, StartOrStop = false, HandleTask = false
                    });
            }
            break;

            case opType.otReDispatch:
            {
                var taskitem = TaskLists.Find(a => a.TaskContent.TaskId == @event.TaskContentInfo.TaskId);
                if (taskitem != null)
                {
                    taskitem.RetryTimes++;
                    //重调度任务把开始时间滞后看看
                    taskitem.NewBeginTime = DateTime.Now.AddSeconds(2);
                    taskitem.HandleTask   = false;
                    DateTime dt = DateTime.Now;
                    if (dt >= DateTimeFormat.DateTimeFromString(taskitem.TaskContent.End))
                    {
                        taskitem.NewEndTime = dt.AddSeconds(2);
                    }
                }
            }
            break;

            default:
                break;
            }
        }
        /*
         * 开始成功就应该监听
         */
        private async Task OnRunningTaskMonitorAsync(object type)
        {
            //    taskid,
            //    (int)task.TaskContent.TaskType,
            //    task.TaskContent.Begin,
            //    chinfo.ChannelId,
            //    chinfo.ChannelIndex,
            //    chinfo.Ip,
            //   task.RetryTimes
            TimerTask param = (TimerTask)type;

            if (_timer == null)
            {
                return;
            }

            var taskinfolst = await _restClient.GetChannelCapturingTaskInfoAsync(param.ChannelId);

            bool runningtask = true;

            if (taskinfolst != null)
            {
                if (taskinfolst.TaskId != param.TaskId)
                {
                    Logger.Info($"OnRunningTaskMonitorAsync not runningtask error {taskinfolst.TaskId} {param.TaskId}");
                    runningtask = false;
                }
                var devicegrain = _services.GetRequiredService <MsvClientCtrlSDK>();
                if (devicegrain != null)
                {
                    var msvtask = await devicegrain.QueryTaskInfoAsync(param.DevicePort, param.DeviceIp, Logger);

                    if (msvtask == null || msvtask.ulID < 1)//说明msv出问题了查不到任务了,采集中剩下部分要跳转, 3次重试后才移动通道
                    {
                        Logger.Info($"OnRunningTaskMonitorAsync task need to check {taskinfolst.TaskId}");
                        if (++param.Timers > 3)
                        {
                            if (_timer == null)
                            {
                                return;
                            }

                            if (param.TaskType == TaskType.TT_VTRUPLOAD)
                            {
                            }
                            else
                            {
                                bool needCreateNewTask = false;
                                if (param.TaskType == TaskType.TT_MANUTASK || param.TaskType == TaskType.TT_OPENEND ||
                                    param.TaskType == TaskType.TT_OPENENDEX)
                                {
                                    needCreateNewTask = true;
                                }
                                else
                                {
                                    // 其它类型的任务,需要检查任务结束时间
                                    // 时间都过去了的任务,就不用再创建了
                                    if (DateTimeFormat.DateTimeFromString(param.BeginTime) < DateTime.Now.AddSeconds(5))
                                    {
                                        needCreateNewTask = true;
                                    }
                                    else
                                    {
                                        // 其它类型的任务,需要检查是否过时,如果已经过时,则需处理该任务
                                        // 已经过时,则需将任务置为无效状态
                                        await _restClient.SetTaskStateAsync(param.TaskId, taskState.tsInvaild);
                                    }
                                }

                                if (needCreateNewTask)
                                {
                                    await _restClient.SetTaskStateAsync(param.TaskId, taskState.tsInvaild);

                                    await _restClient.AddReScheduleTaskAsync(param.TaskId);

                                    if (_timer != null)
                                    {
                                        _timer.Dispose();
                                        _timer = null;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        if (msvtask.ulID > 0 && param.TaskId > 0 && msvtask.ulID != param.TaskId)
                        {
                            Logger.Warn("OnRunningTaskMonitorAsync quit different task");
                            if (_timer != null)
                            {
                                _timer.Dispose();
                                _timer = null;
                            }
                        }
                    }
                }
                else
                {
                    Logger.Error("OnRunningTaskMonitorAsync devicegrain null");
                }
            }
            else
            {
                Logger.Info($"OnRunningTaskMonitorAsync not runningtask {param.TaskId}");
                runningtask = false;
            }

            if (!runningtask && param.RetryTimes > 0)//任务都没开始起,说明重试过,直接换任务通道吧
            {
                var info = await _restClient.ReScheduleTaskChannelAsync(param.TaskId);

                if (info == null)//重新分配任务到其它通道或者啥的
                {
                    await _restClient.CompleteSynTasksAsync(param.TaskId, taskState.tsInvaild, dispatchState.dpsDispatched, syncState.ssSync);
                }

                if (_timer != null)
                {
                    _timer.Dispose();
                    _timer = null;
                }
            }
        }
Exemple #9
0
        public TaskProfile()
        {
            CreateMap <TaskMetadataResponse, DbpTaskMetadata>()
            .ForMember(a => a.Metadatalong, (map) => map.MapFrom(b => b.Metadata));

            CreateMap <DbpTaskMetadata, TaskMetadataResponse>()
            .ForMember(a => a.Metadata, (map) => map.MapFrom(b => b.Metadatalong));

            CreateMap <DbpTaskMetadata, GetQueryTaskMetaData_param>()
            .ForMember(a => a.MetaData, (map) => map.MapFrom(b => b.Metadatalong))
            .AfterMap((a, b) => {
                if (!string.IsNullOrEmpty(a.Metadatalong))
                {
                    b.bRet   = true;
                    b.errStr = "OK";
                }
            });

            CreateMap <DbpTaskCustommetadata, TaskCustomMetadataResponse>();
            CreateMap <DbpTaskCustommetadata, GetTaskCustomMetadata_OUT>();

            CreateMap <TaskContentResponse, DbpTask>()
            .ForMember(a => a.Recunitid, (map) => map.MapFrom(b => b.Unit))
            .ForMember(a => a.Category, (map) => map.MapFrom(b => b.Classify))
            .ForMember(a => a.Description, (map) => map.MapFrom(b => b.TaskDesc))
            .ForMember(a => a.Starttime, (map) => map.MapFrom(b => DateTimeFormat.DateTimeFromString(b.Begin)))
            .ForMember(a => a.Endtime, (map) => map.MapFrom(b => DateTimeFormat.DateTimeFromString(b.End)))
            .ForMember(a => a.Sgroupcolor, (map) => map.MapFrom(b => b.GroupColor))
            .ForMember(a => a.Stampimagetype, (map) => map.MapFrom(b => b.StampImageType))
            .ForMember(a => a.Taskpriority, (map) => map.MapFrom(b => b.Priority))
            .ForMember(a => a.Backtype, (map) => map.MapFrom(b => b.CooperantType));

            CreateMap <DbpTask, TaskContentResponse>()
            .ForMember(a => a.Unit, (map) => map.MapFrom(b => b.Recunitid))
            .ForMember(a => a.Classify, (map) => map.MapFrom(b => b.Category))
            .ForMember(a => a.TaskDesc, (map) => map.MapFrom(b => b.Description))
            .ForMember(a => a.Begin, (map) => map.MapFrom(b => DateTimeFormat.DateTimeToString(b.Starttime)))
            .ForMember(a => a.End, (map) => map.MapFrom(b => DateTimeFormat.DateTimeToString(b.Endtime)))
            .ForMember(a => a.GroupColor, (map) => map.MapFrom(b => b.Sgroupcolor))
            .ForMember(a => a.StampImageType, (map) => map.MapFrom(b => b.Stampimagetype))
            .ForMember(a => a.Priority, (map) => map.MapFrom(b => b.Taskpriority))
            .ForMember(a => a.CooperantType, (map) => map.MapFrom(b => b.Backtype));

            CreateMap <DbpTask, TaskContent>()
            .ForMember(a => a.nTaskID, (y) => y.MapFrom(b => b.Taskid))
            .ForMember(a => a.strTaskName, (y) => y.MapFrom(b => b.Taskname))
            .ForMember(a => a.strTaskDesc, (y) => y.MapFrom(b => b.Description))
            .ForMember(a => a.strClassify, (y) => y.MapFrom(b => b.Category))
            .ForMember(a => a.nChannelID, (y) => y.MapFrom(b => b.Channelid))
            .ForMember(a => a.nUnit, (y) => y.MapFrom(b => b.Recunitid))
            .ForMember(a => a.strUserCode, (y) => y.MapFrom(b => b.Usercode))
            .ForMember(a => a.nSignalID, (y) => y.MapFrom(b => b.Signalid))
            .ForMember(a => a.strBegin, (y) => y.MapFrom(b => DateTimeFormat.DateTimeToString(b.Starttime)))
            .ForMember(a => a.strEnd, (y) => y.MapFrom(b => DateTimeFormat.DateTimeToString(b.Endtime)))

            .ForMember(a => a.emTaskType, (y) => y.MapFrom(b => b.Tasktype))
            .ForMember(a => a.emCooperantType, (y) => y.MapFrom(b => b.Backtype))
            .ForMember(a => a.emState, (y) => y.MapFrom(b => b.State))
            .ForMember(a => a.strStampImage, (y) => y.MapFrom(b => b.Description))
            .ForMember(a => a.strTaskGUID, (y) => y.MapFrom(b => b.Taskguid))
            .ForMember(a => a.nBackupVTRID, (y) => y.MapFrom(b => b.Backupvtrid))

            .ForMember(a => a.emPriority, (y) => y.MapFrom(b => b.Taskpriority))
            .ForMember(a => a.nStampTitleIndex, (y) => y.MapFrom(b => b.Stamptitleindex))
            .ForMember(a => a.nStampImageType, (y) => y.MapFrom(b => b.Stampimagetype))
            .ForMember(a => a.nSGroupColor, (y) => y.MapFrom(b => b.Sgroupcolor));

            CreateMap <TaskContent, TaskContentResponse>()
            .ForMember(x => x.TaskID, (y) => y.MapFrom(z => z.nTaskID))
            .ForMember(x => x.TaskName, (y) => y.MapFrom(z => z.strTaskName))
            .ForMember(x => x.TaskDesc, (y) => y.MapFrom(z => z.strTaskDesc))
            .ForMember(x => x.Classify, (y) => y.MapFrom(z => z.strClassify))
            .ForMember(x => x.ChannelID, (y) => y.MapFrom(z => z.nChannelID))
            .ForMember(x => x.Unit, (y) => y.MapFrom(z => z.nUnit))
            .ForMember(x => x.UserCode, (y) => y.MapFrom(z => z.strUserCode))
            .ForMember(x => x.SignalID, (y) => y.MapFrom(z => z.nSignalID))
            .ForMember(x => x.Begin, (y) => y.MapFrom(z => z.strBegin))
            .ForMember(x => x.End, (y) => y.MapFrom(z => z.strEnd))
            .ForMember(x => x.TaskType, (y) => y.MapFrom(z => z.emTaskType))
            .ForMember(x => x.CooperantType, (y) => y.MapFrom(z => z.emCooperantType))
            .ForMember(x => x.State, (y) => y.MapFrom(z => z.emState))
            .ForMember(x => x.StampImage, (y) => y.MapFrom(z => z.strStampImage))
            .ForMember(x => x.TaskGUID, (y) => y.MapFrom(z => z.strTaskGUID))
            .ForMember(x => x.BackupVTRID, (y) => y.MapFrom(z => z.nBackupVTRID))
            .ForMember(x => x.Priority, (y) => y.MapFrom(z => z.emPriority))
            .ForMember(x => x.StampTitleIndex, (y) => y.MapFrom(z => z.nStampTitleIndex))
            .ForMember(x => x.StampImageType, (y) => y.MapFrom(z => z.nStampImageType))
            .ForMember(x => x.GroupColor, (y) => y.MapFrom(z => z.nSGroupColor));
            CreateMap <AddTaskSvr_IN, TaskInfoResponse>()
            .ForMember(d => d.TaskContent, y => y.MapFrom(s => s.taskAdd))
            .ForMember(d => d.TaskSource, y => y.MapFrom(s => s.taskSrc));


            //ReverseMap
        }
        public override async ValueTask<int> HandleTaskAsync(TaskFullInfo task, ChannelInfo channel)
        {
            Logger.Info($"NormalTaskHandler HandleTaskAsync retrytimes {task.RetryTimes}");

            int taskid = task.TaskContent.TaskId;
            if (task.ContentMeta == null || string.IsNullOrEmpty(task.CaptureMeta))
            {
                await UnlockTaskAsync(taskid, taskState.tsNo, dispatchState.dpsRedispatch, syncState.ssSync);
                return 0;
            }

            if (task.StartOrStop && task.OpType != opType.otDel)
            {
                if (task.TaskContent.TaskType == TaskType.TT_MANUTASK)//已经执行的手动任务不需要执行,未执行的手动任务需要继续执行
                {
                    if (task.TaskContent.State == taskState.tsExecuting || task.TaskContent.State == taskState.tsManuexecuting)
                    {
                        await UnlockTaskAsync(taskid, taskState.tsExecuting, dispatchState.dpsDispatched, syncState.ssSync);
                        return taskid;
                    }
                }
                else if (task.TaskContent.TaskType == TaskType.TT_TIEUP)
                {
                    await HandleTieupTaskAsync(task.TaskContent);
                    return taskid;
                }
                else
                {
                    if (DateTimeFormat.DateTimeFromString(task.TaskContent.End) < DateTime.Now)//普通任务进行时间有效性判断, 
                    {
                        task.StartOrStop = false;//禁止监听任务
                        return taskid;
                    }
                }

                if (channel.CurrentDevState == Device_State.DISCONNECTTED)
                {
                    await UnlockTaskAsync(taskid,
                        taskState.tsNo, dispatchState.dpsRedispatch, syncState.ssSync);
                    return IsNeedRedispatchask(task);
                }

                if (await StartTaskAsync(task, channel) > 0)
                {
                    //成功
                    await UnlockTaskAsync(taskid, taskState.tsExecuting, dispatchState.dpsDispatched, syncState.ssSync);
                    return taskid;
                }
                else
                {
                    //使用备份信号
                    //我擦,居然可以不用写,stop才有
                    Logger.Info("start error. begin to use backupsignal");


                    if (task.TaskContent.TaskType == TaskType.TT_OPENEND ||
                        task.TaskContent.TaskType == TaskType.TT_OPENENDEX)
                    {
                        await UnlockTaskAsync(taskid, taskState.tsInvaild, dispatchState.dpsDispatched, syncState.ssSync);
                    }
                    else
                    {
                        await UnlockTaskAsync(taskid, taskState.tsNo, dispatchState.dpsRedispatch, syncState.ssSync);
                    }

                    //重调度还失败,要看看是否超过了,超过就从列表去了
                    
                    return IsNeedRedispatchask(task);

                }
                
                
            }
            else
            {

                Logger.Info($"task stop timespan {(DateTimeFormat.DateTimeFromString(task.TaskContent.End) - DateTime.Now).TotalSeconds}");
                task.TaskContent.End = DateTimeFormat.DateTimeToString(DateTime.Now);

                if (task.TaskContent.TaskType != TaskType.TT_MANUTASK || 
                    (task.TaskContent.TaskType == TaskType.TT_MANUTASK && task.OpType == opType.otDel))
                {

                    //里面有IsNeedRedispatchask(task);
                    var backinfo = await StopTaskAsync(task, channel);

                    //所有的删除都让入库去做,这里不删除
                    //开始删除素材
                    if (task.OpType == opType.otDel)
                    {
                        await UnlockTaskAsync(task.TaskContent.TaskId, taskState.tsComplete, dispatchState.dpsInvalid, syncState.ssSync);
                        //DeleteClip();
                    }
                    return backinfo;
                }
            }
            return 0;
        }
        public override async ValueTask<int> StartTaskAsync(TaskFullInfo task, ChannelInfo channel)
        {

            var backinfo = await msvClient.QueryTaskInfoAsync(channel.ChannelIndex, channel.Ip, Logger);


            if (backinfo != null)
            {
                if (backinfo.ulID > 0)//存在执行任务
                {
                    if (backinfo.ulID == task.TaskContent.TaskId)
                    {
                        return task.TaskContent.TaskId;
                    }
                    else if (backinfo.ulID < task.TaskContent.TaskId)
                    {
                        Logger.Info($"start msv in stop else {backinfo.ulID}");
                        await ForceStopTaskAsync(task, channel);
                    }

                    if (task.TaskSource == TaskSource.emStreamMediaUploadTask)
                    {
                        return 0;
                    }
                    //前一个任务是手动任务,特别处理无缝任务 bIsStopLastTask
                }

                switch (task.TaskSource)
                {
                    case TaskSource.emMSVUploadTask:
                        {
                            if (!await restClient.SwitchMatrixSignalChannelAsync(task.TaskContent.SignalId, channel.ChannelId))
                            {
                                Logger.Error($"Switchsignalchannel error {task.TaskContent.SignalId} {channel.ChannelId}");
                            }
                        }
                        break;
                    case TaskSource.emRtmpSwitchTask:
                        {
                            if (!await restClient.SwitchMatrixChannelRtmpAsync(channel.ChannelId, task.ContentMeta.SignalRtmpUrl))
                            {
                                Logger.Error($"Switchsignalchannel error {task.TaskContent.SignalId} {channel.ChannelId}");
                            }
                        }
                        break;
                    case TaskSource.emVTRUploadTask:
                        break;
                    case TaskSource.emXDCAMUploadTask:
                        break;
                    case TaskSource.emIPTSUploadTask:
                        break;
                    case TaskSource.emStreamMediaUploadTask:
                        break;
                    case TaskSource.emUnknowTask:
                        break;
                    default:
                        break;
                }


                string capparam = await GetCaptureParmAsync(task, channel);

                DateTime dtcurrent;
                DateTime dtbegin = (task.RetryTimes > 0 && task.NewBeginTime != DateTime.MinValue)?task.NewBeginTime :
                    DateTimeFormat.DateTimeFromString(task.TaskContent.Begin).AddSeconds(-1* taskStartPrevious);

                while(true)
                {
                    dtcurrent = DateTime.Now;
                    if (dtcurrent >= dtbegin)
                    {
                        var recordinfo = msvClient.RecordReady(channel.ChannelIndex, channel.Ip, CreateTaskParam(task.TaskContent), "", capparam, Logger);

                        bool backrecord = await msvClient.RecordAsync(recordinfo, channel.ChannelIndex, channel.Ip, Logger);

                        if (backrecord)
                        {
                           
                            var state = await AutoRetry.RunSyncAsync(() =>
                                                            msvClient.QueryDeviceStateAsync(channel.ChannelIndex, channel.Ip, true, Logger),
                                                                                            (e) =>
                                                                                            {
                                                                                                if (e == Device_State.WORKING)
                                                                                                {
                                                                                                    return true;
                                                                                                }
                                                                                                return false;
                                                                                            }, 4, 500).ConfigureAwait(true);

                            if (state == Device_State.WORKING)
                            {
                                return task.TaskContent.TaskId;
                            }
                            else
                                Logger.Error($"start task error {task.TaskContent.TaskId}");
                        }
                        return 0;
                    }
                    else
                    {
                        await Task.Delay(dtbegin - dtcurrent);
                    }
                }
                
            }
            else
                Logger.Error($"StartTaskAsync QueryTaskInfoAsync error back 0");

            return 0;
        }
Exemple #12
0
        public async Task <ModifyTask_out> ModifyTask([FromBody] ModifyTask_in pIn)
        {
            var Response = new ModifyTask_out
            {
                bRet   = true,
                errStr = "OK"
            };

            try
            {
                string CaptureMeta  = string.Empty;
                string ContentMeta  = string.Empty;
                string MatiralMeta  = string.Empty;
                string PlanningMeta = string.Empty;
                foreach (var item in pIn.metadatas)
                {
                    if (item.emtype == MetaDataType.emCapatureMetaData)
                    {
                        CaptureMeta = item.strMetadata;
                    }
                    else if (item.emtype == MetaDataType.emStoreMetaData)
                    {
                        MatiralMeta = item.strMetadata;
                    }
                    else if (item.emtype == MetaDataType.emContentMetaData)
                    {
                        ContentMeta = item.strMetadata;
                    }
                    else if (item.emtype == MetaDataType.emPlanMetaData)
                    {
                        PlanningMeta = item.strMetadata;
                    }
                }

                await _taskManage.ModifyTask <TaskContent>(pIn.taskModify, CaptureMeta, ContentMeta, MatiralMeta, PlanningMeta);

                //添加后如果开始时间在2分钟以内,需要调度一次
                if ((DateTimeFormat.DateTimeFromString(pIn.taskModify.strBegin) - DateTime.Now).TotalSeconds < 120)
                {
                    await _taskManage.UpdateComingTasks();
                }

                var _globalinterface = ApplicationContext.Current.ServiceProvider.GetRequiredService <IIngestGlobalInterface>();
                if (_globalinterface != null)
                {
                    GlobalInternals re = new GlobalInternals()
                    {
                        funtype = IngestDBCore.GlobalInternals.FunctionType.SetGlobalState, State = GlobalStateName.MODTASK
                    };
                    var response1 = await _globalinterface.SubmitGlobalCallBack(re);

                    if (response1.Code != ResponseCodeDefines.SuccessCode)
                    {
                        Logger.Error("SetGlobalState modtask error");
                    }
                }

                return(Response);
            }
            catch (Exception e)
            {
                if (e.GetType() == typeof(SobeyRecException))//sobeyexcep会自动打印错误
                {
                    SobeyRecException se = e as SobeyRecException;
                    Response.errStr = se.ErrorCode.ToString();
                }
                else
                {
                    Response.errStr = "error info:" + e.ToString();
                    Logger.Error("GetAllChannelCapturingTask" + e.ToString());
                }
                return(Response);
            }
            return(Response);
        }