示例#1
0
        /// <summary>
        /// Retrieve from session.
        /// </summary>
        /// <returns></returns>
        public PrintingCalculator RetrieveFromSession()
        {
            //Read the session cookie
            PrintingCalculator item;

            if(!string.IsNullOrEmpty(UserID))
            {
                item = m_RavenSession.Load<PrintingCalculator>(UserID);

                if(item == null || item.ID < 0)
                {
                    //initialize a link list with max 20 operations
                    item = new PrintingCalculator();

                    CreateSessions(item);
                }
            }
            else
            {
                //initialize a link list with max 20 operations
                item = new PrintingCalculator();

                CreateSessions(item);
            }

            item.SessionTimeOut = m_RavenSession.Advanced.GetMetadataFor(item)["Raven-Expiration-Date"].ToString();

            return item;
        }
示例#2
0
        /// <summary>
        /// Creates the sessions.
        /// </summary>
        /// <param name="item">The item.</param>
        private void CreateSessions(PrintingCalculator item)
        {
            DateTime SessionExpiration = DateTime.UtcNow.AddMinutes(SessionTimeOutValue);

            m_RavenSession.Store(item);
            m_RavenSession.Advanced.GetMetadataFor(item)["Raven-Expiration-Date"] = new RavenJValue(SessionExpiration);
            m_RavenSession.SaveChanges();

            //Save user ID cookie
            HttpCookie authCookie = new HttpCookie(SessionKey, m_RavenSession.Advanced.GetDocumentId(item))
            {
                Expires = SessionExpiration
            };

            HttpContext.Current.Response.Cookies.Add(authCookie);
        }