/// <summary> /// Updates the _session object from the database /// </summary> public void Refresh(bool processRequests, SqlConnection cn, SqlTransaction trans) { SqlCommand cmd = null; try { SqlDataReader u; string commandText = "dbo.getSession"; HttpContext current = HttpContext.Current; if(cn == null) { cmd = new SqlCommand(commandText, Site.SqlConnection); } else { cmd = new SqlCommand(commandText, cn, trans); } cmd.CommandType = CommandType.StoredProcedure; /* this command may stay pending while other commands are executing so a long timeout is requred */ cmd.CommandTimeout = 0; cmd.Parameters.Add("@sessionId", SqlDbType.UniqueIdentifier).Value = new Guid(Id.ToString()); cmd.Parameters.Add("@url", SqlDbType.VarChar).Value = Host + Url; if(current != null) { cmd.Parameters.Add("@querystring", SqlDbType.VarChar).Value = current.Request.QueryString.ToString().MaxLength(7700, true); } else { cmd.Parameters.Add("@querystring", SqlDbType.VarChar).Value = ""; } /* allows keeping the noise from these directores and virtual responders quiet */ cmd.Parameters.Add("@responder", SqlDbType.VarChar).Value = Main.Responder; cmd.Parameters.Add("@adminResponder", SqlDbType.VarChar).Value = Main.AdminResponder; cmd.Parameters.Add("@adminDirectory", SqlDbType.VarChar).Value = Main.AdminDirectory; using(u = cmd.ExecuteReader()) { if(!u.HasRows) { if(current != null) { current.Response.Cookies.Remove(Main.Site.cookie_name); } CreateNewSession(true); Refresh(); return; } /* read the session header */ if(u.Read()) { UserId = u.GetInt32(0); Zip = u.GetString(1); ShippingRate = u.GetInt32(2); context = u.GetString(3); RecordsPerPage = u.GetInt32(4); ListOrder = u.GetInt32(5); ListView = u.GetInt32(6); Wholesale = u.GetInt32(7); UserLevel = u.GetInt32(8); Email = u.GetString(9); AllowPreorders = u.GetInt32(10); AdminScript = u.GetString(11); LogonRedirect = u.GetString(12); UIJson = u.GetString(13); } /* read the session hash table */ u.NextResult(); while(u.Read()) { string keyName = u.GetString(0); if(!Properties.ContainsKey(keyName)) { Properties.Add(u.GetString(0), u.GetString(1)); } } if(UserId > -1) { User = Main.Site.Users.List.Find(delegate(Commerce.User usr) { if(usr.UserId == UserId) { return true; } return false; }); SiteDefaults = Main.Site.Defaults; LoggedOn = true; } if(UserLevel >= Main.Site.administrator_user_level) { Administrator = true; } } } catch(Exception ex) { String.Format("Exception in Session.refresh > {0}", ex.Message); } finally { cmd.Dispose(); } Cart = new Commerce.Cart(this, this.Site); return; }
/// <summary> /// Initializes a new instance of the <see cref="Session"/> class. /// </summary> /// <param name="_site">The _site.</param> /// <param name="sessionId">The session id.</param> public Session( Site _site, Guid sessionId ) { getServerStateInfo(); if( sessionId == Guid.Empty ) { /* Ask the DB for a new sessionid*/ CreateNewSession( false ); } else { Id = sessionId; Refresh( false ); Cart = new Commerce.Cart( this, this.Site ); } }
/// <summary> /// Initializes a new instance of the <see cref="Session"/> class. /// </summary> /// <param name="_site">The _site.</param> /// <param name="sessionId">The session id.</param> /// <param name="cn">The cn.</param> /// <param name="trns">The TRNS.</param> public Session( Site _site, Guid sessionId, SqlConnection cn, SqlTransaction trns ) { getServerStateInfo(); if( sessionId == Guid.Empty ) { /* Ask the DB for a new sessionid*/ CreateNewSession( false, cn, trns ); } else { Id = sessionId; Refresh( false, cn, trns ); Cart = new Commerce.Cart( this, Site ); } }