示例#1
0
 public WSSessionSocketAdapter(WSSession aSession)
 {
     session = aSession;
     session.Closed += HandleClosed;
     session.MessageReceived += HandleMessageReceived;
     session.DataReceived += HandleDataReceivedReceived;
 }
        //命令执行前调用
        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);
            }
        }
示例#3
0
 public WSUserSet(WSRoleSet RoleSet, Func <string, WSSession> ReadWSSession, MetaFunctions _CFunc)
 {
     CFunc = _CFunc;
     if (RoleSet != null)
     {
         foreach (string DBName in RoleSet.Last().Value.Keys)
         {
             WSSession session = ReadWSSession(DBName);
             if (session != null && RoleSet.ContainsKey(session.user.role) && RoleSet[session.user.role].ContainsKey(DBName))
             {
                 WSUserDBSet DBSet = new WSUserDBSet(session);
                 DBSet.AddRange(RoleSet[session.user.role][DBName].Clone(ref DBSet, CFunc));
                 Add(DBName, DBSet);
             }
         }
     }
 }
        //甄玉龙增加燃气校时配置帧
        public void calibraRQ(DeviceDTO dto)
        {
            var       server      = bootstrap.GetServerByName(WS_SERVER);
            WSServer  casicServer = server as WSServer;
            WSSession session     = casicServer.GetSessionByID(dto.SessionId) as WSSession;

            //下发校时信息
            String preTimeCal = "SewTiming:" + session.MacID + ",";
            String postTime   = DateTime.Now.ToString("yyyyMMddHHmmss");
            String timeCal    = preTimeCal + postTime;

            byte[] data1 = new byte[timeCal.Length + 2];
            Encoding.ASCII.GetBytes(timeCal, 0, timeCal.Length, data1, 0);
            data1[timeCal.Length]     = 0x0D;
            data1[timeCal.Length + 1] = 0x0A;
            session.Send(data1, 0, data1.Length);
            session.Logger.Info("校时信息:" + timeCal);
        }
        private bool sendWSConfig(DeviceDTO dto, Dictionary <String, String> settings)
        {
            var       server      = bootstrap.GetServerByName(WS_SERVER);
            WSServer  casicServer = server as WSServer;
            WSSession session     = casicServer.GetSessionByID(dto.SessionId) as WSSession;

            String period = settings["ws_period"];

            if (period == "")
            {
                return(false);
            }

            String sdata0 = "SewAcquireInterval:" + session.MacID + "," + period;

            byte[] data0 = new byte[sdata0.Length + 2];
            Encoding.ASCII.GetBytes(sdata0, 0, sdata0.Length, data0, 0);
            data0[sdata0.Length]     = 0x0D;
            data0[sdata0.Length + 1] = 0x0A;
            session.Send(data0, 0, data0.Length);
            session.Logger.Info("有害气体配置信息:" + sdata0);

            //下发校时信息

            /*
             * String preTimeCal = "SewTiming:" + session.MacID + ",";
             * String postTime = DateTime.Now.ToString("yyyyMMddHHmmss");
             * String timeCal = preTimeCal + postTime;
             *
             * byte[] data1 = new byte[timeCal.Length + 2];
             * Encoding.ASCII.GetBytes(timeCal, 0, timeCal.Length, data1, 0);
             * data1[timeCal.Length] = 0x0D;
             * data1[timeCal.Length + 1] = 0x0A;
             * session.Send(data1, 0, data1.Length);
             * session.Logger.Info("校时信息:" + timeCal);
             * */
            return(true);
        }
