Commit 94f8bd7
Changed files (264)
trunk
build
product
Gorilla.Commons.Infrastructure
Debugging
FileSystem
Logging
Proxies
Registries
Threading
Transactions
Gorilla.Commons.Infrastructure.ThirdParty
Castle
DynamicProxy
Interceptors
Windsor
Configuration
Log4Net
Gorilla.Commons.Utility
Core
Extensions
Gorilla.Commons.Windows.Forms
Databinding
Helpers
Keyboard
Gorilla.Commons.Windows.Forms.ThirdParty
MoMoney.DataAccess
MoMoney.Domain
MoMoney.Presentation
MoMoney.Service
MyMoney
trunk/build/lib/app/gorilla/gorilla.commons.infrastructure.dll
Binary file
trunk/build/lib/app/gorilla/gorilla.commons.infrastructure.thirdparty.dll
Binary file
trunk/build/lib/app/gorilla/gorilla.commons.utility.dll
Binary file
trunk/build/lib/app/gorilla/gorilla.commons.windows.forms.dll
Binary file
trunk/build/lib/app/gorilla/gorilla.commons.windows.forms.thirdparty.dll
Binary file
trunk/product/Gorilla.Commons.Infrastructure/Cloning/BinarySerializer.cs
@@ -1,11 +0,0 @@
-using System.Runtime.Serialization.Formatters.Binary;
-
-namespace Gorilla.Commons.Infrastructure.Cloning
-{
- public class BinarySerializer<T> : Serializer<T>
- {
- public BinarySerializer(string file_path) : base(file_path, new BinaryFormatter())
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Cloning/BinarySerializerSpecs.cs
@@ -1,72 +0,0 @@
-using System;
-using System.IO;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using MbUnit.Framework;
-
-namespace Gorilla.Commons.Infrastructure.Cloning
-{
- [Concern(typeof(BinarySerializer<TestItem>))]
- public abstract class behaves_like_serializer : concerns_for<ISerializer<TestItem>>
- {
- public override ISerializer<TestItem> create_sut()
- {
- return new BinarySerializer<TestItem>(file_name);
- }
-
- context c = () => { file_name = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Serialized.dat"); };
-
- after_each_observation aeo = () => { if (File.Exists(file_name)) File.Delete(file_name); };
-
- protected static string file_name;
- }
-
- public class when_serializing_an_item : behaves_like_serializer
- {
- it should_serialize_the_item_to_a_file = () => FileAssert.Exists(file_name);
-
- because b = () => sut.serialize(new TestItem(string.Empty));
- }
-
- public class when_deserializing_an_item : behaves_like_serializer
- {
- it should_be_able_to_deserialize_from_a_serialized_file = () => result.should_be_equal_to(original);
-
- context c = () => { original = new TestItem("hello world"); };
-
- because b = () =>
- {
- sut.serialize(original);
- result = sut.deserialize();
- };
-
- static TestItem original;
- static TestItem result;
- }
-
- [Serializable]
- public class TestItem : IEquatable<TestItem>
- {
- public TestItem(string text)
- {
- Text = text;
- }
-
- public string Text { get; set; }
-
- public bool Equals(TestItem testItem)
- {
- return testItem != null;
- }
-
- public override bool Equals(object obj)
- {
- return ReferenceEquals(this, obj) || Equals(obj as TestItem);
- }
-
- public override int GetHashCode()
- {
- return 0;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Cloning/ISerializer.cs
@@ -1,10 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Cloning
-{
- public interface ISerializer<T> : IDisposable
- {
- void serialize(T to_serialize);
- T deserialize();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Cloning/Prototype.cs
@@ -1,21 +0,0 @@
-using System.IO;
-
-namespace Gorilla.Commons.Infrastructure.Cloning
-{
- public interface IPrototype
- {
- T clone<T>(T item);
- }
-
- public class Prototype : IPrototype
- {
- public T clone<T>(T item)
- {
- using (var serializer = new BinarySerializer<T>(Path.GetTempFileName()))
- {
- serializer.serialize(item);
- return serializer.deserialize();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Cloning/Serializer.cs
@@ -1,34 +0,0 @@
-using System.IO;
-using System.Runtime.Serialization;
-
-namespace Gorilla.Commons.Infrastructure.Cloning
-{
- public class Serializer<T> : ISerializer<T>
- {
- public Serializer(string file_path, IFormatter formatter)
- {
- this.file_path = file_path;
- this.formatter = formatter;
- }
-
- public void serialize(T to_serialize)
- {
- using (var stream = new FileStream(file_path, FileMode.Create, FileAccess.Write))
- formatter.Serialize(stream, to_serialize);
- }
-
- public T deserialize()
- {
- using (var stream = new FileStream(file_path, FileMode.Open, FileAccess.Read))
- return (T) formatter.Deserialize(stream);
- }
-
- public void Dispose()
- {
- File.Delete(file_path);
- }
-
- readonly string file_path;
- readonly IFormatter formatter;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Container/DependencyResolutionException.cs
@@ -1,13 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Container
-{
- public class DependencyResolutionException<T> : Exception
- {
- public DependencyResolutionException(Exception innerException)
- : base("Could not resolve {0}".formatted_using(typeof (T).FullName), innerException)
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Container/IDependencyRegistry.cs
@@ -1,10 +0,0 @@
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Container
-{
- public interface IDependencyRegistry
- {
- Interface get_a<Interface>();
- IEnumerable<Interface> all_the<Interface>();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Container/Resolve.cs
@@ -1,33 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Container
-{
- static public class Resolve
- {
- static IDependencyRegistry underlying_registry;
- static bool initialized;
-
- static public void initialize_with(IDependencyRegistry registry)
- {
- underlying_registry = registry;
- initialized = registry != null;
- }
-
- static public DependencyToResolve the<DependencyToResolve>()
- {
- try
- {
- return underlying_registry.get_a<DependencyToResolve>();
- }
- catch (Exception e)
- {
- throw new DependencyResolutionException<DependencyToResolve>(e);
- }
- }
-
- static public bool is_initialized()
- {
- return initialized;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Container/ResolveSpecs.cs
@@ -1,56 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Container
-{
- [Concern(typeof (Resolve))]
- public abstract class behaves_like_a_inversion_of_control_container : concerns
- {
- }
-
- public class when_resolving_a_dependency_using_the_container : behaves_like_a_inversion_of_control_container
- {
- context c = () =>
- {
- registry = an<IDependencyRegistry>();
- presenter = an<ICommand>();
- registry.is_told_to(x => x.get_a<ICommand>()).it_will_return(presenter);
- Resolve.initialize_with(registry);
- };
-
- because b = () => { result = Resolve.the<ICommand>(); };
-
- it should_leverage_the_underlying_container_it_was_initialized_with =
- () => registry.was_told_to(x => x.get_a<ICommand>());
-
- it should_return_the_resolved_dependency = () => result.should_be_equal_to(presenter);
-
- after_each_observation a = () => Resolve.initialize_with(null);
-
- static IDependencyRegistry registry;
- static ICommand result;
- static ICommand presenter;
- }
-
- public class when_resolving_a_dependency_that_is_not_registered_ : behaves_like_a_inversion_of_control_container
- {
- context c = () =>
- {
- registry = an<IDependencyRegistry>();
- registry.is_told_to(x => x.get_a<ICommand>()).it_will_throw(new Exception());
- Resolve.initialize_with(registry);
- };
-
- because b = () => { the_call = call.to(() => Resolve.the<ICommand>()); };
-
- after_each_observation a = () => Resolve.initialize_with(null);
-
- it should_throw_a_dependency_resolution_exception =
- () => the_call.should_have_thrown<DependencyResolutionException<ICommand>>();
-
- static IDependencyRegistry registry;
- static Action the_call;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Debugging/Launch.cs
@@ -1,15 +0,0 @@
-using System.Diagnostics;
-
-namespace Gorilla.Commons.Infrastructure.Debugging
-{
- static public class Launch
- {
- static public void the_debugger()
- {
-#if DEBUG
- if (Debugger.IsAttached) Debugger.Break();
- else Debugger.Launch();
-#endif
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Eventing/EventAggregator.cs
@@ -1,66 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq.Expressions;
-using System.Threading;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Eventing
-{
- public interface IEventAggregator
- {
- void subscribe_to<Event>(IEventSubscriber<Event> subscriber) where Event : IEvent;
- void subscribe<Listener>(Listener subscriber) where Listener : class;
- void publish<Event>(Event the_event_to_broadcast) where Event : IEvent;
- void publish<T>(Expression<Action<T>> call) where T : class;
- void publish<Event>() where Event : IEvent, new();
- }
-
- public class EventAggregator : IEventAggregator
- {
- readonly SynchronizationContext context;
- readonly HashSet<object> subscribers;
- readonly object mutex;
-
- public EventAggregator(SynchronizationContext context)
- {
- subscribers = new HashSet<object>();
- mutex = new object();
- this.context = context;
- }
-
- public void subscribe_to<Event>(IEventSubscriber<Event> subscriber) where Event : IEvent
- {
- subscribe(subscriber);
- }
-
- public void subscribe<Listener>(Listener subscriber) where Listener : class
- {
- within_lock(() => subscribers.Add(subscriber));
- }
-
- public void publish<Event>(Event the_event_to_broadcast) where Event : IEvent
- {
- process(() => subscribers.call_on_each<IEventSubscriber<Event>>(x => x.notify(the_event_to_broadcast)));
- }
-
- public void publish<T>(Expression<Action<T>> call) where T : class
- {
- process(() => subscribers.each(x => x.call_on(call.Compile())));
- }
-
- public void publish<Event>() where Event : IEvent, new()
- {
- publish(new Event());
- }
-
- void within_lock(Action action)
- {
- lock (mutex) action();
- }
-
- void process(Action action)
- {
- context.Send(x => action(), new object());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Eventing/EventAggregatorSpecs.cs
@@ -1,77 +0,0 @@
-using System.Data;
-using System.Threading;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Rhino.Mocks;
-
-namespace Gorilla.Commons.Infrastructure.Eventing
-{
- public class behaves_like_event_aggregator : concerns_for<IEventAggregator, EventAggregator>
- {
- public override IEventAggregator create_sut()
- {
- return new EventAggregator(new SynchronizationContext());
- }
- }
-
- public class when_a_event_is_raised_in_the_system : behaves_like_event_aggregator
- {
- it should_notify_all_subscribers_of_the_event = () =>
- {
- first_subscriber.was_told_to<IEventSubscriber<TestEvent>>(x => x.notify(message));
- second_subscriber.was_told_to(x => x.notify(message));
- };
-
- it should_not_notify_any_subscribers_that_subscribed_to_a_different_event =
- () => incorrect_subscriber.was_not_told_to(x => x.notify(Arg<AnotherEvent>.Is.Anything));
-
- context c = () =>
- {
- message = new TestEvent();
- first_subscriber = an<IEventSubscriber<TestEvent>>();
- second_subscriber = an<IEventSubscriber<TestEvent>>();
- incorrect_subscriber = an<IEventSubscriber<AnotherEvent>>();
- };
-
- because b = () =>
- {
- sut.subscribe_to(first_subscriber);
- sut.subscribe(second_subscriber);
- sut.publish(message);
- };
-
- static TestEvent message;
- static IEventSubscriber<TestEvent> first_subscriber;
- static IEventSubscriber<TestEvent> second_subscriber;
- static IEventSubscriber<AnotherEvent> incorrect_subscriber;
- }
-
- public class when_publishing_a_call_to_all_subscribers : behaves_like_event_aggregator
- {
- it should_make_the_call_on_each_subscriber = () => connection.was_told_to(x => x.ChangeDatabase("localhost"));
-
- context c = () =>
- {
- connection = an<IDbConnection>();
- command = an<IDbCommand>();
- };
-
- because b = () =>
- {
- sut.subscribe(connection);
- sut.subscribe(command);
- sut.publish<IDbConnection>(x => x.ChangeDatabase("localhost"));
- };
-
- static IDbConnection connection;
- static IDbCommand command;
- }
-
- public class TestEvent : IEvent
- {
- }
-
- public class AnotherEvent : IEvent
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Eventing/IEvent.cs
@@ -1,6 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Eventing
-{
- public interface IEvent
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Eventing/IEventSubscriber.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Eventing
-{
- public interface IEventSubscriber<Event> where Event : IEvent
- {
- void notify(Event message);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/FileSystem/ApplicationFile.cs
@@ -1,64 +0,0 @@
-using System.IO;
-
-namespace Gorilla.Commons.Infrastructure.FileSystem
-{
- public class ApplicationFile : IFile
- {
- public ApplicationFile(string path)
- {
- this.path = path;
- }
-
- public virtual string path { get; private set; }
-
- public virtual bool does_the_file_exist()
- {
- return !string.IsNullOrEmpty(path) && File.Exists(path);
- }
-
- public void copy_to(string other_path)
- {
- File.Copy(path, other_path, true);
- }
-
- public void delete()
- {
- File.Delete(path);
- }
-
- public static implicit operator ApplicationFile(string file_path)
- {
- return new ApplicationFile(file_path);
- }
-
- public static implicit operator string(ApplicationFile file)
- {
- return file.path;
- }
-
- public bool Equals(ApplicationFile other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return Equals(other.path, path);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (ApplicationFile)) return false;
- return Equals((ApplicationFile) obj);
- }
-
- public override int GetHashCode()
- {
- return (path != null ? path.GetHashCode() : 0);
- }
-
- public override string ToString()
- {
- return path;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/FileSystem/IFile.cs
@@ -1,10 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.FileSystem
-{
- public interface IFile
- {
- string path { get; }
- bool does_the_file_exist();
- void copy_to(string path);
- void delete();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/Console/ConsoleLogger.cs
@@ -1,37 +0,0 @@
-using System;
-using System.IO;
-using System.Threading;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Logging.Console
-{
- public class ConsoleLogger : ILogger
- {
- readonly TextWriter writer;
-
- public ConsoleLogger() : this(System.Console.Out)
- {
- }
-
- public ConsoleLogger(TextWriter writer)
- {
- this.writer = writer;
- }
-
- public void informational(string formatted_string, params object[] arguments)
- {
- writer.WriteLine(formatted_string, arguments);
- }
-
- public void debug(string formatted_string, params object[] arguments)
- {
- writer.WriteLine("Thread: {0}, {1}", Thread.CurrentThread.ManagedThreadId,
- formatted_string.formatted_using(arguments));
- }
-
- public void error(Exception e)
- {
- writer.WriteLine("{0}", e);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/ILogFactory.cs
@@ -1,9 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- public interface ILogFactory
- {
- ILogger create_for(Type type_to_create_logger_for);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/ILoggable.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- public interface ILoggable
- {
-
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/ILogger.cs
@@ -1,11 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- public interface ILogger
- {
- void informational(string formatted_string, params object[] arguments);
- void debug(string formatted_string, params object[] arguments);
- void error(Exception e);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/Log.cs
@@ -1,26 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Infrastructure.Logging.Console;
-
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- public static class Log
- {
- public static ILogger For<T>(T item_to_create_logger_for)
- {
- return For(typeof (T));
- }
-
- public static ILogger For(Type type_to_create_a_logger_for)
- {
- try
- {
- return Resolve.the<ILogFactory>().create_for(type_to_create_a_logger_for);
- }
- catch
- {
- return new ConsoleLogger();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/LoggingExtensions.cs
@@ -1,17 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- public static class LoggingExtensions
- {
- public static ILogger log<T>(this T item_to_log)
- {
- return Log.For(item_to_log);
- }
-
- public static void add_to_log(this Exception error_to_log)
- {
- Log.For(error_to_log).error(error_to_log);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Logging/LogSpecs.cs
@@ -1,31 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Logging
-{
- [Concern(typeof (Log))]
- public class when_creating_a_logger_for_a_particular_type_ : concerns
- {
- it should_return_the_logger_created_for_that_type = () => result.should_be_equal_to(logger);
-
- context c =
- () =>
- {
- var factory = an<ILogFactory>();
- var registry = an<IDependencyRegistry>();
- logger = an<ILogger>();
- registry.is_told_to(x => x.get_a<ILogFactory>()).it_will_return(factory);
- factory.is_told_to(x => x.create_for(typeof (string))).it_will_return(logger);
-
- Resolve.initialize_with(registry);
- };
-
- because b = () => { result = Log.For("mo"); };
-
- after_each_observation a = () => Resolve.initialize_with(null);
-
- static ILogger result;
- static ILogger logger;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/ExceptionExtensions.cs
@@ -1,18 +0,0 @@
-using System;
-using System.Reflection;
-
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- static public class ExceptionExtensions
- {
- static readonly MethodInfo method =
- typeof (Exception).GetMethod("InternalPreserveStackTrace",
- BindingFlags.NonPublic | BindingFlags.Instance);
-
- static public Exception preserve_stack_trace(this Exception exception)
- {
- method.Invoke(exception, new object[0]);
- return exception;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/IInterceptor.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- public interface IInterceptor
- {
- void Intercept(IInvocation invocation);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/IInvocation.cs
@@ -1,12 +0,0 @@
-using System.Reflection;
-
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- public interface IInvocation
- {
- void Proceed();
- object[] Arguments { get; }
- MethodInfo Method { get; }
- object ReturnValue { get; set; }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/MethodCallInvocation.cs
@@ -1,47 +0,0 @@
-using System.Collections.Generic;
-using System.Reflection;
-using System.Runtime.Remoting.Messaging;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- public class MethodCallInvocation<T> : IInvocation
- {
- readonly IMethodCallMessage call;
- readonly T target;
- readonly Stack<IInterceptor> interceptors;
-
- public MethodCallInvocation(IEnumerable<IInterceptor> interceptors, IMethodCallMessage call, T target)
- {
- this.call = call;
- this.target = target;
- this.interceptors = new Stack<IInterceptor>(interceptors);
- Arguments = call.Properties["__Args"].downcast_to<object[]>();
- Method = call.MethodBase.downcast_to<MethodInfo>();
- }
-
- public object[] Arguments { get; set; }
-
- public MethodInfo Method { get; set; }
-
- public object ReturnValue { get; set; }
-
- public void Proceed()
- {
- if (interceptors.Count > 0)
- {
- interceptors.Pop().Intercept(this);
- return;
- }
-
- try
- {
- ReturnValue = call.MethodBase.Invoke(target, Arguments);
- }
- catch (TargetInvocationException e)
- {
- throw e.InnerException.preserve_stack_trace();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/ProxyFactory.cs
@@ -1,10 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- static public class ProxyFactory
- {
- static public T Create<T>(T target, params IInterceptor[] interceptors)
- {
- return new RemotingProxyFactory<T>(target, interceptors).CreateProxy();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/ProxyFactorySpecs.cs
@@ -1,57 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- public class ProxyFactorySpecs
- {
- }
-
- public class when_proxying_a_class_with_interceptors_applied : concerns
- {
- context c = () =>
- {
- interceptors = new MyNameIsSlimShadyInterceptor();
- marshal_mathers = new Person("marshall mathers");
- };
-
- because b =
- () => { some_celebrity = ProxyFactory.Create<IPerson>(marshal_mathers, interceptors); };
-
- it should_all_each_interceptor_to_intercept_the_invocation =
- () => some_celebrity.what_is_your_name().should_be_equal_to("slim shady");
-
- static Person marshal_mathers;
- static IPerson some_celebrity;
- static IInterceptor interceptors;
- }
-
- public interface IPerson
- {
- string what_is_your_name();
- }
-
- public class Person : IPerson
- {
- readonly string my_name;
-
- public Person(string my_name)
- {
- this.my_name = my_name;
- }
-
- public string what_is_your_name()
- {
- return my_name;
- }
- }
-
- public class MyNameIsSlimShadyInterceptor : IInterceptor
- {
- public void Intercept(IInvocation invocation)
- {
- invocation.Proceed();
- invocation.ReturnValue = "slim shady";
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Proxies/RemotingProxyFactory.cs
@@ -1,44 +0,0 @@
-using System.Collections.Generic;
-using System.Runtime.Remoting.Messaging;
-using System.Runtime.Remoting.Proxies;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Proxies
-{
- public class RemotingProxyFactory<T> : RealProxy
- {
- readonly T target;
- readonly IEnumerable<IInterceptor> interceptors;
-
- public RemotingProxyFactory(T target, IEnumerable<IInterceptor> interceptors) : base(typeof (T))
- {
- this.target = target;
- this.interceptors = interceptors;
- }
-
- public override IMessage Invoke(IMessage message)
- {
- if (message.is_an_implementation_of<IMethodCallMessage>())
- {
- var call = message.downcast_to<IMethodCallMessage>();
- var invocation = new MethodCallInvocation<T>(interceptors, call, target);
- invocation.Proceed();
- return ReturnValue(invocation.ReturnValue, invocation.Arguments, call);
- }
- return null;
- }
-
- IMessage ReturnValue(object return_value, object[] out_parameters, IMethodCallMessage call)
- {
- return new ReturnMessage(return_value,
- out_parameters,
- out_parameters == null ? 0 : out_parameters.Length,
- call.LogicalCallContext, call);
- }
-
- public T CreateProxy()
- {
- return GetTransparentProxy().downcast_to<T>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Reflection/ApplicationAssembly.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-
-namespace Gorilla.Commons.Infrastructure.Reflection
-{
- public class ApplicationAssembly : IAssembly
- {
- readonly Assembly assembly;
-
- public ApplicationAssembly(Assembly assembly)
- {
- this.assembly = assembly;
- }
-
- public IEnumerable<Type> all_types()
- {
- return assembly.GetTypes();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Reflection/EnvironmentExtensions.cs
@@ -1,12 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Reflection
-{
- public static class EnvironmentExtensions
- {
- public static string startup_directory<T>(this T item)
- {
- return AppDomain.CurrentDomain.BaseDirectory;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Reflection/IAssembly.cs
@@ -1,10 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Reflection
-{
- public interface IAssembly
- {
- IEnumerable<Type> all_types();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Registries/DefaultRegistry.cs
@@ -1,21 +0,0 @@
-using System.Collections.Generic;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Registries
-{
- public class DefaultRegistry<T> : IRegistry<T>
- {
- private readonly IDependencyRegistry registry;
-
- public DefaultRegistry(IDependencyRegistry registry)
- {
- this.registry = registry;
- }
-
- public IEnumerable<T> all()
- {
- return registry.all_the<T>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Registries/DefaultRegistrySpecs.cs
@@ -1,35 +0,0 @@
-using System.Collections.Generic;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Registries
-{
- [Concern(typeof (DefaultRegistry<int>))]
- public class when_retrieving_all_the_items_from_the_default_repository :
- concerns_for<IRegistry<int>, DefaultRegistry<int>>
- {
- it should_leverage_the_resolver_to_retrieve_all_the_implementations =
- () => registry.was_told_to(r => r.all_the<int>());
-
- it should_return_the_items_resolved_by_the_registry = () => result.should_contain(24);
-
- context c = () =>
- {
- var items_to_return = new List<int> {24};
- registry = an<IDependencyRegistry>();
- registry.is_told_to(r => r.all_the<int>()).it_will_return(items_to_return);
- };
-
- public override IRegistry<int> create_sut()
- {
- return new DefaultRegistry<int>(registry);
- }
-
- because b = () => { result = sut.all(); };
-
- static IDependencyRegistry registry;
- static IEnumerable<int> result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/AsynchronousCommandProcessor.cs
@@ -1,90 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq.Expressions;
-using System.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public class AsynchronousCommandProcessor : ICommandProcessor
- {
- readonly Queue<ICommand> queued_commands;
- readonly EventWaitHandle manual_reset;
- readonly IList<Thread> worker_threads;
- bool keep_working;
-
- public AsynchronousCommandProcessor()
- {
- queued_commands = new Queue<ICommand>();
- worker_threads = new List<Thread>();
- manual_reset = new ManualResetEvent(false);
- }
-
- public void add(Expression<Action> action_to_process)
- {
- add(new ActionCommand(action_to_process));
- }
-
- public void add(ICommand command_to_process)
- {
- lock (queued_commands)
- {
- if (queued_commands.Contains(command_to_process)) return;
- queued_commands.Enqueue(command_to_process);
- reset_thread();
- }
- }
-
- public void run()
- {
- reset_thread();
- keep_working = true;
- var worker_thread = new Thread(run_commands);
- worker_thread.SetApartmentState(ApartmentState.STA);
- worker_threads.Add(worker_thread);
- worker_thread.Start();
- }
-
- public void stop()
- {
- keep_working = false;
- manual_reset.Set();
- manual_reset.Close();
- }
-
- [STAThread]
- void run_commands()
- {
- while (keep_working)
- {
- manual_reset.WaitOne();
- run_next_command();
- }
- }
-
- void run_next_command()
- {
- ICommand command;
- lock (queued_commands)
- {
- if (queued_commands.Count == 0)
- {
- manual_reset.Reset();
- return;
- }
- command = queued_commands.Dequeue();
- }
- command.run();
- reset_thread();
- }
-
- void reset_thread()
- {
- lock (queued_commands)
- {
- if (queued_commands.Count > 0) manual_reset.Set();
- else manual_reset.Reset();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/BackgroundThread.cs
@@ -1,34 +0,0 @@
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface IBackgroundThread : IDisposableCommand
- {
- }
-
- public class BackgroundThread : IBackgroundThread
- {
- readonly IWorkerThread worker_thread;
-
- public BackgroundThread(IDisposableCommand command_to_execute) : this(command_to_execute, new WorkerThread())
- {
- }
-
- public BackgroundThread(IDisposableCommand command_to_execute, IWorkerThread worker_thread)
- {
- this.worker_thread = worker_thread;
- worker_thread.DoWork += (sender, e) => command_to_execute.run();
- worker_thread.Disposed += (sender, e) => command_to_execute.Dispose();
- }
-
- public void run()
- {
- worker_thread.begin();
- }
-
- public void Dispose()
- {
- worker_thread.Dispose();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/BackgroundThreadFactory.cs
@@ -1,33 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface IBackgroundThreadFactory
- {
- IBackgroundThread create_for<CommandToExecute>() where CommandToExecute : IDisposableCommand;
- IBackgroundThread create_for(Action action);
- }
-
- public class BackgroundThreadFactory : IBackgroundThreadFactory
- {
- private readonly IDependencyRegistry registry;
-
- public BackgroundThreadFactory(IDependencyRegistry registry)
- {
- this.registry = registry;
- }
-
- public IBackgroundThread create_for<CommandToExecute>() where CommandToExecute : IDisposableCommand
- {
- return new BackgroundThread(registry.get_a<CommandToExecute>());
- }
-
- public IBackgroundThread create_for(Action action)
- {
- return new BackgroundThread(new DisposableCommand(action));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/BackgroundThreadFactorySpecs.cs
@@ -1,27 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Testing;
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Concern(typeof (BackgroundThreadFactory))]
- public abstract class behaves_like_a_background_thread_factory : concerns_for<IBackgroundThreadFactory, BackgroundThreadFactory>
- {
- context c = () => { registry = the_dependency<IDependencyRegistry>(); };
-
- protected static IDependencyRegistry registry;
- }
-
- public class when_creating_a_background_thread : behaves_like_a_background_thread_factory
- {
- it should_return_an_instance_of_a_background_thread = () => result.should_not_be_null();
-
- it should_lookup_an_instance_of_the_command_to_execute =
- () => registry.was_told_to(r => r.get_a<IDisposableCommand>());
-
- because b = () => { result = sut.create_for<IDisposableCommand>(); };
-
- static IBackgroundThread result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/BackgroundThreadSpecs.cs
@@ -1,40 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using MoMoney.Utility.Core;
-using Rhino.Mocks;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Concern(typeof (BackgroundThread))]
- public abstract class behaves_like_a_background_thread : concerns_for<IBackgroundThread, BackgroundThread>
- {
- context c = () =>
- {
- command_to_execute = the_dependency<IDisposableCommand>();
- worker_thread = the_dependency<IWorkerThread>();
- };
-
- protected static IDisposableCommand command_to_execute;
- protected static IWorkerThread worker_thread;
- }
-
- public class when_executing_a_command_on_a_background_thread : behaves_like_a_background_thread
- {
- it should_execute_the_command_asynchronously = () => command_to_execute.was_told_to(c => c.run());
-
- it should_start_the_worker_thread_asynchronously = () => worker_thread.was_told_to(t => t.begin());
-
- because b = () =>
- {
- sut.run();
- worker_thread.Raise(t => t.DoWork += null, null, null);
- };
- }
-
- public class when_disposing_a_background_thread : behaves_like_a_background_thread
- {
- it should_dispose_the_command_running_on_the_thread = () => worker_thread.was_told_to(w => w.Dispose());
-
- because b = () => sut.Dispose();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/CommandProcessor.cs
@@ -1,37 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq.Expressions;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public class CommandProcessor : ICommandProcessor
- {
- readonly Queue<ICommand> queued_commands;
-
- public CommandProcessor()
- {
- queued_commands = new Queue<ICommand>();
- }
-
- public void add(Expression<Action> action_to_process)
- {
- add(new ActionCommand(action_to_process));
- }
-
- public void add(ICommand command_to_process)
- {
- queued_commands.Enqueue(command_to_process);
- }
-
- public void run()
- {
- while (queued_commands.Count > 0) queued_commands.Dequeue().run();
- }
-
- public void stop()
- {
- queued_commands.Clear();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/CommandProcessorSpecs.cs
@@ -1,51 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Concern(typeof (CommandProcessor))]
- public abstract class behaves_like_a_command_processor : concerns_for<ICommandProcessor, CommandProcessor>
- {
- }
-
- public class when_running_all_the_queued_commands_waiting_for_execution : behaves_like_a_command_processor
- {
- it should_run_the_first_command_in_the_queue = () => first_command.was_told_to(f => f.run());
-
- it should_run_the_second_command_in_the_queue = () => second_command.was_told_to(f => f.run());
-
- context c = () =>
- {
- first_command = an<ICommand>();
- second_command = an<ICommand>();
- };
-
- because b = () =>
- {
- sut.add(first_command);
- sut.add(second_command);
- sut.run();
- };
-
- static ICommand first_command;
- static ICommand second_command;
- }
-
- public class when_attempting_to_rerun_the_command_processor : behaves_like_a_command_processor
- {
- it should_not_re_run_the_commands_that_have_already_executed =
- () => first_command.was_told_to(f => f.run()).only_once();
-
- context c = () => { first_command = an<ICommand>(); };
-
- because b = () =>
- {
- sut.add(first_command);
- sut.run();
- sut.run();
- };
-
- static ICommand first_command;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/ICommandProcessor.cs
@@ -1,13 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ICommandProcessor : ICommand
- {
- void add(Expression<Action> action_to_process);
- void add(ICommand command_to_process);
- void stop();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/IntervalTimer.cs
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Timers;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ITimer
- {
- void start_notifying(ITimerClient client_to_be_notified, TimeSpan span);
- void stop_notifying(ITimerClient client_to_stop_notifying);
- }
-
- public class IntervalTimer : ITimer
- {
- readonly ITimerFactory factory;
- readonly IDictionary<ITimerClient, Timer> timers;
-
- public IntervalTimer() : this(new TimerFactory())
- {
- }
-
- public IntervalTimer(ITimerFactory factory)
- {
- this.factory = factory;
- timers = new Dictionary<ITimerClient, Timer>();
- }
-
- public void start_notifying(ITimerClient client_to_be_notified, TimeSpan span)
- {
- stop_notifying(client_to_be_notified);
-
- var timer = factory.create_for(span);
- timer.Elapsed += (sender, args) => client_to_be_notified.notify();
- timer.Start();
- timers[client_to_be_notified] = timer;
- }
-
- public void stop_notifying(ITimerClient client_to_stop_notifying)
- {
- if (!timers.ContainsKey(client_to_stop_notifying)) return;
- timers[client_to_stop_notifying].Stop();
- timers[client_to_stop_notifying].Dispose();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/IntervalTimerSpecs.cs
@@ -1,125 +0,0 @@
-using System;
-using System.Timers;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Rhino.Mocks;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Concern(typeof (IntervalTimer))]
- public abstract class behaves_like_an_interval_timer : concerns_for<ITimer, IntervalTimer>
- {
- context c = () => { factory = the_dependency<ITimerFactory>(); };
-
- protected static ITimerFactory factory;
- }
-
- public class when_starting_a_timer_for_a_new_client : behaves_like_an_interval_timer
- {
- static ITimerClient client;
- static Timer timer;
-
- it should_create_a_new_timer = () => factory.was_told_to(f => f.create_for(new TimeSpan(0, 10, 0)));
-
- it should_start_the_timer = () => timer.was_told_to(t => t.Start());
-
- context c = () =>
- {
- client = an<ITimerClient>();
- timer = dependency<Timer>();
-
- factory.is_told_to(f => f.create_for(new TimeSpan(0, 10, 0))).it_will_return(timer);
- };
-
- because b = () => sut.start_notifying(client, new TimeSpan(0, 10, 0));
- }
-
- public class when_starting_a_timer_for_an_existing_client : behaves_like_an_interval_timer
- {
- it should_stop_the_previously_started_timer = () =>
- {
- first_timer.was_told_to(t => t.Stop());
- first_timer.was_told_to(t => t.Dispose());
- };
-
- it should_start_a_new_timer = () => second_timer.was_told_to(t => t.Start());
-
- context c = () =>
- {
- client = an<ITimerClient>();
- first_timer = dependency<Timer>();
- second_timer = dependency<Timer>();
-
- factory.is_told_to(f => f.create_for(new TimeSpan(0, 1, 1))).it_will_return(first_timer);
- factory.is_told_to(f => f.create_for(new TimeSpan(0, 2, 2))).it_will_return(second_timer);
- };
-
- because b = () =>
- {
- sut.start_notifying(client, new TimeSpan(0, 1, 1));
- sut.start_notifying(client, new TimeSpan(0, 2, 2));
- };
-
- static ITimerClient client;
- static Timer first_timer;
- static Timer second_timer;
- }
-
- public class when_a_timer_elapses : behaves_like_an_interval_timer
- {
- it should_notify_the_timer_client = () => client.was_told_to(c => c.notify());
-
- static ITimerClient client;
- static Timer timer;
-
- context c = () =>
- {
- client = an<ITimerClient>();
- timer = dependency<Timer>();
- factory.is_told_to(f => f.create_for(Arg<TimeSpan>.Is.Anything)).it_will_return(timer);
- };
-
- because b = () =>
- {
- sut.start_notifying(client, new TimeSpan(0, 10, 0));
- timer.Raise(t => t.Elapsed += null, timer, null);
- };
- }
-
- public class when_stopping_notifications_for_an_existing_timer_client : behaves_like_an_interval_timer
- {
- static ITimerClient client;
- static Timer timer;
-
- it should_stop_the_timer_that_was_started_for_the_client = () => timer.was_told_to(t => t.Stop());
-
- it should_dispose_the_timer_that_was_started_for_the_client = () => timer.was_told_to(t => t.Dispose());
-
- context c = () =>
- {
- client = an<ITimerClient>();
- timer = dependency<Timer>();
-
- when_the(factory).is_told_to(t => t.create_for(Arg<TimeSpan>.Is.Anything)).it_will_return(
- timer);
- };
-
- because b = () =>
- {
- sut.start_notifying(client, new TimeSpan(0, 0, 1));
- sut.stop_notifying(client);
- };
- }
-
- public class when_attempting_to_stop_notification_for_a_client_that_doesnt_have_a_timer_started_for_it :
- behaves_like_an_interval_timer
- {
- it should_not_blow_up = () => { };
-
- context c = () => { client = an<ITimerClient>(); };
-
- because b = () => sut.stop_notifying(client);
-
- static ITimerClient client;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/ISynchronizationContext.cs
@@ -1,8 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ISynchronizationContext : IParameterizedCommand<ICommand>
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/ITimerClient.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ITimerClient
- {
- void notify();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/IWorkerThread.cs
@@ -1,12 +0,0 @@
-using System;
-using System.ComponentModel;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface IWorkerThread : IDisposable
- {
- event DoWorkEventHandler DoWork;
- event EventHandler Disposed;
- void begin();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/SynchronizationContextFactory.cs
@@ -1,25 +0,0 @@
-using System.Threading;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ISynchronizationContextFactory : IFactory<ISynchronizationContext>
- {
- }
-
- public class SynchronizationContextFactory : ISynchronizationContextFactory
- {
- readonly IDependencyRegistry registry;
-
- public SynchronizationContextFactory(IDependencyRegistry registry)
- {
- this.registry = registry;
- }
-
- public ISynchronizationContext create()
- {
- return new SynchronizedContext(registry.get_a<SynchronizationContext>());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/SynchronizedCommand.cs
@@ -1,30 +0,0 @@
-using System;
-using System.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ISynchronizedCommand : IParameterizedCommand<Action>, IParameterizedCommand<ICommand>
- {
- }
-
- public class SynchronizedCommand : ISynchronizedCommand
- {
- readonly SynchronizationContext context;
-
- public SynchronizedCommand(SynchronizationContext context)
- {
- this.context = context;
- }
-
- public void run(Action item)
- {
- context.Post(x => item(), new object());
- }
-
- public void run(ICommand item)
- {
- run(item.run);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/SynchronizedContext.cs
@@ -1,21 +0,0 @@
-using System.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public class SynchronizedContext : ISynchronizationContext
- {
- readonly SynchronizationContext context;
-
- public SynchronizedContext(SynchronizationContext context)
- {
- this.context = context;
- }
-
- public void run(ICommand item)
- {
- context.Post(x => item.run(), new object());
- //context.Send(x => item.run(), new object());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/Synchronizer.cs
@@ -1,189 +0,0 @@
-using System;
-using System.Collections;
-using System.ComponentModel;
-using System.Diagnostics;
-using System.Security.Permissions;
-using System.Threading;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [SecurityPermission(SecurityAction.Demand, ControlThread = true)]
- public class Synchronizer : ISynchronizeInvoke, IDisposable
- {
- readonly WorkerThread worker_thread;
-
- public Synchronizer()
- {
- worker_thread = new WorkerThread(this);
- }
-
- public bool InvokeRequired
- {
- get { return ReferenceEquals(Thread.CurrentThread, worker_thread); }
- }
-
- public IAsyncResult BeginInvoke(Delegate method, object[] args)
- {
- var result = new WorkItem(null, method, args);
- worker_thread.QueueWorkItem(result);
- return result;
- }
-
- public object EndInvoke(IAsyncResult result)
- {
- result.AsyncWaitHandle.WaitOne();
- return ((WorkItem) result).MethodReturnedValue;
- }
-
- public object Invoke(Delegate method, object[] args)
- {
- return EndInvoke(BeginInvoke(method, args));
- }
-
- ~Synchronizer()
- {
- }
-
- public void Dispose()
- {
- worker_thread.Kill();
- }
-
- class WorkerThread
- {
- Thread thread;
- bool end_loop;
- readonly Mutex end_loop_mutex;
- readonly AutoResetEvent item_added;
- Synchronizer synchronizer;
- readonly Queue work_item_queue;
-
- internal WorkerThread(Synchronizer synchronizer)
- {
- this.synchronizer = synchronizer;
- end_loop = false;
- thread = null;
- end_loop_mutex = new Mutex();
- item_added = new AutoResetEvent(false);
- work_item_queue = new Queue();
- CreateThread(true);
- }
-
- internal void QueueWorkItem(WorkItem workItem)
- {
- lock (work_item_queue.SyncRoot)
- {
- work_item_queue.Enqueue(workItem);
- item_added.Set();
- }
- }
-
- bool EndLoop
- {
- set
- {
- end_loop_mutex.WaitOne();
- end_loop = value;
- end_loop_mutex.ReleaseMutex();
- }
- get
- {
- var result = false;
- end_loop_mutex.WaitOne();
- result = end_loop;
- end_loop_mutex.ReleaseMutex();
- return result;
- }
- }
-
- Thread CreateThread(bool autoStart)
- {
- if (thread != null)
- {
- Debug.Assert(false);
- return thread;
- }
- thread = new Thread(Run) {Name = "Synchronizer Worker Thread"};
- if (autoStart)
- {
- thread.Start();
- }
- return thread;
- }
-
- void Start()
- {
- Debug.Assert(thread != null);
- Debug.Assert(thread.IsAlive == false);
- thread.Start();
- }
-
- bool QueueEmpty
- {
- get
- {
- lock (work_item_queue.SyncRoot)
- {
- if (work_item_queue.Count > 0)
- {
- return false;
- }
- return true;
- }
- }
- }
-
- WorkItem GetNext()
- {
- if (QueueEmpty)
- {
- return null;
- }
- lock (work_item_queue.SyncRoot)
- {
- return (WorkItem) work_item_queue.Dequeue();
- }
- }
-
- void Run()
- {
- while (EndLoop == false)
- {
- while (QueueEmpty == false)
- {
- if (EndLoop)
- {
- return;
- }
- var workItem = GetNext();
- workItem.CallBack();
- }
- item_added.WaitOne();
- }
- }
-
- public void Kill()
- {
- //Kill is called on client thread - must use cached thread object
- Debug.Assert(thread != null);
- if (thread.IsAlive == false)
- {
- return;
- }
- EndLoop = true;
- item_added.Set();
-
- //Wait for thread to die
- thread.Join();
- if (end_loop_mutex != null)
- {
- end_loop_mutex.Close();
- }
- if (item_added != null)
- {
- item_added.Close();
- }
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/ThreadingExtensions.cs
@@ -1,12 +0,0 @@
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public static class ThreadingExtensions
- {
- public static IBackgroundThread on_a_background_thread(this IDisposableCommand command)
- {
- return new BackgroundThread(command);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/TimerFactory.cs
@@ -1,22 +0,0 @@
-using System;
-using System.Timers;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public interface ITimerFactory
- {
- Timer create_for(TimeSpan span);
- }
-
- public class TimerFactory : ITimerFactory
- {
- public Timer create_for(TimeSpan span)
- {
- if (span.Seconds > 0) {
- var milliseconds = span.Seconds*1000;
- return new Timer(milliseconds);
- }
- return new Timer(span.Ticks);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/TimerFactorySpecs.cs
@@ -1,41 +0,0 @@
-using System;
-using System.Timers;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Concern(typeof (TimerFactory))]
- public abstract class behaves_like_a_timer_factory : concerns_for<ITimerFactory, TimerFactory>
- {
- public override ITimerFactory create_sut()
- {
- return new TimerFactory();
- }
- }
-
- public class when_creating_a_timer : behaves_like_a_timer_factory
- {
- it should_return_a_timer_with_the_correct_interval = () => result.Interval.should_be_equal_to(1000);
-
- because b = () => { result = sut.create_for(new TimeSpan(0, 0, 1)); };
-
- static Timer result;
- }
-
- public class when_creating_a_timer_with_an_interval_in_milliseconds : behaves_like_a_timer_factory
- {
- it should_return_a_timer_with_the_correct_polling_interval =
- () => result.Interval.should_be_equal_to(milliseconds);
-
- because b = () =>
- {
- var timer_interval = new TimeSpan(50);
- milliseconds = 50;
- result = sut.create_for(timer_interval);
- };
-
- static Timer result;
- static double milliseconds;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/WorkerThread.cs
@@ -1,50 +0,0 @@
-using System;
-using System.ComponentModel;
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- public class WorkerThread : Component, IWorkerThread
- {
- static readonly object do_work_key = new object();
- bool is_running;
- readonly Action background_thread;
-
- public WorkerThread()
- {
- background_thread = worker_thread_start;
- }
-
- public event DoWorkEventHandler DoWork
- {
- add { Events.AddHandler(do_work_key, value); }
- remove { Events.RemoveHandler(do_work_key, value); }
- }
-
- public void begin()
- {
- if (is_running)
- {
- throw new InvalidOperationException("Worker Thread Is Already Running");
- }
- is_running = true;
- background_thread.BeginInvoke(null, null);
- }
-
- void worker_thread_start()
- {
- try
- {
- var handler = (DoWorkEventHandler) Events[do_work_key];
- if (handler != null)
- {
- handler(this, new DoWorkEventArgs(null));
- }
- }
- catch (Exception e)
- {
- this.log().error(e);
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Threading/WorkItem.cs
@@ -1,93 +0,0 @@
-using System;
-using System.Threading;
-
-namespace Gorilla.Commons.Infrastructure.Threading
-{
- [Serializable]
- internal class WorkItem : IAsyncResult
- {
- readonly object[] m_Args;
- readonly object m_AsyncState;
- bool m_Completed;
- readonly Delegate m_Method;
- readonly ManualResetEvent m_Event;
- object m_MethodReturnedValue;
-
- internal WorkItem(object async_state, Delegate method, object[] args)
- {
- m_AsyncState = async_state;
- m_Method = method;
- m_Args = args;
- m_Event = new ManualResetEvent(false);
- m_Completed = false;
- }
-
- //IAsyncResult properties
- object IAsyncResult.AsyncState
- {
- get { return m_AsyncState; }
- }
-
- WaitHandle IAsyncResult.AsyncWaitHandle
- {
- get { return m_Event; }
- }
-
- bool IAsyncResult.CompletedSynchronously
- {
- get { return false; }
- }
-
- bool IAsyncResult.IsCompleted
- {
- get { return Completed; }
- }
-
- bool Completed
- {
- get
- {
- lock (this)
- {
- return m_Completed;
- }
- }
- set
- {
- lock (this)
- {
- m_Completed = value;
- }
- }
- }
-
- //This method is called on the worker thread to execute the method
- internal void CallBack()
- {
- MethodReturnedValue = m_Method.DynamicInvoke(m_Args);
- //Method is done. Signal the world
- m_Event.Set();
- Completed = true;
- }
-
- internal object MethodReturnedValue
- {
- get
- {
- object methodReturnedValue;
- lock (this)
- {
- methodReturnedValue = m_MethodReturnedValue;
- }
- return methodReturnedValue;
- }
- set
- {
- lock (this)
- {
- m_MethodReturnedValue = value;
- }
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/ChangeTracker.cs
@@ -1,59 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class ChangeTracker<T> : IChangeTracker<T> where T : IIdentifiable<Guid>
- {
- readonly ITrackerEntryMapper<T> mapper;
- readonly IStatementRegistry registry;
- readonly IList<ITrackerEntry<T>> items;
- readonly IList<T> to_be_deleted;
-
- public ChangeTracker(ITrackerEntryMapper<T> mapper, IStatementRegistry registry)
- {
- this.mapper = mapper;
- this.registry = registry;
- items = new List<ITrackerEntry<T>>();
- to_be_deleted = new List<T>();
- }
-
- public void register(T entity)
- {
- this.log().debug("registered: {0}", entity);
- items.Add(mapper.map_from(entity));
- }
-
- public void delete(T entity)
- {
- to_be_deleted.Add(entity);
- }
-
- public void commit_to(IDatabase database)
- {
- items.each(x => this.log().debug("committing: {0}", x.current));
- items.each(x => commit(x, database));
- to_be_deleted.each(x => database.apply(registry.prepare_command_for(x)));
- }
-
- public bool is_dirty()
- {
- this.log().debug("is change tracker dirty? {0}",items.Count(x => x.has_changes()) );
- return items.Count(x => x.has_changes()) > 0 || to_be_deleted.Count > 0;
- }
-
- public void Dispose()
- {
- items.Clear();
- }
-
- void commit(ITrackerEntry<T> entry, IDatabase database)
- {
- if (entry.has_changes()) database.apply(registry.prepare_command_for(entry.current));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/ChangeTrackerFactory.cs
@@ -1,23 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class ChangeTrackerFactory : IChangeTrackerFactory
- {
- readonly IStatementRegistry statement_registry;
- readonly IDependencyRegistry registry;
-
- public ChangeTrackerFactory(IStatementRegistry statement_registry, IDependencyRegistry registry)
- {
- this.statement_registry = statement_registry;
- this.registry = registry;
- }
-
- public IChangeTracker<T> create_for<T>() where T : IIdentifiable<Guid>
- {
- return new ChangeTracker<T>(registry.get_a<ITrackerEntryMapper<T>>(), statement_registry);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/ChangeTrackerFactorySpecs.cs
@@ -1,20 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class ChangeTrackerFactorySpecs
- {
- }
-
- public class when_creating_a_change_tracker_for_an_item : concerns_for<IChangeTrackerFactory, ChangeTrackerFactory>
- {
- it should_return_a_new_tracker = () => result.should_not_be_null();
-
- because b = () => { result = sut.create_for<IIdentifiable<Guid>>(); };
-
- static IChangeTracker<IIdentifiable<Guid>> result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/ChangeTrackerSpecs.cs
@@ -1,100 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class ChangeTrackerSpecs
- {
- }
-
- [Concern(typeof (ChangeTracker<IIdentifiable<Guid>>))]
- public abstract class behaves_like_change_tracker :
- concerns_for<IChangeTracker<IIdentifiable<Guid>>, ChangeTracker<IIdentifiable<Guid>>>
- {
- context c = () =>
- {
- mapper = the_dependency<ITrackerEntryMapper<IIdentifiable<Guid>>>();
- registry = the_dependency<IStatementRegistry>();
- };
-
- static protected ITrackerEntryMapper<IIdentifiable<Guid>> mapper;
- static protected IStatementRegistry registry;
- }
-
- public class when_commit_that_changes_made_to_an_item : behaves_like_change_tracker
- {
- it should_save_the_changes_to_the_database = () => database.was_told_to(x => x.apply(statement));
-
- context c = () =>
- {
- item = an<IIdentifiable<Guid>>();
- statement = an<IStatement>();
- database = an<IDatabase>();
- var entry = an<ITrackerEntry<IIdentifiable<Guid>>>();
-
- when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
- when_the(entry).is_told_to(x => x.has_changes()).it_will_return(true);
- when_the(entry).is_told_to(x => x.current).it_will_return(item);
- when_the(registry).is_told_to(x => x.prepare_command_for(item)).it_will_return(statement);
- };
-
- because b = () =>
- {
- sut.register(item);
- sut.commit_to(database);
- };
-
- static IIdentifiable<Guid> item;
- static IDatabase database;
- static IStatement statement;
- }
-
- public class when_checking_if_there_are_changes_and_there_are : behaves_like_change_tracker
- {
- it should_tell_the_truth = () => result.should_be_true();
-
- context c = () =>
- {
- item = an<IIdentifiable<Guid>>();
- var registration = an<ITrackerEntry<IIdentifiable<Guid>>>();
-
- when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(registration);
- when_the(registration).is_told_to(x => x.has_changes()).it_will_return(true);
- when_the(registration).is_told_to(x => x.current).it_will_return(item);
- };
-
- because b = () =>
- {
- sut.register(item);
- result = sut.is_dirty();
- };
-
- static bool result;
- static IIdentifiable<Guid> item;
- }
-
- public class when_checking_if_there_are_changes_and_there_are_not : behaves_like_change_tracker
- {
- it should_tell_the_truth = () => result.should_be_false();
-
- context c = () =>
- {
- item = an<IIdentifiable<Guid>>();
- var entry = an<ITrackerEntry<IIdentifiable<Guid>>>();
-
- when_the(mapper).is_told_to(x => x.map_from(item)).it_will_return(entry);
- when_the(entry).is_told_to(x => x.has_changes()).it_will_return(false);
- };
-
- because b = () =>
- {
- sut.register(item);
- result = sut.is_dirty();
- };
-
- static bool result;
- static IIdentifiable<Guid> item;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/Context.cs
@@ -1,38 +0,0 @@
-using System.Collections;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class Context : IContext
- {
- readonly IDictionary items;
-
- public Context() : this(new Hashtable())
- {
- }
-
- public Context(IDictionary items)
- {
- this.items = items;
- }
-
- public bool contains<T>(IKey<T> key)
- {
- return key.is_found_in(items);
- }
-
- public void add<T>(IKey<T> key, T value)
- {
- key.add_value_to(items, value);
- }
-
- public T value_for<T>(IKey<T> key)
- {
- return key.parse_from(items);
- }
-
- public void remove<T>(IKey<T> key)
- {
- key.remove_from(items);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/EmptyUnitOfWork.cs
@@ -1,21 +0,0 @@
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class EmptyUnitOfWork : IUnitOfWork
- {
- public void commit()
- {
- this.log().debug("committed empty unit of work");
- }
-
- public bool is_dirty()
- {
- return false;
- }
-
- public void Dispose()
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IChangeTracker.cs
@@ -1,17 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IChangeTracker : IDisposable
- {
- bool is_dirty();
- void commit_to(IDatabase database);
- }
-
- public interface IChangeTracker<T> : IChangeTracker where T : IIdentifiable<Guid>
- {
- void register(T value);
- void delete(T entity);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IChangeTrackerFactory.cs
@@ -1,10 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IChangeTrackerFactory
- {
- IChangeTracker<T> create_for<T>() where T : IIdentifiable<Guid>;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IContext.cs
@@ -1,10 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IContext
- {
- bool contains<T>(IKey<T> key);
- void add<T>(IKey<T> key, T value);
- T value_for<T>(IKey<T> key);
- void remove<T>(IKey<T> key);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IDatabase.cs
@@ -1,12 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IDatabase
- {
- IEnumerable<T> fetch_all<T>() where T : IIdentifiable<Guid>;
- void apply(IStatement statement);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IDatabaseConnection.cs
@@ -1,14 +0,0 @@
-using System;
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IDatabaseConnection : IDisposable
- {
- IEnumerable<T> query<T>();
- IEnumerable<T> query<T>(Predicate<T> predicate);
- void delete<T>(T entity);
- void commit();
- void store<T>(T entity);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IdentityMapProxy.cs
@@ -1,50 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class IdentityMapProxy<Key, Value> : IIdentityMap<Key, Value> where Value : IIdentifiable<Guid>
- {
- readonly IIdentityMap<Key, Value> real_map;
- readonly IChangeTracker<Value> change_tracker;
-
- public IdentityMapProxy(IChangeTracker<Value> change_tracker, IIdentityMap<Key, Value> real_map)
- {
- this.change_tracker = change_tracker;
- this.real_map = real_map;
- }
-
- public IEnumerable<Value> all()
- {
- return real_map.all();
- }
-
- public void add(Key key, Value value)
- {
- change_tracker.register(value);
- real_map.add(key, value);
- }
-
- public void update_the_item_for(Key key, Value new_value)
- {
- real_map.update_the_item_for(key, new_value);
- }
-
- public bool contains_an_item_for(Key key)
- {
- return real_map.contains_an_item_for(key);
- }
-
- public Value item_that_belongs_to(Key key)
- {
- return real_map.item_that_belongs_to(key);
- }
-
- public void evict(Key key)
- {
- change_tracker.delete(real_map.item_that_belongs_to(key));
- real_map.evict(key);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IdentityMapSpecs.cs
@@ -1,89 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- [Concern(typeof (IdentityMap<,>))]
- public class behaves_like_identity_map : concerns_for<IIdentityMap<int, string>, IdentityMap<int, string>>
- {
- public override IIdentityMap<int, string> create_sut()
- {
- return new IdentityMap<int, string>();
- }
- }
-
- public class when_getting_an_item_from_the_identity_map_for_an_item_that_has_been_added : behaves_like_identity_map
- {
- it should_return_the_item_that_was_added_for_the_given_key = () => result.should_be_equal_to("1");
-
- because b = () =>
- {
- sut.add(1, "1");
- result = sut.item_that_belongs_to(1);
- };
-
- static string result;
- }
-
- public class when_getting_an_item_from_the_identity_map_that_has_not_been_added : behaves_like_identity_map
- {
- it should_return_the_default_value_for_that_type = () => result.should_be_equal_to(null);
-
- because b = () => { result = sut.item_that_belongs_to(2); };
-
- static string result;
- }
-
- public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_been_added :
- behaves_like_identity_map
- {
- it should_return_true = () => result.should_be_true();
-
- because b = () =>
- {
- sut.add(10, "10");
- result = sut.contains_an_item_for(10);
- };
-
- static bool result;
- }
-
- public class when_checking_if_an_item_has_been_added_to_the_identity_map_that_has_not_been_added :
- behaves_like_identity_map
- {
- it should_return_false = () => result.should_be_false();
-
- because b = () => { result = sut.contains_an_item_for(9); };
-
- static bool result;
- }
-
- public class when_updating_the_value_for_a_key_that_has_already_been_added_to_the_identity_map :
- behaves_like_identity_map
- {
- it should_replace_the_old_item_with_the_new_one = () => result.should_be_equal_to("7");
-
- because b = () =>
- {
- sut.add(6, "6");
- sut.update_the_item_for(6, "7");
- result = sut.item_that_belongs_to(6);
- };
-
- static string result;
- }
-
- public class when_updating_the_value_for_a_key_that_has_not_been_added_to_the_identity_map :
- behaves_like_identity_map
- {
- it should_add_the_new_item = () => result.should_be_equal_to("3");
-
- because b = () =>
- {
- sut.update_the_item_for(3, "3");
- result = sut.item_that_belongs_to(3);
- };
-
- static string result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IIdentityMap.cs
@@ -1,59 +0,0 @@
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IIdentityMap<TKey, TValue>
- {
- IEnumerable<TValue> all();
- void add(TKey key, TValue value);
- void update_the_item_for(TKey key, TValue new_value);
- bool contains_an_item_for(TKey key);
- TValue item_that_belongs_to(TKey key);
- void evict(TKey key);
- }
-
- public class IdentityMap<TKey, TValue> : IIdentityMap<TKey, TValue>
- {
- readonly IDictionary<TKey, TValue> items_in_map;
-
- public IdentityMap() : this(new Dictionary<TKey, TValue>())
- {
- }
-
- public IdentityMap(IDictionary<TKey, TValue> items_in_map)
- {
- this.items_in_map = items_in_map;
- }
-
- public IEnumerable<TValue> all()
- {
- return items_in_map.Values;
- }
-
- public void add(TKey key, TValue value)
- {
- items_in_map.Add(key, value);
- }
-
- public void update_the_item_for(TKey key, TValue new_value)
- {
- if (contains_an_item_for(key)) items_in_map[key] = new_value;
- else add(key, new_value);
- }
-
- public bool contains_an_item_for(TKey key)
- {
- return items_in_map.ContainsKey(key);
- }
-
- public TValue item_that_belongs_to(TKey key)
- {
- return contains_an_item_for(key) ? items_in_map[key] : default(TValue);
- }
-
- public void evict(TKey key)
- {
- if (contains_an_item_for(key)) items_in_map.Remove(key);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IKey.cs
@@ -1,12 +0,0 @@
-using System.Collections;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IKey<T>
- {
- bool is_found_in(IDictionary items);
- T parse_from(IDictionary items);
- void remove_from(IDictionary items);
- void add_value_to(IDictionary items, T value);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IStatement.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IStatement
- {
- void prepare(IDatabaseConnection connection);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/IStatementRegistry.cs
@@ -1,11 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IStatementRegistry
- {
- IStatement prepare_delete_statement_for<T>(T entity) where T : IIdentifiable<Guid>;
- IStatement prepare_command_for<T>(T entity) where T : IIdentifiable<Guid>;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/PerThread.cs
@@ -1,58 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Threading;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class PerThread : IContext
- {
- readonly IDictionary<int, LocalDataStoreSlot> slots;
- readonly object mutex = new object();
-
- public PerThread()
- {
- slots = new Dictionary<int, LocalDataStoreSlot>();
- }
-
- public bool contains<T>(IKey<T> key)
- {
- return key.is_found_in(get_items());
- }
-
- public void add<T>(IKey<T> key, T value)
- {
- key.add_value_to(get_items(), value);
- }
-
- public T value_for<T>(IKey<T> key)
- {
- return key.parse_from(get_items());
- }
-
- public void remove<T>(IKey<T> key)
- {
- key.remove_from(get_items());
- }
-
- IDictionary get_items()
- {
- var id = Thread.CurrentThread.ManagedThreadId;
- within_lock(() =>
- {
- if (!slots.ContainsKey(id))
- {
- var slot = Thread.GetNamedDataSlot(GetType().FullName);
- slots.Add(id, slot);
- Thread.SetData(slot, new Hashtable());
- }
- });
- return (IDictionary) Thread.GetData(slots[id]);
- }
-
- void within_lock(Action action)
- {
- lock (mutex) action();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/Session.cs
@@ -1,104 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ISession : IDisposable
- {
- T find<T>(Guid guid) where T : IIdentifiable<Guid>;
- IEnumerable<T> all<T>() where T : IIdentifiable<Guid>;
- void save<T>(T entity) where T : IIdentifiable<Guid>;
- void delete<T>(T entity) where T : IIdentifiable<Guid>;
- void flush();
- bool is_dirty();
- }
-
- public class Session : ISession
- {
- ITransaction transaction;
- readonly IDatabase database;
- readonly IDictionary<Type, object> identity_maps;
- long id;
-
- public Session(ITransaction transaction, IDatabase database)
- {
- this.database = database;
- this.transaction = transaction;
- identity_maps = new Dictionary<Type, object>();
- id = DateTime.Now.Ticks;
- }
-
- public T find<T>(Guid id) where T : IIdentifiable<Guid>
- {
- if (get_identity_map_for<T>().contains_an_item_for(id))
- {
- return get_identity_map_for<T>().item_that_belongs_to(id);
- }
-
- var entity = database.fetch_all<T>().Single(x => x.id.Equals(id));
- get_identity_map_for<T>().add(id, entity);
- return entity;
- }
-
- public IEnumerable<T> all<T>() where T : IIdentifiable<Guid>
- {
- database
- .fetch_all<T>()
- .where(x => !get_identity_map_for<T>().contains_an_item_for(x.id))
- .each(x => get_identity_map_for<T>().add(x.id, x));
- return get_identity_map_for<T>().all();
- }
-
- public void save<T>(T entity) where T : IIdentifiable<Guid>
- {
- this.log().debug("saving {0}: {1}", id, entity);
- get_identity_map_for<T>().add(entity.id, entity);
- }
-
- public void delete<T>(T entity) where T : IIdentifiable<Guid>
- {
- get_identity_map_for<T>().evict(entity.id);
- }
-
- public void flush()
- {
- this.log().debug("flushing session {0}", id);
- transaction.commit_changes();
- transaction = null;
- }
-
- public bool is_dirty()
- {
- this.log().debug("is dirty? {0}", id);
- return null != transaction && transaction.is_dirty();
- }
-
- public void Dispose()
- {
- if (null != transaction) transaction.rollback_changes();
- }
-
- IIdentityMap<Guid, T> get_identity_map_for<T>() where T : IIdentifiable<Guid>
- {
- return identity_maps.ContainsKey(typeof (T))
- ? identity_maps[typeof (T)].downcast_to<IIdentityMap<Guid, T>>()
- : create_map_for<T>();
- }
-
- IIdentityMap<Guid, T> create_map_for<T>() where T : IIdentifiable<Guid>
- {
- var identity_map = transaction.create_for<T>();
- identity_maps.Add(typeof (T), identity_map);
- return identity_map;
- }
-
- public override string ToString()
- {
- return "session: {0}".formatted_using(id);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/SessionFactory.cs
@@ -1,25 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ISessionFactory : IFactory<ISession>
- {
- }
-
- public class SessionFactory : ISessionFactory
- {
- readonly IDatabase database;
- readonly IChangeTrackerFactory factory;
-
- public SessionFactory(IDatabase database, IChangeTrackerFactory factory)
- {
- this.database = database;
- this.factory = factory;
- }
-
- public ISession create()
- {
- return new Session(new Transaction(database, factory), database);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/SessionFactorySpecs.cs
@@ -1,18 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class SessionFactorySpecs
- {
- }
-
- public class when_creating_a_new_session : concerns_for<ISessionFactory, SessionFactory>
- {
- it should_return_a_new_session = () => result.should_not_be_null();
-
- because b = () => { result = sut.create(); };
-
- static ISession result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/SessionNotStartedException.cs
@@ -1,11 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class SessionNotStartedException : Exception
- {
- public SessionNotStartedException() : base("A session could not be found. Did you forget to open a session?")
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/SessionProvider.cs
@@ -1,28 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ISessionProvider
- {
- ISession get_the_current_session();
- }
-
- public class SessionProvider : ISessionProvider
- {
- readonly IContext context;
- readonly IKey<ISession> session_key;
-
- public SessionProvider(IContext context, IKey<ISession> session_key)
- {
- this.context = context;
- this.session_key = session_key;
- }
-
- public ISession get_the_current_session()
- {
- if (!context.contains(session_key))
- {
- throw new SessionNotStartedException();
- }
- return context.value_for(session_key);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/SessionSpecs.cs
@@ -1,177 +0,0 @@
-using System;
-using System.Collections.Generic;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class SessionSpecs
- {
- }
-
- public class behaves_like_session : concerns_for<ISession, Session>
- {
- context c = () =>
- {
- transaction = the_dependency<ITransaction>();
- database = the_dependency<IDatabase>();
- };
-
- static protected ITransaction transaction;
- static protected IDatabase database;
- }
-
- public class when_saving_a_transient_item_to_a_session : behaves_like_session
- {
- it should_add_the_entity_to_the_identity_map = () => map.was_told_to(x => x.add(guid, entity));
-
- //it should_add_the_item_to_the_current_transaction = () => transaction.was_told_to(x => x.add_transient(entity));
-
- context c = () =>
- {
- guid = Guid.NewGuid();
- entity = an<ITestEntity>();
- map = an<IIdentityMap<Guid, ITestEntity>>();
-
- when_the(entity).is_told_to(x => x.id).it_will_return(guid);
- when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(map);
- };
-
- because b = () => sut.save(entity);
-
- static ITestEntity entity;
- static IIdentityMap<Guid, ITestEntity> map;
- static Guid guid;
- }
-
- public class when_commiting_the_changes_made_in_a_session : behaves_like_session
- {
- it should_commit_all_the_changes_from_the_running_transaction =
- () => transaction.was_told_to(x => x.commit_changes());
-
- it should_not_rollback_any_changes_from_the_running_transaction =
- () => transaction.was_not_told_to(x => x.rollback_changes());
-
- because b = () =>
- {
- sut.flush();
- sut.Dispose();
- };
- }
-
- public class when_closing_a_session_before_flushing_the_changes : behaves_like_session
- {
- it should_rollback_any_changes_made_in_the_current_transaction =
- () => transaction.was_told_to(x => x.rollback_changes());
-
- because b = () => sut.Dispose();
- }
-
- public class when_loading_all_instances_of_a_certain_type_and_some_have_already_been_loaded : behaves_like_session
- {
- it should_return_the_items_from_the_cache = () => results.should_contain(cached_item);
-
- it should_exclude_duplicates_from_the_database = () => results.should_not_contain(database_item);
-
- it should_add_items_from_the_database_to_the_identity_map =
- () => identity_map.was_told_to(x => x.add(id_of_the_uncached_item, uncached_item));
-
- context c = () =>
- {
- id = Guid.NewGuid();
- id_of_the_uncached_item = Guid.NewGuid();
- identity_map = an<IIdentityMap<Guid, ITestEntity>>();
- cached_item = an<ITestEntity>();
- database_item = an<ITestEntity>();
- uncached_item = an<ITestEntity>();
-
- when_the(cached_item).is_told_to(x => x.id).it_will_return(id);
- when_the(database_item).is_told_to(x => x.id).it_will_return(id);
- when_the(uncached_item).is_told_to(x => x.id).it_will_return(id_of_the_uncached_item);
- when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(
- identity_map);
- when_the(identity_map).is_told_to(x => x.contains_an_item_for(id)).it_will_return(true);
- when_the(identity_map).is_told_to(x => x.all()).it_will_return(cached_item);
- when_the(database).is_told_to(x => x.fetch_all<ITestEntity>())
- .it_will_return(database_item, uncached_item);
- };
-
- because b = () =>
- {
- sut.find<ITestEntity>(id);
- results = sut.all<ITestEntity>();
- };
-
- static IEnumerable<ITestEntity> results;
- static Guid id;
- static Guid id_of_the_uncached_item;
- static ITestEntity cached_item;
- static ITestEntity database_item;
- static IIdentityMap<Guid, ITestEntity> identity_map;
- static ITestEntity uncached_item;
- }
-
- public class when_looking_up_a_specific_entity_by_its_id_and_it_has_not_been_loaded_into_the_cache :
- behaves_like_session
- {
- it should_return_that_item = () => { result.should_be_equal_to(correct_item); };
-
- it should_add_that_item_to_the_identity_map = () => map.was_told_to(x => x.add(id, correct_item));
-
- context c = () =>
- {
- id = Guid.NewGuid();
- wrong_item = an<ITestEntity>();
- correct_item = an<ITestEntity>();
- map = an<IIdentityMap<Guid, ITestEntity>>();
- when_the(wrong_item).is_told_to(x => x.id).it_will_return(Guid.NewGuid());
- when_the(correct_item).is_told_to(x => x.id).it_will_return(id);
- when_the(database)
- .is_told_to(x => x.fetch_all<ITestEntity>())
- .it_will_return(wrong_item, correct_item);
- when_the(transaction).is_told_to(x => x.create_for<ITestEntity>())
- .it_will_return(map);
- };
-
- because b = () => { result = sut.find<ITestEntity>(id); };
-
- static Guid id;
- static IIdentifiable<Guid> result;
- static ITestEntity correct_item;
- static ITestEntity wrong_item;
- static IIdentityMap<Guid, ITestEntity> map;
- }
-
- public class when_deleting_an_item_from_the_database : behaves_like_session
- {
- it should_remove_that_item_from_the_cache = () => map.was_told_to(x => x.evict(id));
-
- //it should_mark_the_item_for_deletion_when_the_transaction_is_committed = () => transaction.was_told_to(x => x.mark_for_deletion(entity));
-
- context c = () =>
- {
- id = Guid.NewGuid();
- entity = an<ITestEntity>();
- map = an<IIdentityMap<Guid, ITestEntity>>();
-
- when_the(entity).is_told_to(x => x.id).it_will_return(id);
- when_the(transaction).is_told_to(x => x.create_for<ITestEntity>()).it_will_return(map);
- when_the(database).is_told_to(x => x.fetch_all<ITestEntity>()).it_will_return(entity);
- };
-
- because b = () =>
- {
- sut.find<ITestEntity>(id);
- sut.delete(entity);
- };
-
- static Guid id;
- static IIdentityMap<Guid, ITestEntity> map;
- static ITestEntity entity;
- }
-
- public interface ITestEntity : IIdentifiable<Guid>
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/StatementRegistry.cs
@@ -1,50 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class StatementRegistry : IStatementRegistry
- {
- public IStatement prepare_delete_statement_for<T>(T entity) where T : IIdentifiable<Guid>
- {
- return new DeletionStatement<T>(entity);
- }
-
- public IStatement prepare_command_for<T>(T entity) where T : IIdentifiable<Guid>
- {
- return new SaveOrUpdateStatement<T>(entity);
- }
- }
-
- public class SaveOrUpdateStatement<T> : IStatement where T : IIdentifiable<Guid>
- {
- readonly T entity;
-
- public SaveOrUpdateStatement(T entity)
- {
- this.entity = entity;
- }
-
- public void prepare(IDatabaseConnection connection)
- {
- connection.store(entity);
- this.log().debug("saving: {0}", entity);
- }
- }
-
- public class DeletionStatement<T> : IStatement
- {
- readonly T entity;
-
- public DeletionStatement(T entity)
- {
- this.entity = entity;
- }
-
- public void prepare(IDatabaseConnection connection)
- {
- connection.delete(entity);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/TrackerEntry.cs
@@ -1,47 +0,0 @@
-using System.Reflection;
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ITrackerEntry<T>
- {
- T current { get; }
- bool has_changes();
- }
-
- public class TrackerEntry<T> : ITrackerEntry<T>
- {
- readonly T original;
-
- public TrackerEntry(T original, T current)
- {
- this.original = original;
- this.current = current;
- }
-
- public T current { get; set; }
-
- public bool has_changes()
- {
- this.log().debug("checking for changes");
- var type = original.GetType();
- foreach (var field in type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance))
- {
- var original_value = field.GetValue(original);
- var current_value = field.GetValue(current);
- if (original_value == null && current_value != null)
- {
- this.log().debug("{0} has changes: {1}", field, original);
- return true;
- }
- if (original_value != null && !original_value.Equals(current_value))
- {
- this.log().debug("{0} has changes: {1}", field, original);
- return true;
- }
- }
- this.log().debug("has no changes: {0}", original);
- return false;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/TrackerEntryMapper.cs
@@ -1,29 +0,0 @@
-using Gorilla.Commons.Infrastructure.Cloning;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ITrackerEntryMapper<T> : IMapper<T, ITrackerEntry<T>>
- {
- }
-
- public class TrackerEntryMapper<T> : ITrackerEntryMapper<T>
- {
- readonly IPrototype prototype;
-
- public TrackerEntryMapper(IPrototype prototype)
- {
- this.prototype = prototype;
- }
-
- public ITrackerEntry<T> map_from(T item)
- {
- return new TrackerEntry<T>(create_prototype(item), item);
- }
-
- T create_prototype(T item)
- {
- return prototype.clone(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/TrackerEntrySpecs.cs
@@ -1,136 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class TrackerEntrySpecs
- {
- }
-
- public abstract class behaves_like_tracker_entry : concerns_for<ITrackerEntry<Pillow>>
- {
- }
-
- public class when_comparing_the_current_instance_of_a_component_with_its_original_and_it_has_changes :
- behaves_like_tracker_entry
- {
- it should_indicate_that_there_are_changes = () => result.should_be_true();
-
- because b = () => { result = sut.has_changes(); };
-
- public override ITrackerEntry<Pillow> create_sut()
- {
- return new TrackerEntry<Pillow>(new Pillow("pink"), new Pillow("yellow"));
- }
-
- static bool result;
- }
-
- public class when_the_original_instance_has_a_null_field_that_is_now_not_null :
- behaves_like_tracker_entry
- {
- it should_indicate_that_there_are_changes = () => result.should_be_true();
-
- because b = () => { result = sut.has_changes(); };
-
- public override ITrackerEntry<Pillow> create_sut()
- {
- return new TrackerEntry<Pillow>(new Pillow(null), new Pillow("yellow"));
- }
-
- static bool result;
- }
-
- public class when_the_original_instance_had_a_non_null_field_and_the_current_instance_has_a_null_field :
- behaves_like_tracker_entry
- {
- it should_indicate_that_there_are_changes = () => result.should_be_true();
-
- because b = () => { result = sut.has_changes(); };
-
- context c = () =>
- {
- var id = Guid.NewGuid();
- original = new Pillow("green", id);
- current = new Pillow(null, id);
- };
-
- public override ITrackerEntry<Pillow> create_sut()
- {
- return new TrackerEntry<Pillow>(original, current);
- }
-
- static bool result;
- static Pillow original;
- static Pillow current;
- }
-
- public class when_the_original_instance_has_the_same_value_as_the_current_instance :
- behaves_like_tracker_entry
- {
- it should_indicate_that_there_are_no_changes = () => result.should_be_false();
-
- because b = () => { result = sut.has_changes(); };
-
- context c = () =>
- {
- var id = Guid.NewGuid();
- original = new Pillow("green", id);
- current = new Pillow("green", id);
- };
-
- public override ITrackerEntry<Pillow> create_sut()
- {
- return new TrackerEntry<Pillow>(original, current);
- }
-
- static bool result;
- static Pillow original;
- static Pillow current;
- }
-
- public class Pillow : IIdentifiable<Guid>
- {
- readonly string color;
-
- public Pillow(string color) : this(color, Guid.NewGuid())
- {
- }
-
- public Pillow(string color, Guid id)
- {
- this.color = color;
- this.id = id;
- }
-
- public Guid id { get; set; }
-
- public bool Equals(Pillow other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return other.id.Equals(id);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Pillow)) return false;
- return Equals((Pillow) obj);
- }
-
- public override int GetHashCode()
- {
- return id.GetHashCode();
- }
-
- public override string ToString()
- {
- return "{0} id: {1}".formatted_using(base.ToString(), id);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/Transaction.cs
@@ -1,60 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface ITransaction
- {
- IIdentityMap<Guid, T> create_for<T>() where T : IIdentifiable<Guid>;
- void commit_changes();
- void rollback_changes();
- bool is_dirty();
- }
-
- public class Transaction : ITransaction
- {
- readonly IDatabase database;
- readonly IChangeTrackerFactory factory;
- readonly IDictionary<Type, IChangeTracker> change_trackers;
-
- public Transaction(IDatabase database, IChangeTrackerFactory factory)
- {
- this.factory = factory;
- this.database = database;
- change_trackers = new Dictionary<Type, IChangeTracker>();
- }
-
- public IIdentityMap<Guid, T> create_for<T>() where T : IIdentifiable<Guid>
- {
- return new IdentityMapProxy<Guid, T>(get_change_tracker_for<T>(), new IdentityMap<Guid, T>());
- }
-
- public void commit_changes()
- {
- change_trackers.Values.where(x => x.is_dirty()).each(x => x.commit_to(database));
- }
-
- public void rollback_changes()
- {
- change_trackers.each(x => x.Value.Dispose());
- change_trackers.Clear();
- }
-
- public bool is_dirty()
- {
- this.log().debug("changes trackers {0}", change_trackers.Count);
- this.log().debug("is transaction dirty? {0}", change_trackers.Values.Count(x => x.is_dirty()));
- return change_trackers.Values.Count(x => x.is_dirty()) > 0;
- }
-
- IChangeTracker<T> get_change_tracker_for<T>() where T : IIdentifiable<Guid>
- {
- if (!change_trackers.ContainsKey(typeof (T))) change_trackers.Add(typeof (T), factory.create_for<T>());
- return change_trackers[typeof (T)].downcast_to<IChangeTracker<T>>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/TransactionSpecs.cs
@@ -1,110 +0,0 @@
-using System;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class TransactionSpecs
- {
- }
-
- public class behaves_like_transaction : concerns_for<ITransaction, Transaction>
- {
- context c = () =>
- {
- registry = the_dependency<IStatementRegistry>();
- database = the_dependency<IDatabase>();
- factory = the_dependency<IChangeTrackerFactory>();
- };
-
- static protected IStatementRegistry registry;
- static protected IDatabase database;
- static protected IChangeTrackerFactory factory;
- }
-
- public class when_creating_an_identity_map_for_a_specific_entity : behaves_like_transaction
- {
- it should_return_a_new_identity_map = () => result.should_not_be_null();
-
- because b = () => { result = sut.create_for<IIdentifiable<Guid>>(); };
-
- static IIdentityMap<Guid, IIdentifiable<Guid>> result;
- }
-
- public class when_committing_a_transaction_and_an_item_in_the_identity_map_has_changed : behaves_like_transaction
- {
- it should_commit_the_changes_to_that_item = () => tracker.was_told_to<IChangeTracker<IMovie>>(x => x.commit_to(database));
-
- context c = () =>
- {
- movie = new Movie("Goldeneye");
- tracker = an<IChangeTracker<IMovie>>();
-
- when_the(factory).is_told_to(x => x.create_for<IMovie>()).it_will_return(tracker);
- when_the(tracker).is_told_to(x => x.is_dirty()).it_will_return(true);
- };
-
-
- because b = () =>
- {
- sut.create_for<IMovie>().add(movie.id, movie);
- movie.change_name_to("Austin Powers");
- sut.commit_changes();
- };
-
- static IMovie movie;
- static IChangeTracker<IMovie> tracker;
- }
-
- public class when_deleting_a_set_of_entities_from_the_database : behaves_like_transaction
- {
- it should_prepare_to_delete_that_item_form_the_database = () => tracker.was_told_to(x => x.delete(movie));
-
- it should_delete_all_items_marked_for_deletion = () => tracker.was_told_to(x => x.commit_to(database));
-
- context c = () =>
- {
- movie = new Movie("Goldeneye");
- tracker = an<IChangeTracker<IMovie>>();
-
- when_the(factory).is_told_to(x => x.create_for<IMovie>()).it_will_return(tracker);
- when_the(tracker).is_told_to(x => x.is_dirty()).it_will_return(true);
- };
-
- because b = () =>
- {
- var map = sut.create_for<IMovie>();
- map.add(movie.id, movie);
- map.evict(movie.id);
- sut.commit_changes();
- };
-
- static IMovie movie;
- static IChangeTracker<IMovie> tracker;
- }
-
- public interface IMovie : IIdentifiable<Guid>
- {
- string name { get; }
- void change_name_to(string name);
- }
-
- internal class Movie : IMovie
- {
- public Movie(string name)
- {
- id = Guid.NewGuid();
- this.name = name;
- }
-
- public string name { get; set; }
-
- public void change_name_to(string new_name)
- {
- name = new_name;
- }
-
- public Guid id { get; set; }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/TypedKey.cs
@@ -1,50 +0,0 @@
-using System.Collections;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public class TypedKey<T> : IKey<T>
- {
- public bool is_found_in(IDictionary items)
- {
- return items.Contains(create_key());
- }
-
- public T parse_from(IDictionary items)
- {
- return (T) items[create_key()];
- }
-
- public void remove_from(IDictionary items)
- {
- if (is_found_in(items)) items.Remove(create_key());
- }
-
- public void add_value_to(IDictionary items, T value)
- {
- items[create_key()] = value;
- }
-
- public bool Equals(TypedKey<T> obj)
- {
- return !ReferenceEquals(null, obj);
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (TypedKey<T>)) return false;
- return Equals((TypedKey<T>) obj);
- }
-
- public override int GetHashCode()
- {
- return GetType().GetHashCode();
- }
-
- string create_key()
- {
- return GetType().FullName;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/UnitOfWork.cs
@@ -1,42 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IUnitOfWork : IDisposable
- {
- void commit();
- bool is_dirty();
- }
-
- public class UnitOfWork : IUnitOfWork
- {
- readonly ISession session;
- readonly IContext context;
- readonly IKey<ISession> key;
-
- public UnitOfWork(ISession session, IContext context, IKey<ISession> key)
- {
- this.session = session;
- this.context = context;
- this.key = key;
- }
-
- public void commit()
- {
- if (is_dirty()) session.flush();
- }
-
- public bool is_dirty()
- {
- this.log().debug("is session dirty? {0}", session.is_dirty());
- return session.is_dirty();
- }
-
- public void Dispose()
- {
- context.remove(key);
- session.Dispose();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Transactions/UnitOfWorkFactory.cs
@@ -1,39 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Transactions
-{
- public interface IUnitOfWorkFactory : IFactory<IUnitOfWork>
- {
- }
-
- public class UnitOfWorkFactory : IUnitOfWorkFactory
- {
- readonly IContext context;
- readonly ISessionFactory factory;
- readonly IKey<ISession> key;
-
- public UnitOfWorkFactory(IContext context, ISessionFactory factory, IKey<ISession> key)
- {
- this.context = context;
- this.key = key;
- this.factory = factory;
- }
-
- public IUnitOfWork create()
- {
- return unit_of_work_been_started() ? new EmptyUnitOfWork() : start_a_new_unit_of_work();
- }
-
- bool unit_of_work_been_started()
- {
- return context.contains(key);
- }
-
- IUnitOfWork start_a_new_unit_of_work()
- {
- var session = factory.create();
- context.add(key, session);
- return new UnitOfWork(session, context, key);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/CommandFactory.cs
@@ -1,25 +0,0 @@
-using Gorilla.Commons.Infrastructure.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface ICommandFactory
- {
- ICommand create_for<T>(ICallback<T> item, IQuery<T> query);
- }
-
- public class CommandFactory : ICommandFactory
- {
- readonly ISynchronizationContextFactory factory;
-
- public CommandFactory(ISynchronizationContextFactory factory)
- {
- this.factory = factory;
- }
-
- public ICommand create_for<T>(ICallback<T> item, IQuery<T> query)
- {
- return new RunQueryCommand<T>(item, new ProcessQueryCommand<T>(query, factory));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/CommandPump.cs
@@ -1,56 +0,0 @@
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Infrastructure.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface ICommandPump
- {
- ICommandPump run<Command>() where Command : ICommand;
- ICommandPump run<Command>(Command command) where Command : ICommand;
- ICommandPump run<Command, T>(T input) where Command : IParameterizedCommand<T>;
- ICommandPump run<T>(ICallback<T> item, IQuery<T> query);
- ICommandPump run<Output, Query>(ICallback<Output> item) where Query : IQuery<Output>;
- }
-
- public class CommandPump : ICommandPump
- {
- readonly ICommandProcessor processor;
- readonly IDependencyRegistry registry;
- readonly ICommandFactory factory;
-
- public CommandPump(ICommandProcessor processor, IDependencyRegistry registry, ICommandFactory factory)
- {
- this.processor = processor;
- this.factory = factory;
- this.registry = registry;
- }
-
- public ICommandPump run<Command>() where Command : ICommand
- {
- return run(registry.get_a<Command>());
- }
-
- public ICommandPump run<Command>(Command command) where Command : ICommand
- {
- processor.add(command);
- return this;
- }
-
- public ICommandPump run<Command, T>(T input) where Command : IParameterizedCommand<T>
- {
- processor.add(() => registry.get_a<Command>().run(input));
- return this;
- }
-
- public ICommandPump run<T>(ICallback<T> item, IQuery<T> query)
- {
- return run(factory.create_for(item, query));
- }
-
- public ICommandPump run<Output, Query>(ICallback<Output> item) where Query : IQuery<Output>
- {
- return run(item, registry.get_a<Query>());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/Gorilla.Commons.Infrastructure.csproj
@@ -1,183 +0,0 @@
-๏ปฟ<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Gorilla.Commons.Infrastructure</RootNamespace>
- <AssemblyName>Gorilla.Commons.Infrastructure</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="bdddoc, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\bdd.doc\bdddoc.dll</HintPath>
- </Reference>
- <Reference Include="developwithpassion.bdd, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
- </Reference>
- <Reference Include="MbUnit.Framework, Version=2.4.2.175, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\mbunit\MbUnit.Framework.dll</HintPath>
- </Reference>
- <Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Cloning\BinarySerializer.cs" />
- <Compile Include="Cloning\BinarySerializerSpecs.cs" />
- <Compile Include="Cloning\ISerializer.cs" />
- <Compile Include="Cloning\Prototype.cs" />
- <Compile Include="Cloning\Serializer.cs" />
- <Compile Include="CommandFactory.cs" />
- <Compile Include="CommandPump.cs" />
- <Compile Include="Container\DependencyResolutionException.cs" />
- <Compile Include="Container\IDependencyRegistry.cs" />
- <Compile Include="Container\Resolve.cs" />
- <Compile Include="Container\ResolveSpecs.cs" />
- <Compile Include="Debugging\Launch.cs" />
- <Compile Include="Eventing\EventAggregator.cs" />
- <Compile Include="Eventing\EventAggregatorSpecs.cs" />
- <Compile Include="Eventing\IEvent.cs" />
- <Compile Include="Eventing\IEventSubscriber.cs" />
- <Compile Include="FileSystem\ApplicationFile.cs" />
- <Compile Include="FileSystem\IFile.cs" />
- <Compile Include="ICallbackCommand.cs" />
- <Compile Include="Logging\Console\ConsoleLogger.cs" />
- <Compile Include="Logging\ILogFactory.cs" />
- <Compile Include="Logging\ILoggable.cs" />
- <Compile Include="Logging\ILogger.cs" />
- <Compile Include="Logging\Log.cs" />
- <Compile Include="Logging\LoggingExtensions.cs" />
- <Compile Include="Logging\LogSpecs.cs" />
- <Compile Include="ProcessQueryCommand.cs" />
- <Compile Include="Proxies\ExceptionExtensions.cs" />
- <Compile Include="Proxies\IInterceptor.cs" />
- <Compile Include="Proxies\IInvocation.cs" />
- <Compile Include="Proxies\MethodCallInvocation.cs" />
- <Compile Include="Proxies\ProxyFactory.cs" />
- <Compile Include="Proxies\ProxyFactorySpecs.cs" />
- <Compile Include="Proxies\RemotingProxyFactory.cs" />
- <Compile Include="Reflection\ApplicationAssembly.cs" />
- <Compile Include="Reflection\EnvironmentExtensions.cs" />
- <Compile Include="Reflection\IAssembly.cs" />
- <Compile Include="Registries\DefaultRegistry.cs" />
- <Compile Include="Registries\DefaultRegistrySpecs.cs" />
- <Compile Include="RunQueryCommand.cs" />
- <Compile Include="Threading\AsynchronousCommandProcessor.cs" />
- <Compile Include="Threading\BackgroundThread.cs" />
- <Compile Include="Threading\BackgroundThreadFactory.cs" />
- <Compile Include="Threading\BackgroundThreadFactorySpecs.cs" />
- <Compile Include="Threading\BackgroundThreadSpecs.cs" />
- <Compile Include="Threading\CommandProcessor.cs" />
- <Compile Include="Threading\CommandProcessorSpecs.cs" />
- <Compile Include="Threading\ICommandProcessor.cs" />
- <Compile Include="Threading\IntervalTimer.cs" />
- <Compile Include="Threading\IntervalTimerSpecs.cs" />
- <Compile Include="Threading\ISynchronizationContext.cs" />
- <Compile Include="Threading\ITimerClient.cs" />
- <Compile Include="Threading\IWorkerThread.cs" />
- <Compile Include="Threading\SynchronizationContextFactory.cs" />
- <Compile Include="Threading\SynchronizedCommand.cs" />
- <Compile Include="Threading\SynchronizedContext.cs" />
- <Compile Include="Threading\Synchronizer.cs" />
- <Compile Include="Threading\ThreadingExtensions.cs" />
- <Compile Include="Threading\TimerFactory.cs" />
- <Compile Include="Threading\TimerFactorySpecs.cs" />
- <Compile Include="Threading\WorkerThread.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="Threading\WorkItem.cs" />
- <Compile Include="Transactions\ChangeTracker.cs" />
- <Compile Include="Transactions\ChangeTrackerFactory.cs" />
- <Compile Include="Transactions\ChangeTrackerFactorySpecs.cs" />
- <Compile Include="Transactions\ChangeTrackerSpecs.cs" />
- <Compile Include="Transactions\Context.cs" />
- <Compile Include="Transactions\EmptyUnitOfWork.cs" />
- <Compile Include="Transactions\IChangeTracker.cs" />
- <Compile Include="Transactions\IChangeTrackerFactory.cs" />
- <Compile Include="Transactions\IContext.cs" />
- <Compile Include="Transactions\IDatabase.cs" />
- <Compile Include="Transactions\IDatabaseConnection.cs" />
- <Compile Include="Transactions\IdentityMapProxy.cs" />
- <Compile Include="Transactions\IdentityMapSpecs.cs" />
- <Compile Include="Transactions\IIdentityMap.cs" />
- <Compile Include="Transactions\IKey.cs" />
- <Compile Include="Transactions\IStatement.cs" />
- <Compile Include="Transactions\IStatementRegistry.cs" />
- <Compile Include="Transactions\PerThread.cs" />
- <Compile Include="Transactions\Session.cs" />
- <Compile Include="Transactions\SessionFactory.cs" />
- <Compile Include="Transactions\SessionFactorySpecs.cs" />
- <Compile Include="Transactions\SessionNotStartedException.cs" />
- <Compile Include="Transactions\SessionProvider.cs" />
- <Compile Include="Transactions\SessionSpecs.cs" />
- <Compile Include="Transactions\StatementRegistry.cs" />
- <Compile Include="Transactions\TrackerEntry.cs" />
- <Compile Include="Transactions\TrackerEntryMapper.cs" />
- <Compile Include="Transactions\TrackerEntrySpecs.cs" />
- <Compile Include="Transactions\Transaction.cs" />
- <Compile Include="Transactions\TransactionSpecs.cs" />
- <Compile Include="Transactions\TypedKey.cs" />
- <Compile Include="Transactions\UnitOfWork.cs" />
- <Compile Include="Transactions\UnitOfWorkFactory.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
- <Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
- <Name>Gorilla.Commons.Testing</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/ICallbackCommand.cs
@@ -1,8 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface ICallbackCommand<T> : IParameterizedCommand<ICallback<T>>
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/ProcessQueryCommand.cs
@@ -1,28 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface IProcessQueryCommand<T> : IParameterizedCommand<ICallback<T>>
- {
- }
-
- public class ProcessQueryCommand<T> : IProcessQueryCommand<T>
- {
- readonly IQuery<T> query;
- readonly ISynchronizationContextFactory factory;
-
- public ProcessQueryCommand(IQuery<T> query, ISynchronizationContextFactory factory)
- {
- this.query = query;
- this.factory = factory;
- }
-
- public void run(ICallback<T> callback)
- {
- var dto = query.fetch();
- factory.create().run(new ActionCommand((Action) (()=> callback.run(dto))));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure/RunQueryCommand.cs
@@ -1,25 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface IRunQueryCommand<T> : ICommand
- {
- }
-
- public class RunQueryCommand<T> : IRunQueryCommand<T>
- {
- readonly ICallback<T> callback;
- readonly IProcessQueryCommand<T> command;
-
- public RunQueryCommand(ICallback<T> callback, IProcessQueryCommand<T> command)
- {
- this.callback = callback;
- this.command = command;
- }
-
- public void run()
- {
- command.run(callback);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Autofac/AutofacDependencyRegistry.cs
@@ -1,27 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Autofac;
-using Gorilla.Commons.Infrastructure.Container;
-
-namespace Gorilla.Commons.Infrastructure.Autofac
-{
- internal class AutofacDependencyRegistry : IDependencyRegistry
- {
- readonly Func<IContainer> container;
-
- public AutofacDependencyRegistry(Func<IContainer> container)
- {
- this.container = container;
- }
-
- public Interface get_a<Interface>()
- {
- return container().Resolve<Interface>();
- }
-
- public IEnumerable<Interface> all_the<Interface>()
- {
- return container().Resolve<IEnumerable<Interface>>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Autofac/AutofacDependencyRegistryBuilder.cs
@@ -1,73 +0,0 @@
-using System;
-using Autofac;
-using Autofac.Builder;
-using Autofac.Modules;
-using AutofacContrib.DynamicProxy2;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Autofac
-{
- public class AutofacDependencyRegistryBuilder : IDependencyRegistration
- {
- readonly ContainerBuilder builder;
- readonly Func<IContainer> container;
-
- public AutofacDependencyRegistryBuilder() : this(new ContainerBuilder())
- {
- }
-
- public AutofacDependencyRegistryBuilder(ContainerBuilder builder)
- {
- this.builder = builder;
- builder.RegisterModule(new ImplicitCollectionSupportModule());
- builder.RegisterModule(new StandardInterceptionModule());
- builder.SetDefaultScope(InstanceScope.Factory);
- container = () => builder.Build();
- container = container.memorize();
- }
-
- public void singleton<Contract, Implementation>() where Implementation : Contract
- {
- builder.Register<Implementation>().As<Contract>().SingletonScoped();
- }
-
- public void singleton<Contract>(Func<Contract> instance_of_the_contract)
- {
- builder.Register(x => instance_of_the_contract()).As<Contract>().SingletonScoped();
- }
-
- public void transient<Contract, Implementation>() where Implementation : Contract
- {
- transient(typeof (Contract), typeof (Implementation));
- }
-
- public void transient(Type contract, Type implementation)
- {
- if (contract.is_a_generic_type())
- builder.RegisterGeneric(implementation).As(contract).FactoryScoped();
- else
- builder.Register(implementation).As(contract).FactoryScoped();
- }
-
- public void proxy<T>(IConfiguration<IProxyBuilder<T>> configuration, Func<T> target)
- {
- var proxy_builder = new ProxyBuilder<T>();
- configuration.configure(proxy_builder);
- builder.Register(x => proxy_builder.create_proxy_for(target)).As<T>().FactoryScoped();
- }
-
- public void proxy<T, Configuration>(Func<T> target)
- where Configuration : IConfiguration<IProxyBuilder<T>>, new()
- {
- proxy(new Configuration(), target);
- }
-
- public IDependencyRegistry build()
- {
- return new AutofacDependencyRegistry(container);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Autofac/AutofacSpecs.cs
@@ -1,69 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using Autofac;
-using Autofac.Builder;
-using Autofac.Modules;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Autofac
-{
- public class when_trying_to_register_a_single_item_in_the_autofac_container : concerns
- {
- it should_resolve_that_item = () => result.should_be_an_instance_of<A>();
-
- context c = () =>
- {
- builder = new ContainerBuilder();
- builder.Register<A>().As<ITestItem>().FactoryScoped();
- container = builder.Build();
- };
-
- because b = () => { result = container.Resolve<ITestItem>(); };
-
- after_each_observation after_each = () => container.Dispose();
-
- static ContainerBuilder builder;
- static IContainer container;
- static ITestItem result;
- }
-
- public class when_trying_to_resolve_all_the_components_that_implement_a_common_interface : concerns
- {
- it should_return_each_component = () =>
- {
- results.Count().should_be_equal_to(2);
- results.First().should_be_an_instance_of<A>();
- results.Skip(1).First().should_be_an_instance_of<B>();
- };
-
- context c = () =>
- {
- builder = new ContainerBuilder();
- builder.RegisterModule(new ImplicitCollectionSupportModule());
- builder.Register<A>().As<ITestItem>().FactoryScoped();
- builder.Register<B>().As<ITestItem>().FactoryScoped();
- container = builder.Build();
- };
-
- because b = () => { results = container.Resolve<IEnumerable<ITestItem>>(); };
-
- after_each_observation after_each = () => container.Dispose();
-
- static ContainerBuilder builder;
- static IContainer container;
- static IEnumerable<ITestItem> results;
- }
-
- public interface ITestItem
- {
- }
-
- public class A : ITestItem
- {
- }
-
- public class B : ITestItem
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/IMethodCallTracker.cs
@@ -1,11 +0,0 @@
-using System.Collections.Generic;
-using Castle.Core.Interceptor;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public interface IMethodCallTracker<TypeToProxy> : IInterceptor
- {
- TypeToProxy target { get; }
- IEnumerable<string> methods_to_intercept();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/MethodCallTracker.cs
@@ -1,41 +0,0 @@
-using System.Collections.Generic;
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public class MethodCallTracker<TypeToProxy> : IMethodCallTracker<TypeToProxy>
- {
- readonly IList<string> the_name_of_each_method_to_intercept;
-
- public MethodCallTracker() : this(new List<string>())
- {
- }
-
- public MethodCallTracker(IList<string> the_name_of_each_method_to_intercept)
- {
- this.the_name_of_each_method_to_intercept = the_name_of_each_method_to_intercept;
- }
-
- public TypeToProxy target { get; set; }
-
- public void Intercept(IInvocation invocation)
- {
- set_return_value_for(invocation);
- if (the_name_of_each_method_to_intercept.Contains(invocation.Method.Name)) return;
- the_name_of_each_method_to_intercept.Add(invocation.Method.Name);
- }
-
- public IEnumerable<string> methods_to_intercept()
- {
- return the_name_of_each_method_to_intercept;
- }
-
- static void set_return_value_for(IInvocation invocation)
- {
- var return_type = invocation.Method.ReturnType;
- if (return_type == typeof (void)) return;
- invocation.ReturnValue = return_type.default_value();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/MethodCallTrackerSpecs.cs
@@ -1,47 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using Castle.Core.Interceptor;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- [Concern(typeof (MethodCallTracker<IAnInterface>))]
- public class behaves_like_method_call_tracker :
- concerns_for<IMethodCallTracker<IAnInterface>, MethodCallTracker<IAnInterface>>
- {
- public override IMethodCallTracker<IAnInterface> create_sut()
- {
- return new MethodCallTracker<IAnInterface>();
- }
- }
-
- public class when_tracking_the_calls_to_intercept_on_a_type : behaves_like_method_call_tracker
- {
- static IInvocation invocation;
- static IEnumerable<string> result;
-
- context c = () =>
- {
- invocation = an<IInvocation>();
- invocation
- .is_told_to(s => s.Method)
- .it_will_return(typeof (IAnInterface).GetMethod("ValueReturningMethodWithAnArgument"));
- };
-
- because b = () =>
- {
- sut.Intercept(invocation);
- result = sut.methods_to_intercept();
- };
-
- it should_return_all_the_methods_that_are_specified_for_interception =
- () => result.should_contain(typeof (IAnInterface).GetMethod("ValueReturningMethodWithAnArgument").Name);
-
- it should_only_contain_the_methods_specified_for_interception = () => result.Count().should_be_equal_to(1);
-
- it should_specify_the_default_return_value_for_the_method_to_intercept =
- //() => invocation.was_told_to(i => i.ReturnValue = 0);
- () => invocation.ReturnValue.should_be_equal_to(0);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/RaiseEventInterceptor.cs
@@ -1,25 +0,0 @@
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Eventing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public interface IRaiseEventInterceptor<Event> : IInterceptor where Event : IEvent, new()
- {
- }
-
- public class RaiseEventInterceptor<Event> : IRaiseEventInterceptor<Event> where Event : IEvent, new()
- {
- readonly IEventAggregator broker;
-
- public RaiseEventInterceptor(IEventAggregator broker)
- {
- this.broker = broker;
- }
-
- public void Intercept(IInvocation invocation)
- {
- invocation.Proceed();
- broker.publish(new Event());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/RunOnBackgroundThreadInterceptor.cs
@@ -1,25 +0,0 @@
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Threading;
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public class RunOnBackgroundThreadInterceptor<CommandToExecute> : IInterceptor
- where CommandToExecute : IDisposableCommand
- {
- readonly IBackgroundThreadFactory thread_factory;
-
- public RunOnBackgroundThreadInterceptor(IBackgroundThreadFactory thread_factory)
- {
- this.thread_factory = thread_factory;
- }
-
- public virtual void Intercept(IInvocation invocation)
- {
- using (thread_factory.create_for<CommandToExecute>())
- {
- invocation.Proceed();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/RunOnBackgroundThreadInterceptorSpecs.cs
@@ -1,44 +0,0 @@
-using Castle.Core.Interceptor;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Threading;
-using Gorilla.Commons.Testing;
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- [Concern(typeof (RunOnBackgroundThreadInterceptor<>))]
- public class behaves_like_background_thread_interceptor :
- concerns_for<IInterceptor, RunOnBackgroundThreadInterceptor<IDisposableCommand>>
- {
- context c = () => { thread_factory = the_dependency<IBackgroundThreadFactory>(); };
-
- static protected IBackgroundThreadFactory thread_factory;
- }
-
- public class when_intercepting_a_call_to_a_method_that_takes_a_long_time_to_complete :
- behaves_like_background_thread_interceptor
- {
- context c = () =>
- {
- invocation = an<IInvocation>();
- background_thread = an<IBackgroundThread>();
- thread_factory
- .is_told_to(f => f.create_for<IDisposableCommand>())
- .it_will_return(background_thread);
- };
-
- because b = () => sut.Intercept(invocation);
-
- it should_display_a_progress_bar_on_a_background_thread =
- () => thread_factory.was_told_to(f => f.create_for<IDisposableCommand>());
-
- it should_proceed_with_the_orginal_invocation_on_the_actual_object =
- () => invocation.was_told_to(i => i.Proceed());
-
- it should_hide_the_progress_bar_when_the_invocation_is_completed =
- () => background_thread.was_told_to(b => b.Dispose());
-
- static IInvocation invocation;
- static IBackgroundThread background_thread;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/RunOnUIThread.cs
@@ -1,25 +0,0 @@
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Threading;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public class RunOnUIThread : IInterceptor
- {
- readonly ISynchronizationContextFactory factory;
-
- public RunOnUIThread() : this(Lazy.load<ISynchronizationContextFactory>())
- {
- }
-
- public RunOnUIThread(ISynchronizationContextFactory factory)
- {
- this.factory = factory;
- }
-
- public void Intercept(IInvocation invocation)
- {
- factory.create().run(new ActionCommand(invocation.Proceed));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/SelectiveInterceptor.cs
@@ -1,27 +0,0 @@
-using System.Collections.Generic;
-using Castle.Core.Interceptor;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public class SelectiveInterceptor : IInterceptor
- {
- private readonly IList<string> methods_to_intercept;
- private readonly IInterceptor underlying_interceptor;
-
- public SelectiveInterceptor(IEnumerable<string> methods_to_intercept, IInterceptor underlying_interceptor)
- {
- this.methods_to_intercept = new List<string>(methods_to_intercept);
- this.underlying_interceptor = underlying_interceptor;
- }
-
- public void Intercept(IInvocation invocation)
- {
- if (methods_to_intercept.Contains(invocation.Method.Name))
- {
- underlying_interceptor.Intercept(invocation);
- return;
- }
- invocation.Proceed();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/SynchronizedInterceptor.cs
@@ -1,25 +0,0 @@
-using System;
-using System.ComponentModel;
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public interface ISynchronizedInterceptor : IInterceptor
- {
- }
-
- public class SynchronizedInterceptor<T> : ISynchronizedInterceptor where T : ISynchronizeInvoke
- {
- public void Intercept(IInvocation invocation)
- {
- var target = invocation.InvocationTarget.downcast_to<T>();
- target.BeginInvoke(do_it(invocation.Proceed), new object[] {});
- }
-
- Delegate do_it(Action action)
- {
- return action;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/Interceptors/UnitOfWorkInterceptor.cs
@@ -1,36 +0,0 @@
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Eventing;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Infrastructure.Transactions;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors
-{
- public interface IUnitOfWorkInterceptor : IInterceptor
- {
- }
-
- public class UnitOfWorkInterceptor : IUnitOfWorkInterceptor
- {
- readonly IEventAggregator broker;
- readonly IUnitOfWorkFactory factory;
-
- public UnitOfWorkInterceptor(IEventAggregator broker, IUnitOfWorkFactory factory)
- {
- this.broker = broker;
- this.factory = factory;
- }
-
- public void Intercept(IInvocation invocation)
- {
- using (var unit_of_work = factory.create())
- {
- this.log().debug("intercepting: {0}", invocation);
- invocation.Proceed();
- broker.publish<ICallback<IUnitOfWork>>(x => x.run(unit_of_work));
- this.log().debug("committing unit of work");
- unit_of_work.commit();
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IConstraintSelector.cs
@@ -1,8 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IConstraintSelector<TypeToPutConstraintOn>
- {
- TypeToPutConstraintOn intercept_on { get; }
- void intercept_all();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IInterceptorConstraint.cs
@@ -1,48 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IInterceptorConstraint<TypeToPutConstraintOn> : IConstraintSelector<TypeToPutConstraintOn>
- {
- IEnumerable<string> methods_to_intercept();
- }
-
- public class InterceptorConstraint<TypeToPutConstraintOn> : IInterceptorConstraint<TypeToPutConstraintOn>
- {
- readonly IMethodCallTracker<TypeToPutConstraintOn> call_tracker;
- bool intercept_all_calls;
-
- public InterceptorConstraint(IMethodCallTracker<TypeToPutConstraintOn> call_tracker)
- {
- this.call_tracker = call_tracker;
- }
-
- public TypeToPutConstraintOn intercept_on
- {
- get { return call_tracker.target; }
- }
-
- public void intercept_all()
- {
- intercept_all_calls = true;
- }
-
- public IEnumerable<string> methods_to_intercept()
- {
- return intercept_all_calls ? gell_all_methods() : call_tracker.methods_to_intercept();
- }
-
- IEnumerable<string> gell_all_methods()
- {
- return all_methods().Select(x => x.Name);
- }
-
- IEnumerable<MethodInfo> all_methods()
- {
- return typeof (TypeToPutConstraintOn).GetMethods(BindingFlags.Public | BindingFlags.Instance);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IInterceptorConstraintFactory.cs
@@ -1,26 +0,0 @@
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IInterceptorConstraintFactory
- {
- IInterceptorConstraint<Type> CreateFor<Type>();
- }
-
- public class InterceptorConstraintFactory : IInterceptorConstraintFactory
- {
- readonly IMethodCallTrackerFactory factory;
-
- public InterceptorConstraintFactory() : this(new MethodCallTrackerFactory())
- {
- }
-
- public InterceptorConstraintFactory(IMethodCallTrackerFactory factory)
- {
- this.factory = factory;
- }
-
- public IInterceptorConstraint<Type> CreateFor<Type>()
- {
- return new InterceptorConstraint<Type>(factory.create_for<Type>());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IMethodCallTrackerFactory.cs
@@ -1,32 +0,0 @@
-using Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IMethodCallTrackerFactory
- {
- IMethodCallTracker<TypeToProxy> create_for<TypeToProxy>();
- }
-
- public class MethodCallTrackerFactory : IMethodCallTrackerFactory
- {
- private readonly ProxyGenerator generator;
-
- public MethodCallTrackerFactory() : this(new ProxyGenerator())
- {
- }
-
- public MethodCallTrackerFactory(ProxyGenerator generator)
- {
- this.generator = generator;
- }
-
- public IMethodCallTracker<TypeToProxy> create_for<TypeToProxy>()
- {
- var call_tracker_interceptor = new MethodCallTracker<TypeToProxy>();
- var target = generator.CreateInterfaceProxyWithoutTarget<TypeToProxy>(call_tracker_interceptor);
- call_tracker_interceptor.target = target;
- return call_tracker_interceptor;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/InterceptorConstraintFactorySpecs.cs
@@ -1,27 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- [Concern(typeof (InterceptorConstraintFactory))]
- public class behaves_like_constraint_factory :
- concerns_for<IInterceptorConstraintFactory, InterceptorConstraintFactory>
- {
- context c = () => { method_call_tracker_factory = the_dependency<IMethodCallTrackerFactory>(); };
-
- protected static IMethodCallTrackerFactory method_call_tracker_factory;
- }
-
- public class when_creating_a_constraint_for_a_type_to_intercept_on : behaves_like_constraint_factory
- {
- static IInterceptorConstraint<string> result;
-
- it should_create_a_method_call_tracker_for_the_type_to_place_a_constraint_on =
- () => method_call_tracker_factory.was_told_to(f => f.create_for<string>());
-
- it should_return_an_instance_of_an_interceptor_constraint =
- () => result.should_be_an_instance_of<InterceptorConstraint<string>>();
-
- because b = () => { result = sut.CreateFor<string>(); };
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/InterceptorConstraintSpecs.cs
@@ -1,54 +0,0 @@
-using System.Collections.Generic;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- [Concern(typeof (InterceptorConstraint<string>))]
- public class behaves_like_constraint : concerns_for<IInterceptorConstraint<string>, InterceptorConstraint<string>>
- {
- context c = () => { method_call_tracker = the_dependency<IMethodCallTracker<string>>(); };
-
- protected static IMethodCallTracker<string> method_call_tracker;
- }
-
- public class when_asking_for_all_the_methods_to_intercept : behaves_like_constraint
- {
- static IEnumerable<string> result;
- static IList<string> methods_to_intercept;
-
- it should_return_all_the_recorded_method_calls_from_the_call_tracker =
- () => result.should_be_equal_to(methods_to_intercept);
-
- context c = () =>
- {
- methods_to_intercept = new List<string>();
- method_call_tracker
- .is_told_to(t => t.methods_to_intercept())
- .it_will_return(methods_to_intercept);
- };
-
- because b = () => { result = sut.methods_to_intercept(); };
- }
-
- [Concern(typeof (InterceptorConstraint<int>))]
- public class when_asking_for_the_target_of_the_interception_constrain :
- concerns_for<IInterceptorConstraint<int>, InterceptorConstraint<int>>
- {
- static IMethodCallTracker<int> method_call_tracker;
- static int result;
- const int target_of_interception = 7;
-
- context c = () =>
- {
- method_call_tracker = the_dependency<IMethodCallTracker<int>>();
- method_call_tracker.is_told_to(t => t.target).it_will_return(target_of_interception);
- };
-
- because b = () => { result = sut.intercept_on; };
-
- it should_return_the_target_of_the_method_call_tracker =
- () => result.should_be_equal_to(target_of_interception);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IProxyBuilder.cs
@@ -1,15 +0,0 @@
-using System;
-using Castle.Core.Interceptor;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IProxyBuilder<TypeToProxy>
- {
- IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>(Interceptor interceptor)
- where Interceptor : IInterceptor;
-
- IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>() where Interceptor : IInterceptor, new();
- TypeToProxy create_proxy_for(TypeToProxy target);
- TypeToProxy create_proxy_for(Func<TypeToProxy> target);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/IProxyFactory.cs
@@ -1,10 +0,0 @@
-using System;
-using Castle.Core.Interceptor;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public interface IProxyFactory
- {
- TypeToProxy create_proxy_for<TypeToProxy>(Func<TypeToProxy> implementation, params IInterceptor[] interceptors);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/LazyLoadedInterceptor.cs
@@ -1,21 +0,0 @@
-using System;
-using Castle.Core.Interceptor;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- internal class LazyLoadedInterceptor<T> : IInterceptor
- {
- private readonly Func<T> get_the_implementation;
-
- public LazyLoadedInterceptor(Func<T> get_the_implementation)
- {
- this.get_the_implementation = get_the_implementation;
- }
-
- public void Intercept(IInvocation invocation)
- {
- var method = invocation.GetConcreteMethodInvocationTarget();
- invocation.ReturnValue = method.Invoke(get_the_implementation(), invocation.Arguments);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/ProxyBuilder.cs
@@ -1,66 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public class ProxyBuilder<TypeToProxy> : IProxyBuilder<TypeToProxy>
- {
- readonly IDictionary<IInterceptor, IInterceptorConstraint<TypeToProxy>> constraints;
- readonly IProxyFactory proxy_factory;
- readonly IInterceptorConstraintFactory constraint_factory;
-
- public ProxyBuilder() : this(new ProxyFactory(), new InterceptorConstraintFactory())
- {
- }
-
- public ProxyBuilder(IProxyFactory proxy_factory, IInterceptorConstraintFactory constraint_factory)
- {
- this.proxy_factory = proxy_factory;
- this.constraint_factory = constraint_factory;
- constraints = new Dictionary<IInterceptor, IInterceptorConstraint<TypeToProxy>>();
- }
-
- public IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>(Interceptor interceptor)
- where Interceptor : IInterceptor
- {
- var constraint = constraint_factory.CreateFor<TypeToProxy>();
- constraints.Add(interceptor, constraint);
- return constraint;
- }
-
- public IConstraintSelector<TypeToProxy> add_interceptor<Interceptor>() where Interceptor : IInterceptor, new()
- {
- return add_interceptor(new Interceptor());
- }
-
- public TypeToProxy create_proxy_for(TypeToProxy target)
- {
- return create_proxy_for(() => target);
- }
-
- public TypeToProxy create_proxy_for(Func<TypeToProxy> target)
- {
- return proxy_factory.create_proxy_for(target, all_interceptors_with_their_constraints().ToArray());
- }
-
- IEnumerable<IInterceptor> all_interceptors_with_their_constraints()
- {
- foreach (var pair in constraints)
- {
- var constraint = pair.Value;
- var interceptor = pair.Key;
- if (constraint.methods_to_intercept().Count() > 0)
- {
- yield return new SelectiveInterceptor(constraint.methods_to_intercept(), interceptor);
- }
- else
- {
- yield return interceptor;
- }
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/ProxyBuilderSpecs.cs
@@ -1,204 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using Castle.Core.Interceptor;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- [Concern(typeof (ProxyBuilder<IAnInterface>))]
- public class behaves_like_proxy_builder : concerns_for<IProxyBuilder<IAnInterface>, ProxyBuilder<IAnInterface>>
- {
- public override IProxyBuilder<IAnInterface> create_sut()
- {
- return new ProxyBuilder<IAnInterface>();
- }
- }
-
- public class when_building_a_proxy_for_a_type : behaves_like_proxy_builder
- {
- it should_make_sure_the_original_call_gets_forwarded_to_the_item_to_proxy =
- () =>
- {
- an_implementation_of_the_interface.was_told_to(i => i.OneMethod());
- an_implementation_of_the_interface.was_told_to(i => i.SecondMethod());
- };
-
- it should_allow_each_intercepter_to_intercept_the_call =
- () =>
- {
- SomeInterceptor.MethodsCalled.Count().should_be_equal_to(2);
- AnotherInterceptor.MethodsCalled.Count().should_be_equal_to(2);
- };
-
- context c = () => { an_implementation_of_the_interface = an<IAnInterface>(); };
-
- because b = () =>
- {
- sut.add_interceptor<SomeInterceptor>();
- sut.add_interceptor<AnotherInterceptor>();
- var proxy = sut.create_proxy_for(() => an_implementation_of_the_interface);
- proxy.OneMethod();
- proxy.SecondMethod();
- };
-
- after_each_observation ae = () =>
- {
- SomeInterceptor.Cleanup();
- AnotherInterceptor.Cleanup();
- };
-
- static IAnInterface an_implementation_of_the_interface;
- }
-
- [Integration]
- public class when_building_a_proxy_to_target_certain_methods_on_a_type : behaves_like_proxy_builder
- {
- it should_only_intercept_calls_on_the_method_that_was_specified =
- () =>
- {
- SomeInterceptor.MethodsCalled.Count().should_be_equal_to(1);
- SomeInterceptor.MethodsCalled.First().Name.should_be_equal_to("OneMethod");
- };
-
- context c = () => { an_implementation = an<IAnInterface>(); };
-
- because b = () =>
- {
- var constraint = sut.add_interceptor<SomeInterceptor>();
- constraint.intercept_on.OneMethod();
-
- var proxy = sut.create_proxy_for(() => an_implementation);
- proxy.OneMethod();
- proxy.SecondMethod();
- };
-
- after_each_observation ae = () =>
- {
- SomeInterceptor.Cleanup();
- AnotherInterceptor.Cleanup();
- };
-
- static IAnInterface an_implementation;
- }
-
- public class when_proxying_all_calls_on_a_target : behaves_like_proxy_builder
- {
- it should_intercept_each_call =
- () =>
- {
- SomeInterceptor.MethodsCalled.Count().should_be_equal_to(3 );
- SomeInterceptor.MethodsCalled.First().Name.should_be_equal_to("OneMethod");
- SomeInterceptor.MethodsCalled.Skip(1).First().Name.should_be_equal_to("SecondMethod");
- SomeInterceptor.MethodsCalled.Skip(2).First().Name.should_be_equal_to("region");
- };
-
- context c = () => { an_implementation = an<IAnInterface>(); };
-
- because b = () =>
- {
- var constraint = sut.add_interceptor<SomeInterceptor>();
- constraint.intercept_all();
-
- var proxy = sut.create_proxy_for(() => an_implementation);
- proxy.OneMethod();
- proxy.SecondMethod();
- proxy.region(() => "mo");
- };
-
- after_each_observation ae = () =>
- {
- SomeInterceptor.Cleanup();
- AnotherInterceptor.Cleanup();
- };
-
- static IAnInterface an_implementation;
- }
-
- public interface IAnInterface
- {
- string GetterAndSetterProperty { get; set; }
- void OneMethod();
- void SecondMethod();
- int FirstValueReturningMethod();
- int ValueReturningMethodWithAnArgument(int number);
- void region<T>(Func<T> call);
- }
-
- public class SomeInterceptor : IInterceptor
- {
- public static bool WasCalled;
- public static IList<MethodInfo> MethodsCalled;
-
- static SomeInterceptor()
- {
- MethodsCalled = new List<MethodInfo>();
- }
-
- public void Intercept(IInvocation invocation)
- {
- WasCalled = true;
- MethodsCalled.Add(invocation.Method);
- invocation.Proceed();
- }
-
- public static void Cleanup()
- {
- WasCalled = false;
- MethodsCalled.Clear();
- }
- }
-
- public class AnotherInterceptor : IInterceptor
- {
- public static bool WasCalled;
- public static IList<MethodInfo> MethodsCalled;
-
- static AnotherInterceptor()
- {
- MethodsCalled = new List<MethodInfo>();
- }
-
- public void Intercept(IInvocation invocation)
- {
- WasCalled = true;
- MethodsCalled.Add(invocation.Method);
- invocation.Proceed();
- }
-
- public static void Cleanup()
- {
- WasCalled = false;
- MethodsCalled.Clear();
- }
- }
-
- public class SomeImplementation : IAnInterface
- {
- public string GetterAndSetterProperty { get; set; }
-
- public void OneMethod()
- {
- }
-
- public void SecondMethod()
- {
- }
-
- public int FirstValueReturningMethod()
- {
- return 1;
- }
-
- public int ValueReturningMethodWithAnArgument(int number)
- {
- return number + 1;
- }
-
- public void region<T>(Func<T> call)
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/ProxyFactory.cs
@@ -1,48 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Castle.Core.Interceptor;
-using Castle.DynamicProxy;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- public class ProxyFactory : IProxyFactory
- {
- readonly ProxyGenerator generator;
-
- public ProxyFactory() : this(new ProxyGenerator())
- {
- }
-
- public ProxyFactory(ProxyGenerator generator)
- {
- this.generator = generator;
- }
-
- public TypeToProxy create_proxy_for<TypeToProxy>(Func<TypeToProxy> implementation, params IInterceptor[] interceptors)
- {
- return create_proxy_for(lazy_load(implementation), interceptors);
- }
-
- T lazy_load<T>(Func<T> implementation)
- {
- if (typeof (T).IsInterface)
- {
- return generator.CreateInterfaceProxyWithoutTarget<T>(new LazyLoadedInterceptor<T>(implementation));
- }
- return generator.CreateClassProxy<T>(new LazyLoadedInterceptor<T>(implementation));
- }
-
- TypeToProxy create_proxy_for<TypeToProxy>(TypeToProxy implementation,
- IEnumerable<IInterceptor> interceptors)
- {
- if (typeof (TypeToProxy).IsInterface)
- {
- return generator.CreateInterfaceProxyWithTarget<TypeToProxy>(implementation, interceptors.ToArray());
- }
- var list = interceptors.ToList();
- list.Add(new LazyLoadedInterceptor<TypeToProxy>(() => implementation));
- return generator.CreateClassProxy<TypeToProxy>(list.ToArray());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/DynamicProxy/ProxyFactorySpecs.cs
@@ -1,104 +0,0 @@
-using System;
-using System.Data;
-using Castle.Core.Interceptor;
-using developwithpassion.bdd.contexts;
-using developwithpassion.bdd.mbunit;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.DynamicProxy
-{
- [Concern(typeof(ProxyFactory))]
- public abstract class behaves_like_proxy_factory : concerns_for<IProxyFactory, ProxyFactory>
- {
- public override IProxyFactory create_sut()
- {
- return new ProxyFactory();
- }
- }
-
- public class when_creating_a_proxy_with_a_target : behaves_like_proxy_factory
- {
- it should_forward_all_calls_to_the_target = () => target.was_told_to(x => x.Open());
-
- it should_return_a_proxy_to_the_target = () =>
- {
- AssertionExtensions.should_not_be_null(result);
- result.GetType().should_not_be_equal_to(target.GetType());
- };
-
- it should_allow_the_interceptors_to_intercept_all_calls =
- () => AssertionExtensions.should_be_true(interceptor.recieved_call);
-
- context c = () => { target = the_dependency<IDbConnection>(); };
-
- because b = () =>
- {
- interceptor = new TestInterceptor();
- result = sut.create_proxy_for(() => target, interceptor);
- result.Open();
- };
-
- static IDbConnection target;
- static IDbConnection result;
- static TestInterceptor interceptor;
- }
-
- public class when_creating_a_proxy_of_a_target_but_a_call_has_not_been_made_to_the_proxy_yet :
- behaves_like_proxy_factory
- {
- it should_not_create_an_instance_of_the_target = () => AssertionExtensions.should_be_false(TestClass.was_created);
-
- context c = TestClass.reset;
-
- because b = () => { result = sut.create_proxy_for<IDisposable>(() => new TestClass()); };
-
- after_each_observation ae = TestClass.reset;
-
- static IDisposable result;
- }
-
- public class when_creating_a_proxy_of_a_component_that_does_not_implement_an_interface : behaves_like_proxy_factory
- {
- it should_return_a_proxy = () => AssertionExtensions.should_not_be_null(result);
-
- because b = () => { result = sut.create_proxy_for(() => new ClassWithNoInterface()); };
-
- after_each_observation ae = TestClass.reset;
-
- static ClassWithNoInterface result;
- }
-
- public class ClassWithNoInterface
- {
- }
-
- public class TestClass : IDisposable
- {
- public static bool was_created;
-
- public TestClass()
- {
- was_created = true;
- }
-
- public static void reset()
- {
- was_created = false;
- }
-
- public void Dispose()
- {
- }
- }
-
- public class TestInterceptor : IInterceptor
- {
- public bool recieved_call { get; set; }
-
- public void Intercept(IInvocation invocation)
- {
- recieved_call = true;
- invocation.Proceed();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/ApplyLoggingInterceptor.cs
@@ -1,21 +0,0 @@
-using Castle.Core;
-using Castle.MicroKernel.Registration;
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public class ApplyLoggingInterceptor : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- var implementation = registration.Implementation;
- if (typeof (ILoggable).IsAssignableFrom(implementation))
- {
- registration
- .Interceptors(new InterceptorReference(typeof (ILoggingInterceptor)))
- .First
- .If((k, m) => true);
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/ComponentRegistrationConfiguration.cs
@@ -1,21 +0,0 @@
-using Castle.MicroKernel.Registration;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public interface IRegistrationConfiguration : IConfiguration<ComponentRegistration>
- {
- }
-
- public class ComponentRegistrationConfiguration : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- ConfigurationExtensions.then(new RegisterComponentContract()
- .then(new ConfigureComponentLifestyle()), new ApplyLoggingInterceptor())
- //.then(new LogComponent())
- .configure(registration);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/ConfigureComponentLifestyle.cs
@@ -1,18 +0,0 @@
-using Castle.Core;
-using Castle.MicroKernel.Registration;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public class ConfigureComponentLifestyle : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- var implementation = registration.Implementation;
- if (implementation.GetCustomAttributes(typeof (SingletonAttribute), false).Length > 0)
- {
- registration.LifeStyle.Is(LifestyleType.Singleton);
- }
- registration.LifeStyle.Is(LifestyleType.Transient);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/IComponentExclusionSpecification.cs
@@ -1,9 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public interface IComponentExclusionSpecification : ISpecification<Type>
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/LogComponent.cs
@@ -1,12 +0,0 @@
-using Castle.MicroKernel.Registration;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public class LogComponent : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- var implementation = registration.Implementation;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/LoggingInterceptor.cs
@@ -1,22 +0,0 @@
-using System.Diagnostics;
-using Castle.Core.Interceptor;
-using Gorilla.Commons.Infrastructure.Logging;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public interface ILoggingInterceptor : IInterceptor
- {
- }
-
- public class LoggingInterceptor : ILoggingInterceptor
- {
- public void Intercept(IInvocation invocation)
- {
- var stopwatch = new Stopwatch();
- stopwatch.Start();
- invocation.Proceed();
- stopwatch.Stop();
- this.log().debug("{0}.{1} took {2}", invocation.TargetType.Name, invocation.Method.Name, stopwatch.Elapsed);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/Configuration/RegisterComponentContract.cs
@@ -1,16 +0,0 @@
-using Castle.MicroKernel.Registration;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration
-{
- public class RegisterComponentContract : IRegistrationConfiguration
- {
- public void configure(ComponentRegistration registration)
- {
- var implementation = registration.Implementation;
- if (implementation.GetInterfaces().Length == 0)
- {
- registration.For(implementation);
- }
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/WindsorContainerFactory.cs
@@ -1,17 +0,0 @@
-using Castle.Windsor;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor
-{
- public interface IWindsorContainerFactory : IFactory<IWindsorContainer>
- {
- }
-
- public class WindsorContainerFactory : IWindsorContainerFactory
- {
- public IWindsorContainer create()
- {
- return new WindsorContainer();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/WindsorDependencyRegistry.cs
@@ -1,79 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Castle.Core;
-using Castle.Windsor;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor
-{
- internal class WindsorDependencyRegistry : IDependencyRegistration, IDependencyRegistry
- {
- readonly IWindsorContainer underlying_container;
-
- public WindsorDependencyRegistry(IWindsorContainer container)
- {
- underlying_container = container;
- }
-
- public Interface get_a<Interface>()
- {
- return underlying_container.Kernel.Resolve<Interface>();
- }
-
- public IEnumerable<Interface> all_the<Interface>()
- {
- return underlying_container.ResolveAll<Interface>();
- }
-
- public void singleton<Interface, Implementation>() where Implementation : Interface
- {
- var interface_type = typeof (Interface);
- var implementation_type = typeof (Implementation);
- underlying_container.AddComponent(create_a_key_using(interface_type, implementation_type), interface_type,
- implementation_type);
- }
-
- public void singleton<Contract>(Func<Contract> instance_of_the_contract)
- {
- underlying_container.Kernel.AddComponentInstance<Contract>(instance_of_the_contract());
- }
-
- public void transient<Interface, Implementation>() where Implementation : Interface
- {
- transient(typeof (Interface), typeof (Implementation));
- }
-
- public void transient(Type contract, Type implementation)
- {
- underlying_container.AddComponentLifeStyle(
- create_a_key_using(contract, implementation),
- contract, implementation, LifestyleType.Transient);
- }
-
- string create_a_key_using(Type interface_type, Type implementation_type)
- {
- return "{0}-{1}".formatted_using(interface_type.FullName, implementation_type.FullName);
- }
-
- public void proxy<T>(IConfiguration<IProxyBuilder<T>> configuration, Func<T> target)
- {
- var builder = new ProxyBuilder<T>();
- configuration.configure(builder);
- singleton(() => builder.create_proxy_for(target));
- }
-
- public void proxy<T, Configuration>(Func<T> target)
- where Configuration : IConfiguration<IProxyBuilder<T>>, new()
- {
- proxy(new Configuration(), target);
- }
-
- public IDependencyRegistry build()
- {
- return this;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/WindsorDependencyRegistrySpecs.cs
@@ -1,44 +0,0 @@
-using Castle.Core;
-using Castle.Windsor;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor
-{
- [Concern(typeof (WindsorDependencyRegistry))]
- internal class behaves_like_windsor_dependency_registry :
- concerns_for<IDependencyRegistry, WindsorDependencyRegistry>
- {
- }
-
- internal class when_registering_a_singleton_component_with_the_windsor_container :
- behaves_like_windsor_dependency_registry
- {
- it should_return_the_same_instance_each_time_its_resolved =
- () => result.should_be_the_same_instance_as(sut.get_a<IBird>());
-
- it should_not_return_null = () => result.should_not_be_null();
-
- context c = () =>
- {
- var container = the_dependency<IWindsorContainer>();
- var bird = new BlueBird();
- container.is_told_to(x => x.Resolve<IBird>()).it_will_return(bird).Repeat.Any();
- };
-
- because b = () => { result = sut.get_a<IBird>(); };
-
-
- static IBird result;
- }
-
- [Singleton]
- public class BlueBird : IBird
- {
- }
-
- public interface IBird
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Castle/Windsor/WindsorExtensions.cs
@@ -1,20 +0,0 @@
-using System;
-using Castle.MicroKernel.Registration;
-
-namespace Gorilla.Commons.Infrastructure.Castle.Windsor
-{
- public static class WindsorExtensions
- {
- public static BasedOnDescriptor LastInterface(this ServiceDescriptor descriptor)
- {
- return descriptor.Select((type, base_type) =>
- {
- Type first = null;
- var interfaces = type.GetInterfaces();
- if (interfaces.Length > 0) first = interfaces[0];
-
- return (first != null) ? new[] {first} : null;
- });
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Log4Net/Log4NetLogFactory.cs
@@ -1,27 +0,0 @@
-using System;
-using System.IO;
-using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Infrastructure.Reflection;
-using log4net;
-using log4net.Config;
-
-namespace Gorilla.Commons.Infrastructure.Log4Net
-{
- public class Log4NetLogFactory : ILogFactory
- {
- public Log4NetLogFactory()
- {
- XmlConfigurator.Configure(PathToConfigFile());
- }
-
- public ILogger create_for(Type type_to_create_logger_for)
- {
- return new Log4NetLogger(LogManager.GetLogger(type_to_create_logger_for));
- }
-
- private FileInfo PathToConfigFile()
- {
- return new FileInfo(Path.Combine(this.startup_directory(), "log4net.config.xml"));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Log4Net/Log4NetLogger.cs
@@ -1,31 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Logging;
-using log4net;
-
-namespace Gorilla.Commons.Infrastructure.Log4Net
-{
- public class Log4NetLogger : ILogger
- {
- readonly ILog log;
-
- public Log4NetLogger(ILog log)
- {
- this.log = log;
- }
-
- public void informational(string formatted_string, params object[] arguments)
- {
- log.InfoFormat(formatted_string, arguments);
- }
-
- public void debug(string formatted_string, params object[] arguments)
- {
- log.DebugFormat(formatted_string, arguments);
- }
-
- public void error(Exception e)
- {
- log.Error(e.ToString());
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Gorilla.Commons.Infrastructure.ThirdParty.csproj
@@ -1,160 +0,0 @@
-๏ปฟ<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{04DC09B4-5DF9-44A6-8DD1-05941F0D0228}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Gorilla.Commons.Infrastructure</RootNamespace>
- <AssemblyName>Gorilla.Commons.Infrastructure.ThirdParty</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="Autofac, Version=1.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\auto.fac\Autofac.dll</HintPath>
- </Reference>
- <Reference Include="AutofacContrib.DynamicProxy2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\auto.fac.contrib\AutofacContrib.DynamicProxy2.dll</HintPath>
- </Reference>
- <Reference Include="bdddoc, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\bdd.doc\bdddoc.dll</HintPath>
- </Reference>
- <Reference Include="Castle.Core, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\castle\Castle.Core.dll</HintPath>
- </Reference>
- <Reference Include="Castle.DynamicProxy2, Version=2.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\castle\Castle.DynamicProxy2.dll</HintPath>
- </Reference>
- <Reference Include="Castle.MicroKernel, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\castle\Castle.MicroKernel.dll</HintPath>
- </Reference>
- <Reference Include="Castle.Windsor, Version=1.0.3.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\castle\Castle.Windsor.dll</HintPath>
- </Reference>
- <Reference Include="developwithpassion.bdd, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
- </Reference>
- <Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\log4net\log4net.dll</HintPath>
- </Reference>
- <Reference Include="MbUnit.Framework, Version=2.4.2.175, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\mbunit\MbUnit.Framework.dll</HintPath>
- </Reference>
- <Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Autofac\AutofacDependencyRegistry.cs" />
- <Compile Include="Autofac\AutofacDependencyRegistryBuilder.cs" />
- <Compile Include="Autofac\AutofacSpecs.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\RaiseEventInterceptor.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\RunOnUIThread.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\SynchronizedInterceptor.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\UnitOfWorkInterceptor.cs" />
- <Compile Include="Castle\Windsor\WindsorExtensions.cs" />
- <Compile Include="IDependencyRegistration.cs" />
- <Compile Include="Log4Net\Log4NetLogFactory.cs" />
- <Compile Include="Log4Net\Log4NetLogger.cs" />
- <Compile Include="Castle\DynamicProxy\IConstraintSelector.cs" />
- <Compile Include="Castle\DynamicProxy\IInterceptorConstraint.cs" />
- <Compile Include="Castle\DynamicProxy\IInterceptorConstraintFactory.cs" />
- <Compile Include="Castle\DynamicProxy\IMethodCallTrackerFactory.cs" />
- <Compile Include="Castle\DynamicProxy\InterceptorConstraintFactorySpecs.cs" />
- <Compile Include="Castle\DynamicProxy\InterceptorConstraintSpecs.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\IMethodCallTracker.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\MethodCallTracker.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\MethodCallTrackerSpecs.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\RunOnBackgroundThreadInterceptor.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\RunOnBackgroundThreadInterceptorSpecs.cs" />
- <Compile Include="Castle\DynamicProxy\Interceptors\SelectiveInterceptor.cs" />
- <Compile Include="Castle\DynamicProxy\IProxyBuilder.cs" />
- <Compile Include="Castle\DynamicProxy\IProxyFactory.cs" />
- <Compile Include="Lazy.cs" />
- <Compile Include="Castle\DynamicProxy\LazyLoadedInterceptor.cs" />
- <Compile Include="LazySpecs.cs" />
- <Compile Include="Castle\DynamicProxy\ProxyBuilder.cs" />
- <Compile Include="Castle\DynamicProxy\ProxyBuilderSpecs.cs" />
- <Compile Include="Castle\DynamicProxy\ProxyFactory.cs" />
- <Compile Include="Castle\DynamicProxy\ProxyFactorySpecs.cs" />
- <Compile Include="Castle\Windsor\Configuration\ApplyLoggingInterceptor.cs" />
- <Compile Include="Castle\Windsor\Configuration\ComponentRegistrationConfiguration.cs" />
- <Compile Include="Castle\Windsor\Configuration\ConfigureComponentLifestyle.cs" />
- <Compile Include="Castle\Windsor\Configuration\IComponentExclusionSpecification.cs" />
- <Compile Include="Castle\Windsor\Configuration\LogComponent.cs" />
- <Compile Include="Castle\Windsor\Configuration\LoggingInterceptor.cs" />
- <Compile Include="Castle\Windsor\Configuration\RegisterComponentContract.cs" />
- <Compile Include="Castle\Windsor\WindsorContainerFactory.cs" />
- <Compile Include="Castle\Windsor\WindsorDependencyRegistry.cs" />
- <Compile Include="Castle\Windsor\WindsorDependencyRegistrySpecs.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
- <Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
- <Name>Gorilla.Commons.Testing</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/IDependencyRegistration.cs
@@ -1,17 +0,0 @@
-using System;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public interface IDependencyRegistration : IBuilder<IDependencyRegistry>
- {
- void singleton<Contract, Implementation>() where Implementation : Contract;
- void singleton<Contract>(Func<Contract> instance_of_the_contract);
- void transient<Contract, Implementation>() where Implementation : Contract;
- void transient(Type contract, Type implementation);
- void proxy<T>(IConfiguration<IProxyBuilder<T>> configuration, Func<T> target);
- void proxy<T, Configuration>(Func<T> target) where Configuration : IConfiguration<IProxyBuilder<T>>, new();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/Lazy.cs
@@ -1,28 +0,0 @@
-using System;
-using Castle.Core.Interceptor;
-using Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Castle.DynamicProxy;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Infrastructure
-{
- public static class Lazy
- {
- public static T load<T>() where T : class
- {
- return create_proxy_for<T>(create_interceptor_for<T>());
- }
-
- static IInterceptor create_interceptor_for<T>() where T : class
- {
- Func<T> get_the_implementation = Resolve.the<T>;
- return new LazyLoadedInterceptor<T>(get_the_implementation.memorize());
- }
-
- static T create_proxy_for<T>(IInterceptor interceptor)
- {
- return new ProxyGenerator().CreateInterfaceProxyWithoutTarget<T>(interceptor);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Infrastructure.ThirdParty/LazySpecs.cs
@@ -1,190 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Infrastructure
-{
- [Concern(typeof (Lazy))]
- public abstract class behaves_like_a_lazy_loaded_object : concerns
- {
- context c = () =>
- {
- test_container = dependency<IDependencyRegistry>();
- Resolve.initialize_with(test_container);
- };
-
- after_each_observation a = () => Resolve.initialize_with(null);
-
- protected static IDependencyRegistry test_container;
- }
-
- public class when_calling_a_method_with_no_arguments_on_a_lazy_loaded_proxy : behaves_like_a_lazy_loaded_object
- {
- it should_forward_the_original_call_to_the_target = () => target.was_told_to<ITargetObject>(t => t.OneMethod());
-
- context c = () =>
- {
- target = an<ITargetObject>();
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target).Repeat.Once();
- };
-
- because b = () =>
- {
- var result = Lazy.load<ITargetObject>();
- result.OneMethod();
- };
-
- static ITargetObject target;
- }
-
- public class when_calling_a_method_that_returns_an_argument_on_a_lazy_loaded_proxy :
- behaves_like_a_lazy_loaded_object
- {
- it should_return_the_value_from_the_actual_target = () => result.should_be_equal_to(10);
-
- context c = () =>
- {
- var target = an<ITargetObject>();
-
- target.is_told_to(x => x.FirstValueReturningMethod()).it_will_return(10);
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target) .Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<ITargetObject>();
- result = proxy.FirstValueReturningMethod();
- };
-
- static int result;
- }
-
- public class when_calling_different_methods_on_an_proxied_object : behaves_like_a_lazy_loaded_object
- {
- it should_only_load_the_object_once =
- () => MockingExtensions.was_told_to(test_container, x => x.get_a<ITargetObject>()).only_once();
-
- context c = () =>
- {
- var target = an<ITargetObject>();
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target).Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<ITargetObject>();
- proxy.SecondMethod();
- proxy.FirstValueReturningMethod();
- };
- }
-
- public class when_calling_a_method_that_takes_in_a_single_input_parameter_on_a_proxied_object :
- behaves_like_a_lazy_loaded_object
- {
- it should_forward_the_call_to_the_original_target =
- () => target.was_told_to(x => x.ValueReturningMethodWithAnArgument(88));
-
- it should_return_the_correct_result = () => result.should_be_equal_to(99);
-
- context c = () =>
- {
- target = an<ITargetObject>();
-
- target.is_told_to(x => x.ValueReturningMethodWithAnArgument(88)).it_will_return(99);
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target).Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<ITargetObject>();
- result = proxy.ValueReturningMethodWithAnArgument(88);
- };
-
- static ITargetObject target;
- static int result;
- }
-
- public class when_accessing_the_value_of_a_property_on_a_proxied_object : behaves_like_a_lazy_loaded_object
- {
- it should_return_the_correct_value = () => result.should_be_equal_to("mo");
-
- context c = () =>
- {
- var target = an<ITargetObject>();
-
- target.GetterAndSetterProperty = "mo";
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target).Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<ITargetObject>();
- result = proxy.GetterAndSetterProperty;
- };
-
- static string result;
- }
-
- public class when_setting_the_value_of_a_property_on_a_proxied_object : behaves_like_a_lazy_loaded_object
- {
- it should_set_the_value_on_the_original_target =
- () => target.was_told_to(x => x.GetterAndSetterProperty = "khan");
-
- context c = () =>
- {
- target = dependency<ITargetObject>();
- test_container.is_told_to(t => t.get_a<ITargetObject>()).it_will_return(target) .Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<ITargetObject>();
- proxy.GetterAndSetterProperty = "khan";
- };
-
- static ITargetObject target;
- }
-
- public class when_calling_a_generic_method_on_a_proxied_object : behaves_like_a_lazy_loaded_object
- {
- it should_forward_the_call_to_the_target =
- () => MockingExtensions.was_told_to(target, x => x.ValueReturningMethodWithAnArgument("blah"));
-
- it should_return_the_correct_result = () => result.should_be_equal_to("hooray");
-
- context c = () =>
- {
- target = an<IGenericInterface<string>>();
-
- target.is_told_to(x => x.ValueReturningMethodWithAnArgument("blah")).it_will_return("hooray");
- test_container.is_told_to(t => t.get_a<IGenericInterface<string>>()).it_will_return(target).Repeat.Once();
- };
-
- because b = () =>
- {
- var proxy = Lazy.load<IGenericInterface<string>>();
- result = proxy.ValueReturningMethodWithAnArgument("blah");
- };
-
- static IGenericInterface<string> target;
- static string result;
- }
-
- public interface IGenericInterface<T>
- {
- T GetterAndSetterProperty { get; set; }
- void OneMethod();
- void SecondMethod();
- T FirstValueReturningMethod();
- T ValueReturningMethodWithAnArgument(T item);
- }
-
- public interface ITargetObject
- {
- string GetterAndSetterProperty { get; set; }
- void OneMethod();
- void SecondMethod();
- int FirstValueReturningMethod();
- int ValueReturningMethodWithAnArgument(int number);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ActionCommand.cs
@@ -1,25 +0,0 @@
-using System;
-using System.Linq.Expressions;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class ActionCommand : ICommand
- {
- readonly Action action;
-
- public ActionCommand(Expression<Action> action) : this(action.Compile())
- {
-
- }
-
- public ActionCommand(Action action)
- {
- this.action = action;
- }
-
- public void run()
- {
- action();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/AndSpecification.cs
@@ -1,19 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class AndSpecification<T> : ISpecification<T>
- {
- readonly ISpecification<T> left;
- readonly ISpecification<T> right;
-
- public AndSpecification(ISpecification<T> left, ISpecification<T> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public bool is_satisfied_by(T item)
- {
- return left.is_satisfied_by(item) && right.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/AnonymousDisposable.cs
@@ -1,19 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class AnonymousDisposable : IDisposable
- {
- readonly Action action;
-
- public AnonymousDisposable(Action action)
- {
- this.action = action;
- }
-
- public void Dispose()
- {
- action();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ChainedCommand.cs
@@ -1,20 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class ChainedCommand : ICommand
- {
- private readonly ICommand left;
- private readonly ICommand right;
-
- public ChainedCommand(ICommand left, ICommand right)
- {
- this.left = left;
- this.right = right;
- }
-
- public void run()
- {
- left.run();
- right.run();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ChainedConfiguration.cs
@@ -1,20 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class ChainedConfiguration<T> : IConfiguration<T>
- {
- readonly IConfiguration<T> first;
- readonly IConfiguration<T> second;
-
- public ChainedConfiguration(IConfiguration<T> first, IConfiguration<T> second)
- {
- this.first = first;
- this.second = second;
- }
-
- public void configure(T item)
- {
- first.configure(item);
- second.configure(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ChainedMapper.cs
@@ -1,19 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class ChainedMapper<Left, Middle, Right> : IMapper<Left, Right>
- {
- private readonly IMapper<Left, Middle> left;
- private readonly IMapper<Middle, Right> right;
-
- public ChainedMapper(IMapper<Left, Middle> left, IMapper<Middle, Right> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public Right map_from(Left item)
- {
- return right.map_from(left.map_from(item));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ComponentFactory.cs
@@ -1,14 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IComponentFactory<T> : IFactory<T> where T : new()
- {
- }
-
- public class ComponentFactory<T> : IComponentFactory<T> where T : new()
- {
- public T create()
- {
- return new T();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/DisposableCommand.cs
@@ -1,24 +0,0 @@
-using System;
-using MoMoney.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class DisposableCommand : IDisposableCommand
- {
- readonly Action action;
-
- public DisposableCommand(Action action)
- {
- this.action = action;
- }
-
- public void run()
- {
- action();
- }
-
- public void Dispose()
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/EmptyCallback.cs
@@ -1,13 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class EmptyCallback<T> : ICallback<T>, ICallback
- {
- public void run(T item)
- {
- }
-
- public void run()
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/EmptyCommand.cs
@@ -1,9 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class EmptyCommand : ICommand
- {
- public void run()
- {
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/Factory.cs
@@ -1,6 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public delegate Out Factory<In, Out>(In input);
-
- public delegate Out Factory<Out>();
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/FilteredVisitor.cs
@@ -1,19 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class FilteredVisitor<T> : IVisitor<T>
- {
- readonly ISpecification<T> condition;
- readonly IVisitor<T> visitor;
-
- public FilteredVisitor(ISpecification<T> condition, IVisitor<T> visitor)
- {
- this.condition = condition;
- this.visitor = visitor;
- }
-
- public void visit(T item_to_visit)
- {
- if (condition.is_satisfied_by(item_to_visit)) visitor.visit(item_to_visit);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IBuilder.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IBuilder<T>
- {
- T build();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ICallback.cs
@@ -1,10 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface ICallback : ICommand
- {
- }
-
- public interface ICallback<T> : IParameterizedCommand<T>
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ICommand.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface ICommand
- {
- void run();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IConfiguration.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IConfiguration<T>
- {
- void configure(T item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IDisposableCommand.cs
@@ -1,8 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace MoMoney.Utility.Core
-{
- public interface IDisposableCommand : ICommand, IDisposable
- {}
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IFactory.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IFactory<T>
- {
- T create();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IIdentifiable.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IIdentifiable<T>
- {
- T id { get; }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IImport.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IImport<T>
- {
- void import(T item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IMapper.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IMapper<Input, Output>
- {
- Output map_from(Input item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IParameterizedCommand.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IParameterizedCommand<T>
- {
- void run(T item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IParser.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IParser<T>
- {
- T parse();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IQuery.cs
@@ -1,12 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IQuery<TOutput>
- {
- TOutput fetch();
- }
-
- public interface IQuery<TInput, TOutput>
- {
- TOutput fetch(TInput item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IRegistry.cs
@@ -1,9 +0,0 @@
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IRegistry<T>
- {
- IEnumerable<T> all();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/ISpecification.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface ISpecification<T>
- {
- bool is_satisfied_by(T item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IState.cs
@@ -1,6 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IState
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IStateContext.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IStateContext<T> where T : IState
- {
- void change_state_to(T new_state);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IValueReturningVisitor.cs
@@ -1,8 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IValueReturningVisitor<Value, T> : IVisitor<T>
- {
- Value value { get; }
- void reset();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IVisitable.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IVisitable<T>
- {
- void accept(IVisitor<T> visitor);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/IVisitor.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public interface IVisitor<T>
- {
- void visit(T item_to_visit);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/Mapper.cs
@@ -1,19 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class Mapper<Input, Output> : IMapper<Input, Output>
- {
- private readonly Converter<Input, Output> converter;
-
- public Mapper(Converter<Input, Output> converter)
- {
- this.converter = converter;
- }
-
- public Output map_from(Input item)
- {
- return converter(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/NotSpecification.cs
@@ -1,17 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class NotSpecification<T> : ISpecification<T>
- {
- readonly ISpecification<T> item_to_match;
-
- public NotSpecification(ISpecification<T> item_to_match)
- {
- this.item_to_match = item_to_match;
- }
-
- public bool is_satisfied_by(T item)
- {
- return !item_to_match.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/NotSpecificationSpecs.cs
@@ -1,43 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class NotSpecificationSpecs
- {
- }
-
- public class when_checking_if_a_condition_is_not_met : concerns_for<ISpecification<int>, NotSpecification<int>>
- {
- static protected ISpecification<int> criteria;
-
- context c = () => { criteria = the_dependency<ISpecification<int>>(); };
-
- public override ISpecification<int> create_sut()
- {
- return new NotSpecification<int>(criteria);
- }
- }
-
- public class when_a_condition_is_not_met : when_checking_if_a_condition_is_not_met
- {
- context c = () => when_the(criteria).is_told_to(x => x.is_satisfied_by(1)).it_will_return(false);
-
- because b = () => { result = sut.is_satisfied_by(1); };
-
- it should_return_true = () => result.should_be_true();
-
- static bool result;
- }
-
- public class when_a_condition_is_met : when_checking_if_a_condition_is_not_met
- {
- context c = () => when_the(criteria).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
-
- because b = () => { result = sut.is_satisfied_by(1); };
-
- it should_return_false = () => result.should_be_false();
-
- static bool result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/OrSpecification.cs
@@ -1,19 +0,0 @@
-namespace Gorilla.Commons.Utility.Core
-{
- public class OrSpecification<T> : ISpecification<T>
- {
- readonly ISpecification<T> left;
- readonly ISpecification<T> right;
-
- public OrSpecification(ISpecification<T> left, ISpecification<T> right)
- {
- this.left = left;
- this.right = right;
- }
-
- public bool is_satisfied_by(T item)
- {
- return left.is_satisfied_by(item) || right.is_satisfied_by(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/OrSpecificationSpecs.cs
@@ -1,52 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public abstract class when_checking_if_one_of_two_conditions_are_met :
- concerns_for<ISpecification<int>, OrSpecification<int>>
- {
- public override ISpecification<int> create_sut()
- {
- return new OrSpecification<int>(left, right);
- }
-
- context c = () =>
- {
- left = an<ISpecification<int>>();
- right = an<ISpecification<int>>();
- };
-
- protected static ISpecification<int> left;
- protected static ISpecification<int> right;
- }
-
- public class when_one_of_the_conditions_is_met : when_checking_if_one_of_two_conditions_are_met
- {
- it should_return_true = () => result.should_be_true();
-
- context c = () => when_the(left).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- because b = () => { result = sut.is_satisfied_by(1); };
-
- static bool result;
- }
-
- public class when_the_second_condition_is_met : when_checking_if_one_of_two_conditions_are_met
- {
- it should_return_true = () => result.should_be_true();
-
- context c = () => when_the(right).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- because b = () => { result = sut.is_satisfied_by(1); };
-
- static bool result;
- }
-
- public class when_neither_conditions_are_met : when_checking_if_one_of_two_conditions_are_met
- {
- it should_return_false = () => result.should_be_false();
-
- because b = () => { result = sut.is_satisfied_by(1); };
-
- static bool result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/PredicateSpecification.cs
@@ -1,19 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility.Core
-{
- public class PredicateSpecification<T> : ISpecification<T>
- {
- readonly Predicate<T> criteria;
-
- public PredicateSpecification(Predicate<T> criteria)
- {
- this.criteria = criteria;
- }
-
- public bool is_satisfied_by(T item)
- {
- return criteria(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Core/PredicateSpecificationSpecs.cs
@@ -1,17 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Core
-{
- [Concern(typeof (PredicateSpecification<>))]
- public class when_checking_if_a_criteria_is_met_and_it_is : concerns
- {
- it should_return_true = () => new PredicateSpecification<int>(x => true).is_satisfied_by(1).should_be_true();
- }
-
- [Concern(typeof (PredicateSpecification<>))]
- public class when_checking_if_a_criteria_is_met_and_it_is_not : concerns
- {
- it should_return_true = () => new PredicateSpecification<int>(x => false).is_satisfied_by(1).should_be_false();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/CommandExtensions.cs
@@ -1,23 +0,0 @@
-using System;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- static public class CommandExtensions
- {
- static public ICommand then<Command>(this ICommand left) where Command : ICommand, new()
- {
- return then(left, new Command());
- }
-
- static public ICommand then(this ICommand left, ICommand right)
- {
- return new ChainedCommand(left, right);
- }
-
- static public ICommand then(this ICommand left, Action right)
- {
- return new ChainedCommand(left, new ActionCommand(right));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/ConfigurationExtensions.cs
@@ -1,12 +0,0 @@
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class ConfigurationExtensions
- {
- public static IConfiguration<T> then<T>(this IConfiguration<T> first, IConfiguration<T> second)
- {
- return new ChainedConfiguration<T>(first, second);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/ConversionExtensions.cs
@@ -1,37 +0,0 @@
-using System;
-using System.Collections;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class ConversionExtensions
- {
- public static T downcast_to<T>(this object object_to_cast)
- {
- return (T) object_to_cast;
- }
-
- public static T converted_to<T>(this object item_to_convert)
- {
- if (item_to_convert.is_an_implementation_of<IConvertible>())
- {
- return (T) Convert.ChangeType(item_to_convert, typeof (T));
- }
- return item_to_convert.downcast_to<T>();
- }
-
- public static bool is_an_implementation_of<T>(this object item)
- {
- return item is T;
- }
-
- public static void call_on<T>(this object target, Action<T> action) where T : class
- {
- if (target as T != null) action(target as T);
- }
-
- public static void call_on_each<T>(this IEnumerable items, Action<T> action) where T : class
- {
- foreach (var item in items) item.call_on(action);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/EnumerableExtensions.cs
@@ -1,46 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- static public class EnumerableExtensions
- {
- static public IEnumerable<T> where<T>(this IEnumerable<T> items, Func<T, bool> condition_is_met)
- {
- return null == items ? Enumerable.Empty<T>() : items.Where(condition_is_met);
- }
-
- static public IList<T> databind<T>(this IEnumerable<T> items_to_bind_to)
- {
- return null == items_to_bind_to ? new List<T>() : items_to_bind_to.ToList();
- }
-
- static public IEnumerable<T> sorted_using<T>(this IEnumerable<T> items_to_sort, IComparer<T> sorting_algorithm)
- {
- var sorted_items = new List<T>(items_to_sort);
- sorted_items.Sort(sorting_algorithm);
- return sorted_items;
- }
-
- static public IEnumerable<T> all<T>(this IEnumerable<T> items)
- {
- foreach (var item in items ?? Enumerable.Empty<T>()) yield return item;
- }
-
- static public void each<T>(this IEnumerable<T> items, Action<T> action)
- {
- foreach (var item in items ?? Enumerable.Empty<T>()) action(item);
- }
-
- static public IEnumerable<T> join_with<T>(this IEnumerable<T> left, IEnumerable<T> right)
- {
- if (null == right) return left;
-
- var list = new List<T>();
- list.AddRange(left);
- list.AddRange(right);
- return list;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/EnumerableExtensionsSpecs.cs
@@ -1,28 +0,0 @@
-using System.Collections.Generic;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public class EnumerableExtensionsSpecs
- {
- }
-
- public class when_joining_one_collection_with_another : concerns
- {
- it should_return_the_items_from_both = () =>
- {
- results.should_contain(1);
- results.should_contain(2);
- };
-
- because b = () => { results = new List<int> {1}.join_with(new List<int> {2}); };
-
- static IEnumerable<int> results;
- }
-
- public class when_attemping_to_join_a_list_with_a_null_value : concerns
- {
- it should_return_the_original_list = () => new List<int> {1}.join_with(null).should_contain(1);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/FuncExtensions.cs
@@ -1,26 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class FuncExtensions
- {
- public static Func<T> memorize<T>(this Func<T> item) where T : class
- {
- T the_implementation = null;
- return () =>
- {
- if (null == the_implementation)
- {
- lock (typeof (FuncExtensions))
- {
- if (null == the_implementation)
- {
- the_implementation = item();
- }
- }
- }
- return the_implementation;
- };
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/ListExtensions.cs
@@ -1,42 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- static public class ListExtensions
- {
- static public IListConstraint<T> add<T>(this ICollection<T> items, T item)
- {
- return new ListConstraint<T>(items, item);
- }
-
- static public IListConstraint<T> add_range<T>(this ICollection<T> items, IEnumerable<T> item)
- {
- return new ListConstraint<T>(items, item.ToArray());
- }
- }
-
- public class ListConstraint<T> : IListConstraint<T>
- {
- readonly ICollection<T> items;
- readonly T[] items_to_add;
-
- public ListConstraint(ICollection<T> list_to_constrain, params T[] items_to_add)
- {
- items = list_to_constrain;
- this.items_to_add = items_to_add;
- items_to_add.each(list_to_constrain.Add);
- }
-
- public void unless(Func<T, bool> predicate)
- {
- items_to_add.where(predicate).each(x => items.Remove(x));
- }
- }
-
- public interface IListConstraint<T>
- {
- void unless(Func<T, bool> predicate);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/ListExtensionsSpecs.cs
@@ -1,60 +0,0 @@
-using System.Collections.Generic;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public class when_adding_an_item_to_a_list : concerns
- {
- because b = () =>
- {
- list = new List<string>();
- list.add("mo");
- };
-
- it should_add_the_item_to_the_list = () => list.should_contain("mo");
-
- static List<string> list;
- }
-
- public abstract class when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met : concerns
- {
- context c = () => { list = new List<string>(); };
-
- static protected List<string> list;
- }
-
- public class when_the_condition_is_not_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- because b = () => list.add("mo").unless(x => false);
-
- it should_add_the_item_to_the_list = () => list.should_contain("mo");
- }
-
- public class when_the_condition_is_met : when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- because b = () => list.add("mo").unless(x => true);
-
- it should_not_add_the_item_to_the_list = () => list.should_not_contain("mo");
- }
-
- public class when_some_of_the_items_meet_the_conditions_and_some_do_not :
- when_asked_to_only_add_an_item_to_a_list_if_a_condition_is_not_met
- {
- because b = () => list
- .add_range(new List<string> {"mo", "khan"})
- .unless(x => x.Equals("mo"));
-
- it should_add_the_items_that_do_not_meet_the_condition = () =>
- {
- list.Count.should_be_equal_to(1);
- list.should_contain("khan");
- };
-
- it should_not_add_the_items_that_do_meet_the_condition = () => list.should_not_contain("mo");
- }
-
- public class ListExtensionsSpecs
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/MappingExtensions.cs
@@ -1,33 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class MappingExtensions
- {
- public static Output map_using<Input, Output>(this Input item, Converter<Input, Output> conversion)
- {
- return conversion(item);
- }
-
- public static IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
- Converter<Input, Output> mapper)
- {
- return null == items ? new List<Output>() : items.Select(x => mapper(x));
- }
-
- public static IEnumerable<Output> map_all_using<Input, Output>(this IEnumerable<Input> items,
- IMapper<Input, Output> mapper)
- {
- return null == items ? new List<Output>() : items.Select(x => mapper.map_from(x));
- }
-
- public static IMapper<Left, Right> then<Left, Middle, Right>(this IMapper<Left, Middle> left,
- IMapper<Middle, Right> right)
- {
- return new ChainedMapper<Left, Middle, Right>(left, right);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/MappingExtensionsSpecs.cs
@@ -1,31 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace MoMoney.Utility.Extensions
-{
- [Concern(typeof (MappingExtensions))]
- public class when_transforming_type_A_to_type_B_then_C : concerns
- {
- it should_return_the_correct_result = () => result.should_be_equal_to(1);
-
- context c = () =>
- {
- first_mapper = an<IMapper<object, string>>();
- second_mapper = an<IMapper<string, int>>();
- a = 1;
-
- MockingExtensions.it_will_return(MockingExtensions.is_told_to(when_the(first_mapper), x => x.map_from(a)), "1");
- MockingExtensions.it_will_return(MockingExtensions.is_told_to(when_the(second_mapper), x => x.map_from("1")), 1);
- };
-
- because b = () => { result = first_mapper.then(second_mapper).map_from(a); };
-
-
- static int result;
- static IMapper<object, string> first_mapper;
- static IMapper<string, int> second_mapper;
- static object a;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/NumericConversions.cs
@@ -1,22 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class NumericConversions
- {
- public static int to_int<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (int)).downcast_to<int>();
- }
-
- public static long to_long<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (long)).downcast_to<long>();
- }
-
- public static double to_double<T>(this T item) where T : IConvertible
- {
- return Convert.ChangeType(item, typeof (double)).downcast_to<double>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/NumericConversionsSpecs.cs
@@ -1,29 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public class when_converting_a_valid_string_to_a_long : concerns
- {
- it should_return_the_correct_result = () => result.should_be_equal_to(88L);
-
- context c = () => { valid_numeric_string = "88"; };
-
- because b = () => { result = valid_numeric_string.to_long(); };
-
- static long result;
- static string valid_numeric_string;
- }
-
- public class when_converting_a_valid_string_to_an_int : concerns
- {
- it should_return_the_correct_result = () => result.should_be_equal_to(66);
-
- context c = () => { valid_numeric_string = "66"; };
-
- because b = () => { result = valid_numeric_string.to_int(); };
-
- static int result;
- static string valid_numeric_string;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/RegistryExtensions.cs
@@ -1,30 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class RegistryExtensions
- {
- public static K find_an_implementation_of<T, K>(this IRegistry<T> registry) where K : T
- {
- try
- {
- return registry
- .all()
- .Single(p => p.is_an_implementation_of<K>())
- .downcast_to<K>();
- }
- catch (Exception exception)
- {
- throw new Exception("Could Not Find an implementation of".formatted_using(typeof (K)), exception);
- }
- }
-
- public static IEnumerable<T> sort_all_using<T>(this IRegistry<T> registry, IComparer<T> comparer)
- {
- return registry.all().sorted_using(comparer);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/SpecificationExtensions.cs
@@ -1,41 +0,0 @@
-using System;
-using System.Collections.Generic;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- static public class SpecificationExtensions
- {
- static public IEnumerable<T> that_satisfy<T>(this IEnumerable<T> items_to_peek_in_to,
- Predicate<T> criteria_to_satisfy)
- {
- foreach (var item in items_to_peek_in_to ?? new List<T>())
- if (item.satisfies(criteria_to_satisfy)) yield return item;
- }
-
- static public bool satisfies<T>(this T item_to_interrogate, Predicate<T> criteria_to_satisfy)
- {
- return criteria_to_satisfy(item_to_interrogate);
- }
-
- static public bool satisfies<T>(this T item_to_validate, ISpecification<T> criteria_to_satisfy)
- {
- return item_to_validate.satisfies(criteria_to_satisfy.is_satisfied_by);
- }
-
- static public ISpecification<T> and<T>(this ISpecification<T> left, ISpecification<T> right)
- {
- return new AndSpecification<T>(left, right);
- }
-
- static public ISpecification<T> or<T>(this ISpecification<T> left, ISpecification<T> right)
- {
- return new OrSpecification<T>(left, right);
- }
-
- static public ISpecification<T> not<T>(this ISpecification<T> original)
- {
- return new NotSpecification<T>(original);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/SpecificationExtensionsSpecs.cs
@@ -1,64 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public class when_evaluating_two_conditions : concerns
- {
- context c = () =>
- {
- left = an<ISpecification<int>>();
- right = an<ISpecification<int>>();
- };
-
- static protected ISpecification<int> left;
- static protected ISpecification<int> right;
- }
-
- public class when_checking_if_two_conditions_are_met_and_they_are : when_evaluating_two_conditions
- {
- it should_return_true = () => result.should_be_true();
-
- context c = () =>
- {
- when_the(right).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- when_the(left).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- };
-
- because b = () => { result = left.or(right).is_satisfied_by(1); };
-
- static bool result;
- }
-
- public class when_checking_if_one_of_two_conditions_are_met_and_the_left_one_is_not : when_evaluating_two_conditions
- {
- it should_return_true = () => result.should_be_true();
-
- context c = () =>
- {
- when_the(right).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- when_the(left).is_told_to(x => x.is_satisfied_by(1)).it_will_return(false);
- };
-
- because b = () => { result = left.or(right).is_satisfied_by(1); };
-
- static bool result;
- }
-
- public class when_checking_if_one_of_two_conditions_are_met_and_the_right_one_is_not :
- when_evaluating_two_conditions
- {
- it should_return_true = () => result.should_be_true();
-
- context c = () =>
- {
- when_the(right).is_told_to(x => x.is_satisfied_by(1)).it_will_return(false);
- when_the(left).is_told_to(x => x.is_satisfied_by(1)).it_will_return(true);
- };
-
- because b = () => { result = left.or(right).is_satisfied_by(1); };
-
- static bool result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/StringExtensions.cs
@@ -1,25 +0,0 @@
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class StringExtensions
- {
- public static string formatted_using(this string formatted_string, params object[] arguments)
- {
- return string.Format(formatted_string, arguments);
- }
-
- public static bool is_equal_to_ignoring_case(this string left, string right)
- {
- return string.Compare(left, right, true) == 0;
- }
-
- public static bool is_blank(this string message)
- {
- return string.IsNullOrEmpty(message);
- }
-
- public static string to_string<T>(this T item)
- {
- return "{0}".formatted_using(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/TypeExtensions.cs
@@ -1,40 +0,0 @@
-using System;
-using System.Linq;
-using System.Reflection;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public static class TypeExtensions
- {
- public static Type last_interface(this Type type)
- {
- return type.GetInterfaces()[type.GetInterfaces().Length - 1];
- }
-
- public static Type first_interface(this Type type)
- {
- return type.GetInterfaces()[0];
- }
-
- public static bool is_a_generic_type(this Type type)
- {
- //return type.IsGenericType;
- return type.IsGenericTypeDefinition;
- }
-
- public static object default_value(this Type type)
- {
- return (type.IsValueType ? Activator.CreateInstance(type) : null);
- }
-
- public static Attribute get_attribute<Attribute>(this ICustomAttributeProvider provider)
- where Attribute : System.Attribute
- {
- return
- provider
- .GetCustomAttributes(typeof (Attribute), false)
- .Select(x => x.downcast_to<Attribute>())
- .First();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/TypeExtensionsSpecs.cs
@@ -1,41 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- public class when_getting_the_last_interface_for_a_type : concerns
- {
- it should_return_the_correct_one =
- () => typeof (TestType).last_interface().should_be_equal_to(typeof (ITestType));
- }
-
- public class when_getting_the_first_interface_for_a_type : concerns
- {
- it should_return_the_correct_one = () => typeof (TestType).first_interface().should_be_equal_to(typeof (IBase));
- }
-
- public class when_checking_if_a_type_represents_a_generic_type_definition : concerns
- {
- it should_tell_the_truth = () => {
- typeof (IRegistry<>).is_a_generic_type().should_be_true();
- typeof (IRegistry<int>).is_a_generic_type().should_be_false();
- };
- }
-
- public interface IBase
- {
- }
-
- public class BaseType : IBase
- {
- }
-
- public interface ITestType
- {
- }
-
- public class TestType : BaseType, ITestType
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Extensions/VisitorExtensions.cs
@@ -1,20 +0,0 @@
-using System.Collections.Generic;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Utility.Extensions
-{
- static public class VisitorExtensions
- {
- static public Result return_value_from_visiting_all_items_with<Result, T>(this IEnumerable<T> items, IValueReturningVisitor<Result, T> visitor)
- {
- visitor.reset();
- items.visit_all_items_with(visitor);
- return visitor.value;
- }
-
- static public void visit_all_items_with<T>(this IEnumerable<T> items, IVisitor<T> visitor)
- {
- items.each(visitor.visit);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Clock.cs
@@ -1,36 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility
-{
- public static class Clock
- {
- private static Func<DateTime> time_provider;
-
- static Clock()
- {
- reset();
- }
-
- public static Date today()
- {
- return time_provider();
- }
-
- public static DateTime now()
- {
- return time_provider();
- }
-
-#if DEBUG
- public static void change_time_provider_to(Func<DateTime> new_time_provider)
- {
- if (new_time_provider != null) time_provider = new_time_provider;
- }
-#endif
-
- public static void reset()
- {
- time_provider = () => DateTime.Now;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Date.cs
@@ -1,89 +0,0 @@
-using System;
-using System.Globalization;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Utility
-{
- [Serializable]
- public class Date : IComparable<Date>, IComparable, IEquatable<Date>
- {
- readonly long ticks;
-
- public Date(int year, int month, int day)
- {
- ticks = new DateTime(year, month, day).Ticks;
- }
-
- public bool is_in(Year the_year)
- {
- return the_year.represents(to_date_time());
- }
-
- public DateTime to_date_time()
- {
- return new DateTime(ticks);
- }
-
- static public implicit operator Date(DateTime date)
- {
- return new Date(date.Year, date.Month, date.Day);
- }
-
- static public implicit operator DateTime(Date date)
- {
- return date.to_date_time();
- }
-
- public int CompareTo(Date other)
- {
- var the_other_date = other.downcast_to<Date>();
- if (ticks.Equals(the_other_date.ticks))
- {
- return 0;
- }
- return ticks > the_other_date.ticks ? 1 : -1;
- }
-
- public bool Equals(Date other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return other.ticks == ticks;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Date)) return false;
- return Equals((Date) obj);
- }
-
- public override int GetHashCode()
- {
- return ticks.GetHashCode();
- }
-
- public static bool operator ==(Date left, Date right)
- {
- return Equals(left, right);
- }
-
- public static bool operator !=(Date left, Date right)
- {
- return !Equals(left, right);
- }
-
- public override string ToString()
- {
- return new DateTime(ticks, DateTimeKind.Local).ToString("MMM dd yyyy", CultureInfo.InvariantCulture);
- }
-
- int IComparable.CompareTo(object obj)
- {
- if (obj.is_an_implementation_of<Date>())
- return CompareTo(obj.downcast_to<Date>());
- throw new InvalidOperationException();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/DateSpecs.cs
@@ -1,39 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility
-{
- public class DateSpecs
- {
- }
-
- [Concern(typeof (Date))]
- public class when_two_dates_that_represent_the_same_day_are_asked_if_they_are_equal : concerns_for<Date>
- {
- it should_return_true = () => result.should_be_equal_to(true);
-
- public override Date create_sut()
- {
- return new Date(2008, 09, 25);
- }
-
- because b = () => { result = sut.Equals(new Date(2008, 09, 25)); };
-
- static bool result;
- }
-
- [Concern(typeof (Date))]
- public class when_an_older_date_is_compared_to_a_younger_date : concerns_for<Date>
- {
- it should_return_a_positive_number = () => result.should_be_greater_than(0);
-
- public override Date create_sut()
- {
- return new Date(2008, 09, 25);
- }
-
- because b = () => { result = sut.CompareTo(new Date(2007, 01, 01)); };
-
- static int result;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Gorilla.Commons.Utility.csproj
@@ -1,141 +0,0 @@
-๏ปฟ<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Gorilla.Commons.Utility</RootNamespace>
- <AssemblyName>Gorilla.Commons.Utility</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="bdddoc, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\bdd.doc\bdddoc.dll</HintPath>
- </Reference>
- <Reference Include="developwithpassion.bdd, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
- </Reference>
- <Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Clock.cs" />
- <Compile Include="Core\ActionCommand.cs" />
- <Compile Include="Core\AndSpecification.cs" />
- <Compile Include="Core\AnonymousDisposable.cs" />
- <Compile Include="Core\ChainedCommand.cs" />
- <Compile Include="Core\ChainedConfiguration.cs" />
- <Compile Include="Core\ChainedMapper.cs" />
- <Compile Include="Core\DisposableCommand.cs" />
- <Compile Include="Core\EmptyCallback.cs" />
- <Compile Include="Core\EmptyCommand.cs" />
- <Compile Include="Core\ComponentFactory.cs" />
- <Compile Include="Core\Factory.cs" />
- <Compile Include="Core\FilteredVisitor.cs" />
- <Compile Include="Core\IBuilder.cs" />
- <Compile Include="Core\ICallback.cs" />
- <Compile Include="Core\ICommand.cs" />
- <Compile Include="Core\IConfiguration.cs" />
- <Compile Include="Core\IDisposableCommand.cs" />
- <Compile Include="Core\IFactory.cs" />
- <Compile Include="Core\IIdentifiable.cs" />
- <Compile Include="Core\IImport.cs" />
- <Compile Include="Core\IMapper.cs" />
- <Compile Include="Core\IParameterizedCommand.cs" />
- <Compile Include="Core\IParser.cs" />
- <Compile Include="Core\IQuery.cs" />
- <Compile Include="Core\IRegistry.cs" />
- <Compile Include="Core\ISpecification.cs" />
- <Compile Include="Core\IState.cs" />
- <Compile Include="Core\IStateContext.cs" />
- <Compile Include="Core\IValueReturningVisitor.cs" />
- <Compile Include="Core\IVisitable.cs" />
- <Compile Include="Core\IVisitor.cs" />
- <Compile Include="Core\Mapper.cs" />
- <Compile Include="Core\NotSpecification.cs" />
- <Compile Include="Core\NotSpecificationSpecs.cs" />
- <Compile Include="Core\OrSpecification.cs" />
- <Compile Include="Core\OrSpecificationSpecs.cs" />
- <Compile Include="Core\PredicateSpecification.cs" />
- <Compile Include="Core\PredicateSpecificationSpecs.cs" />
- <Compile Include="Date.cs" />
- <Compile Include="DateSpecs.cs" />
- <Compile Include="Extensions\CommandExtensions.cs" />
- <Compile Include="Extensions\ConfigurationExtensions.cs" />
- <Compile Include="Extensions\ConversionExtensions.cs" />
- <Compile Include="Extensions\EnumerableExtensions.cs" />
- <Compile Include="Extensions\EnumerableExtensionsSpecs.cs" />
- <Compile Include="Extensions\FuncExtensions.cs" />
- <Compile Include="Extensions\ListExtensions.cs" />
- <Compile Include="Extensions\ListExtensionsSpecs.cs" />
- <Compile Include="Extensions\MappingExtensions.cs" />
- <Compile Include="Extensions\MappingExtensionsSpecs.cs" />
- <Compile Include="Extensions\NumericConversions.cs" />
- <Compile Include="Extensions\NumericConversionsSpecs.cs" />
- <Compile Include="Extensions\RegistryExtensions.cs" />
- <Compile Include="Extensions\SpecificationExtensionsSpecs.cs" />
- <Compile Include="Extensions\SpecificationExtensions.cs" />
- <Compile Include="Extensions\StringExtensions.cs" />
- <Compile Include="Extensions\TypeExtensions.cs" />
- <Compile Include="Extensions\TypeExtensionsSpecs.cs" />
- <Compile Include="Extensions\VisitorExtensions.cs" />
- <Compile Include="Percent.cs" />
- <Compile Include="PercentSpecs.cs" />
- <Compile Include="Year.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
- <Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
- <Name>Gorilla.Commons.Testing</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Percent.cs
@@ -1,62 +0,0 @@
-using System;
-using System.Globalization;
-
-namespace Gorilla.Commons.Utility
-{
- public class Percent
- {
- readonly double percentage;
-
- public Percent(double percentage)
- {
- this.percentage = percentage;
- }
-
- public Percent(double portion_of_total, double total)
- {
- percentage = portion_of_total/total;
- percentage *= 100;
- percentage = Math.Round(percentage, 1);
- }
-
- public bool represents(Percent other_percent)
- {
- return Equals(other_percent);
- }
-
- public bool is_less_than(Percent other_percent)
- {
- return percentage.CompareTo(other_percent.percentage) < 0;
- }
-
- public static implicit operator Percent(double percentage)
- {
- return new Percent(percentage);
- }
-
- public bool Equals(Percent other)
- {
- if (ReferenceEquals(null, other)) return false;
- if (ReferenceEquals(this, other)) return true;
- return other.percentage == percentage;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Percent)) return false;
- return Equals((Percent) obj);
- }
-
- public override int GetHashCode()
- {
- return percentage.GetHashCode();
- }
-
- public override string ToString()
- {
- return percentage.ToString(CultureInfo.InvariantCulture);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/PercentSpecs.cs
@@ -1,30 +0,0 @@
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Utility
-{
- public class when_comparing_fifty_divided_by_one_hundred_to_fifty_percent : concerns
- {
- it they_should_be_equal = () => new Percent(50, 100).should_be_equal_to<Percent>(50);
- }
-
- public class when_calculating_a_fractional_percentage : concerns
- {
- it should_return_the_correct_percentage = () => new Percent(30, 90).should_be_equal_to<Percent>(33.3);
- }
-
- public class when_checking_if_50_percent_is_less_than_51_percent : concerns
- {
- it should_return_true = () => new Percent(50).is_less_than(new Percent(51)).should_be_true();
- }
-
- public class when_checking_if_51_percent_is_less_than_50_percent : concerns
- {
- it should_return_false = () => new Percent(51).is_less_than(new Percent(50)).should_be_false();
- }
-
- public class when_checking_if_50_percent_is_less_than_50_percent : concerns
- {
- it should_return_false = () => new Percent(50).is_less_than(new Percent(50)).should_be_false();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Utility/Year.cs
@@ -1,53 +0,0 @@
-using System;
-
-namespace Gorilla.Commons.Utility
-{
- public class Year
- {
- readonly int the_underlying_year;
-
- public Year(int year) : this(new DateTime(year, 01, 01))
- {
- }
-
- public Year(DateTime date)
- {
- the_underlying_year = date.Year;
- }
-
- static public implicit operator Year(int year)
- {
- return new Year(year);
- }
-
- public bool Equals(Year obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- return obj.the_underlying_year == the_underlying_year;
- }
-
- public override bool Equals(object obj)
- {
- if (ReferenceEquals(null, obj)) return false;
- if (ReferenceEquals(this, obj)) return true;
- if (obj.GetType() != typeof (Year)) return false;
- return Equals((Year) obj);
- }
-
- public override int GetHashCode()
- {
- return the_underlying_year;
- }
-
- public bool represents(DateTime time)
- {
- return time.Year.Equals(the_underlying_year);
- }
-
- public override string ToString()
- {
- return the_underlying_year.ToString();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/BindingSelector.cs
@@ -1,30 +0,0 @@
-using System;
-using System.Linq.Expressions;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public interface IBindingSelector<TypeToBindTo>
- {
- IPropertyBinder<TypeToBindTo, TypeOfProperty> bind_to_property<TypeOfProperty>(
- Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to);
- }
-
- public class BindingSelector<TypeToBindTo> : IBindingSelector<TypeToBindTo>
- {
- private readonly TypeToBindTo thing_to_bind_to;
- private readonly IPropertyInspectorFactory factory;
-
- public BindingSelector(TypeToBindTo thing_to_bind_to, IPropertyInspectorFactory factory)
- {
- this.thing_to_bind_to = thing_to_bind_to;
- this.factory = factory;
- }
-
- public IPropertyBinder<TypeToBindTo, TypeOfProperty> bind_to_property<TypeOfProperty>(
- Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
- {
- var property_information = factory.create<TypeToBindTo, TypeOfProperty>().inspect(property_to_bind_to);
- return new PropertyBinder<TypeToBindTo, TypeOfProperty>(property_information, thing_to_bind_to);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/BindingSelectorSpecs.cs
@@ -1,50 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public class BindingSelectorSpecs
- {
- }
-
- [Concern(typeof (BindingSelector<IAnInterface>))]
- public class when_selecting_a_property_as_the_target_of_a_binding : concerns_for<IBindingSelector<IAnInterface>>
- {
- it should_return_a_binder_bound_to_the_correct_property =
- () => result.property.Name.should_be_equal_to("FirstName");
-
- it should_inspect_the_expression_for_the_property_information =
- () => inspector.was_told_to(i => i.inspect(expression_to_parse));
-
- context c = () =>
- {
- thing_to_bind_to = an<IAnInterface>();
- factory = an<IPropertyInspectorFactory>();
- inspector = an<IPropertyInspector<IAnInterface, string>>();
-
- factory.is_told_to(f => f.create<IAnInterface, string>()).it_will_return(inspector);
-
- inspector.is_told_to(i => i.inspect(null))
- .IgnoreArguments().it_will_return(typeof (IAnInterface).GetProperty("FirstName"));
- };
-
- because b = () =>
- {
- expression_to_parse = (s => s.FirstName);
- result = sut.bind_to_property(expression_to_parse);
- };
-
- public override IBindingSelector<IAnInterface> create_sut()
- {
- return new BindingSelector<IAnInterface>(thing_to_bind_to, factory);
- }
-
- static IAnInterface thing_to_bind_to;
- static IPropertyBinder<IAnInterface, string> result;
- static IPropertyInspectorFactory factory;
- static IPropertyInspector<IAnInterface, string> inspector;
- static Expression<Func<IAnInterface, string>> expression_to_parse;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/ComboBoxDataBindingSpecs.cs
@@ -1,66 +0,0 @@
-using System.Windows.Forms;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- [Concern(typeof (Create))]
- public class when_binding_a_property_from_an_object_to_a_combo_box : concerns
- {
- it should_initialize_the_combo_box_with_the_current_value_of_the_property =
- () => combo_box.SelectedItem.should_be_equal_to(baby_girl);
-
- context c = () =>
- {
- combo_box = new ComboBox();
- thing_to_bind_to = an<IAnInterface>();
- baby_girl = an<IAnInterface>();
- baby_boy = an<IAnInterface>();
-
- combo_box.Items.Add(baby_boy);
- combo_box.Items.Add(baby_girl);
-
- when_the(thing_to_bind_to).is_asked_for(t => t.Child).it_will_return(baby_girl);
- };
-
- because b = () => Create
- .binding_for(thing_to_bind_to)
- .bind_to_property(t => t.Child)
- .bound_to_control(combo_box);
-
- static ComboBox combo_box;
- static IAnInterface thing_to_bind_to;
- static IAnInterface baby_girl;
- static IAnInterface baby_boy;
- }
-
- [Concern(typeof (Create))]
- public class when_changing_the_selected_item_on_a_combo_box_that_is_bound_to_a_property : concerns
- {
- it should_change_the_value_of_the_property_that_the_combo_box_is_bound_to =
- () => thing_to_bind_to.Child.should_be_equal_to(baby_boy);
-
- context c = () =>
- {
- combo_box = new ComboBox();
- baby_girl = an<IAnInterface>();
- baby_boy = an<IAnInterface>();
- thing_to_bind_to = new AnImplementation {Child = baby_girl};
-
- combo_box.Items.Add(baby_boy);
- combo_box.Items.Add(baby_girl);
-
- Create
- .binding_for(thing_to_bind_to)
- .bind_to_property(t => t.Child)
- .bound_to_control(combo_box);
- };
-
- because b = () => { combo_box.SelectedItem = baby_boy; };
-
- static ComboBox combo_box;
- static IAnInterface thing_to_bind_to;
- static IAnInterface baby_girl;
- static IAnInterface baby_boy;
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/ComboBoxPropertyBinding.cs
@@ -1,23 +0,0 @@
-using System.Windows.Forms;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public class ComboBoxPropertyBinding<TypeToBindTo, PropertyType> : IPropertyBinding<PropertyType>
- {
- private readonly IPropertyBinder<TypeToBindTo, PropertyType> binder;
-
- public ComboBoxPropertyBinding(ComboBox control, IPropertyBinder<TypeToBindTo, PropertyType> binder)
- {
- this.binder = binder;
- control.SelectedItem = binder.current_value();
- control.SelectedIndexChanged +=
- delegate { binder.change_value_of_property_to(control.SelectedItem.converted_to<PropertyType>()); };
- }
-
- public PropertyType current_value()
- {
- return binder.current_value();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/ControlBindingExtensions.cs
@@ -1,29 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public static class ControlBindingExtensions
- {
- public static IPropertyBinding<PropertyType> bound_to_control<TypeToBindTo, PropertyType>(
- this IPropertyBinder<TypeToBindTo, PropertyType> binder,
- Control control)
- {
- return new TextPropertyBinding<TypeToBindTo, PropertyType>(control, binder);
- }
-
- public static IPropertyBinding<PropertyType> bound_to_control<TypeToBindTo, PropertyType>(
- this IPropertyBinder<TypeToBindTo, PropertyType> binder,
- ComboBox control)
- {
- return new ComboBoxPropertyBinding<TypeToBindTo, PropertyType>(control, binder);
- }
-
- public static IPropertyBinding<DateTime> bound_to_control<TypeToBindTo>(
- this IPropertyBinder<TypeToBindTo, DateTime> binder,
- DateTimePicker control)
- {
- return new DateTimePickerPropertyBinding<TypeToBindTo>(control, binder);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/Create.cs
@@ -1,24 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public static class Create
- {
- public static IBindingSelector<TypeToBindTo> binding_for<TypeToBindTo>(TypeToBindTo thing_to_bind_to)
- {
- return new BindingSelector<TypeToBindTo>(thing_to_bind_to, new PropertyInspectorFactory());
- }
-
- public static IPropertyBinding<TypeOfProperty> bind_to<TypeToBindTo, TypeOfProperty>(
- this Control control,
- TypeToBindTo dto,
- Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
- {
- return binding_for(dto)
- .bind_to_property(property_to_bind_to)
- .bound_to_control(control);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/DateTimePickerPropertyBinding.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public class DateTimePickerPropertyBinding<TypeToBindTo> : IPropertyBinding<DateTime>
- {
- private readonly IPropertyBinder<TypeToBindTo, DateTime> binder;
-
- public DateTimePickerPropertyBinding(DateTimePicker control, IPropertyBinder<TypeToBindTo, DateTime> binder)
- {
- this.binder = binder;
- control.ValueChanged += (o, e) => binder.change_value_of_property_to(control.Value);
- }
-
- public DateTime current_value()
- {
- return binder.current_value();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/DateTimePropertyBindingSpecs.cs
@@ -1,39 +0,0 @@
-using System;
-using System.Windows.Forms;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- [Concern(typeof (Create))]
- public class when_a_new_date_is_selected_by_a_date_time_picker_that_is_bound_to_a_property : concerns
- {
- it should_update_the_value_of_the_property =
- () => Assertions.should_be_equal_to(thing_to_bind_to.birth_day, november_nineteenth);
-
- context c = () =>
- {
- date_time_picker = new DateTimePicker {Value = DateTime.Now};
- thing_to_bind_to = new TestDTO {birth_day = DateTime.Now};
-
- Create.binding_for(thing_to_bind_to)
- .bind_to_property(x => x.birth_day)
- .bound_to_control(date_time_picker);
- };
-
- because b = () => { date_time_picker.Value = november_nineteenth; };
-
- static DateTimePicker date_time_picker;
- static TestDTO thing_to_bind_to;
- static readonly DateTime november_nineteenth = new DateTime(2006, 11, 19);
- }
-
- public class TestDTO
- {
- public DateTime birth_day { get; set; }
- }
-
- public class DateTimePropertyBindingSpecs
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/IPropertyBinding.cs
@@ -1,7 +0,0 @@
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public interface IPropertyBinding<PropertyType>
- {
- PropertyType current_value();
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/ListboxExtensions.cs
@@ -1,15 +0,0 @@
-using System.Collections.Generic;
-using System.Windows.Forms;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- static public class ListboxExtensions
- {
- static public void bind_to<T>(this ComboBox control, IEnumerable<T> items)
- {
- control.Items.Clear();
- items.each(x => control.Items.Add(x));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/PropertyBinder.cs
@@ -1,34 +0,0 @@
-using System.Reflection;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public interface IPropertyBinder<TypeToBindTo, PropertyType>
- {
- TypeToBindTo target { get; }
- PropertyInfo property { get; }
- PropertyType current_value();
- void change_value_of_property_to(PropertyType new_value);
- }
-
- public class PropertyBinder<TypeToBindTo, PropertyType> : IPropertyBinder<TypeToBindTo, PropertyType>
- {
- public PropertyBinder(PropertyInfo propery_information, TypeToBindTo target)
- {
- property = target.GetType().GetProperty(propery_information.Name);
- this.target = target;
- }
-
- public TypeToBindTo target { get; private set; }
- public PropertyInfo property { get; private set; }
-
- public PropertyType current_value()
- {
- return (PropertyType) property.GetValue(target, null);
- }
-
- public void change_value_of_property_to(PropertyType value)
- {
- property.SetValue(target, value, null);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/PropertyBinderSpecs.cs
@@ -1,48 +0,0 @@
-using System.Reflection;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- [Concern(typeof (PropertyBinder<IAnInterface, string>))]
- public abstract class behaves_like_a_property_binder :
- concerns_for<IPropertyBinder<IAnInterface, string>, PropertyBinder<IAnInterface, string>>
- {
- public override IPropertyBinder<IAnInterface, string> create_sut()
- {
- return new PropertyBinder<IAnInterface, string>(property, target);
- }
-
- context c = () =>
- {
- target = new AnImplementation {FirstName = "malik"};
- property = typeof (IAnInterface).GetProperty("FirstName");
- };
-
- static protected IAnInterface target;
- static protected PropertyInfo property;
- }
-
- public class when_changing_the_value_of_correctly_bound_property : behaves_like_a_property_binder
- {
- it should_update_the_value_of_the_property_of_the_target_of_the_binder =
- () => target.FirstName.should_be_equal_to(first_name);
-
- because b = () => sut.change_value_of_property_to(first_name);
-
- const string first_name = "mo";
- }
-
- public class when_retrieving_the_current_value_of_a_bound_property : behaves_like_a_property_binder
- {
- it should_return_the_correct_value = () => result.should_be_equal_to("malik");
-
- because b = () => { result = sut.current_value(); };
-
- static string result;
- }
-
- public class PropertyBinderSpecs
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/PropertyInspector.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Linq.Expressions;
-using System.Reflection;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public interface IPropertyInspector<TypeToBindTo, TypeOfProperty>
- {
- PropertyInfo inspect(Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to);
- }
-
- public class PropertyInspector<TypeToBindTo, TypeOfProperty> : IPropertyInspector<TypeToBindTo, TypeOfProperty>
- {
- public PropertyInfo inspect(Expression<Func<TypeToBindTo, TypeOfProperty>> property_to_bind_to)
- {
- var expression = property_to_bind_to.Body.downcast_to<MemberExpression>();
- return expression.Member.downcast_to<PropertyInfo>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/PropertyInspectorFactory.cs
@@ -1,15 +0,0 @@
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public interface IPropertyInspectorFactory
- {
- IPropertyInspector<TypeToInspect, TypeOfProperty> create<TypeToInspect, TypeOfProperty>();
- }
-
- public class PropertyInspectorFactory : IPropertyInspectorFactory
- {
- public IPropertyInspector<TypeToInspect, TypeOfProperty> create<TypeToInspect, TypeOfProperty>()
- {
- return new PropertyInspector<TypeToInspect, TypeOfProperty>();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/PropertyInspectorSpecs.cs
@@ -1,26 +0,0 @@
-using System.Reflection;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- [Concern(typeof (PropertyInspector<IAnInterface, string>))]
- public class when_parsing_a_valie_expression_for_the_information_on_the_property :
- concerns_for<IPropertyInspector<IAnInterface, string>, PropertyInspector<IAnInterface, string>>
- {
- it should_return_the_correct_property_information = () => result.Name.should_be_equal_to("FirstName");
-
- because b = () => { result = sut.inspect(s => s.FirstName); };
-
- public override IPropertyInspector<IAnInterface, string> create_sut()
- {
- return new PropertyInspector<IAnInterface, string>();
- }
-
- static PropertyInfo result;
- }
-
- public class PropertyInspectorSpecs
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/TextBoxDataBindingSpecs.cs
@@ -1,65 +0,0 @@
-using System.Windows.Forms;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- [Concern(typeof (Create))]
- public class when_binding_a_property_on_an_object_to_a_textbox : concerns
- {
- it should_initialize_the_text_of_the_textbox_to_the_value_of_the_property =
- () => text_box.Text.should_be_equal_to(first_name);
-
- context c = () =>
- {
- thing_to_bind_to = an<IAnInterface>();
- text_box = new TextBox();
- thing_to_bind_to.is_asked_for(t => t.FirstName).it_will_return(first_name);
- };
-
- because b = () => Create
- .binding_for(thing_to_bind_to)
- .bind_to_property(t => t.FirstName)
- .bound_to_control(text_box);
-
- static TextBox text_box;
- static IAnInterface thing_to_bind_to;
- static string first_name = "mO";
- }
-
- [Concern(typeof (Create))]
- public class when_updating_the_text_of_a_bound_text_box : concerns
- {
- it should_update_the_value_of_the_property_that_the_textbox_is_bound_to =
- () => thing_to_bind_to.FirstName.should_be_equal_to(expected_name);
-
- context c = () =>
- {
- thing_to_bind_to = new AnImplementation {FirstName = "abshir"};
- text_box = new TextBox();
-
- Create
- .binding_for(thing_to_bind_to)
- .bind_to_property(t => t.FirstName)
- .bound_to_control(text_box);
- };
-
- because b = () => { text_box.Text = expected_name; };
-
- static TextBox text_box;
- static IAnInterface thing_to_bind_to;
- static string expected_name = "ugo";
- }
-
- public interface IAnInterface
- {
- string FirstName { get; }
- IAnInterface Child { get; }
- }
-
- public class AnImplementation : IAnInterface
- {
- public string FirstName { get; set; }
- public IAnInterface Child { get; set; }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Databinding/TextPropertyBinding.cs
@@ -1,24 +0,0 @@
-using System;
-using System.Windows.Forms;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Databinding
-{
- public class TextPropertyBinding<TypeToBindTo, PropertyType> : IPropertyBinding<PropertyType>
- {
- private readonly IPropertyBinder<TypeToBindTo, PropertyType> binder;
-
- public TextPropertyBinding(Control control, IPropertyBinder<TypeToBindTo, PropertyType> binder)
- {
- this.binder = binder;
- control.Text = "{0}".formatted_using(binder.current_value());
- control.TextChanged +=
- (o, e) => binder.change_value_of_property_to(control.Text.converted_to<PropertyType>());
- }
-
- public PropertyType current_value()
- {
- return binder.current_value();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/BindableListBox.cs
@@ -1,30 +0,0 @@
-using System.Collections.Generic;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class BindableListBox<TItemToBindTo> : IBindableList<TItemToBindTo>
- {
- readonly IListControl<TItemToBindTo> list_control;
-
- public BindableListBox(IListControl<TItemToBindTo> list_control)
- {
- this.list_control = list_control;
- }
-
- public void bind_to(IEnumerable<TItemToBindTo> items)
- {
- items.each(x => list_control.add_item(x));
- }
-
- public TItemToBindTo get_selected_item()
- {
- return list_control.get_selected_item();
- }
-
- public void set_selected_item(TItemToBindTo item)
- {
- list_control.set_selected_item(item);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/BindableListExtensions.cs
@@ -1,17 +0,0 @@
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- static public class BindableListExtensions
- {
- static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this ListBox listbox)
- {
- return BindableListFactory.create_for(new ListBoxListControl<TItemToBindTo>(listbox));
- }
-
- static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this ComboBox combobox)
- {
- return BindableListFactory.create_for(new ComboBoxListControl<TItemToBindTo>(combobox));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/BindableListFactory.cs
@@ -1,10 +0,0 @@
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- static public class BindableListFactory
- {
- static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(IListControl<TItemToBindTo> list_control)
- {
- return new BindableListBox<TItemToBindTo>(list_control);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/BitmapRegion.cs
@@ -1,125 +0,0 @@
-using System.Drawing;
-using System.Drawing.Drawing2D;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public static class BitmapRegion
- {
- /// <summary>
- /// Create and apply the region on the supplied control
- /// </summary>
- /// <param name="control">The Control object to apply the region to</param>
- /// <param name="bitmap">The Bitmap object to create the region from</param>
- public static void CreateControlRegion(Control control, Bitmap bitmap)
- {
- // Return if control and bitmap are null
- if (control == null || bitmap == null)
- return;
-
- // Set our control's size to be the same as the bitmap + 6 pixels so that the borders don't affect it.
- control.Width = bitmap.Width;
- control.Height = bitmap.Height;
-
- // Check if we are dealing with Form here
- if (control is Form)
- {
- // Cast to a Form object
- var form = (Form) control;
-
- // Set our form's size to be a little larger that the bitmap just
- // in case the form's border style is not set to none in the first place
- form.Width += 15;
- form.Height += 35;
-
- // No border
- form.FormBorderStyle = FormBorderStyle.None;
-
- // Set bitmap as the background image
- form.BackgroundImage = bitmap;
-
- // Calculate the graphics path based on the bitmap supplied
- var graphicsPath = CalculateControlGraphicsPath(bitmap);
-
- // Apply new region
- form.Region = new Region(graphicsPath);
- }
-
- // Check if we are dealing with Button here
- else if (control is Button)
- {
- // Cast to a button object
- var button = (Button) control;
-
- // Do not show button text
- button.Text = "";
-
- // Change cursor to hand when over button
- button.Cursor = Cursors.Hand;
-
- // Set background image of button
- button.BackgroundImage = bitmap;
-
- // Calculate the graphics path based on the bitmap supplied
- var graphicsPath = CalculateControlGraphicsPath(bitmap);
-
- // Apply new region
- button.Region = new Region(graphicsPath);
- }
- }
-
- /// <summary>
- /// Calculate the graphics path that representing the figure in the bitmap
- /// excluding the transparent color which is the top left pixel.
- /// </summary>
- /// <param name="bitmap">The Bitmap object to calculate our graphics path from</param>
- /// <returns>Calculated graphics path</returns>
- static GraphicsPath CalculateControlGraphicsPath(Bitmap bitmap)
- {
- // Create GraphicsPath for our bitmap calculation
- var graphicsPath = new GraphicsPath();
-
- // Use the top left pixel as our transparent color
- var colorTransparent = bitmap.GetPixel(0, 0);
-
- // This is to store the column value where an opaque pixel is first found.
- // This value will determine where we start scanning for trailing opaque pixels.
- var colOpaquePixel = 0;
-
- // Go through all rows (Y axis)
- for (var row = 0; row < bitmap.Height; row ++)
- {
- // Reset value
- colOpaquePixel = 0;
-
- // Go through all columns (X axis)
- for (var col = 0; col < bitmap.Width; col ++)
- {
- // If this is an opaque pixel, mark it and search for anymore trailing behind
- if (bitmap.GetPixel(col, row) != colorTransparent)
- {
- // Opaque pixel found, mark current position
- colOpaquePixel = col;
-
- // Create another variable to set the current pixel position
- var colNext = col;
-
- // Starting from current found opaque pixel, search for anymore opaque pixels
- // trailing behind, until a transparent pixel is found or minimum width is reached
- for (colNext = colOpaquePixel; colNext < bitmap.Width; colNext ++)
- if (bitmap.GetPixel(colNext, row) == colorTransparent)
- break;
-
- // Form a rectangle for line of opaque pixels found and add it to our graphics path
- graphicsPath.AddRectangle(new Rectangle(colOpaquePixel, row, colNext - colOpaquePixel, 1));
-
- // No need to scan the line of opaque pixels just found
- col = colNext;
- }
- }
- }
- // Return calculated graphics path
- return graphicsPath;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/ButtonExtensions.cs
@@ -1,48 +0,0 @@
-using System;
-using System.Drawing;
-using System.Windows.Forms;
-using Gorilla.Commons.Infrastructure.Container;
-using Gorilla.Commons.Utility.Core;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- static public class ButtonExtensions
- {
- static public Button will_be_shown_as(this Button button, Bitmap image)
- {
- BitmapRegion.CreateControlRegion(button, image);
- button.MouseLeave += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
- button.FlatAppearance.BorderSize = 0; //needs to be here so edges don't get affected by borders
- return button;
- }
-
- static public Button when_hovered_over_will_show(this Button button, Bitmap image)
- {
- button.MouseEnter += (sender, e) => BitmapRegion.CreateControlRegion(button, image);
- return button;
- }
-
- static public Button will_execute<Command>(this Button button, Func<bool> when) where Command : ICommand
- {
- button.Click += (sender, e) => { if (when()) Resolve.the<Command>().run(); };
- button.Enabled = when();
- return button;
- }
-
- static public Control with_tool_tip(this Control control, string title, string caption)
- {
- var tip = new ToolTip
- {
- IsBalloon = true,
- ToolTipTitle = title,
- ToolTipIcon = ToolTipIcon.Info,
- UseAnimation = true,
- UseFading = true,
- AutoPopDelay = 10000,
- };
- tip.SetToolTip(control, caption);
- control.Controls.Add(new ControlAdapter(tip));
- return control;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/ComboBoxListControl.cs
@@ -1,31 +0,0 @@
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class ComboBoxListControl<TItemToStore> : IListControl<TItemToStore>
- {
- readonly ComboBox combo_box;
-
- public ComboBoxListControl(ComboBox combo_box)
- {
- this.combo_box = combo_box;
- }
-
- public TItemToStore get_selected_item()
- {
- return (TItemToStore) combo_box.SelectedItem;
- }
-
- public void add_item(TItemToStore item)
- {
- combo_box.Items.Add(item);
- combo_box.SelectedIndex = 0;
- }
-
- public void set_selected_item(TItemToStore item)
- {
- if (!Equals(item, default(TItemToStore)))
- if (combo_box.Items.Contains(item)) combo_box.SelectedItem = item;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/ControlAdapter.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class ControlAdapter : Control
- {
- readonly IDisposable item;
-
- public ControlAdapter(IDisposable item)
- {
- this.item = item;
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing) item.Dispose();
- base.Dispose(disposing);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/ControlExtensions.cs
@@ -1,13 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- static public class ControlExtensions
- {
- static public IDisposable suspend_layout(this Control control)
- {
- return new SuspendLayout(control);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/Events.cs
@@ -1,34 +0,0 @@
-using System;
-using System.ComponentModel;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class Events
- {
- public interface ControlEvents : IEventTarget
- {
- void OnEnter(EventArgs args);
- void OnKeyPress(KeyPressEventArgs args);
- void OnKeyUp(KeyEventArgs args);
- void OnKeyDown(KeyEventArgs args);
- void OnClick(EventArgs args);
- void OnDoubleClick(EventArgs args);
- void OnDragDrop(DragEventArgs args);
- void OnDragEnter(DragEventArgs args);
- void OnDragLeave(EventArgs args);
- void OnDragOver(DragEventArgs args);
- void OnMouseWheel(MouseEventArgs args);
- void OnValidated(EventArgs args);
- void OnValidating(CancelEventArgs args);
- }
-
- public interface FormEvents : ControlEvents
- {
- void OnActivated(EventArgs e);
- void OnDeactivate(EventArgs e);
- void OnClosed(EventArgs e);
- void OnClosing(CancelEventArgs e);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/EventTrigger.cs
@@ -1,81 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public static class EventTrigger
- {
- const BindingFlags binding_flags =
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance;
-
- static readonly IDictionary<ExpressionType, Func<Expression, object>> expression_handlers;
-
- static EventTrigger()
- {
- expression_handlers = new Dictionary<ExpressionType, Func<Expression, object>>();
- expression_handlers[ExpressionType.New] = instantiate_value;
- expression_handlers[ExpressionType.MemberAccess] = get_value_from_member_access;
- expression_handlers[ExpressionType.Constant] = get_constant_value;
- }
-
- public static void trigger_event<Target>(Expression<Action<Target>> expression_representing_event_to_raise,
- object target) where Target : IEventTarget
- {
- var method_call_expression = expression_representing_event_to_raise.Body.downcast_to<MethodCallExpression>();
- var method_args = get_parameters_from(method_call_expression.Arguments);
- var method_name = method_call_expression.Method.Name;
- var method = target.GetType().GetMethod(method_name, binding_flags);
-
- method.Invoke(target, method_args.ToArray());
- }
-
- static object get_constant_value(Expression expression)
- {
- return expression.downcast_to<ConstantExpression>().Value;
- }
-
- static object get_value_from_member_access(Expression expression)
- {
- var member_expression = expression.downcast_to<MemberExpression>();
- var type = member_expression.Member.DeclaringType;
- var member = (FieldInfo) member_expression.Member;
- var value = member.GetValue(Activator.CreateInstance(type));
- return value;
- }
-
- static object instantiate_value(Expression expression)
- {
- var new_expression = expression.downcast_to<NewExpression>();
- var args = new_expression.Arguments.Select(x => get_value_from_evaluating(x));
- return new_expression.Constructor.Invoke(args.ToArray());
- }
-
- static IEnumerable<object> get_parameters_from(IEnumerable<Expression> parameter_expressions)
- {
- foreach (var expression in parameter_expressions)
- {
- if (can_handle(expression)) yield return get_value_from_evaluating(expression);
- else cannot_handle(expression);
- }
- }
-
- static void cannot_handle(Expression expression)
- {
- throw new ArgumentException("cannot parse {0}".formatted_using(expression));
- }
-
- static object get_value_from_evaluating(Expression expression)
- {
- return expression_handlers[expression.NodeType](expression);
- }
-
- static bool can_handle(Expression expression)
- {
- return expression_handlers.ContainsKey(expression.NodeType);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/EventTriggerExtensions.cs
@@ -1,14 +0,0 @@
-using System;
-using System.Linq.Expressions;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public static class EventTriggerExtensions
- {
- public static void control_is<Control>(this Control target, Expression<Action<Events.ControlEvents>> expression)
- where Control : System.Windows.Forms.Control
- {
- EventTrigger.trigger_event(expression, target);
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/EventTriggerSpecs.cs
@@ -1,65 +0,0 @@
-using System;
-using System.Windows.Forms;
-using developwithpassion.bdd.contexts;
-using Gorilla.Commons.Testing;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class when_invoking_a_call_on_a_target_via_reflection : concerns
- {
- it should_correctly_call_that_method =
- () =>
- {
- Assertions.should_be_true(control.called_on_key_press);
- Assertions.should_be_false(control.called_on_enter);
- };
-
- context c = () => { control = new TestControl(); };
-
- because b =
- () =>
- EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new KeyPressEventArgs('A')), control);
-
- static TestControl control;
- }
-
- public class when_invoking_a_call_on_a_target_by_passing_in_a_parameter : concerns
- {
- it should_make_the_call_correctly = () => control.key_press_arguments.should_be_equal_to(args);
-
- //[Test]
- //public void should_make_the_call_correctly2()
- //{
- // var new_args = new KeyPressEventArgs('A');
- // control = new TestControl();
- // EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(new_args), control);
- // control.key_press_arguments.should_be_equal_to(new_args);
- //}
-
- context c = () => { control = new TestControl(); };
-
- because b = () => EventTrigger.trigger_event<Events.ControlEvents>(x => x.OnKeyPress(args), control);
-
- static TestControl control;
-
- static readonly KeyPressEventArgs args = new KeyPressEventArgs('A');
- }
-
- internal class TestControl
- {
- public bool called_on_enter;
- public bool called_on_key_press;
- public KeyPressEventArgs key_press_arguments;
-
- protected void OnEnter(EventArgs args)
- {
- called_on_enter = true;
- }
-
- protected void OnKeyPress(KeyPressEventArgs args)
- {
- called_on_key_press = true;
- key_press_arguments = args;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/IBindableList.cs
@@ -1,11 +0,0 @@
-using System.Collections.Generic;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public interface IBindableList<TItemToBindTo>
- {
- void bind_to(IEnumerable<TItemToBindTo> items);
- TItemToBindTo get_selected_item();
- void set_selected_item(TItemToBindTo item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/IEventTarget.cs
@@ -1,6 +0,0 @@
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public interface IEventTarget
- {
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/IListControl.cs
@@ -1,9 +0,0 @@
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public interface IListControl<ItemToStore>
- {
- ItemToStore get_selected_item();
- void add_item(ItemToStore item);
- void set_selected_item(ItemToStore item);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/ListBoxListControl.cs
@@ -1,29 +0,0 @@
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class ListBoxListControl<TItemToStore> : IListControl<TItemToStore>
- {
- readonly ListBox list_box;
-
- public ListBoxListControl(ListBox list_box)
- {
- this.list_box = list_box;
- }
-
- public TItemToStore get_selected_item()
- {
- return (TItemToStore) list_box.SelectedItem;
- }
-
- public void add_item(TItemToStore item)
- {
- list_box.Items.Add(item);
- }
-
- public void set_selected_item(TItemToStore item)
- {
- if (list_box.Items.Contains(item)) list_box.SelectedItem = item;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Helpers/SuspendLayout.cs
@@ -1,21 +0,0 @@
-using System;
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Helpers
-{
- public class SuspendLayout : IDisposable
- {
- readonly Control control;
-
- public SuspendLayout(Control control)
- {
- this.control = control;
- control.SuspendLayout();
- }
-
- public void Dispose()
- {
- control.ResumeLayout();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Keyboard/ShortcutKey.cs
@@ -1,24 +0,0 @@
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Keyboard
-{
- public class ShortcutKey
- {
- private readonly Keys key;
-
- public ShortcutKey(Keys key)
- {
- this.key = key;
- }
-
- public ShortcutKey and(ShortcutKey other_key)
- {
- return new ShortcutKey(key | other_key.key);
- }
-
- public static implicit operator Keys(ShortcutKey key_to_convert)
- {
- return key_to_convert.key;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Keyboard/ShortcutKeys.cs
@@ -1,16 +0,0 @@
-using System.Windows.Forms;
-
-namespace Gorilla.Commons.Windows.Forms.Keyboard
-{
- static public class ShortcutKeys
- {
- static public readonly ShortcutKey control = new ShortcutKey(Keys.Control);
- static public readonly ShortcutKey alt = new ShortcutKey(Keys.Alt);
- static public readonly ShortcutKey none = new ShortcutKey(Keys.None);
- static public readonly ShortcutKey L = new ShortcutKey(Keys.L);
- static public readonly ShortcutKey N = new ShortcutKey(Keys.N);
- static public readonly ShortcutKey O = new ShortcutKey(Keys.O);
- static public readonly ShortcutKey S = new ShortcutKey(Keys.S);
- static public readonly ShortcutKey X = new ShortcutKey(Keys.X);
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Resources/ApplicationIcon.cs
@@ -1,44 +0,0 @@
-using System;
-using System.Drawing;
-using System.IO;
-using Gorilla.Commons.Infrastructure.Reflection;
-
-namespace Gorilla.Commons.Windows.Forms.Resources
-{
- public class ApplicationIcon : IDisposable
- {
- readonly Icon underlying_icon;
-
- public ApplicationIcon(string name_of_the_icon, Action<ApplicationIcon> action)
- {
- this.name_of_the_icon = name_of_the_icon;
- if (icon_can_be_found())
- {
- action(this);
- underlying_icon = new Icon(find_full_path_to(this));
- }
- }
-
- public string name_of_the_icon { get; private set; }
-
- public virtual void Dispose()
- {
- if (underlying_icon != null) underlying_icon.Dispose();
- }
-
- static public implicit operator Icon(ApplicationIcon icon_to_convert)
- {
- return icon_to_convert.underlying_icon;
- }
-
- protected string find_full_path_to(ApplicationIcon icon_to_convert)
- {
- return Path.Combine(icon_to_convert.startup_directory() + @"\icons", icon_to_convert.name_of_the_icon);
- }
-
- protected bool icon_can_be_found()
- {
- return File.Exists(find_full_path_to(this));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Resources/ApplicationImage.cs
@@ -1,39 +0,0 @@
-using System;
-using System.Drawing;
-using System.IO;
-using Gorilla.Commons.Infrastructure.Reflection;
-
-namespace Gorilla.Commons.Windows.Forms.Resources
-{
- public class ApplicationImage : IDisposable
- {
- readonly string name_of_the_image;
- readonly Image underlying_image;
-
- public ApplicationImage(string name_of_the_image)
- {
- this.name_of_the_image = name_of_the_image;
- underlying_image = Image.FromFile(FullPathToTheFile(this));
- }
-
- public static implicit operator Image(ApplicationImage image_to_convert)
- {
- return image_to_convert.underlying_image;
- }
-
- public static implicit operator Bitmap(ApplicationImage image_to_convert)
- {
- return new Bitmap(image_to_convert);
- }
-
- string FullPathToTheFile(ApplicationImage image_to_convert)
- {
- return Path.Combine(image_to_convert.startup_directory() + @"\images", image_to_convert.name_of_the_image);
- }
-
- public void Dispose()
- {
- underlying_image.Dispose();
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Resources/HybridIcon.cs
@@ -1,29 +0,0 @@
-using System;
-using System.Drawing;
-
-namespace Gorilla.Commons.Windows.Forms.Resources
-{
- public class HybridIcon : ApplicationIcon
- {
- readonly Image underlying_image;
-
- public HybridIcon(string name_of_the_icon, Action<ApplicationIcon> action) : base(name_of_the_icon, action)
- {
- if (icon_can_be_found())
- {
- underlying_image = Image.FromFile(find_full_path_to(this));
- }
- }
-
- public override void Dispose()
- {
- base.Dispose();
- if (underlying_image != null) underlying_image.Dispose();
- }
-
- static public implicit operator Image(HybridIcon icon_to_convert)
- {
- return icon_to_convert.underlying_image;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms/Gorilla.Commons.Windows.Forms.csproj
@@ -1,129 +0,0 @@
-๏ปฟ<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{54B55B2B-A58F-45DF-A446-234C9D70DC0B}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Gorilla.Commons.Windows.Forms</RootNamespace>
- <AssemblyName>Gorilla.Commons.Windows.Forms</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="bdddoc, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\bdd.doc\bdddoc.dll</HintPath>
- </Reference>
- <Reference Include="developwithpassion.bdd, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
- </Reference>
- <Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Drawing" />
- <Reference Include="System.Windows.Forms" />
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Databinding\BindingSelector.cs" />
- <Compile Include="Databinding\BindingSelectorSpecs.cs" />
- <Compile Include="Databinding\ComboBoxDataBindingSpecs.cs" />
- <Compile Include="Databinding\ComboBoxPropertyBinding.cs" />
- <Compile Include="Databinding\ControlBindingExtensions.cs" />
- <Compile Include="Databinding\Create.cs" />
- <Compile Include="Databinding\DateTimePickerPropertyBinding.cs" />
- <Compile Include="Databinding\DateTimePropertyBindingSpecs.cs" />
- <Compile Include="Databinding\IPropertyBinding.cs" />
- <Compile Include="Databinding\ListboxExtensions.cs" />
- <Compile Include="Databinding\PropertyBinder.cs" />
- <Compile Include="Databinding\PropertyBinderSpecs.cs" />
- <Compile Include="Databinding\PropertyInspector.cs" />
- <Compile Include="Databinding\PropertyInspectorFactory.cs" />
- <Compile Include="Databinding\PropertyInspectorSpecs.cs" />
- <Compile Include="Databinding\TextBoxDataBindingSpecs.cs" />
- <Compile Include="Databinding\TextPropertyBinding.cs" />
- <Compile Include="Helpers\BindableListBox.cs" />
- <Compile Include="Helpers\BindableListExtensions.cs" />
- <Compile Include="Helpers\BindableListFactory.cs" />
- <Compile Include="Helpers\BitmapRegion.cs" />
- <Compile Include="Helpers\ButtonExtensions.cs" />
- <Compile Include="Helpers\ComboBoxListControl.cs" />
- <Compile Include="Helpers\ControlAdapter.cs">
- <SubType>Component</SubType>
- </Compile>
- <Compile Include="Helpers\ControlExtensions.cs" />
- <Compile Include="Helpers\Events.cs" />
- <Compile Include="Helpers\EventTrigger.cs" />
- <Compile Include="Helpers\EventTriggerExtensions.cs" />
- <Compile Include="Helpers\EventTriggerSpecs.cs" />
- <Compile Include="Helpers\IBindableList.cs" />
- <Compile Include="Helpers\IEventTarget.cs" />
- <Compile Include="Helpers\IListControl.cs" />
- <Compile Include="Helpers\ListBoxListControl.cs" />
- <Compile Include="Helpers\SuspendLayout.cs" />
- <Compile Include="Keyboard\ShortcutKey.cs" />
- <Compile Include="Keyboard\ShortcutKeys.cs" />
- <Compile Include="Resources\ApplicationIcon.cs" />
- <Compile Include="Resources\ApplicationImage.cs" />
- <Compile Include="Resources\HybridIcon.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
- <Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
- <Name>Gorilla.Commons.Testing</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms.ThirdParty/Krypton/BindableListExtensions.cs
@@ -1,18 +0,0 @@
-using ComponentFactory.Krypton.Toolkit;
-using Gorilla.Commons.Windows.Forms.Helpers;
-
-namespace Gorilla.Commons.Windows.Forms.Krypton
-{
- static public class BindableListExtensions
- {
- static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this KryptonListBox listbox)
- {
- return BindableListFactory.create_for(new KryptonListBoxListControl<TItemToBindTo>(listbox));
- }
-
- static public IBindableList<TItemToBindTo> create_for<TItemToBindTo>(this KryptonComboBox combobox)
- {
- return BindableListFactory.create_for(new KryptonComboBoxListControl<TItemToBindTo>(combobox));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms.ThirdParty/Krypton/KryptonComboBoxListControl.cs
@@ -1,32 +0,0 @@
-using ComponentFactory.Krypton.Toolkit;
-using Gorilla.Commons.Windows.Forms.Helpers;
-
-namespace Gorilla.Commons.Windows.Forms.Krypton
-{
- public class KryptonComboBoxListControl<TItemToStore> : IListControl<TItemToStore>
- {
- readonly KryptonComboBox combo_box;
-
- public KryptonComboBoxListControl(KryptonComboBox combo_box)
- {
- this.combo_box = combo_box;
- }
-
- public TItemToStore get_selected_item()
- {
- return (TItemToStore) combo_box.SelectedItem;
- }
-
- public void add_item(TItemToStore item)
- {
- combo_box.Items.Add(item);
- combo_box.SelectedIndex = 0;
- }
-
- public void set_selected_item(TItemToStore item)
- {
- if (!Equals(item, default(TItemToStore)))
- if (combo_box.Items.Contains(item)) combo_box.SelectedItem = item;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms.ThirdParty/Krypton/KryptonListBoxListControl.cs
@@ -1,30 +0,0 @@
-using ComponentFactory.Krypton.Toolkit;
-using Gorilla.Commons.Windows.Forms.Helpers;
-
-namespace Gorilla.Commons.Windows.Forms.Krypton
-{
- public class KryptonListBoxListControl<TItemToStore> : IListControl<TItemToStore>
- {
- readonly KryptonListBox list_box;
-
- public KryptonListBoxListControl(KryptonListBox list_box)
- {
- this.list_box = list_box;
- }
-
- public TItemToStore get_selected_item()
- {
- return (TItemToStore) list_box.SelectedItem;
- }
-
- public void add_item(TItemToStore item)
- {
- list_box.Items.Add(item);
- }
-
- public void set_selected_item(TItemToStore item)
- {
- if (list_box.Items.Contains(item)) list_box.SelectedItem = item;
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms.ThirdParty/Krypton/ListboxExtensions.cs
@@ -1,15 +0,0 @@
-using System.Collections.Generic;
-using ComponentFactory.Krypton.Toolkit;
-using Gorilla.Commons.Utility.Extensions;
-
-namespace Gorilla.Commons.Windows.Forms.Krypton
-{
- static public class ListboxExtensions
- {
- static public void bind_to<T>(this KryptonComboBox control, IEnumerable<T> items)
- {
- control.Items.Clear();
- items.each(x => control.Items.Add(x));
- }
- }
-}
\ No newline at end of file
trunk/product/Gorilla.Commons.Windows.Forms.ThirdParty/Gorilla.Commons.Windows.Forms.ThirdParty.csproj
@@ -1,79 +0,0 @@
-๏ปฟ<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>9.0.30729</ProductVersion>
- <SchemaVersion>2.0</SchemaVersion>
- <ProjectGuid>{8050731D-48B2-4636-9D1C-2B6D052F39DC}</ProjectGuid>
- <OutputType>Library</OutputType>
- <AppDesignerFolder>Properties</AppDesignerFolder>
- <RootNamespace>Gorilla.Commons.Windows.Forms</RootNamespace>
- <AssemblyName>Gorilla.Commons.Windows.Forms.ThirdParty</AssemblyName>
- <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
- <FileAlignment>512</FileAlignment>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- <ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
- </PropertyGroup>
- <ItemGroup>
- <Reference Include="ComponentFactory.Krypton.Toolkit, Version=3.0.8.0, Culture=neutral, PublicKeyToken=a87e673e9ecb6e8e, processorArchitecture=MSIL">
- <SpecificVersion>False</SpecificVersion>
- <HintPath>..\..\build\lib\app\component.factory\ComponentFactory.Krypton.Toolkit.dll</HintPath>
- </Reference>
- <Reference Include="System" />
- <Reference Include="System.Core">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Windows.Forms" />
- <Reference Include="System.Xml.Linq">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data.DataSetExtensions">
- <RequiredTargetFramework>3.5</RequiredTargetFramework>
- </Reference>
- <Reference Include="System.Data" />
- <Reference Include="System.Xml" />
- </ItemGroup>
- <ItemGroup>
- <Compile Include="Krypton\BindableListExtensions.cs" />
- <Compile Include="Krypton\KryptonComboBoxListControl.cs" />
- <Compile Include="Krypton\KryptonListBoxListControl.cs" />
- <Compile Include="Krypton\ListboxExtensions.cs" />
- </ItemGroup>
- <ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Windows.Forms\Gorilla.Commons.Windows.Forms.csproj">
- <Project>{54B55B2B-A58F-45DF-A446-234C9D70DC0B}</Project>
- <Name>Gorilla.Commons.Windows.Forms</Name>
- </ProjectReference>
- </ItemGroup>
- <ItemGroup>
- <Folder Include="Properties\" />
- </ItemGroup>
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
- <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
- Other similar extension points exist, see Microsoft.Common.targets.
- <Target Name="BeforeBuild">
- </Target>
- <Target Name="AfterBuild">
- </Target>
- -->
-</Project>
\ No newline at end of file
trunk/product/MoMoney.DataAccess/MoMoney.DataAccess.csproj
@@ -47,6 +47,14 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
</Reference>
+ <Reference Include="gorilla.commons.infrastructure, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.infrastructure.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.utility, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.utility.dll</HintPath>
+ </Reference>
<Reference Include="MbUnit.Framework, Version=2.4.2.175, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\mbunit\MbUnit.Framework.dll</HintPath>
@@ -82,18 +90,10 @@
<Compile Include="IDatabaseConfiguration.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
<ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
<Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
<Name>Gorilla.Commons.Testing</Name>
</ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
<ProjectReference Include="..\MoMoney.Domain\MoMoney.Domain.csproj">
<Project>{BE790BCC-4412-473F-9D0A-5AA48FE7A74F}</Project>
<Name>MoMoney.Domain</Name>
trunk/product/MoMoney.Domain/MoMoney.Domain.csproj
@@ -39,6 +39,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
</Reference>
+ <Reference Include="gorilla.commons.utility, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.utility.dll</HintPath>
+ </Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
@@ -93,10 +97,6 @@
<Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
<Name>Gorilla.Commons.Testing</Name>
</ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
</ItemGroup>
<ItemGroup>
<Folder Include="Properties\" />
trunk/product/MoMoney.Presentation/MoMoney.Presentation.csproj
@@ -51,6 +51,22 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
</Reference>
+ <Reference Include="gorilla.commons.infrastructure, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.infrastructure.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.utility, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.utility.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.windows.forms, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.windows.forms.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.windows.forms.thirdparty, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.windows.forms.thirdparty.dll</HintPath>
+ </Reference>
<Reference Include="MbUnit.Framework, Version=2.4.2.175, Culture=neutral, PublicKeyToken=5e72ecd30bc408d5">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\mbunit\MbUnit.Framework.dll</HintPath>
@@ -424,26 +440,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
<ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
<Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
<Name>Gorilla.Commons.Testing</Name>
</ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Windows.Forms.ThirdParty\Gorilla.Commons.Windows.Forms.ThirdParty.csproj">
- <Project>{8050731D-48B2-4636-9D1C-2B6D052F39DC}</Project>
- <Name>Gorilla.Commons.Windows.Forms.ThirdParty</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Windows.Forms\Gorilla.Commons.Windows.Forms.csproj">
- <Project>{54B55B2B-A58F-45DF-A446-234C9D70DC0B}</Project>
- <Name>Gorilla.Commons.Windows.Forms</Name>
- </ProjectReference>
<ProjectReference Include="..\MoMoney.DTO\MoMoney.DTO.csproj">
<Project>{ACF52FAB-435B-48C9-A383-C787CB2D8000}</Project>
<Name>MoMoney.DTO</Name>
trunk/product/MoMoney.Service/MoMoney.Service.csproj
@@ -39,6 +39,14 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
</Reference>
+ <Reference Include="gorilla.commons.infrastructure, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.infrastructure.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.utility, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.utility.dll</HintPath>
+ </Reference>
<Reference Include="Rhino.Mocks, Version=3.5.0.1337, Culture=neutral, PublicKeyToken=0b3305902db7183f, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\rhino.mocks\Rhino.Mocks.dll</HintPath>
@@ -95,18 +103,10 @@
<Compile Include="Infrastructure\Updating\WhatIsTheAvailableVersion.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
<ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
<Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
<Name>Gorilla.Commons.Testing</Name>
</ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
<ProjectReference Include="..\MoMoney.DataAccess\MoMoney.DataAccess.csproj">
<Project>{580E68A8-EDEE-4350-8BBE-A053645B0F83}</Project>
<Name>MoMoney.DataAccess</Name>
trunk/product/MyMoney/boot/container/registration/proxy_configuration/ServiceLayerConfiguration.cs
@@ -12,9 +12,7 @@ namespace MoMoney.boot.container.registration.proxy_configuration
public void configure(IProxyBuilder<T> item)
{
item.add_interceptor(Lazy.load<IUnitOfWorkInterceptor>()).intercept_all();
- item.add_interceptor(
- new SecuringProxy(new IsInRole("Users").or(new IsInRole("Administrators"))))
- .intercept_all();
+ //item.add_interceptor( new SecuringProxy(new IsInRole("Users").or(new IsInRole("Administrators")))) .intercept_all();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/auto_wire_components_in_to_the.cs
@@ -1,9 +1,12 @@
using System;
using System.Reflection;
using Gorilla.Commons.Infrastructure;
+using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
using Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration;
+using Gorilla.Commons.Infrastructure.Eventing;
using Gorilla.Commons.Infrastructure.Reflection;
using Gorilla.Commons.Utility.Extensions;
+using MoMoney.Infrastructure.Container.Windsor.configuration;
namespace MoMoney.boot.container.registration
{
@@ -12,6 +15,11 @@ namespace MoMoney.boot.container.registration
readonly IDependencyRegistration registrar;
readonly IComponentExclusionSpecification exclusion_policy;
+ public auto_wire_components_in_to_the(IDependencyRegistration registrar)
+ : this(registrar, new ComponentExclusionSpecification())
+ {
+ }
+
public auto_wire_components_in_to_the(IDependencyRegistration registration,
IComponentExclusionSpecification exclusion_policy)
{
@@ -22,6 +30,7 @@ namespace MoMoney.boot.container.registration
public void run()
{
run(new ApplicationAssembly(Assembly.GetExecutingAssembly()));
+ //run(new ApplicationAssembly(Assembly.GetAssembly(typeof(IEventAggregator))));
}
public void run(IAssembly item)
trunk/product/MyMoney/boot/container/registration/wire_up_the_data_access_components_into_the.cs
@@ -1,10 +1,13 @@
using Gorilla.Commons.Infrastructure;
+using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
+using Gorilla.Commons.Infrastructure.Cloning;
using Gorilla.Commons.Infrastructure.Container;
using Gorilla.Commons.Infrastructure.Transactions;
using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
using MoMoney.boot.container.registration.proxy_configuration;
using MoMoney.DataAccess;
+using MoMoney.DataAccess.Db40;
namespace MoMoney.boot.container.registration
{
@@ -21,7 +24,19 @@ namespace MoMoney.boot.container.registration
{
register.singleton<IDatabase, ObjectDatabase>();
register.singleton(() => Resolve.the<IDatabase>().downcast_to<IDatabaseConfiguration>());
+ register.transient<ISessionProvider, SessionProvider>();
register.proxy<ISession, NoConfiguration<ISession>>( () => Resolve.the<ISessionProvider>().get_the_current_session());
+
+ register.transient<IUnitOfWorkInterceptor, UnitOfWorkInterceptor>();
+ register.transient<IUnitOfWorkFactory, UnitOfWorkFactory>();
+ register.transient<ISessionFactory, SessionFactory>();
+ register.transient<IChangeTrackerFactory, ChangeTrackerFactory>();
+ register.transient<IStatementRegistry, StatementRegistry>();
+ register.transient<IConnectionFactory, ConnectionFactory>();
+ register.transient<IConfigureDatabaseStep, ConfigureDatabaseStep>();
+ register.transient<IPrototype, Prototype>();
+
+
}
}
}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_essential_services_into_the.cs
@@ -1,12 +1,8 @@
-using System.ComponentModel;
-using System.Deployment.Application;
using Gorilla.Commons.Infrastructure;
using Gorilla.Commons.Infrastructure.Container;
using Gorilla.Commons.Infrastructure.Log4Net;
using Gorilla.Commons.Infrastructure.Logging;
-using Gorilla.Commons.Infrastructure.Threading;
using Gorilla.Commons.Utility.Core;
-using MoMoney.Tasks.infrastructure.updating;
namespace MoMoney.boot.container.registration
{
@@ -24,11 +20,6 @@ namespace MoMoney.boot.container.registration
registration.singleton<IDependencyRegistration>(() => registration);
registration.singleton<IDependencyRegistry>(() => registration.build());
registration.singleton<ILogFactory, Log4NetLogFactory>();
- registration.singleton<ICommandProcessor, AsynchronousCommandProcessor>();
- registration.singleton(() => AsyncOperationManager.SynchronizationContext);
- registration.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(new object()));
- registration.singleton<ApplicationDeployment>( () => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
- registration.singleton<IDeployment>( () => ApplicationDeployment.IsNetworkDeployed ? (IDeployment) new CurrentDeployment() : (IDeployment) new NullDeployment());
}
}
}
\ No newline at end of file
trunk/product/MyMoney/boot/container/registration/wire_up_the_infrastructure_in_to_the.cs
@@ -1,10 +1,14 @@
+using System.ComponentModel;
+using System.Deployment.Application;
using Gorilla.Commons.Infrastructure;
+using Gorilla.Commons.Infrastructure.Castle.DynamicProxy.Interceptors;
using Gorilla.Commons.Infrastructure.Eventing;
using Gorilla.Commons.Infrastructure.Registries;
using Gorilla.Commons.Infrastructure.Threading;
using Gorilla.Commons.Infrastructure.Transactions;
using Gorilla.Commons.Utility.Core;
using MoMoney.Presentation.Model.Projects;
+using MoMoney.Tasks.infrastructure.updating;
namespace MoMoney.boot.container.registration
{
@@ -24,9 +28,24 @@ namespace MoMoney.boot.container.registration
registry.singleton<IProjectController, ProjectController>();
registry.transient(typeof (IRegistry<>), typeof (DefaultRegistry<>));
registry.transient(typeof (ITrackerEntryMapper<>), typeof (TrackerEntryMapper<>));
- registry.transient(typeof(IKey<>), typeof(TypedKey<>));
+ registry.transient(typeof (IKey<>), typeof (TypedKey<>));
registry.transient(typeof (IComponentFactory<>), typeof (ComponentFactory<>));
registry.singleton<IContext, Context>();
+
+ registry.singleton(() => AsyncOperationManager.SynchronizationContext);
+ registry.singleton<AsyncOperation>(() => AsyncOperationManager.CreateOperation(new object()));
+ registry.singleton<ApplicationDeployment>(
+ () => ApplicationDeployment.IsNetworkDeployed ? ApplicationDeployment.CurrentDeployment : null);
+ registry.singleton<IDeployment>(
+ () =>
+ ApplicationDeployment.IsNetworkDeployed
+ ? (IDeployment) new CurrentDeployment()
+ : (IDeployment) new NullDeployment());
+
+ registry.transient<ICommandPump, CommandPump>();
+ registry.transient<ICommandFactory, CommandFactory>();
+ registry.transient<ISynchronizationContextFactory, SynchronizationContextFactory>();
+ registry.singleton<ICommandProcessor, AsynchronousCommandProcessor>();
}
}
}
\ No newline at end of file
trunk/product/MyMoney/boot/container/wire_up_the_container.cs
@@ -1,33 +1,28 @@
using Gorilla.Commons.Infrastructure;
using Gorilla.Commons.Infrastructure.Autofac;
-using Gorilla.Commons.Infrastructure.Castle.Windsor.Configuration;
using Gorilla.Commons.Infrastructure.Container;
using Gorilla.Commons.Utility.Core;
using Gorilla.Commons.Utility.Extensions;
using MoMoney.boot.container.registration;
-using MoMoney.Infrastructure.Container.Windsor.configuration;
namespace MoMoney.boot.container
{
internal class wire_up_the_container : ICommand
{
readonly IDependencyRegistration registry;
- readonly IComponentExclusionSpecification specification;
- public wire_up_the_container()
- : this(new AutofacDependencyRegistryBuilder(), new ComponentExclusionSpecification())
+ public wire_up_the_container() : this(new AutofacDependencyRegistryBuilder())
{
}
- public wire_up_the_container(IDependencyRegistration registry, IComponentExclusionSpecification specification)
+ public wire_up_the_container(IDependencyRegistration registry)
{
this.registry = registry;
- this.specification = specification;
}
public void run()
{
- new auto_wire_components_in_to_the(registry, specification)
+ new auto_wire_components_in_to_the(registry)
.then(new wire_up_the_essential_services_into_the(registry))
.then(new wire_up_the_data_access_components_into_the(registry))
.then(new wire_up_the_infrastructure_in_to_the(registry))
trunk/product/MyMoney/MyMoney.csproj
@@ -95,6 +95,22 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\test\developwithpassion\developwithpassion.bdd.dll</HintPath>
</Reference>
+ <Reference Include="gorilla.commons.infrastructure, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.infrastructure.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.infrastructure.thirdparty, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.infrastructure.thirdparty.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.utility, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.utility.dll</HintPath>
+ </Reference>
+ <Reference Include="gorilla.commons.windows.forms, Version=2009.5.5.1633, Culture=neutral, PublicKeyToken=687787ccb6c36c9f, processorArchitecture=MSIL">
+ <SpecificVersion>False</SpecificVersion>
+ <HintPath>..\..\build\lib\app\gorilla\gorilla.commons.windows.forms.dll</HintPath>
+ </Reference>
<Reference Include="JetBrains.Annotations, Version=4.1.933.3, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\lib\app\jetbrains\JetBrains.Annotations.dll</HintPath>
@@ -241,26 +257,10 @@
<Compile Include="boot\container\registration\wire_up_the_views_in_to_the.cs" />
</ItemGroup>
<ItemGroup>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure.ThirdParty\Gorilla.Commons.Infrastructure.ThirdParty.csproj">
- <Project>{04DC09B4-5DF9-44A6-8DD1-05941F0D0228}</Project>
- <Name>Gorilla.Commons.Infrastructure.ThirdParty</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Infrastructure\Gorilla.Commons.Infrastructure.csproj">
- <Project>{AA5EEED9-4531-45F7-AFCD-AD9717D2E405}</Project>
- <Name>Gorilla.Commons.Infrastructure</Name>
- </ProjectReference>
<ProjectReference Include="..\Gorilla.Commons.Testing\Gorilla.Commons.Testing.csproj">
<Project>{44E65096-9657-4716-90F8-4535BABE8039}</Project>
<Name>Gorilla.Commons.Testing</Name>
</ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Utility\Gorilla.Commons.Utility.csproj">
- <Project>{DD8FD29E-7424-415C-9BA3-7D9F6ECBA161}</Project>
- <Name>Gorilla.Commons.Utility</Name>
- </ProjectReference>
- <ProjectReference Include="..\Gorilla.Commons.Windows.Forms\Gorilla.Commons.Windows.Forms.csproj">
- <Project>{54B55B2B-A58F-45DF-A446-234C9D70DC0B}</Project>
- <Name>Gorilla.Commons.Windows.Forms</Name>
- </ProjectReference>
<ProjectReference Include="..\MoMoney.DataAccess\MoMoney.DataAccess.csproj">
<Project>{580E68A8-EDEE-4350-8BBE-A053645B0F83}</Project>
<Name>MoMoney.DataAccess</Name>