public async Task <TASK_PARAM> QueryTaskInfoAsync(int nChPort, string strMsvIP, /*int taskid,*/ Sobey.Core.Log.ILogger logger) { logger.Info($"MsvSDK prepare QueryTaskState(ip={strMsvIP})"); try { TASK_PARAM info = IsTestDevice(strMsvIP, nChPort) ? await _clientSdk.Test_MSVQueryRuningTaskAsync(strMsvIP, nChPort, 0, logger).ConfigureAwait(true) : await _clientSdk.MSVQueryRuningTaskAsync(strMsvIP, nChPort, logger).ConfigureAwait(true); if (info == null) { logger.Error($" MSVQueryRuningTask net Error {_clientSdk.MSVGetLastErrorString()}"); return(null); } //string strbtime = info.tmBeg.ToString("yy-MM-dd hh:mm:ss"); //string stretime = info.tmBeg.ToString("yy-MM-dd hh:mm:ss"); //info.tmBeg = Convert.ToDateTime(strbtime); //info.tmEnd = Convert.ToDateTime(stretime); //MSVTskParam2ClientParam(info, ref tskparam); return(info); } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::QueryTaskState, Exception:{e.Message}"); return(null); } }
public async Task <TaskParam> TraceAsync(int nChPort, string strMsvIP, TaskParam pTaskparam, string strTaskName, string pCaptureparam, Sobey.Core.Log.ILogger logger) { MSV_RET ret; try { TASK_PARAM tmptaskparam = new TASK_PARAM(); ClientParam2MSVTskParam(pTaskparam, ref tmptaskparam); TASK_ALL_PARAM_NEW task = new TASK_ALL_PARAM_NEW(); task.taskParam.ulID = tmptaskparam.ulID; task.taskParam.strName = strTaskName; task.nCutLen = 10; task.captureParam = pCaptureparam; //ret = _clientSdk.MSVStartRetrospectTask(strMsvIP, task, nChPort, logger); ret = await _clientSdk.MSVStartRetrospectTaskAsync(strMsvIP, task, nChPort, logger).ConfigureAwait(true); if (ret != MSV_RET.MSV_SUCCESS) { logger.Error($"MSVStartRetrospectTask falied, error:{_clientSdk.MSVGetLastErrorString()} "); return(pTaskparam); } logger.Info($"MSVStartRetrospectTask end......MsvUdpClientCtrlSDK Trace"); } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::Trace falied, Exception:{e.Message} "); return(null); } return(null); }
public async Task <bool> RecordAsync(TASK_ALL_PARAM_NEW allparam, int nChPort, string strMsvIP, Sobey.Core.Log.ILogger logger) { MSV_RET ret; string strMutPath = ""; string strPath = ""; int nMsvRet = 0; try { var _xml = new XmlDocument(); _xml.LoadXml(allparam.captureParam); XmlElement _root = _xml.DocumentElement; XmlNode pathNode = _root.SelectSingleNode("multiDest"); if (pathNode != null) { strPath = pathNode.InnerText; strMutPath = string.Format("<multiDest><taskid>{0}</taskid>{1}</multiDest>", allparam.taskParam.ulID, strPath); //ret = _clientSdk.MSVSetMulDestPath(strMsvIP, strMutPath, logger); ret = await _clientSdk.MSVSetMulDestPathAsync(strMsvIP, nChPort, strMutPath, logger).ConfigureAwait(true); if (ret == MSV_RET.MSV_NETERROR) { logger.Error($"MSVSetMulDestPath::taskName={allparam.taskParam.strName};Error:{_clientSdk.MSVGetLastErrorString()}!"); } } allparam.nCutLen = 10; logger.Info($"MsvSDK Record Prepare Cast MSVStartTaskNew Function ip={strMsvIP} port={nChPort} cutlen={allparam.nCutLen}"); //ret = _clientSdk.MSVStartTaskNew(strMsvIP, m_taskAllParam, nChPort, logger); ret = await _clientSdk.MSVStartTaskNewAsync(strMsvIP, allparam, nChPort, logger).ConfigureAwait(true);; nMsvRet = Convert.ToInt32(ret); if (ret == MSV_RET.MSV_NETERROR) { logger.Error("MsvSDK Record Failed(MSV_NETERROR)!...........MsvUdpClientCtrlSDK::Record"); return(false); } if (ret != MSV_RET.MSV_SUCCESS) { logger.Error($"MsvSDK Record Failed {ret} {_clientSdk.MSVGetLastErrorString()}"); return(false); } return(true); } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::Record, Exception:{e.Message}"); return(false); } }
//capture 刚发采集命令发完要完全确认状态 public async Task <Device_State> QueryDeviceStateAsync(int nChPort, string strMsvIP, bool capture, Sobey.Core.Log.ILogger logger) { try { MSV_STATE state = await _clientSdk.MSVQueryStateAsync(strMsvIP, nChPort, logger).ConfigureAwait(true); if (state == null) { logger.Error($"MSVQueryState MSV_NETERROR, {strMsvIP}:{nChPort}, error: {_clientSdk.MSVGetLastErrorString()}"); return(Device_State.DISCONNECTTED); } logger.Info($"MSVQueryState End, state:{state.msv_capture_state}......"); if (capture) { if (state.msv_capture_state == CAPTURE_STATE.CS_CAPTURE || state.msv_capture_state == CAPTURE_STATE.CS_CAPTURE_ACTIVE) { return(Device_State.WORKING); } else { return(Device_State.CONNECTED); } } else { if (state.msv_capture_state == CAPTURE_STATE.CS_PAUSE || state.msv_capture_state == CAPTURE_STATE.CS_CAPTURE) { return(Device_State.WORKING); } else { return(Device_State.CONNECTED); } } } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::QueryState, Exception {e.Message}"); return(Device_State.DISCONNECTTED); } }
public async Task <long> StopAsync(int nChPort, string strMsvIP, int taskID, Sobey.Core.Log.ILogger logger) { try { long nRetTaskId = await _clientSdk.MSVStopTaskAsync(strMsvIP, taskID, nChPort, logger).ConfigureAwait(true); if (nRetTaskId <= 0) { logger.Error($"MSVStopTask failed, error:{_clientSdk.MSVGetLastErrorString()} "); return(0); } logger.Info($"MSVStopTask end,MsvUdpClientCtrlSDK::Stop nRetTaskId::{nRetTaskId} "); return(nRetTaskId); } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::Stop, Exception:{e.Message} "); return(0); } }
private async Task OnCheckAllDeviceAsync(object type) { bool request = false; if (_lstTimerScheduleDevice.Count > 0) { foreach (var item in _lstTimerScheduleDevice) { var state = await _msvClient.QueryDeviceStateAsync(item.ChannelIndex, item.Ip, false, Logger); MSV_Mode msvmode = MSV_Mode.NETWORK; if (state == Device_State.DISCONNECTTED) { msvmode = MSV_Mode.ERROR; Logger.Warn($"QueryDeviceState {state}"); } bool changedstate = false; if (item.CurrentDevState != state || msvmode != item.LastMsvMode) { changedstate = true; item.LastDevState = item.CurrentDevState; item.LastMsvMode = msvmode; item.CurrentDevState = state; if (!await _restClient.UpdateMSVChannelStateAsync(item.ChannelId, item.LastMsvMode, item.CurrentDevState).ConfigureAwait(true)) { Logger.Error("OnCheckAllChannelsAsync UpdateMSVChannelStateAsync error"); } } if (item.LastDevState == Device_State.DISCONNECTTED && item.CurrentDevState == Device_State.CONNECTED && item.NeedStopFlag) { item.NeedStopFlag = false; } if (item.LastDevState == Device_State.DISCONNECTTED && item.CurrentDevState == Device_State.WORKING && changedstate) { var taskinfo = await _msvClient.QueryTaskInfoAsync(item.ChannelIndex, item.Ip, Logger); if (taskinfo != null && taskinfo.ulID > 0) { var cptaskinfo = await _restClient.GetChannelCapturingTaskInfoAsync(item.ChannelId); bool needstop = true; if (cptaskinfo != null && cptaskinfo.TaskId == taskinfo.ulID) { Logger.Info("OnCheckAllChannelsAsync not needstop"); needstop = false; } if (needstop) { /* * 应该不用通知出去,任务那边监听可以管理 */ item.NeedStopFlag = true; await _msvClient.StopAsync(item.ChannelIndex, item.Ip, cptaskinfo.TaskId, Logger); } else { item.NeedStopFlag = false; } } } } request = await _grainFactory.GetGrain <IDeviceInspections>(0).SubmitChannelInfoAsync(_grainKey, _lstTimerScheduleDevice, false); } if (request) { _lstTimerScheduleDevice = await _grainFactory.GetGrain <IDeviceInspections>(0).RequestChannelInfoAsync(_grainKey); } }
private async Task OnScheduleTaskAsync(object type) { //如果判断到是周期任务,那么需要对它做分任务的处理 //这个步骤挪到后台server去做 //任务分发的时候要向请求通道是否存在,不存在提交一个自检请求 var _lstRemoveTask = new List <DispatchTask>(); if (this.State.Count > 0) { var lsttask = this.State; if (lsttask != null && lsttask.Count > 0) { foreach (var task in lsttask) { if (task.State == (int)taskState.tsReady && task.Tasktype != (int)TaskType.TT_TIEUP) { if (task.Tasktype == (int)TaskType.TT_PERIODIC && task.State == (int)taskState.tsReady && task.OldChannelid == 0) { if ((task.NewBegintime - DateTime.Now).TotalSeconds <= _taskSchedulePreviousSeconds) { var info = await _restClient.CreatePeriodcTaskAsync(task.Taskid); Logger.Info($"create period task {task.Taskid}"); if (info != null) { _lstRemoveTask.Add(task); //周期母任务更新后,再加进去,进行下一个周期 var taskperiod = await _restClient.GetTaskDBAsync(task.Taskid); if (taskperiod.Endtime > DateTime.Now && taskperiod.NewBegintime > DateTime.Now) { await GrainFactory.GetGrain <IReminderTask>(0).AddTaskAsync(taskperiod); } } } } else { if ((task.Starttime - DateTime.Now).TotalSeconds <= _taskSchedulePreviousSeconds) { if (task.Endtime > DateTime.Now) { await GrainFactory.GetGrain <ITask>(task.Channelid.GetValueOrDefault())?.AddTaskAsync(_mapper.Map <TaskContent>(task)); task.State = (int)taskState.tsExecuting; Logger.Info($"add task excuter {task.Taskid}"); } else { _lstRemoveTask.Add(task); } } } } else if (task.State == (int)taskState.tsExecuting || task.State == (int)taskState.tsManuexecuting) { var spansecond = (task.Endtime - DateTime.Now).TotalSeconds; if (spansecond < _taskSchedulePreviousSeconds) { if (await GrainFactory.GetGrain <ITask>(task.Channelid.GetValueOrDefault())?.StopTaskAsync(_mapper.Map <TaskContent>(task))) { _lstRemoveTask.Add(task); Logger.Info($"stop task {task.Taskid}"); } } } } if (_lstRemoveTask.Count > 0) { lock (this.State) { if (this.State.Count > 0) { var lst = _lstRemoveTask.Select(x => x.Taskid).ToList(); this.State.RemoveAll(x => lst.Contains(x.Taskid)); } if (this.State.Count == 0 && _dispoScheduleTimer != null) { _dispoScheduleTimer.Dispose(); _dispoScheduleTimer = null; } } } } else { lock (this.State) { this.State.Clear(); if (this.State.Count == 0 && _dispoScheduleTimer != null) { _dispoScheduleTimer.Dispose(); _dispoScheduleTimer = null; } Logger.Info("clear all scheduletask"); } } } }
public TASK_ALL_PARAM_NEW RecordReady(int nChPort, string strMsvIP, TaskParam pTaskparam, string strTaskName, string pCaptureparam, Sobey.Core.Log.ILogger logger) { if (pTaskparam == null) { logger.Error("RecordReady: pTaskparam is null!"); return(null); } TASK_PARAM param = new TASK_PARAM(); TASK_PARAM taskParam = new TASK_PARAM(); try { logger.Info($"MsvSDK Record Ready!,taskID:{pTaskparam.taskID},pCaptureparam:{pCaptureparam} "); XmlDocument doc = new XmlDocument(); doc.LoadXml(pCaptureparam); XmlNode root = doc.DocumentElement; //string curDate = DateTime.Now.ToString("yyyy-MM-dd") + '\\'; string curDate = DateTime.Now.ToString("yyyy-MM-dd"); if (root != null) { //XmlNode _capTure = root.SelectSingleNode("CAPTUREPARAM"); XmlNode _fileName0 = root.SelectSingleNode("path0FileName"); if (_fileName0 != null) { string fileName0 = _fileName0.InnerText; //fileName0 += curDate; // int nIndex = fileName0.LastIndexOf('\\'); // if (nIndex == fileName0.Length - 1) // fileName0 = fileName0.Substring(0, nIndex); // int nPos = fileName0.LastIndexOf('\\'); // fileName0 = fileName0.Insert(nPos + 1, curDate); //fileName0 = fileName0.Substring(0, nPos + 1); //fileName0 = fileName0 + curDate; fileName0 = fileName0.Replace("yyyy-mm-dd", curDate); _fileName0.InnerText = fileName0; } else { logger.Error("Not find fileName0:"); } XmlNode _fileName1 = root.SelectSingleNode("path1FileName"); if (_fileName1 != null) { string fileName1 = _fileName1.InnerText; //fileName1 += curDate; // int nIndex = fileName1.LastIndexOf('\\'); // if (nIndex == fileName1.Length - 1) // fileName1 = fileName1.Substring(0, nIndex); // int nPos = fileName1.LastIndexOf('\\'); // fileName1 = fileName1.Insert(nPos + 1, curDate); //fileName1 = fileName1.Substring(0, nPos + 1); //fileName1 = fileName1 + curDate; fileName1 = fileName1.Replace("yyyy-mm-dd", curDate); _fileName1.InnerText = fileName1; } else { logger.Error("Not find fileName1:"); } } else { logger.Error("root is null"); } pCaptureparam = doc.InnerXml; logger.Info($"MsvSDK Record Ready!, taskID:{pTaskparam.taskID}, lastCapture:{pCaptureparam}...........RecordReady"); ClientParam2MSVTskParam(pTaskparam, ref param); taskParam.bRetrospect = param.bRetrospect; taskParam.bUseTime = param.bUseTime; taskParam.channel = param.channel; taskParam.dwCutClipFrame = param.dwCutClipFrame; taskParam.nInOutCount = param.nInOutCount; taskParam.strName = param.strName; for (int i = 0; i < taskParam.nInOutCount; i++) { taskParam.dwInFrame[i] = param.dwInFrame[i]; taskParam.dwOutFrame[i] = param.dwOutFrame[i]; taskParam.dwTotalFrame[i] = param.dwTotalFrame[i]; } taskParam.nSignalID = param.nSignalID; taskParam.nTimeCode = param.nTimeCode; //m_taskparam.strDesc.Format(_T("%s"),pTaskparam->strDesc); //m_taskParam.strName = strTaskName; taskParam.tmBeg = DateTime.Now; taskParam.tmEnd = DateTime.Now; taskParam.ulID = param.ulID; taskParam.TaskMode = (TASK_MODE)param.TaskMode; taskParam.TaskState = (TASK_STATE)param.TaskState; //m_taskAllParam.captureParam = pCaptureparam; //m_taskAllParam.nCutLen = 10; //m_taskAllParam.taskParam = m_taskParam; //m_taskAllParam.taskParam.strName = strTaskName; logger.Info($"curent strTaskName: {strTaskName}"); return(new TASK_ALL_PARAM_NEW() { captureParam = pCaptureparam, nCutLen = 10, taskParam = taskParam }); } catch (Exception e) { logger.Error($"MsvUdpClientCtrlSDK::RecordReady, Exception:{e.Message}"); return(null); } }
public async Task <SDISignalStatus> QuerySDIFormatAsync(int nChPort, string strMsvIP, Sobey.Core.Log.ILogger logger) { try { //ret = _clientSdk.MSVQuerySDIFormat(strMsvIP, ref singleType, ref bIsBack, logger, nChPort); var ret = await _clientSdk.MSVQuerySDIFormatAsync(strMsvIP, logger, nChPort).ConfigureAwait(true); if (ret == null) { logger.Error($"Cast Interface Function MSVQuerySDIFormat Error!(error {_clientSdk.MSVGetLastErrorString()})...........MsvUdpClientCtrlSDK::QuerySDIFormat"); return(null); } logger.Info($"Cast Interface Function QuerySDIFormat!(vedioformat ={ret.VideoFormat} :width :{ret.nWidth})...........MsvUdpClientCtrlSDK::QuerySDIFormat"); int pnSingleType = 255; bool bValidVideo = false; switch (ret.VideoFormat) { case SignalFormat._invalid_vid_format: pnSingleType = 254; break; //case 4095: // { // bValidVideo = TRUE; // } case SignalFormat._unknown_vid_format: pnSingleType = 255; break; default: bValidVideo = true; break; } if (bValidVideo) { if (ret.nWidth > 0 && ret.nWidth <= 720) { pnSingleType = 0; } else if (ret.nWidth >= 3840) { pnSingleType = 2; } else if (ret.nWidth > 720) { pnSingleType = 1; } else { pnSingleType = 254; bValidVideo = false; } ret.SignalType = pnSingleType; return(ret); } return(null); } catch (System.Exception e) { logger.Error($"Cast Interface Function MSVQuerySDIFormat Exception! {e.Message})...........MsvUdpClientCtrlSDK::QuerySDIFormat"); return(null); } }