Esempio n. 1
0
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session;

            BLL.DeviceLog       bllLog    = new DeviceLog();
            BLL.Device          bllDevice = new Device();
            Model.DeviceLogInfo log       = new Model.DeviceLogInfo();
            log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
            log.OPERATETYPE = "下发";
            log.LOGTIME     = DateTime.Now;

            if (session.Conf != null)
            {
                //记录实际下发信息
                string   content  = session.Conf.FrameContent;
                string[] items    = content.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                byte[]   sendData = new byte[items.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    sendData[i] = byte.Parse(items[i], System.Globalization.NumberStyles.HexNumber);
                }
                log.MESSAGE = "更新渗漏配置:密集开始时间:" + sendData[4] + ":" + sendData[5] +
                              "样本间隔:" + sendData[6] + "采集个数:" + sendData[7];
            }
            else
            {
                //记录默认配置信息
                byte[] set = ApplicationContext.getInstance().getDefaultSLConfig();
                log.MESSAGE = "更新渗漏配置:密集开始时间:" + set[4] + ":" + set[5] +
                              "样本间隔:" + set[6] + "采集个数:" + set[7];
            }
            bllLog.insert(log);
        }
        // public AsyncLogCommandFilter(ILogger logger)
        // {
        //     _logger = logger;
        // }
        public override async ValueTask OnCommandExecutedAsync(CommandExecutingContext commandContext)
        {
            string log = $"Executed:Accept Command:{commandContext.CurrentCommand.ToString()} from:{commandContext.Session.SessionID}";

            //_logger.LogInformation(log);
            Console.WriteLine(log);
        }
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            try
            {
                StringRequestInfo requestInfo = (StringRequestInfo)commandContext.RequestInfo;

                //TODO: construct the receving casic data
                String deviceId = requestInfo.Parameters[3];
                String pduType  = requestInfo.Parameters[6];

                //print the receving data
                String devType  = new CasicCmd().getDeviceTypeByPdu(pduType);
                String operType = new CasicCmd().getOpeTypeByPdu(pduType);

                if (devType != "集中器")
                {
                    Model.DeviceLogInfo1 log = new Model.DeviceLogInfo1();
                    log.DEVICECODE  = deviceId;
                    log.DEVTYPE     = devType;
                    log.OPERATETYPE = operType;
                    log.LOGTIME     = DateTime.Now;
                    log.MESSAGE     = operType;
                    new BLL.DeviceLog1().insert(log);
                }
            }
            catch (Exception e)
            {
                ((CasicSession)commandContext.Session).Logger.Error(e.Message);
            }
        }
        public override async ValueTask <bool> OnCommandExecutingAsync(CommandExecutingContext commandContext)
        {
            Console.WriteLine("Hello Executing");
            await Task.Delay(0);

            return(true);
        }
Esempio n. 5
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            ChatSession session = (ChatSession)commandContext.Session;
            string      command = commandContext.CurrentCommand.Name;

            if (!session.IsLogin)
            {
                if (!command.Equals("Login"))
                {
                    session.Send($"请先完成登陆,在做别的操作");
                    session.Close();
                    commandContext.Cancel = true;//取消命令,不再继续
                }
                else
                {
                }
            }
            else if (!session.IsOnLine)
            {
                session.LastHBTime = DateTime.Now;//客户端给我发消息,证明在线
            }
            else
            {
            }
        }
Esempio n. 6
0
            public override ValueTask <bool> OnCommandExecutingAsync(CommandExecutingContext commandContext)
            {
                var sessionState = commandContext.Session.DataContext as SessionState;

                sessionState.ExecutionCount++;
                return(new ValueTask <bool>(true));
            }
Esempio n. 7
0
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            BinaryRequestInfo request = (BinaryRequestInfo)commandContext.RequestInfo;

            byte[] sim    = new byte[6];
            byte[] header = headerToByteArray(request.Key);
            byte[] body   = request.Body;
            Buffer.BlockCopy(body, 0, sim, 0, 6);
            if (!Utility.CodeUtils.CRC16_validate(header, body))
            {
                commandContext.Cancel = true;
            }

            //sim卡号
            string code = BitConverter.ToString(sim, 0, sim.Length).Replace("-", "").Substring(1);

            //打印燃气设备号
            commandContext.Session.Logger.Info("燃气智能检测终端编号:" + code);

            object obj = new BLL.Device().getDeviceIdByCode(code);

            if (null == obj || string.IsNullOrEmpty(obj.ToString()))
            {
                commandContext.Cancel = true;
            }
            else
            {
                RQSession session = (RQSession)commandContext.Session;
                session.ID = Convert.ToInt32(obj);
            }
        }
Esempio n. 8
0
            public override bool OnCommandExecuting(CommandExecutingContext commandContext)
            {
                var sessionState = commandContext.Session.DataContext as SessionState;

                sessionState.ExecutionCount--;
                return(true);
            }
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            try
            {
                EmsSession session = (EmsSession)commandContext.Session;
                session.Logger.Info("#############################Filter开始执行#############################");
                if (session.Initial)
                {
                    session.Logger.Info("已经登录过啦!");
                    return;
                }
                StringRequestInfo request      = (StringRequestInfo)commandContext.RequestInfo;
                string            code         = request.Parameters[0];
                string[]          dataList     = code.Split('$');
                string            patrolerName = dataList[0];
                string            macId        = dataList[1];
                byte[]            data         = new byte[128];

                Model.Patroler patroler = new BLL.Patroler().getPatrolerByName(patrolerName);
                if (null == patroler)
                {
                    session.Logger.Info("没有找到巡检员:" + patrolerName);
                    data = Encoding.UTF8.GetBytes("none" + "\r\n");
                    session.Send(data, 0, data.Length);
                    commandContext.Cancel = true;
                    return;
                }

                Model.Equipment equipment = new BLL.Equipment().getEquipmentByMacId(macId);
                if (null == equipment)
                {
                    session.Logger.Info("没有找到设备:" + macId);
                    data = Encoding.UTF8.GetBytes("none" + "\r\n");
                    session.Send(data, 0, data.Length);
                    commandContext.Cancel = true;
                    return;
                }

                session.Patroler  = patroler;
                session.Equipment = equipment;
                session.Initial   = true;
                session.Logger.Info("已经找到设备和人了");
                session.Logger.Info("#############################Filter成功执行#############################");
                session.Logger.Info("\n");
                session.Logger.Info("\n");
                session.Logger.Info("\n");
            }
            catch (Exception e)
            {
                commandContext.Session.Logger.Error("#############################EMSFilter执行错误#############################");
                commandContext.Session.Logger.Error(e.ToString());
                commandContext.Session.Logger.Error("\n");
                commandContext.Session.Logger.Error("\n");
                commandContext.Session.Logger.Error("\n");
            }
        }
Esempio n. 10
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            var session = commandContext.Session as MyAppSession;

            //If the session is not logged in, cancel the executing of the command
            if (!session.IsLoggedIn)
            {
                commandContext.Cancel = true;
            }
        }
Esempio n. 11
0
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            string        strMsg = "";
            string        l      = Environment.NewLine;
            MyRequestInfo info   = (MyRequestInfo)commandContext.RequestInfo;
            DateTime      dt     = DateTime.Now;

            strMsg += ("命令 " + info.Key + " 执行完时间为:" + dt + l);
            Log(strMsg);
            //LogHelper.Error(dt + "  " + info.EquipmentID + "  " + info.Key + "结束");
        }
