예제 #1
0
            private string getString(int userId)
            {
                sessionId sessionId = new sessionId();

                get(userId, ref sessionId);
                return(sessionId.IsNull ? null : sessionId.ToHexString());
            }
예제 #2
0
파일: CMSControl.cs 프로젝트: Firren666/CMS
 public static bool connect()
 {
     mSessionId = cmsserver.startSession("TestSession", "");
     cmsserver.configureSessionTimout(mSessionId, -2);
     //Console.WriteLine("PespectiveMgtAPI connected: " + cmsserver);
     return mSessionId.id > 0;
 }
예제 #3
0
 /// <summary>
 /// 新建会话信息
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="timeout"></param>
 /// <param name="value"></param>
 public void New(ref sessionId sessionId, DateTime timeout, valueType value)
 {
     Timeout = timeout;
     Low     = sessionId.Low;
     High    = sessionId.High;
     Value   = value;
     sessionId.IndexIdentity = Identity;
 }
예제 #4
0
        public void Remove(ref sessionId sessionId)
        {
            valueType value;

            Monitor.Enter(queueLock);
            queue.Remove(sessionId, out value);
            Monitor.Exit(queueLock);
            Remove(sessionId);
        }
예제 #5
0
 /// <summary>
 /// 设置Session值
 /// </summary>
 /// <param name="sessionId">Session名称</param>
 /// <param name="value">值</param>
 /// <returns>Session是否被更新</returns>
 public bool Set(ref sessionId sessionId, valueType value)
 {
     fastCSharp.net.returnValue <sessionId> newSessionId = Set(sessionId, value);
     if (newSessionId.IsReturn)
     {
         set(ref newSessionId.Value, value);
         return(newSessionId.Value.Equals(ref sessionId) != 0);
     }
     return(false);
 }
예제 #6
0
 /// <summary>
 /// 获取会话信息
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="timeout"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 public bool Get(ref sessionId sessionId, DateTime timeout, ref valueType value)
 {
     if (((Low ^ sessionId.Low) | (High ^ sessionId.High) | (Identity ^ sessionId.IndexIdentity)) == 0 && Timeout != DateTime.MinValue)
     {
         value   = Value;
         Timeout = timeout;
         return(true);
     }
     return(false);
 }
예제 #7
0
 /// <summary>
 /// 删除会话信息
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public bool Remove(ref sessionId sessionId)
 {
     if (((Low ^ sessionId.Low) | (High ^ sessionId.High) | (Identity ^ sessionId.IndexIdentity)) == 0 && Timeout != DateTime.MinValue)
     {
         Value = default(valueType);
         ++Identity;
         Timeout = DateTime.MinValue;
         return(true);
     }
     return(false);
 }
예제 #8
0
        public valueType Get(ref sessionId sessionId, valueType nullValue)
        {
            valueType value;

            if (TryGet(sessionId, out value).Value)
            {
                set(ref sessionId, value);
                return(value);
            }
            return(nullValue);
        }
예제 #9
0
 /// <summary>
 /// 获取Session值
 /// </summary>
 /// <param name="sessionId">Session名称</param>
 /// <param name="value">返回值</param>
 /// <returns>是否存在返回值</returns>
 public bool TryGet(ref sessionId sessionId, out valueType value)
 {
     value = default(valueType);
     if (sessionId.Low != 0 && (uint)sessionId.Index < (uint)Pool.Pool.Length && Pool.Enter())
     {
         bool isValue = Pool.Pool[sessionId.Index].Get(ref sessionId, date.nowTime.Now.AddTicks(timeoutTicks), ref value);
         Pool.Exit();
         return(isValue);
     }
     return(false);
 }
예제 #10
0
 /// <summary>
 /// 设置Session缓存
 /// </summary>
 /// <param name="sessionId"></param>
 /// <param name="value"></param>
 private void set(ref sessionId sessionId, valueType value)
 {
     Monitor.Enter(queueLock);
     try
     {
         queue.Set(sessionId, value);
         if (queue.Count > queueCount)
         {
             queue.UnsafePopValue();
         }
     }
     finally { Monitor.Exit(queueLock); }
 }
예제 #11
0
 /// <summary>
 /// 设置Session值
 /// </summary>
 /// <param name="sessionId">Session名称</param>
 /// <param name="value">值</param>
 /// <returns>是否设置成功</returns>
 public unsafe int Set(ref sessionId sessionId, valueType value)
 {
     if (sessionId.Low != 0 && (uint)sessionId.Index < (uint)Pool.Pool.Length && Pool.Pool[sessionId.Index].Check(ref sessionId) && Pool.Enter())
     {
         if (Pool.Pool[sessionId.Index].Set(ref sessionId, date.nowTime.Now.AddTicks(timeoutTicks), value))
         {
             Pool.Exit();
             return(1);
         }
         Pool.Exit();
     }
     return(0);
 }