示例#6
0
        private WSSession ReadWSSession(string dbName)
        {
            WSSession session = null;

            if (!string.IsNullOrEmpty(dbName))
            {
                try
                {
                    WSSecurityMeta meta = SecurityMap[dbName];
                    session = new WSSession(Request.SessionID, meta);

                    /**********************
                     * ANDVO@NOTE:
                     * DO NOT do [ZoneContext = Request.ZoneContext;]
                     * because it will use Request's zone, when it MUST BE zone for the argument:'dbName' !!!
                     * */
                    using (WSDataContext ZoneContext = GetInternalContext(meta.Zone, Request.ID, $"{GetType().Name}.ReadWSSession('{dbName}')"))
                    {
                        if (ZoneContext != null && !ZoneContext.IsDisposed && ZoneContext.Connection.State == System.Data.ConnectionState.Open)
                        {
                            if (meta.SessionType != null)
                            {
                                MethodInfo mInfo = ZoneContext.GetType().GetMethod("GetTable", new Type[] { });

                                var tObj = mInfo.MakeGenericMethod(new Type[] { meta.SessionType }).Invoke(ZoneContext, new object[] { });

                                Func <WSDynamicEntity, bool> func = s => s.readPropertyValue(WSConstants.PARAMS.SESSIONID.NAME, "").ToString().ToLower().Equals(Request.SessionID.ToLower());

                                MethodInfo[] methods = typeof(Enumerable).GetMethods(BindingFlags.Static | BindingFlags.Public);

                                var method = methods.FirstOrDefault(m => m.Name == "FirstOrDefault" && m.GetParameters().Count() == 2).MakeGenericMethod(typeof(WSDynamicEntity));

                                WSDynamicEntity sessionEntity = (WSDynamicEntity)method.Invoke(null, new object[] { tObj, func });

                                if (sessionEntity != null)
                                {
                                    WSDynamicEntity userEntity = (WSDynamicEntity)sessionEntity.GetType().GetProperties().Single(x => x.PropertyType == meta.UserType).GetValue(sessionEntity, null);

                                    if (userEntity != null)
                                    {
                                        object _id        = userEntity.TryReadPropertyValue("UserID", out _id) ? _id : null;
                                        object _email     = userEntity.TryReadPropertyValue("Email", out _email) ? _email : null;
                                        object _firstname = userEntity.TryReadPropertyValue("FirstName", out _firstname) ? _firstname : null;
                                        object _lastname  = userEntity.TryReadPropertyValue("LastName", out _lastname) ? _lastname : null;
                                        object _isactive  = userEntity.TryReadPropertyValue("IsActive", out _isactive) ? _isactive : null;
                                        object _login     = userEntity.TryReadPropertyValue("Login", out _login) ? _login : null;

                                        WSDynamicEntity roleEntity = (WSDynamicEntity)userEntity.GetType().GetProperties().FirstOrDefault(x => x.PropertyType == meta.RoleType).GetValue(userEntity, null);

                                        if (roleEntity != null)
                                        {
                                            object _role     = roleEntity.TryReadPropertyValue("ID", out _role) ? _role : null;
                                            object _roleName = roleEntity.TryReadPropertyValue("Name", out _roleName) ? _roleName : null;

                                            int    id    = int.TryParse(_id.ToString(), out id) ? id : -1;
                                            string email = _email != null?_email.ToString() : string.Empty;

                                            string login = _login != null?_login.ToString() : string.Empty;

                                            string firstname = _firstname != null?_firstname.ToString() : string.Empty;

                                            string lastname = _lastname != null?_lastname.ToString() : string.Empty;

                                            bool   isactive = bool.TryParse(_isactive.ToString(), out isactive) ? isactive : false;
                                            byte   role     = byte.TryParse(_role == null ? null : _role.ToString(), out role) ? role : WSConstants.DEFAULT_USER_ROLE;
                                            string roleName = _roleName != null?_roleName.ToString() : string.Empty;

                                            session.user = new WSUserToken()
                                            {
                                                id        = id,
                                                email     = email,
                                                login     = login,
                                                firstname = firstname,
                                                lastname  = lastname,
                                                isactive  = isactive,
                                                role      = role,
                                                roleName  = roleName
                                            };
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e) { RegError(GetType(), e, ref LoadStatus); }
            }
            return(session);
        }
 public override void ChannelRegistered(IChannelHandlerContext context)
 {
     _Session = new WSSession(_ClusterClient, _LoggerFactory, context);
     base.ChannelRegistered(context);
 }
示例#8
0
 public WSUserDBSet(WSSession _DBSession)
 {
     DBSession = _DBSession;
 }