Esempio n. 12
0
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            var session   = commandContext.Session;
            var startTime = session.Items.GetValue <DateTime>("StartTime");
            var ts        = DateTime.Now.Subtract(startTime);

            if (ts.TotalSeconds > 5 && session.Logger.IsInfoEnabled)
            {
                session.Logger.InfoFormat("A command '{0}' took {1} seconds!", commandContext.CurrentCommand.Name, ts.ToString());
            }
        }
        /// <summary>
        /// 命令结束后调用
        /// </summary>
        /// <param name="commandContext"></param>
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            CustomSession session = (CustomSession)commandContext.Session;

            if (session != null)
            {
                var startTime = session.Items.GetValue <DateTime>("StartTime");
                var ts        = DateTime.Now.Subtract(startTime);
                if (ts.TotalSeconds > 5 && session.Logger.IsInfoEnabled)
                {
                    session.Logger.InfoFormat("命令'{0}' 执行时间: {1} 秒!", commandContext.CurrentCommand.Name, ts.ToString());
                }
            }
        }
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            StringRequestInfo request = (StringRequestInfo)commandContext.RequestInfo;
            string            devCode = request.Parameters[4];

            commandContext.Session.Logger.Info("渗漏预警设备(" + devCode + ")" + "->服务器:噪声数据上传" + request.Body);

            //解析上传的时间是否合法:采集时间:不是2014年立即丢弃
            //String uptime = request.Parameters[7];
            //if (Int32.Parse(uptime.Substring(8, 2), System.Globalization.NumberStyles.HexNumber) < 14)
            // {
            //     commandContext.Cancel = true;
            // }
        }
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            SZSLNoiseSession session = (SZSLNoiseSession)commandContext.Session;

            BLL.DeviceLog bllLog    = new DeviceLog();
            BLL.Device    bllDevice = new Device();

            Model.DeviceLogInfo log = new Model.DeviceLogInfo();
            log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
            log.MESSAGE     = "渗漏噪声服务器地址配置:" + ApplicationContext.getInstance().getSLIpConfig();
            log.OPERATETYPE = "下发";
            log.LOGTIME     = DateTime.Now;

            bllLog.insert(log);
        }
Esempio n. 16
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            //throw new NotImplementedException();

            MySession session = commandContext.Session as MySession;

            //判断是否已登录
            if (session != null && !session.isLogin)
            {
                //判断当前命令是否为LOGIN
                if (!commandContext.RequestInfo.Key.Equals("LOGIN"))
                {
                }
            }
        }
        /// <summary>
        /// 执行命令前调用
        /// </summary>
        /// <param name="commandContext"></param>
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            CustomSession session = (CustomSession)commandContext.Session;

            if (session != null)
            {
                session.Items["StartTime"] = DateTime.Now;

                if (commandContext.RequestInfo.Key.Equals("-1"))
                {
                    session.Push(Convert.ToUInt16(commandContext.RequestInfo.Key), "未知命令!");
                    //取消执行当前命令
                    commandContext.Cancel = true;
                }
            }
        }
Esempio n. 18
0
        //命令执行前调用
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            StringRequestInfo request = (StringRequestInfo)commandContext.RequestInfo;
            string            code    = request.Parameters[0];
            object            obj     = new BLL.Device().getDeviceIdByCode(code);

            if (null == obj || string.IsNullOrEmpty(obj.ToString()))
            {
                commandContext.Cancel = true;
            }
            else
            {
                WSSession session = (WSSession)commandContext.Session;
                session.ID = Convert.ToInt32(obj);
            }
        }
Esempio n. 19
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            var session = commandContext.Session as ChatSession;

            //If the session is not logged in, cancel the executing of the command
            if (session.User == null)
            {
                ResultInfo result = new ResultInfo()
                {
                    RMsg = $"未登陆,命令执行失败。"
                };
                ArraySegmentWrapper segmentWrapper = new ArraySegmentWrapper(Constants.ERROR_PERMIT_RESPONSE_KEY, JConverter.SerializeToBytes(result));
                session.Send(segmentWrapper.Wrapper());

                session.Close();
                commandContext.Cancel = true;
            }
        }