예제 #12
0
 /// <summary>
 /// 删除Session
 /// </summary>
 /// <param name="sessionId">Session名称</param>
 public void Remove(ref sessionId sessionId)
 {
     if (sessionId.Low != 0 && (uint)sessionId.Index < (uint)Pool.Pool.Length && Pool.Enter())
     {
         if (Pool.Pool[sessionId.Index].Remove(ref sessionId))
         {
             Pool.FreeExit(sessionId.Index);
         }
         else
         {
             Pool.Exit();
         }
     }
 }
예제 #13
0
 /// <summary>
 /// 设置Session值
 /// </summary>
 /// <param name="sessionId">Session名称</param>
 /// <param name="value">值</param>
 /// <returns>Session是否被更新</returns>
 public unsafe bool New(ref sessionId sessionId, valueType value)
 {
     if (Pool.Enter())
     {
         try
         {
             sessionId.Index = Pool.GetIndexContinue();
             Pool.Pool[sessionId.Index].New(ref sessionId, date.nowTime.Now.AddTicks(timeoutTicks), value);
         }
         finally { Pool.Exit(); }
         return(true);
     }
     return(false);
 }
예제 #14
0
            /// <summary>
            /// 获取用户长连接轮询验证
            /// </summary>
            /// <param name="userId">用户标识</param>
            /// <param name="sessionId">长连接轮询验证,0表示失败</param>
            public void Get(int userId, out sessionId sessionId)
            {
                int index = userId >> 8;

                if ((uint)index < (uint)sessions.Length)
                {
                    Monitor.Enter(sessionLock);
                    sessionId = sessions[index].Timeout > date.NowSecond ? sessions[index].SessionId : sessions[index].New(date.NowSecond.AddTicks(timeoutTicks));
                    Monitor.Exit(sessionLock);
                }
                else
                {
                    sessionId = default(sessionId);
                }
            }
예제 #15
0
                /// <summary>
                /// 添加用户长连接轮询验证
                /// </summary>
                /// <param name="userId"></param>
                /// <returns></returns>
                public string Add(int userId)
                {
                    sessionTimeout value;

                    if (!sessions.TryGetValue(userId, out value))
                    {
                        sessionId sessionId = default(sessionId);
                        sessionId.New();
                        Monitor.Enter(sessionLock);
                        try
                        {
                            if (!sessions.ContainsKey(userId))
                            {
                                sessions.Add(userId, value = new sessionTimeout {
                                    SessionId = sessionId, Timeout = date.NowSecond.AddTicks(timeoutTicks)
                                });
                            }
                        }
                        finally { Monitor.Exit(sessionLock); }
                    }
                    return(value.SessionId.ToHexString());
                }
예제 #16
0
                /// <summary>
                /// 获取用户长连接轮询验证
                /// </summary>
                /// <param name="userId">用户标识</param>
                /// <param name="sessionId">长连接轮询验证,0表示失败</param>
                public void Get(int userId, ref sessionId sessionId)
                {
                    sessionTimeout value;

                    if (sessions.TryGetValue(userId, out value))
                    {
                        if (value.Timeout > date.NowSecond)
                        {
                            sessionId = value.SessionId;
                            return;
                        }
                        sessionId.New();
                        Monitor.Enter(sessionLock);
                        try
                        {
                            sessions[userId] = new sessionTimeout {
                                SessionId = sessionId, Timeout = date.NowSecond.AddTicks(timeoutTicks)
                            };
                        }
                        finally { Monitor.Exit(sessionLock); }
                        return;
                    }
                    sessionId.Null();
                }
예제 #17
0
 public bool Set(ref sessionId sessionId, object value)
 {
     return(Set(ref sessionId, (valueType)value));
 }
예제 #18
0
 /// <summary>
 /// 检测会话是否有效
 /// </summary>
 /// <param name="sessionId"></param>
 /// <returns></returns>
 public bool Check(ref sessionId sessionId)
 {
     return(Identity == sessionId.IndexIdentity && ((Low ^ sessionId.Low) | (High ^ sessionId.High)) == 0 && Timeout != DateTime.MinValue);
 }
예제 #19
0
 private void get(int userId, ref sessionId sessionId)
 {
     sessions[userId & 0xff].Get(userId, ref sessionId);
 }