From: <mar...@us...> - 2010-02-19 14:51:02
|
Revision: 33 http://cronoscontrol.svn.sourceforge.net/cronoscontrol/?rev=33&view=rev Author: marioarce Date: 2010-02-19 14:50:23 +0000 (Fri, 19 Feb 2010) Log Message: ----------- Ticket #5 added the property CronosControlEntities ObjectContext that gets a shared CronosControlEntities instance, created in order to have one shared CronosControlEntities instance per HTTP request see http://dotnetslackers.com/articles/ado_net/Managing-Entity-Framework-ObjectContext-lifespan-and-scope-in-n-layered-ASP-NET-applications.aspx Modified Paths: -------------- source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs Modified: source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs =================================================================== --- source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs 2010-02-19 14:45:32 UTC (rev 32) +++ source/trunk/CronosControl/Libraries/BusinessLogic/CronosControlContext.cs 2010-02-19 14:50:23 UTC (rev 33) @@ -123,6 +123,16 @@ application.Response.Cookies.Remove(key); application.Response.Cookies.Add(cookie); } + + /// <summary> + /// Sets the CultureInfo + /// </summary> + /// <param name="culture">Culture</param> + public void SetCulture(CultureInfo culture) + { + Thread.CurrentThread.CurrentCulture = culture; + Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; + } #endregion #region Properties @@ -147,21 +157,6 @@ } /// <summary> - /// Gets or sets a value indicating whether the context is running in admin-mode - /// </summary> - public bool IsAdmin - { - get - { - return isAdmin; - } - set - { - isAdmin = value; - } - } - - /// <summary> /// Gets or sets an object item in the context by the specified key. /// </summary> /// <param name="key">The key of the value to get.</param> @@ -193,73 +188,96 @@ } /// <summary> - /// Gets or sets the current session + /// Gets or sets the current project /// </summary> - public ProjectUserSession Session + public Project CurrentProject { get { - return this.GetSession(false); + return this.currentProject; } set { - Current[CONST_PROJECTUSERSESSION] = value; + this.currentProject = value; } } /// <summary> - /// Gets or sets the current user + /// Gets or sets the current company /// </summary> - public User User + public Company CurrentCompany { get { - return this.currentProjectUser; + return this.currentCompany; } set { - this.currentProjectUser = value; + this.currentCompany = value; } } /// <summary> - /// Gets or sets the current project + /// Gets or sets a value indicating whether the context is running in admin-mode /// </summary> - public Project CurrentProject + public bool IsAdmin { get { - return this.currentProject; + return isAdmin; } set { - this.currentProject = value; + isAdmin = value; } } /// <summary> - /// Gets or sets the current company + /// Gets a shared CronosControlEntities instance /// </summary> - public Company CurrentCompany + public CronosControlEntities ObjectContext { get { - return this.currentCompany; + string objectContextKey = "cronosControlObjectContext_" + HttpContext.Current.GetHashCode().ToString("x"); + if (!HttpContext.Current.Items.Contains(objectContextKey)) + { + HttpContext.Current.Items.Add(objectContextKey, new CronosControlEntities()); + } + // one shared CronosControlEntities instance per HTTP request + // see http://dotnetslackers.com/articles/ado_net/Managing-Entity-Framework-ObjectContext-lifespan-and-scope-in-n-layered-ASP-NET-applications.aspx + return HttpContext.Current.Items[objectContextKey] as CronosControlEntities; } + } + + /// <summary> + /// Gets or sets the current session + /// </summary> + public ProjectUserSession Session + { + get + { + return this.GetSession(false); + } set { - this.currentCompany = value; + Current[CONST_PROJECTUSERSESSION] = value; } } /// <summary> - /// Sets the CultureInfo + /// Gets or sets the current user /// </summary> - /// <param name="culture">Culture</param> - public void SetCulture(CultureInfo culture) + public User User { - Thread.CurrentThread.CurrentCulture = culture; - Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture; + get + { + return this.currentProjectUser; + } + set + { + this.currentProjectUser = value; + } } #endregion } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |