Commit c95ffa4

mo <email@solidware.ca>
2011-03-20 05:14:18
add simple context and scoped storage context.
1 parent d6b3738
product/infrastructure/threading/BackgroundThreadFactory.cs
@@ -21,12 +21,12 @@ namespace gorilla.infrastructure.threading
 
         public IBackgroundThread create_for<CommandToExecute>() where CommandToExecute : DisposableCommand
         {
-            return new BackgroundThread(registry.get_a<CommandToExecute>());
+            return new WorkderBackgroundThread(registry.get_a<CommandToExecute>());
         }
 
         public IBackgroundThread create_for(Action action)
         {
-            return new BackgroundThread(new AnonymousDisposableCommand(action));
+            return new WorkderBackgroundThread(new AnonymousDisposableCommand(action));
         }
 
         class AnonymousDisposableCommand : DisposableCommand
product/infrastructure/threading/PerThread.cs
@@ -6,7 +6,7 @@ using gorilla.utility;
 
 namespace gorilla.infrastructure.threading
 {
-    public class PerThread : IContext
+    public class PerThread : Context
     {
         readonly IDictionary<int, LocalDataStoreSlot> slots;
         readonly object mutex = new object();
product/infrastructure/threading/ThreadingExtensions.cs
@@ -6,7 +6,7 @@ namespace gorilla.infrastructure.threading
     {
         static public IBackgroundThread on_a_background_thread(this DisposableCommand command)
         {
-            return new BackgroundThread(command);
+            return new WorkderBackgroundThread(command);
         }
     }
 }
\ No newline at end of file
product/infrastructure/threading/BackgroundThread.cs → product/infrastructure/threading/WorkderBackgroundThread.cs
@@ -4,13 +4,13 @@ namespace gorilla.infrastructure.threading
 {
     public interface IBackgroundThread : DisposableCommand {}
 
-    public class BackgroundThread : IBackgroundThread
+    public class WorkderBackgroundThread : IBackgroundThread
     {
         readonly IWorkerThread worker_thread;
 
-        public BackgroundThread(DisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread()) {}
+        public WorkderBackgroundThread(DisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread()) {}
 
-        public BackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread)
+        public WorkderBackgroundThread(DisposableCommand command_to_execute, IWorkerThread worker_thread)
         {
             this.worker_thread = worker_thread;
             worker_thread.DoWork += (sender, e) => command_to_execute.run();
product/infrastructure/infrastructure.csproj
@@ -91,7 +91,7 @@
     <Compile Include="reflection\Assembly.cs" />
     <Compile Include="registries\DefaultRegistry.cs" />
     <Compile Include="threading\AsynchronousCommandProcessor.cs" />
-    <Compile Include="threading\BackgroundThread.cs" />
+    <Compile Include="threading\WorkderBackgroundThread.cs" />
     <Compile Include="threading\BackgroundThreadFactory.cs" />
     <Compile Include="threading\CommandProcessor.cs" />
     <Compile Include="threading\CurrentThread.cs" />
product/utility/IContext.cs → product/utility/Context.cs
@@ -1,6 +1,6 @@
 namespace gorilla.utility
 {
-    public interface IContext
+    public interface Context
     {
         bool contains<T>(Key<T> key);
         void add<T>(Key<T> key, T value);
product/utility/ScopedContext.cs
@@ -0,0 +1,32 @@
+namespace gorilla.utility
+{
+    public class ScopedContext : Context
+    {
+        IScopedStorage storage;
+
+        public ScopedContext(IScopedStorage storage)
+        {
+            this.storage = storage;
+        }
+
+        public bool contains<T>(Key<T> key)
+        {
+            return key.is_found_in(storage.provide_storage());
+        }
+
+        public void add<T>(Key<T> key, T value)
+        {
+            key.add_value_to(storage.provide_storage(), value);
+        }
+
+        public T value_for<T>(Key<T> key)
+        {
+            return key.parse_from(storage.provide_storage());
+        }
+
+        public void remove<T>(Key<T> key)
+        {
+            key.remove_from(storage.provide_storage());
+        }
+    }
+}
\ No newline at end of file
product/utility/SimpleContext.cs
@@ -0,0 +1,34 @@
+using System.Collections;
+
+namespace gorilla.utility
+{
+    public class SimpleContext : Context
+    {
+        Hashtable items;
+
+        public SimpleContext(Hashtable items)
+        {
+            this.items = items;
+        }
+
+        public bool contains<T>(Key<T> key)
+        {
+            return key.is_found_in(items);
+        }
+
+        public void add<T>(Key<T> key, T value)
+        {
+            key.add_value_to(items, value);
+        }
+
+        public T value_for<T>(Key<T> key)
+        {
+            return key.parse_from(items);
+        }
+
+        public void remove<T>(Key<T> key)
+        {
+            key.remove_from(items);
+        }
+    }
+}
\ No newline at end of file
product/utility/utility.csproj
@@ -79,7 +79,7 @@
     <Compile Include="Command.cs" />
     <Compile Include="Configuration.cs" />
     <Compile Include="ComponentFactory.cs" />
-    <Compile Include="IContext.cs" />
+    <Compile Include="Context.cs" />
     <Compile Include="Id.cs" />
     <Compile Include="DisposableCommand.cs" />
     <Compile Include="Factory.cs" />
@@ -92,7 +92,9 @@
     <Compile Include="Parser.cs" />
     <Compile Include="Query.cs" />
     <Compile Include="Registry.cs" />
+    <Compile Include="ScopedContext.cs" />
     <Compile Include="Settings.cs" />
+    <Compile Include="SimpleContext.cs" />
     <Compile Include="Specification.cs" />
     <Compile Include="State.cs" />
     <Compile Include="SubjectOf.cs" />