Instance() public static méthode

单实例模式
public static Instance ( ) : SessionManage
Résultat SessionManage
Exemple #1
0
        /// <summary>
        /// 断开监控管理连接
        /// </summary>
        /// <returns></returns>
        public SmcErr Disconnect()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            SmcErr          err   = new CgwError();

            if (OperationContext.Current != null)
            {
                //string strSessionId = OperationContext.Current.SessionId;
                string strSessionId = currentSessionID;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Info("Client DisConnect MonitorManageService Successful,Current.Cgw IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                    logEx.Warn("Current SessionId is null ! ");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
                logEx.Warn("Current SessionId is null ! ");
            }

            return(err);
        }
Exemple #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="sessionGuid">唯一标识</param>
 public CgwSession(Guid sessionGuid, string sessionId)
 {
     SessionGuid     = sessionGuid;
     SessionId       = sessionId;
     LastVisitedTime = DateTime.Now;
     SessionManage.Instance().AddSession(sessionGuid, this);
 }
Exemple #3
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="password">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(out string sessionID)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            sessionID = "";
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return(err);
            }

            //获取SessionManage中Session个数
            if (SessionManage.Instance().GetSessionsCount() == 0)
            {
                Guid sessionGuid = Guid.NewGuid();

                sessionID        = OperationContext.Current.SessionId;
                currentSessionID = sessionID;
                //保存至CGW的session管理中
                CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

                MessageProperties properties = OperationContext.Current.IncomingMessageProperties;                                        //获取传进的消息属性

                RemoteEndpointMessageProperty endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; //获取消息发送的远程终结点IP和端口
                if (endpoint != null)
                {
                    CgwConst.ClientIp = endpoint.Address; // 获取发送消息的客户端的 IP 地址。
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is : {0}", CgwConst.ClientIp);
                }
                else
                {
                    logEx.Info("Client Connect MonitorManageService Successful,Current.Client IP is  null.");
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_COUNT_MAX);
                logEx.Warn("Session Count is  Top Of Max number !");
            }

            return(err);
        }
Exemple #4
0
        /// <summary>
        /// 检查Session
        /// </summary>
        /// <returns></returns>
        private SmcErr CheckSession(string sessionID)
        {
            NLogEx.LoggerEx logEx      = new NLogEx.LoggerEx(log);
            SmcErr          err        = new CgwError();
            CgwSession      CgwSession = null;

            if (OperationContext.Current != null)
            {
                //string strSessionId = OperationContext.Current.SessionId;
                string strSessionId = sessionID;
                err = SessionManage.Instance().GetSessionsBySessionId(strSessionId, out CgwSession);

                if (err.IsSuccess() == false || CgwSession == null)
                {
                    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_SESSION_NULL);
                }
                else
                {
                    if (CgwSession != null)
                    {
                        //更新Session最后访问时间
                        CgwSession.LastVisitedTime = DateTime.Now;
                        //logEx.Trace("Current SessionId is:{0}, LastVisitedTime is :{1}", strSessionId, CgwSession.LastVisitedTime.ToLongTimeString());
                        logEx.Trace("LastVisitedTime is :{0}", CgwSession.LastVisitedTime.ToLongTimeString());

                        if (isLoadSuccess == false)
                        {
                            err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                        }
                    }
                }
            }
            else
            {
                err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_CURRENTSESSION_NULL);
            }
            return(err);
        }