Esempio n. 20
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            string    strMsg  = "";
            string    l       = Environment.NewLine;
            MySession session = ((MySession)(commandContext.Session));

            session.dateCommandReceive = DateTime.Now;
            DateTime      dt             = DateTime.Now;
            string        strEntireFrame = ((MyRequestInfo)commandContext.RequestInfo).EntireFrame;
            MyRequestInfo info           = (MyRequestInfo)commandContext.RequestInfo;

            strMsg += ("receive from: " + session.RemoteEndPoint.ToString()) + l;
            strMsg += ("接收到数据:" + strEntireFrame) + l;
            strMsg += ("设备类型:" + info.EquipmentType) + l;
            strMsg += ("设备号:" + info.EquipmentID) + l;
            strMsg += ("控制码:" + info.CtrlCodeBin);
            Log(strMsg);
            //LogHelper.Error(dt + "  " + info.EquipmentID + "  " + info.Key+"开始");
        }
        /// <summary>
        /// 执行命令前调用
        /// </summary>
        /// <param name="commandContext"></param>
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            CustomSession session = (CustomSession)commandContext.Session;

            if (session != null)
            {
                session.Items["StartTime"] = DateTime.Now;

                if (commandContext.RequestInfo.Key.Equals("-1"))
                {
                    CustomCommand comm = (CustomCommand)Enum.Parse(typeof(CustomCommand), commandContext.RequestInfo.Key);

                    string json = "未知命令!".GetTransmitPackets(comm);
                    session.Send(comm, json);

                    //取消执行当前命令
                    commandContext.Cancel = true;
                }
            }
        }
        //命令执行后调用
        public override void OnCommandExecuted(CommandExecutingContext commandContext)
        {
            BLL.DeviceLog    bllLog    = new DeviceLog();
            BLL.Device       bllDevice = new Device();
            SZSLNoiseSession session   = (SZSLNoiseSession)commandContext.Session;

            try
            {
                Model.DeviceLogInfo log = new Model.DeviceLogInfo();
                log.DEVICE_ID   = Convert.ToInt32(bllDevice.getDeviceIdByCode(session.MacID));
                log.MESSAGE     = "渗漏噪声数据上传";
                log.OPERATETYPE = "上报";
                log.LOGTIME     = DateTime.Now;
                bllLog.insert(log);
            }
            catch (Exception e)
            {
                commandContext.Session.Logger.Error("设备重启记录保存异常" + e.ToString());
            }
        }
Esempio n. 23
0
        public override void OnCommandExecuting(CommandExecutingContext commandContext)
        {
            DateTime   now     = DateTime.Now;
            ComSession session = commandContext.Session as ComSession;

            if (now.Subtract(session.lastTime).TotalSeconds > 1)
            {
                session.lastTime = now;
                session.LastRecieveDataLength = 0;
            }
            else
            {
                session.LastRecieveDataLength++;
                if (session.LastRecieveDataLength > 5)
                {
                    Monitor.Print(session.RemoteEndPoint.Address.ToString() +
                                  " send too many data to server in a second");
                    (session.AppServer as PlayServer).IPFilter.add(session.RemoteEndPoint);
                    session.Close();
                }
            }
        }
Esempio n. 24
0
 /// <summary>
 /// Called when [command executed].
 /// </summary>
 /// <param name="commandContext">The command context.</param>
 public abstract void OnCommandExecuted(CommandExecutingContext commandContext);
Esempio n. 25
0
 public override ValueTask OnCommandExecutedAsync(CommandExecutingContext commandContext)
 {
     return(new ValueTask());
 }
Esempio n. 26
0
 public override ValueTask <bool> OnCommandExecutingAsync(CommandExecutingContext commandContext)
 {
     return(new ValueTask <bool>(true));
 }
Esempio n. 27
0
 public override ValueTask OnCommandExecutedAsync(CommandExecutingContext commandContext)
 {
     Interlocked.Increment(ref _total);
     return(new ValueTask());
 }
Esempio n. 28
0
 public override void OnCommandExecuting(CommandExecutingContext commandContext)
 {
     commandContext.Session.Items["StartTime"] = DateTime.Now;
 }
Esempio n. 29
0
 //命令执行后调用
 public override void OnCommandExecuted(CommandExecutingContext commandContext)
 {
 }
Esempio n. 30
0
 public override void OnCommandExecuted(CommandExecutingContext commandContext)
 {
     Interlocked.Increment(ref m_Total);
 }