Permalink
Browse files

Big big code cleanup (from StyleCop scan)

  • Loading branch information...
Chakrit Wichian
Chakrit Wichian committed Jul 20, 2010
1 parent c13102b commit f98ee1295b282c2601894a7969a39ce5434b7fbe
View
@@ -5,3 +5,4 @@ test_bin
TestResults
*.suo
*.user
+*.Cache
@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
-using NHaml;
-
using Fu.Services.Templating;
namespace Fu.Results
@@ -26,7 +24,7 @@ public HamlResult(string hamlFilename, params string[] layouts)
protected override IEnumerable<string> GetTemplateNames(IFuContext context)
- { return new[] { HamlFilename }.Concat(LayoutFilenames); }
+ { return (new[] { HamlFilename }).Concat(LayoutFilenames); }
protected override System.Type GetTemplateType(IFuContext context)
{ return typeof(HamlTemplateBase); }
@@ -3,13 +3,12 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Net.Mime;
using System.Text;
-using NHaml;
-
using Fu.Services.Templating;
+using NHaml;
+
namespace Fu.Results
{
public abstract class HamlResultBase : ResultBase
View
@@ -1,37 +0,0 @@
-
-using System;
-using System.Web;
-using System.Web.Hosting;
-using System.IO;
-
-namespace Fu
-{
- // TODO:
- public class AspNetHost : MarshalByRefObject
- {
- //private IApp _app;
-
-
- public static AspNetHost Create(IApp app)
- {
- var host = (AspNetHost)ApplicationHost.CreateApplicationHost(
- typeof(AspNetHost), "/", app.Settings.BasePath);
-
- host.Initialize(app);
- return host;
- }
-
- private void Initialize(IApp app)
- {
-
- }
-
-
- public void ProcessRequest(string page, string query, string output)
- {
- var writer = (TextWriter)File.CreateText(output);
- //var request = new SimpleWorkerRequest(page, query, output);
- //HttpRuntime.ProcessRequest(request);
- }
- }
-}
View
@@ -57,7 +57,6 @@
<Compile Include="..\..\FuAssemblyInfo.cs">
<Link>Properties\FuAssemblyInfo.cs</Link>
</Compile>
- <Compile Include="AspNetApp.cs" />
<Compile Include="Presets\ControllersBasedApp.cs" />
<Compile Include="IFuController.cs" />
<Compile Include="FuController.cs" />
@@ -1,65 +1,50 @@
using System;
-using System.Threading;
using ISessionDict = System.Collections.Generic.IDictionary<string, Fu.Services.Sessions.ISession>;
-using SessionDict = System.Collections.Generic.Dictionary<string, Fu.Services.Sessions.ISession>;
+using SessionDict = System.Collections.Concurrent.ConcurrentDictionary<string, Fu.Services.Sessions.ISession>;
namespace Fu.Services.Sessions
{
public class DictionarySessionStore : ISessionStore
{
- // TODO: Eliminate locks
- ReaderWriterLockSlim _lock;
- ISessionDict _sessions;
+ private ISessionDict _sessions;
public DictionarySessionStore()
{
- _lock = new ReaderWriterLockSlim();
_sessions = new SessionDict();
}
public ISession CreateSession(string sessionId)
{
try {
- _lock.EnterWriteLock();
- if (_sessions.ContainsKey(sessionId))
- throw new InvalidOperationException(string.Format(
- @"DictionarySessionStore.CreateNew: Session Id #{0} already exists",
- sessionId));
-
- var session = new DictionarySession(sessionId);
- _sessions.Add(sessionId, session);
-
- return session;
+ // reserve a session id
+ // this line will throw an exception if the id already exists
+ _sessions.Add(sessionId, null);
+ return _sessions[sessionId] = new DictionarySession(sessionId);
+ }
+ catch (ArgumentException e) {
+ throw new InvalidOperationException(string.Format(
+ @"DictionarySessionStore.CreateNew: Session Id #{0} already exists",
+ sessionId), e);
}
- finally { _lock.ExitWriteLock(); }
}
public ISession GetSession(string sessionId)
{
- try {
- _lock.EnterReadLock();
- ISession result;
- if (_sessions.TryGetValue(sessionId, out result))
- return result;
+ ISession result;
+ if (_sessions.TryGetValue(sessionId, out result))
+ return result;
- return null;
- }
- finally { _lock.ExitReadLock(); }
+ return null;
}
public void DeleteSession(string sessionId)
{
- try {
- _lock.EnterWriteLock();
- if (_sessions.ContainsKey(sessionId))
- _sessions.Remove(sessionId);
-
- }
- finally { _lock.ExitWriteLock(); }
+ if (_sessions.ContainsKey(sessionId))
+ _sessions.Remove(sessionId);
}
public void DeleteSession(ISession session)
@@ -36,10 +36,10 @@ public class StronglyTypedSessionWrapperGenerator
unit.ReferencedAssemblies.Add(targetAsmFilename);
CompilerResults result;
- //TempFileCollection tfc = new TempFileCollection(
- // Environment.CurrentDirectory, true);
+ // TempFileCollection tfc = new TempFileCollection(
+ // Environment.CurrentDirectory, true);
- //result = new CompilerResults(tfc);
+ // result = new CompilerResults(tfc);
result = provider.CompileAssemblyFromDom(new CompilerParameters {
GenerateExecutable = false,
GenerateInMemory = false,
View
@@ -1,3 +1,4 @@
+// <auto-generated />
using System;
View
@@ -9,6 +9,7 @@
desc["BadRequestDataException"] =
"Unable to parse the request data.";
#>
+// <auto-generated />
using System;
View
@@ -1,24 +1,24 @@
using System;
-using System.Collections.Generic;
-using System.Xml.Serialization;
using System.IO;
+using System.Xml.Serialization;
namespace Fu
{
[Serializable]
public partial class FuSettings
{
+ public readonly SessionSettings Session = new SessionSettings();
+ public readonly ThreadPoolSettings ThreadPool = new ThreadPoolSettings();
+
+
public string[] Hosts = new[] { "localhost:80" };
public string BasePath = "";
public string Encoding = "utf-8";
public bool EnableStats = false;
public int ListenerThreads = 25;
-
- public readonly SessionSettings Session = new SessionSettings();
- public readonly ThreadPoolSettings ThreadPool = new ThreadPoolSettings();
}
[Serializable]
@@ -1,7 +1,6 @@
-using System.IO;
using System;
-using System.Net.Mime;
+using System.IO;
namespace Fu.Results
{
@@ -7,7 +7,7 @@ namespace Fu.Results
public class CustomResult : ResultBase
{
- public RenderDelegate _render;
+ private RenderDelegate _render;
public CustomResult(string contentType, RenderDelegate renderAction)
{
@@ -1,7 +1,7 @@
using System.IO;
-using System.Text;
using System.Net.Mime;
+using System.Text;
using Fu.Contexts;
@@ -3,6 +3,14 @@ namespace Fu.Services
{
// simple service to provide a static singleton object
// such as settings throughout the app
+ public static class ObjectProvider
+ {
+ public static ObjectProvider<T> For<T>(T obj)
+ {
+ return new ObjectProvider<T>(obj);
+ }
+ }
+
public class ObjectProvider<T> : IService<T>
{
private T _obj;
@@ -13,12 +21,4 @@ public class ObjectProvider<T> : IService<T>
public bool CanGetServiceObject(IFuContext input) { return _obj != null; }
public T GetServiceObject(IFuContext input) { return _obj; }
}
-
- public static class ObjectProvider
- {
- public static ObjectProvider<T> For<T>(T obj)
- {
- return new ObjectProvider<T>(obj);
- }
- }
}
View
@@ -9,6 +9,9 @@ namespace Fu.Steps
// TODO: Still needs tests in the wild to make sure these work properly
public static class Cache
{
+ protected const long OneSecond = 10000 * 1000 /* 10,000 ticks = 1 ms */;
+
+
public static Continuation Expires(this ICacheSteps _, TimeSpan time)
{ return _.Expires(c => DateTime.Now.Add(time)); }
@@ -102,11 +105,9 @@ public static Continuation ETag(this ICacheSteps _, string etag)
private static long roughCompare(DateTime d1, DateTime d2)
{
- const long oneSecond = 10000 * 1000 /* 10,000 ticks = 1 ms */;
-
// eliminate differences smaller than 1 second interval
var result = (d1 - d2).Ticks;
- result -= result % oneSecond;
+ result -= result % OneSecond;
return result;
}
@@ -1,3 +1,4 @@
+// <auto-generated />
using System.Collections.Generic;
@@ -16,6 +16,7 @@
errors[503] = "ServiceUnavailable";
#>
+// <auto-generated />
using System.Collections.Generic;
@@ -1,4 +1,5 @@
-
+// <auto-generated />
+
namespace Fu.Steps
{
public static partial class Http
@@ -12,6 +12,7 @@
status[304] = "NotModified";
#>
+// <auto-generated />
namespace Fu.Steps
{
View
@@ -5,8 +5,7 @@
using Fu.Contexts;
using ContDict = System.Collections.Generic.IDictionary<string, Fu.Continuation>;
-using ContRegexDict = System.Collections.Generic.IDictionary<
- System.Text.RegularExpressions.Regex, Fu.Continuation>;
+using ContRegexDict = System.Collections.Generic.IDictionary<System.Text.RegularExpressions.Regex, Fu.Continuation>;
namespace Fu.Steps
{
View
@@ -2,13 +2,11 @@
using Microsoft.FSharp.Core;
// damn the Units !
-using FSAction =
- Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>;
+// FSAction = void()
+using FSAction = Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>;
-using FSContinuation = // == FSharpFunc<FSAction, FSAction>
- Microsoft.FSharp.Core.FSharpFunc<
- Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>,
- Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>>;
+// FSContinuation == FSharpFunc<FSAction, FSAction>
+using FSContinuation = Microsoft.FSharp.Core.FSharpFunc<Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>, Microsoft.FSharp.Core.FSharpFunc<Fu.IFuContext, Microsoft.FSharp.Core.Unit>>;
namespace Fu
{
@@ -1,4 +1,4 @@
-// AUTOGENERATED
+// <auto-generated />
using Fu.Steps;
namespace Fu
@@ -11,7 +11,7 @@
"Walk"
};
#>
-// AUTOGENERATED
+// <auto-generated />
using Fu.Steps;
namespace Fu

0 comments on commit f98ee12

Please sign in to comment.