From d5f24d33ba90f7f361af51a67b33246db1693963 Mon Sep 17 00:00:00 2001 From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com> Date: Sun, 6 Jun 2010 12:16:43 +0000 Subject: [PATCH] Web.config is used for application configuration --- Common/Config.cs | 11 ++++++++--- Core/Config.cs | 22 +++++++++++++++++++--- Core/Core.csproj | 1 + IISMainHandler/IISMainHandler.csproj | 1 + IISMainHandler/MainHandler.cs | 3 +++ IISMainHandler/WebContext.cs | 6 ++++++ IISMainHandler/handlers/DebugHandler.cs | 1 + 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Common/Config.cs b/Common/Config.cs index 0ef6436..0f1e0cd 100644 --- a/Common/Config.cs +++ b/Common/Config.cs @@ -2,16 +2,21 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Collections.Specialized; namespace FLocal.Common { public class Config : FLocal.Core.Config { - protected Config() : base() { + protected Config(NameValueCollection data) : base(data) { } - public static void Init() { - doInit(() => new Config()); + public static void Init(NameValueCollection data) { + doInit(() => new Config(data)); + } + + public static void ReInit(NameValueCollection data) { + doReInit(() => new Config(data)); } } diff --git a/Core/Config.cs b/Core/Config.cs index bbd14d9..4d624af 100644 --- a/Core/Config.cs +++ b/Core/Config.cs @@ -2,12 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Collections.Specialized; namespace FLocal.Core { public class Config where T : Config { - private static T _instance; + private static T _instance = null; public static T instance { get { @@ -16,16 +17,31 @@ namespace FLocal.Core { } } - protected Config() { + private NameValueCollection data; + + public string AppInfo { + get { + return data["AppInfo"]; + } + } + + protected Config(NameValueCollection data) { + this.data = data; } protected static void doInit(Func configCreator) { if(_instance != null) throw new FLocalException("already initialized"); - lock(_instance) { + lock(typeof(Config)) { if(_instance != null) throw new FLocalException("already initialized"); _instance = configCreator(); } } + protected static void doReInit(Func configCreator) { + lock(typeof(Config)) { + _instance = configCreator(); + } + } + } } diff --git a/Core/Core.csproj b/Core/Core.csproj index cad1790..0016adb 100644 --- a/Core/Core.csproj +++ b/Core/Core.csproj @@ -64,6 +64,7 @@ + diff --git a/IISMainHandler/IISMainHandler.csproj b/IISMainHandler/IISMainHandler.csproj index f6a0eee..7138d5c 100644 --- a/IISMainHandler/IISMainHandler.csproj +++ b/IISMainHandler/IISMainHandler.csproj @@ -32,6 +32,7 @@ + 3.5 diff --git a/IISMainHandler/MainHandler.cs b/IISMainHandler/MainHandler.cs index b54e77f..f00bc48 100644 --- a/IISMainHandler/MainHandler.cs +++ b/IISMainHandler/MainHandler.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; +using System.Configuration; namespace FLocal.IISHandler { public class MainHandler : IHttpHandler { @@ -12,6 +13,8 @@ namespace FLocal.IISHandler { } public void ProcessRequest(HttpContext httpcontext) { + FLocal.Common.Config.ReInit(ConfigurationManager.AppSettings); + WebContext context = new WebContext(httpcontext); ISpecificHandler handler = HandlersFactory.getHandler(context); handler.Handle(context); diff --git a/IISMainHandler/WebContext.cs b/IISMainHandler/WebContext.cs index d9497b1..4f75958 100644 --- a/IISMainHandler/WebContext.cs +++ b/IISMainHandler/WebContext.cs @@ -27,6 +27,12 @@ namespace FLocal.IISHandler { } } + public Common.Config config { + get { + return Common.Config.instance; + } + } + public WebContext(HttpContext httpcontext) { this.httpcontext = httpcontext; } diff --git a/IISMainHandler/handlers/DebugHandler.cs b/IISMainHandler/handlers/DebugHandler.cs index 03639c0..6576dc3 100644 --- a/IISMainHandler/handlers/DebugHandler.cs +++ b/IISMainHandler/handlers/DebugHandler.cs @@ -18,6 +18,7 @@ namespace FLocal.IISHandler.handlers { context.httpresponse.WriteLine("Page: " + this.type); context.httpresponse.WriteLine("Path: " + context.httprequest.Path); context.httpresponse.WriteLine("PathInfo: " + context.httprequest.PathInfo); + context.httpresponse.WriteLine("AppInfo: " + context.config.AppInfo); } }