예제 #1
0
        /// <summary>
        /// 初始化上面的 Effect
        /// </summary>
        /// <param name="sysService"></param>
        public SysEffects(SysService sysService)
        {
            UnityIocService.AssertIsFirstInject(GetType());
            Logger = LoggerHelper.CreateLogger(GetType().ToString());
            //启动http解析服务
            StartHttpSystem = App.Store.asyncAction <SysActions.StartHttpSystem, bool>(
                async(dispatch, getState, instance) => {
                dispatch(instance);
                var isStarted = await sysService.StartHttpSystem(instance);
                if (isStarted)
                {
                    App.Store.Dispatch(new SysActions.StartHttpSystemSuccess());
                }
                else
                {
                    App.Store.Dispatch(new SysActions.StartHttpSystemFailed());
                }
                return(isStarted);
            });
            //启动关闭显示器定时器
            StartCloseScreenTimer = App.Store.asyncActionVoid <SysActions.StartCloseScreenTimer>(
                async(dispatch, getState, instance) => {
                dispatch(instance);
                await Task.Run(() => {
                    if (CloseScrrenTimer != null)
                    {
                        YUtil.RecoveryTimeout(CloseScrrenTimer);
                    }
                    else
                    {
                        CloseScrrenTimer = YUtil.SetInterval(instance.Interval, () => {
                            App.Store.Dispatch(new SysActions.CloseScreen());
                        });
                    }
                });
            });

            //停止关闭显示器定时器
            StopCloseScrenTimer = App.Store.asyncActionVoid <SysActions.StopCloseScreenTimer>(
                async(dispatch, getState, instance) => {
                dispatch(instance);
                await Task.Run(() => {
                    if (CloseScrrenTimer != null)
                    {
                        YUtil.ClearTimeout(CloseScrrenTimer);
                    }
                });
            });
        }
예제 #2
0
 /// <summary>
 /// 向某个ip发送命令,这里的ip必须是底层可以执行动作的ip
 /// </summary>
 /// <param name="ip"></param>
 /// <param name="action"></param>
 public void SendAction(string ip, SmAction action)
 {
     using (ActionLock.Lock()) {
         if (ActionClientDict.TryGetValue(ip, out var state))
         {
             try {
                 tcpServer.Send(state, SmParamApi.BuildAlarmPackage(state.ModuleAddr, action));
                 Logger.Debug($"发送命令 {Enum.GetName(typeof(SmAction), action)} 成功 {ip}");
                 ActionCache[ip] = SmAction.NoAction;
             } catch {
                 ActionCache[ip] = action;
                 YUtil.RecoveryTimeout(ScanActionTimer);
             }
         }
     }
 }