Exemple #1
0
        public async Task <bool> UpdateMSVChannelStateAsync(int id, MSV_Mode mode, Device_State state)
        {
            var back = await AutoRetry.RunAsync <ResponseMessage <bool> >(() =>
            {
                return(PostAsync <ResponseMessage <bool> >(
                           //$"{IngestDbUrl}/{DEVICEAPI20}/channelstate/{id}",
                           $"{IngestDbUrl}/{DEVICEAPI30}/channel/{id}/state",
                           new { DevState = state, MSVMode = mode }, GetIngestHeader()));
            }).ConfigureAwait(true);

            if (back != null)
            {
                return(back.Ext);
            }
            return(false);
        }
        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);
            }
        }