Web.config is used for application configuration

main
Inga 🏳‍🌈 15 years ago
parent 7901f25ed7
commit d5f24d33ba
  1. 11
      Common/Config.cs
  2. 22
      Core/Config.cs
  3. 1
      Core/Core.csproj
  4. 1
      IISMainHandler/IISMainHandler.csproj
  5. 3
      IISMainHandler/MainHandler.cs
  6. 6
      IISMainHandler/WebContext.cs
  7. 1
      IISMainHandler/handlers/DebugHandler.cs

@ -2,16 +2,21 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Collections.Specialized;
namespace FLocal.Common { namespace FLocal.Common {
public class Config : FLocal.Core.Config<Config> { public class Config : FLocal.Core.Config<Config> {
protected Config() : base() { protected Config(NameValueCollection data) : base(data) {
} }
public static void Init() { public static void Init(NameValueCollection data) {
doInit(() => new Config()); doInit(() => new Config(data));
}
public static void ReInit(NameValueCollection data) {
doReInit(() => new Config(data));
} }
} }

@ -2,12 +2,13 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Collections.Specialized;
namespace FLocal.Core { namespace FLocal.Core {
public class Config<T> where T : Config<T> { public class Config<T> where T : Config<T> {
private static T _instance; private static T _instance = null;
public static T instance { public static T instance {
get { 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<T> configCreator) { protected static void doInit(Func<T> configCreator) {
if(_instance != null) throw new FLocalException("already initialized"); if(_instance != null) throw new FLocalException("already initialized");
lock(_instance) { lock(typeof(Config<T>)) {
if(_instance != null) throw new FLocalException("already initialized"); if(_instance != null) throw new FLocalException("already initialized");
_instance = configCreator(); _instance = configCreator();
} }
} }
protected static void doReInit(Func<T> configCreator) {
lock(typeof(Config<T>)) {
_instance = configCreator();
}
}
} }
} }

@ -64,6 +64,7 @@
<Compile Include="DB\ITableSpec.cs" /> <Compile Include="DB\ITableSpec.cs" />
<Compile Include="DB\JoinSpec.cs" /> <Compile Include="DB\JoinSpec.cs" />
<Compile Include="DB\SortSpec.cs" /> <Compile Include="DB\SortSpec.cs" />
<Compile Include="DB\Transaction.cs" />
<Compile Include="delegates\Lazy.cs" /> <Compile Include="delegates\Lazy.cs" />
<Compile Include="delegates\Predicate.cs" /> <Compile Include="delegates\Predicate.cs" />
<Compile Include="exceptions\CriticalException.cs" /> <Compile Include="exceptions\CriticalException.cs" />

@ -32,6 +32,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Web; using System.Web;
using System.Configuration;
namespace FLocal.IISHandler { namespace FLocal.IISHandler {
public class MainHandler : IHttpHandler { public class MainHandler : IHttpHandler {
@ -12,6 +13,8 @@ namespace FLocal.IISHandler {
} }
public void ProcessRequest(HttpContext httpcontext) { public void ProcessRequest(HttpContext httpcontext) {
FLocal.Common.Config.ReInit(ConfigurationManager.AppSettings);
WebContext context = new WebContext(httpcontext); WebContext context = new WebContext(httpcontext);
ISpecificHandler handler = HandlersFactory.getHandler(context); ISpecificHandler handler = HandlersFactory.getHandler(context);
handler.Handle(context); handler.Handle(context);

@ -27,6 +27,12 @@ namespace FLocal.IISHandler {
} }
} }
public Common.Config config {
get {
return Common.Config.instance;
}
}
public WebContext(HttpContext httpcontext) { public WebContext(HttpContext httpcontext) {
this.httpcontext = httpcontext; this.httpcontext = httpcontext;
} }

@ -18,6 +18,7 @@ namespace FLocal.IISHandler.handlers {
context.httpresponse.WriteLine("Page: " + this.type); context.httpresponse.WriteLine("Page: " + this.type);
context.httpresponse.WriteLine("Path: " + context.httprequest.Path); context.httpresponse.WriteLine("Path: " + context.httprequest.Path);
context.httpresponse.WriteLine("PathInfo: " + context.httprequest.PathInfo); context.httpresponse.WriteLine("PathInfo: " + context.httprequest.PathInfo);
context.httpresponse.WriteLine("AppInfo: " + context.config.AppInfo);
} }
} }

Loading…
Cancel
Save