[gbrainy] Thread friendly session storage + plus Help namespace fix



commit 9bb6193e0b2b68ea8e6076181bdd5c53380e2ca5
Author: Jordi Mas <jmas softcatala org>
Date:   Sun Nov 20 18:05:01 2011 +0100

    Thread friendly session storage + plus Help namespace fix

 src/Clients/WebForms/Global.asax.cs        |   68 +++++++++++++++++++---------
 src/Clients/WebForms/Help.aspx             |    4 +-
 src/Clients/WebForms/Help.aspx.cs          |   21 ++++++++-
 src/Clients/WebForms/Help.aspx.designer.cs |   15 +++++-
 src/Clients/WebForms/Status.aspx.cs        |   10 ++++-
 5 files changed, 89 insertions(+), 29 deletions(-)
---
diff --git a/src/Clients/WebForms/Global.asax.cs b/src/Clients/WebForms/Global.asax.cs
index b63e8c3..217a7d4 100644
--- a/src/Clients/WebForms/Global.asax.cs
+++ b/src/Clients/WebForms/Global.asax.cs
@@ -1,3 +1,21 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i HernÃndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
 
 using System;
 using System.IO;
@@ -60,15 +78,18 @@ namespace gbrainy.Clients.WebForms
 			Logger.Debug ("Global.Session_Start. Session {0}", Session.SessionID);
 
 			WebSession details = new WebSession (HttpContext.Current.Session);
-
-			if (Sessions.ContainsKey (Session.SessionID))
-			{
-				Sessions [Session.SessionID] = details;
-			}
-			else
+			
+			lock (Sessions)
 			{
-				TotalSessions++;
-				Sessions.Add (Session.SessionID, details);
+				if (Sessions.ContainsKey (Session.SessionID))
+				{
+					Sessions [Session.SessionID] = details;
+				}
+				else
+				{
+					TotalSessions++;
+					Sessions.Add (Session.SessionID, details);
+				}
 			}
 		}
 
@@ -101,22 +122,25 @@ namespace gbrainy.Clients.WebForms
 				sessionid = Session.SessionID;
 
 			Logger.Debug ("Global.Session_End. Session {0}", sessionid);
-
-			if (Sessions.ContainsKey (sessionid)) {
-				Sessions.Remove (sessionid);
-
-				try
-				{
-					File.Delete (GameImage.GetImageFileName (Session.SessionID));
-				}
-				catch (Exception ex)
-				{
-					Logger.Error ("Global.Session_End. Could not delete {0}, exception: {1}",
-							GameImage.GetImageFileName (Session.SessionID), ex);
+			
+			lock (Sessions)
+			{
+				if (Sessions.ContainsKey (sessionid)) {
+					Sessions.Remove (sessionid);
+	
+					try
+					{
+						File.Delete (GameImage.GetImageFileName (Session.SessionID));
+					}
+					catch (Exception ex)
+					{
+						Logger.Error ("Global.Session_End. Could not delete {0}, exception: {1}",
+								GameImage.GetImageFileName (Session.SessionID), ex);
+					}
 				}
+				else
+					Logger.Error ("Global.Session_End. Could not find session " + Session.SessionID);
 			}
-			else
-				Logger.Error ("Global.Session_End. Could not find session " + Session.SessionID);
 		}
 
 		protected virtual void Application_End (Object sender, EventArgs e)
diff --git a/src/Clients/WebForms/Help.aspx b/src/Clients/WebForms/Help.aspx
index ca88280..264d02f 100644
--- a/src/Clients/WebForms/Help.aspx
+++ b/src/Clients/WebForms/Help.aspx
@@ -1,4 +1,4 @@
-<%@ Page Language="C#" Inherits="gbrainy.Clients.WebForms.Download" MasterPageFile="~/MasterPage.master" %>
+<%@ Page Language="C#" Inherits="gbrainy.Clients.WebForms.Help" MasterPageFile="~/MasterPage.master" %>
 <%@ MasterType VirtualPath="~/MasterPage.master" %>
 <asp:Content ContentPlaceHolderID="main_placeholder" ID="main_placeholderContent" runat="server">
 	
@@ -78,4 +78,4 @@
 	<ul><li>The enjoyment obtained from a puzzle is proportional to the time spent on it.</li></ul>
 	<ul><li>Think of breaking down every problem into simpler components.</li></ul>
 	<ul><li>When answering verbal analogies pay attention to the verb tense.</li></ul>
-</asp:Content>
\ No newline at end of file
+</asp:Content>
diff --git a/src/Clients/WebForms/Help.aspx.cs b/src/Clients/WebForms/Help.aspx.cs
index fbc16ad..aaa5875 100644
--- a/src/Clients/WebForms/Help.aspx.cs
+++ b/src/Clients/WebForms/Help.aspx.cs
@@ -1,9 +1,28 @@
+/*
+ * Copyright (C) 2011 Jordi Mas i HernÃndez <jmas softcatala org>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
 
 using System;
 using System.Web;
 using System.Web.UI;
 
-namespace WebForms
+namespace gbrainy.Clients.WebForms
 {	public partial class Help : System.Web.UI.Page
 	{
 	}
diff --git a/src/Clients/WebForms/Help.aspx.designer.cs b/src/Clients/WebForms/Help.aspx.designer.cs
index 59b54f7..a045931 100644
--- a/src/Clients/WebForms/Help.aspx.designer.cs
+++ b/src/Clients/WebForms/Help.aspx.designer.cs
@@ -1,7 +1,7 @@
 // ------------------------------------------------------------------------------
 //  <autogenerated>
 //      This code was generated by a tool.
-//      Mono Runtime Version: 2.0.50727.1433
+//      Mono Runtime Version: 4.0.30319.1
 // 
 //      Changes to this file may cause incorrect behavior and will be lost if 
 //      the code is regenerated.
@@ -9,7 +9,16 @@
 // ------------------------------------------------------------------------------
 
 namespace gbrainy.Clients.WebForms {
-
-	public partial class Download {
+	
+	
+	public partial class Help {
+		
+		protected System.Web.UI.WebControls.Content main_placeholderContent;
+		
+		public new gbrainy.Clients.WebForms.MasterPage Master {
+			get {
+				return ((gbrainy.Clients.WebForms.MasterPage)(base.Master));
+			}
+		}
 	}
 }
diff --git a/src/Clients/WebForms/Status.aspx.cs b/src/Clients/WebForms/Status.aspx.cs
index bc2da07..9f2a347 100644
--- a/src/Clients/WebForms/Status.aspx.cs
+++ b/src/Clients/WebForms/Status.aspx.cs
@@ -56,8 +56,16 @@ namespace gbrainy.Clients.WebForms
 	{
 		updated_label.Text = "Updated: " + DateTime.Now;
 
+		WebSession[] sessions;
+
+		lock (Global.Sessions)
+		{
+			sessions = new WebSession [Global.Sessions.Count];
+			Global.Sessions.Values.CopyTo (sessions, 0);
+		}
+
 		// Sessions
-		foreach (WebSession session in Global.Sessions.Values)
+		foreach (WebSession session in sessions)
 		{
 			TableRow r = new TableRow ();
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]