コード例 #1
0
		private void appServer_NewRequestReceived(CommonSession session, StringRequestInfo requestInfo)
		{
			switch (requestInfo.Key.ToUpper())
			{
				case ("ECHO"):
					session.Send(requestInfo.Body);
					break;

				case ("ADD"):
					session.Send(requestInfo.Parameters.Select(p => Convert.ToInt32(p)).Sum().ToString());
					break;

				case ("MULT"):

					var result = 1;

					foreach (var factor in requestInfo.Parameters.Select(p => Convert.ToInt32(p)))
					{
						result *= factor;
					}

					session.Send(result.ToString());
					break;
			}
		}
コード例 #2
0
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void removeLouverlightSensor(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.lls.TryRemove(key, out cs);
        }
コード例 #3
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var userSession = filterContext.HttpContext.Session[ConstantParam.SESSION_USER];

            if (userSession == null)
            {
                filterContext.Result = new RedirectResult("~/testA/Account/LogOff");
            }
            else
            {
                var accountSessionModel = (AccountSessionModel)CommonSession.SessionSatae_Deserialize(typeof(AccountSessionModel), userSession.ToString());

                //获取请求地址
                string controller = filterContext.RouteData.Values["controller"].ToString();
                string action     = filterContext.RouteData.Values["action"].ToString();
                string reqUrl     = "/" + controller + "/" + action;

                //如果当前用户未拥有该权限
                if (!accountSessionModel.PermissionDic.ContainsKey(reqUrl.ToLower()))
                {
                    filterContext.Result = new RedirectResult("~/testA/Account/LogOff");
                }
            }

            base.OnActionExecuting(filterContext);
        }
コード例 #4
0
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void removeTh10w(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.th10w.TryRemove(key, out cs);
        }
コード例 #5
0
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void removeAnemoclinoGrap(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.anemoclinoGrap.TryRemove(key, out cs);
        }
コード例 #6
0
        /// <summary>
        /// 获取对象集合
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static CommonSession getTh11s(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.th11s.TryGetValue(key, out cs);
            return(cs);
        }
コード例 #7
0
 /// <summary>
 /// 更新对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void updateAnemoclinoGrap(string key, CommonSession cs)
 {
     if (ThJob.anemoclinoGrap == null)
     {
         ThJob.anemoclinoGrap = new ConcurrentDictionary <String, CommonSession>();
     }
     ThJob.anemoclinoGrap.AddOrUpdate(key, cs, (oldKey, oldValue) => cs);
 }
コード例 #8
0
 /// <summary>
 /// 更新对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void updateTh10w(string key, CommonSession cs)
 {
     if (ThJob.th10w == null)
     {
         ThJob.th10w = new ConcurrentDictionary <String, CommonSession>();
     }
     ThJob.th10w.AddOrUpdate(key, cs, (oldKey, oldValue) => cs);
 }
コード例 #9
0
        /// <summary>
        /// 获取对象集合
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static CommonSession getAnemoclinoGrap(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.anemoclinoGrap.TryGetValue(key, out cs);
            return(cs);
        }
コード例 #10
0
 /// <summary>
 /// 更新对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void updateLouverlightSensor(string key, CommonSession cs)
 {
     if (ThJob.lls == null)
     {
         ThJob.lls = new ConcurrentDictionary <String, CommonSession>();
     }
     ThJob.lls.AddOrUpdate(key, cs, (oldKey, oldValue) => cs);
 }
コード例 #11
0
        /// <summary>
        /// 获取对象集合
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static CommonSession getLouverlightSensor(string key)
        {
            //判断静态变量中是否存在当前SESSION
            CommonSession cs = null;

            ThJob.lls.TryGetValue(key, out cs);
            return(cs);
        }
コード例 #12
0
        static void louverlightSensor_Server_NewSessionConnected(LouverlightSensorProtocolSession session)
        {
            //识别码_IP生成KEY用于保存session
            string        key = session.SessionID;
            CommonSession cs  = new CommonSession();

            cs.session = session;
            ThJob.addLouverlightSensor(key, cs);
            ///连接打开
            printConnectioned(session.SessionID, session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString());
        }
コード例 #13
0
        static void anemoclinograp_Server_NewSessionConnected(ANEMOCLINOGRAPProtocolSession session)
        {
            //识别码_IP生成KEY用于保存session
            string        key = session.SessionID;
            CommonSession cs  = new CommonSession();

            cs.session = session;
            ThJob.addAnemoclinoGrap(key, cs);

            ///连接打开
            printConnectioned(session.SessionID, session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString());
        }
コード例 #14
0
        static void actwcar_Server_NewSessionConnected(ACTWCARProtocolSession session)
        {
            //识别码_IP生成KEY用于保存session
            string        key = session.SessionID;
            CommonSession cs  = new CommonSession();

            cs.session = session;
            ThJob.addTw(key, cs);

            ///连接打开
            printConnectioned(session.SessionID, session.RemoteEndPoint.Address.ToString(), session.RemoteEndPoint.Port.ToString());
        }
コード例 #15
0
        /// <summary>
        /// 保存会话
        /// </summary>
        /// <param name="user"></param>
        private void SaveSession(User user)
        {
            var userSession = new AccountSessionModel()
            {
                UserId   = user.Id,
                Account  = user.Account,
                NickName = user.NickName
            };

            var userMenus = db.vUserMenus.Where(p => p.UserId == user.Id).OrderBy(p => p.OrderId).Select(pm => new MenuModel()
            {
                MenuId   = pm.Id,
                MenuName = pm.Name,
                MenuUrl  = pm.Href.ToLower(),
                ParentId = pm.ParentId,
                MenuCss  = pm.IconInfo,
                Order    = pm.OrderId
            }).ToList();

            var userPermissions = db.vUserPermissions.Where(p => p.UserId == user.Id).Select(p => new PermissionModel()
            {
                Name = p.Name,
                Url  = p.Href.ToLower()
            }).ToList();

            try
            {
                userSession.MenuList      = userMenus;
                userSession.PermissionDic = userPermissions.ToDictionary(k => k.Url, v => v.Name);

                Session[ConstantParam.SESSION_USER] = CommonSession.SessionSatae_Serialize(userSession);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #16
0
        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void removeTh11s(string key)
        {
            CommonSession cs = null;

            ThJob.th11s.TryRemove(key, out cs);
        }
コード例 #17
0
		private	void appServer_SessionClosed(CommonSession session, CloseReason reason)
		{
			session.Send(string.Format("A session is closed for {0}.", reason));
		}
コード例 #18
0
 /// <summary>
 /// 添加对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void addTh10w(string key, CommonSession cs)
 {
     ThJob.updateTh10w(key, cs);
 }
コード例 #19
0
 /// <summary>
 /// 删除对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void addAnemoclinoGrap(string key, CommonSession cs)
 {
     ThJob.updateAnemoclinoGrap(key, cs);
 }
コード例 #20
0
        public void Execute(IJobExecutionContext context)
        {
            List <string> delList = new List <string>();

            //定时清理指定时间之前的SESSION连接
            foreach (KeyValuePair <string, CommonSession> th in th10w)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    TH10WProtocolSession session = ((TH10WProtocolSession)(th.Value).session);
                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTh10w(key);
                }
            }

            delList = new List <string>();

            //th11s定时下发查询指令
            foreach (KeyValuePair <string, CommonSession> th in th11s)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    TH11SProtocolSession session = ((TH11SProtocolSession)(th.Value).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("010300000002C40B");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTh11s(key);
                }
            }

            delList = new List <string>();

            //ane定时下发查询指令
            foreach (KeyValuePair <string, CommonSession> th in anemoclinoGrap)
            {
                if (th.Value != null)
                {
                    //定时下发查询指令
                    ANEMOCLINOGRAPProtocolSession session = ((ANEMOCLINOGRAPProtocolSession)(th.Value).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("0101C1E0");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeAnemoclinoGrap(key);
                }
            }

            delList = new List <string>();

            //ACTW-CAR小型清洁刷式温盐传感器
            foreach (KeyValuePair <string, CommonSession> th in tw)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    ACTWCARProtocolSession session = ((ACTWCARProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    if (!ThJob.twIsWorking(th.Key))
                    {
                        session.Send("1111776970652C302C0D");
                        //设置设备工作状态
                        ThJob.setTwIsWorking(th.Key, true);
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeTw(key);
                }
            }

            delList = new List <string>();

            //ACLW-CAR传感器通讯协议与电气参数
            foreach (KeyValuePair <string, CommonSession> th in lw)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    ACLWCARProtocolSession session = ((ACLWCARProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    if (!ThJob.lwIsWorking(th.Key))
                    {
                        session.Send("1111776970652C302C0D");
                        ThJob.setLwIsWorking(th.Key, true);
                    }
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeLw(key);
                }
            }

            delList = new List <string>();

            //百叶箱光照传感器
            foreach (KeyValuePair <string, CommonSession> th in lls)
            {
                if (th.Value != null)
                {
                    CommonSession cs = th.Value;
                    //定时下发查询指令
                    LouverlightSensorProtocolSession session = ((LouverlightSensorProtocolSession)(cs).session);

                    //清理5分钟前的连接
                    if ((DateTime.Now - session.LastActiveTime).TotalMilliseconds > ThJob.clearTime)
                    {
                        //记录要删除的KEY
                        delList.Add(session.SessionID);
                        continue;
                    }

                    session.Send("010300000006C5C8");
                }
            }

            //删除记录的KEY
            if (delList != null && delList.Count > 0)
            {
                foreach (string key in delList)
                {
                    ThJob.removeLouverlightSensor(key);
                }
            }
        }
コード例 #21
0
        /// <summary>
        /// 获取工作状态
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static bool lwIsWorking(string key)
        {
            CommonSession cs = ThJob.getLw(key);

            return(cs == null ? false : cs.isWorking);
        }
コード例 #22
0
        /// <summary>
        /// 设置工作状态
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static void setLwIsWorking(string key, bool status)
        {
            CommonSession cs = ThJob.getLw(key);

            cs.isWorking = status;
        }
コード例 #23
0
 /// <summary>
 /// 添加对象
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public static void addLouverlightSensor(string key, CommonSession cs)
 {
     ThJob.updateLouverlightSensor(key, cs);
 }
コード例 #24
0
		private void appServer_NewSessionConnected(CommonSession session)
		{
			session.Send("Welcome to SuperSocket Server");
		}