示例#1
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;
            }
        }
示例#2
0
        public void RegisterOuterEventSubscriber(string sessionId, string topic, SubscriberLocation location)
        {
            if (subscribers.ContainsKey(sessionId + topic))
            {
                return;
            }

            if (!events.ContainsKey(topic))
            {
                throw new ArgumentException("系统中没有topic为 [" + topic + "] 的事件");
            }
            EventCollector collector;

            if (eventCollectors.ContainsKey(sessionId))
            {
                collector = eventCollectors[sessionId];
            }
            else
            {
                collector = new EventCollector();
                eventCollectors.Add(sessionId, collector);
            }
            collector.RegisterEvent(topic, events[topic].EventInfo, kernel[events[topic].EventInfo.DeclaringType]);
            EventSubscriberInfo subInfo = new EventSubscriberInfo(topic, location, "", "");

            AddEventSubscriber(sessionId + topic, subInfo);
            if (!outerSubscriberMapping.ContainsKey(sessionId))
            {
                outerSubscriberMapping.Add(sessionId, new List <string>());
            }
            outerSubscriberMapping[sessionId].Add(topic);
            AddOuterSubscriberToPublisherInfo(sessionId + topic, subInfo);
            db.Store(new OuterEventInfo(sessionId, topic, location));
        }
示例#3
0
 /// <summary>
 /// 创建一个软件更新项目
 /// </summary>
 /// <param name="project">软件更新项目配置信息</param>
 public void CreateUpgradeProject(UpgradeProject project)
 {
     db.Store(project);
     if (UpgradeProjectCreated != null)
     {
         UpgradeProjectCreated(this, new EventArgs <UpgradeProject>(project));
     }
 }
        /// <summary>
        /// 保存授权信息
        /// </summary>
        /// <param name="authorizationStore">授权信息</param>
        public void SaveAuthorization(AuthorizationStore authorizationStore)
        {
            DeleteAuthorization(authorizationStore.Role);
            db.Store(authorizationStore);

            // 触发事件处理程序
            if (AuthorizationChanged != null)
            {
                AuthorizationChanged(this, new EventArgs <string>(authorizationStore.Role));
            }
        }
示例#5
0
        /// <summary>
        /// 保存操作命令
        /// </summary>
        /// <param name="command">命令</param>
        public void Save(AuthorizationCommand command)
        {
            Delete(command);

            // 为操作指定一个唯一的序号
            if (command.Sequence == -1)
            {
                IList <AuthorizationCommand> lcs = db.Query <AuthorizationCommand>((AuthorizationCommand cmd) => cmd.Category == command.Category);
                command.Sequence = lcs.Count + 1;
            }
            db.Store(command);
        }
示例#6
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);
        }
示例#7
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()));
                }
            }
        }
示例#8
0
        /// <summary>
        /// Sets the specified property.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="property">The property.</param>
        /// <param name="value">The value.</param>
        public void Set <T>(string property, T value)
        {
            IList <Property> list = db.Load <Property>(delegate(Property prop) {
                return(prop.Name == property);
            });
            object oldValue = null;

            if (list.Count > 0)
            {
                oldValue = list[0].Current;
                db.Delete(list[0]);
            }

            Property item = new Property {
                Name    = property,
                Current = value
            };

            db.Store(item);
            OnPropertyChanged(new PropertyChangedEventArgs(item, oldValue)); // 触发事件
        }
示例#9
0
 /// <summary>
 /// 保存列表布局到数据库
 /// </summary>
 /// <param name="layout">布局信息</param>
 public void StoreLayout(Layout layout)
 {
     DeleteLayout(layout.User, layout.AppUri);
     db.Store(layout);
 }
 /// <summary>
 /// 保存授权节点
 /// </summary>
 /// <param name="node">授权节点</param>
 public void Save(AuthorizationNode node)
 {
     Delete(node);
     db.Store(node);
 }