Exemplo n.º 1
0
 /// <summary>
 /// 获取指定软件项目的最新版本
 /// </summary>
 /// <param name="product">项目名称</param>
 /// <returns>返回更新项目配置情况</returns>
 public UpgradeProject GetUpgradeProject(string product)
 {
     lock (SyncObj)
     {
         IList <UpgradeProject> projects = db.Load <UpgradeProject>(delegate(UpgradeProject project) {
             return(product == project.Product);
         });
         if (projects.Count > 0)
         {
             UpgradeProject project = projects[0];
             foreach (UpgradeProject proj in projects)
             {
                 Version ver1 = new Version(project.Version);
                 Version ver2 = new Version(proj.Version);
                 if (ver1 < ver2 || project.UpgradePatchTime < proj.UpgradePatchTime)
                 {
                     project = proj;
                 }
             }
             return(project);
         }
         else
         {
             return(null);
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 注册会话
        /// </summary>
        /// <param name="sessionId">会话标识</param>
        /// <param name="user">用户名</param>
        /// <param name="ipAddress">调用方IP地址</param>
        /// <param name="encryptKey">密钥</param>
        public void Register(string sessionId, string user, string ipAddress, string encryptKey)
        {
            lock (syncObj) {
                if (sessions.ContainsKey(sessionId))
                {
                    throw new ArgumentException(String.Format("会话管理器中已经存在 [{0}] 的会话", sessionId));
                }

                logger.Info(String.Format("注册来自 {0} [{1}] 的会话 : [{2}]", user, ipAddress, sessionId));
                SessionState session = new SessionState(sessionId, timeOut);
                session[SessionVariables.SESSION_ID]             = sessionId;
                session[SessionVariables.SESSION_CURRENT_USER]   = user;
                session[SessionVariables.SESSION_CLIENT_ADDRESS] = ipAddress;
                session[SessionVariables.SESSION_ENCRYPTKEY]     = encryptKey;
                session[SessionVariables.SESSION_LOGIN_TIME]     = DateTime.Now;

                // 会话状态上下文变化事件
                session.ContextChanged += new EventHandler(delegate(object sender, EventArgs e) {
                    string id = ((SessionState)sender).SessionId;
                    IList <SessionState> list = db.Load <SessionState>(delegate(SessionState ss) {
                        return(ss.SessionId == id);
                    });
                    if (list.Count > 0)
                    {
                        db.Delete(list[0]); // 删除原来的会话状态数据
                    }
                    db.Store(sender);
                });

                // 将新注册的会话资料保存到数据库
                db.Store(session);
                sessions[sessionId] = session;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 清除所有的操作命令
        /// </summary>
        public void Clear()
        {
            IList <AuthorizationCommand> lcs = db.Load <AuthorizationCommand>();

            foreach (AuthorizationCommand cmd in lcs)
            {
                db.Delete(cmd);
            }
        }
        /// <summary>
        /// 删除所有的授权节点信息
        /// </summary>
        public void Clear()
        {
            IList <AuthorizationNode> lns = db.Load <AuthorizationNode>();

            foreach (AuthorizationNode an in lns)
            {
                db.Delete(an);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Deletes the specified property.
        /// </summary>
        /// <param name="property">The property.</param>
        public void Delete(string property)
        {
            IList <Property> objs = db.Load <Property>(delegate(Property prop) {
                return(prop.Name == property);
            });

            foreach (Property obj in objs)
            {
                db.Delete(obj);
            }
        }
Exemplo n.º 6
0
        private void ReregisterOuterEvent()
        {
            List <OuterEventInfo> eventList = new List <OuterEventInfo>(db.Load <OuterEventInfo>());

            eventList.ForEach(delegate(OuterEventInfo info) {
                try {
                    RegisterOuterEventSubscriber(info.SessionId, info.Topic, info.Location);
                }
                catch {
                    db.Delete(info);
                }
            });
        }
        /// <summary>
        /// 获取指定用户的授权信息
        /// </summary>
        /// <param name="username">用户名称</param>
        /// <returns>返回特定用户的授权信息</returns>
        public IList <AuthorizationStore> GetAuthorizationsByUser(string username)
        {
            string[] roles = Roles.GetRolesForUser(username);
            List <AuthorizationStore> list = new List <AuthorizationStore>();

            foreach (string role in roles)
            {
                IList <AuthorizationStore> results = db.Load <AuthorizationStore>(delegate(AuthorizationStore authStore) {
                    return(authStore.Role == role);
                });
                list.AddRange(results);
            }
            return(list);
        }
Exemplo n.º 8
0
        public void SessionStateStoreTest()
        {
            SessionState session = new SessionState("12345", 100);

            db.Store(session);

            IList <SessionState> list = db.Load <SessionState>(delegate(SessionState ss){
                return(ss.SessionId == "12345");
            });

            Assert.AreEqual(1, list.Count);
            Assert.AreEqual("12345", list[0].SessionId);
        }
Exemplo n.º 9
0
        public void Enqueue(Request request)
        {
            IList <Request> results = dbService.Load <Request>(delegate(Request queryRequest) {
                return(queryRequest.RequestId == request.RequestId);
            });

            if (results.Count == 0)
            {
                dbService.Store(request);
                if (RequestQueueChanged != null)
                {
                    RequestQueueChanged(this, new RequestQueueEventArgs(request, GetCount()));
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySessionService"/> class.
        /// </summary>
        /// <param name="dbService">The db service.</param>
        /// <param name="configService">The config service.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dispatcher">The dispatcher.</param>
        public SessionService(IDb4oDatabaseService dbService, IConfigurationService configService, ILoggerFactory loggerFactory, IEventDispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
            logger = loggerFactory.CreateLogger<SessionService>("Framework");
            db = dbService.Open(SESSION_DB);

            // 加载会话数据库中的会话信息
            foreach (SessionState session in db.Load<SessionState>()) {
                sessions.Add(session.SessionId, session);
            }

            try {
                IConfiguration conf = new XMLConfiguration(configService.GetItem(SESSION_PAPH));
                timeOut = conf.Attributes["timeout"] != null ? Int32.Parse(conf.Attributes["timeout"]) : SESSION_DEFAULT_TIMEOUT;
                checkSpan = conf.Attributes["checkspan"] != null ? Int32.Parse(conf.Attributes["checkspan"]) : SESSION_DEFAULT_CHECKSPAN;
            }
            catch {
                timeOut = SESSION_DEFAULT_TIMEOUT;
                checkSpan = SESSION_DEFAULT_CHECKSPAN;
            }
            Start(); // 启动会话管理
        }
Exemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MySessionService"/> class.
        /// </summary>
        /// <param name="dbService">The db service.</param>
        /// <param name="configService">The config service.</param>
        /// <param name="loggerFactory">The logger factory.</param>
        /// <param name="dispatcher">The dispatcher.</param>
        public SessionService(IDb4oDatabaseService dbService, IConfigurationService configService, ILoggerFactory loggerFactory, IEventDispatcher dispatcher)
        {
            this.dispatcher = dispatcher;
            logger          = loggerFactory.CreateLogger <SessionService>("Framework");
            db = dbService.Open(SESSION_DB);

            // 加载会话数据库中的会话信息
            foreach (SessionState session in db.Load <SessionState>())
            {
                sessions.Add(session.SessionId, session);
            }

            try {
                IConfiguration conf = new XMLConfiguration(configService.GetItem(SESSION_PAPH));
                timeOut = conf.Attributes["timeout"] != null?Int32.Parse(conf.Attributes["timeout"]) : SESSION_DEFAULT_TIMEOUT;

                checkSpan = conf.Attributes["checkspan"] != null?Int32.Parse(conf.Attributes["checkspan"]) : SESSION_DEFAULT_CHECKSPAN;
            }
            catch {
                timeOut   = SESSION_DEFAULT_TIMEOUT;
                checkSpan = SESSION_DEFAULT_CHECKSPAN;
            }
            Start(); // 启动会话管理
        }