Inheritance: System.Entity
Ejemplo n.º 1
0
 /// <summary>
 /// SessionStateProviderBase.CreateUninitializedItem
 /// </summary>
 public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
 {
     using (var s = NHOpenIDMembershipProvider.GetNHibernateSession())
     {
         using (s.BeginTransaction())
         {
             Session session;
             session = s.CreateQuery("from Session where sessionId = :id").SetParameter<string>("id",id).UniqueResult<Session>();
             if (session==null) {
                 session = new Session();
             }
             session.SessionId = id;
             session.ApplicationName = m_applicationName;
             session.Created = DateTime.Now;
             session.Expires = DateTime.Now.AddMinutes((Double)timeout);
             session.Timeout = timeout;
             session.Locked = false;
             session.LockId = 0;
             session.LockDate = DateTime.Now;
             session.Data = string.Empty;
             session.Flags = 1;
             s.SaveOrUpdate(session);
             s.Transaction.Commit();
         }
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// SessionStateProviderBase.SetAndReleaseItemExclusive
 /// </summary>
 public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem)
 {
     // Serialize the SessionStateItemCollection as a string
     string serializedItems = Serialize((SessionStateItemCollection)item.Items);
     using (var s = NHOpenIDMembershipProvider.GetNHibernateSession())
     {
         var c = s.CreateCriteria<Session>();
         c.Add(Expression.Eq("SessionId", id));
         c.Add(Expression.Eq("ApplicationName", m_applicationName));
         try
         {
             var sessions = c.List<Session>();
             if (newItem)
             {
                 using (s.BeginTransaction())
                 {
                     foreach (var session in sessions)
                     {
                         s.Delete(session);
                     }
                     var sess = new Session();
                     sess.SessionId = id;
                     sess.ApplicationName = m_applicationName;
                     sess.Created = DateTime.Now;
                     sess.Expires = DateTime.Now.AddMinutes((Double)item.Timeout);
                     sess.Timeout = item.Timeout;
                     sess.Locked = false;
                     sess.LockId = 0;
                     sess.LockDate = DateTime.Now;
                     sess.Data = serializedItems;
                     sess.Flags = 0;
                     s.Save(sess);
                     s.Transaction.Commit();
                 }
             }
             else
             {
                 using (s.BeginTransaction())
                 {
                     foreach (var session in sessions)
                     {
                         if (session.LockId == (int)lockId)
                         {
                             session.Expires = DateTime.Now.AddMinutes((Double)item.Timeout);
                             session.Locked = false;
                             session.Data = serializedItems;
                             s.Update(session);
                         }
                     }
                     s.Transaction.Commit();
                 }
             }
         }
         catch (NHibernate.HibernateException e)
         {
             throw new ProviderException(e.ToString());
         }
     }
 }