Instance() public static method

单实例模式
public static Instance ( ) : SessionManage
return SessionManage
コード例 #1
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);
 }
コード例 #2
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;
                if (!string.IsNullOrEmpty(strSessionId))
                {
                    err = SessionManage.Instance().RemoveSessionBySessionId(strSessionId);
                    logEx.Info("SMC DisConnect CgwService Successful,Current.SMC IP is : {0}", CgwConst.SmcIp);
                }
                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);
        }
コード例 #3
0
        /// <summary>
        /// 连接融合网关
        /// </summary>
        /// <param name="cgwPwd">连接字符串</param>
        /// <returns></returns>
        public SmcErr Connect(string cgwPwd)
        {
            SmcErr err = new CgwError();

            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            if (isLoadSuccess == false)
            {
                err.SetErrorNo(CgwError.ERR_CGW_IS_LOADING);
                return(err);
            }
            //if (false == string.IsNullOrEmpty(cgwPwd))
            //{

            ////进行SHA256加密
            //string newPassword = CommonFunction.SHA256Encrypt(strPwd);
            //保存当前会话
            //if (newPassword == cgwPwd)
            //{
            //获取SessionManage中Session个数
            if (SessionManage.Instance().GetSessionsCount() == 0)
            {
                Guid sessionGuid = Guid.NewGuid();
                //保存至CGW的session管理中
                CgwSession CgwSession = new CgwSession(sessionGuid, OperationContext.Current.SessionId);

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

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

            //}
            //else
            //{
            //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_INCORRECT);
            //    logEx.Error("Connect Password is Incorrect !");
            //}
            //}
            //else
            //{
            //    err.SetErrorNo(CgwError.ERR_CGW_BUSINESS_PASSWORD_NULL);
            //    logEx.Error("Connect Password is null !");
            //}
            return(err);
        }
コード例 #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void fileWatcher_Deleted(object sender, FileSystemEventArgs e)
        {
            if (this.licenseFileOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
            {
                LoggerEx logEx = new LoggerEx(log);
                try
                {
                    fileWatcher.EnableRaisingEvents = false;
                    if (e.ChangeType == WatcherChangeTypes.Deleted)
                    {
                        uint   resultErr = 0;
                        byte[] bteLic;
                        if (File.Exists(strPathLic))
                        {
                            bteLic = File.ReadAllBytes(strPathLic);
                        }
                        else
                        {
                            byte[] b = new byte[0];
                            bteLic = b;
                            int licCountNew = 0;
                            if (licCount != licCountNew)
                            {
                                SessionManage.Instance().RemoveAllSession();
                                logEx.Trace("License have changed! the New Count is:{0}, the Old Count:{1} ", licCountNew.ToString(), licCount.ToString());
                                licCount = licCountNew;
                            }
                        }
                        CLicenseManagedAdapter licMan = new CLicenseManagedAdapter();
                        SmcErr smcErr = Convert2ErrNo(licMan.ActivateLicenseKey(bteLic, ref resultErr));
                    }
                    fileWatcher.EnableRaisingEvents = true;
                }

                catch (Exception ex)
                {
                    logEx.Error("fileWatcher_Deleted Exception:{0}", ex.ToString());
                }
                finally
                {
                    this.licenseFileOperateLock.ExitWriteLock();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// 获取控制项信息
        /// </summary>
        /// <param name="err"></param>
        /// <param name="licMan"></param>
        private SmcErr GetControlLicItem(List <ConfigItem> configList)
        {
            LoggerEx logEx  = new LoggerEx(log);
            SmcErr   smcErr = new SmcErr();
            CLicenseManagedAdapter licMan          = new CLicenseManagedAdapter();
            List <LKItemValue>     licItemTypeList = new List <LKItemValue>();

            smcErr = Convert2ErrNo(licMan.GetLicenseInfo(ref licItemTypeList));
            if (smcErr.IsSuccess())
            {
                licenseInfo.IsMonitorPlatform = false;
                licenseInfo.IsEltePlatform    = false;
                foreach (LKItemValue item in licItemTypeList)
                {
                    if (LicItemfType.LicItemMaxChannelNum == item.ItemID)
                    {
                        int licCountNew = Convert.ToInt32(item.ItemValue);
                        if (licCount != licCountNew)
                        {
                            SessionManage.Instance().RemoveAllSession();
                            logEx.Trace("License have changed! the New Count is:{0}, the Old Count:{1} ", licCountNew.ToString(), licCount.ToString());
                            licCount = licCountNew;
                        }
                    }
                    if (item.ItemID.ToString() == "LicItemMonitorEnable" && item.ItemValue.ToString() == "1")
                    {
                        licenseInfo.IsMonitorPlatform = true;
                    }
                    if (item.ItemID.ToString() == "LicItemELTEEnable" && item.ItemValue.ToString() == "1")
                    {
                        licenseInfo.IsEltePlatform = true;
                    }

                    logEx.Info("GetControlLicItem item:{0},{1}", item.ItemID, item.ItemValue);
                }
            }
            else
            {
                logEx.Warn("GetControlLicItem errNo:{0}", smcErr.ErrNo);
            }

            return(smcErr);
        }
コード例 #6
0
        /// <summary>
        /// 检查Session
        /// </summary>
        /// <returns></returns>
        private SmcErr CheckSession()
        {
            NLogEx.LoggerEx logEx      = new NLogEx.LoggerEx(log);
            SmcErr          err        = new CgwError();
            CgwSession      CgwSession = null;

            if (OperationContext.Current != null)
            {
                string strSessionId = OperationContext.Current.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 Id is:{0}, LastVisitedTime is :{1}", strSessionId, CgwSession.LastVisitedTime.ToLongTimeString());
                        logEx.Trace("Current 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);
        }