diff --git a/Eve-O-Preview/ApplicationBase/ApplicationController.cs b/Eve-O-Preview/ApplicationBase/ApplicationController.cs new file mode 100644 index 0000000..5109d99 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/ApplicationController.cs @@ -0,0 +1,69 @@ +namespace EveOPreview +{ + public class ApplicationController : IApplicationController + { + private readonly IIocContainer _container; + + public ApplicationController(IIocContainer container) + { + this._container = container; + this._container.RegisterInstance(this); + } + + public IApplicationController RegisterView() + where TView : IView + where TImplementation : class, TView + { + this._container.Register(); + return this; + } + + public IApplicationController RegisterInstance(TArgument instance) + { + this._container.RegisterInstance(instance); + return this; + } + + public IApplicationController RegisterService() + where TImplementation : class, TService + { + this._container.Register(); + return this; + } + + public void Run() + where TPresenter : class, IPresenter + { + if (!this._container.IsRegistered()) + { + this._container.Register(); + } + + TPresenter presenter = this._container.Resolve(); + presenter.Run(); + } + + public void Run(TParameter args) + where TPresenter : class, IPresenter + { + if (!this._container.IsRegistered()) + { + this._container.Register(); + } + + TPresenter presenter = this._container.Resolve(); + presenter.Run(args); + } + + public TService Create() + where TService : class + { + if (!this._container.IsRegistered()) + { + this._container.Register(); + } + + return this._container.Resolve(); + } + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/IApplicationController.cs b/Eve-O-Preview/ApplicationBase/IApplicationController.cs new file mode 100644 index 0000000..0f07c48 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/IApplicationController.cs @@ -0,0 +1,26 @@ +namespace EveOPreview +{ + /// + /// Application controller + /// + public interface IApplicationController + { + IApplicationController RegisterView() + where TPresenter : class, TView + where TView : IView; + + IApplicationController RegisterInstance(T instance); + + IApplicationController RegisterService() + where TImplementation : class, TService; + + void Run() + where TPresenter : class, IPresenter; + + void Run(TArgument args) + where TPresenter : class, IPresenter; + + TService Create() + where TService : class; + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/IIocContainer.cs b/Eve-O-Preview/ApplicationBase/IIocContainer.cs new file mode 100644 index 0000000..273de67 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/IIocContainer.cs @@ -0,0 +1,18 @@ +using System; +using System.Linq.Expressions; + +namespace EveOPreview +{ + /// + /// Generic interface for an Inversion Of Control container + /// + public interface IIocContainer + { + void Register() where TImplementation : TService; + void Register(); + void RegisterInstance(T instance); + TService Resolve(); + bool IsRegistered(); + void Register(Expression> factory); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/IPresenter.cs b/Eve-O-Preview/ApplicationBase/IPresenter.cs new file mode 100644 index 0000000..34b6c70 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/IPresenter.cs @@ -0,0 +1,7 @@ +namespace EveOPreview +{ + public interface IPresenter + { + void Run(); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/IPresenterGeneric.cs b/Eve-O-Preview/ApplicationBase/IPresenterGeneric.cs new file mode 100644 index 0000000..915b855 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/IPresenterGeneric.cs @@ -0,0 +1,7 @@ +namespace EveOPreview +{ + public interface IPresenter + { + void Run(TArgument args); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/IView.cs b/Eve-O-Preview/ApplicationBase/IView.cs new file mode 100644 index 0000000..acfd9c0 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/IView.cs @@ -0,0 +1,12 @@ +namespace EveOPreview +{ + /// + /// Properties and methods that are common for all views + /// + public interface IView + { + void Show(); + void Hide(); + void Close(); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs b/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs new file mode 100644 index 0000000..73567c9 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/LightInjectContainer.cs @@ -0,0 +1,48 @@ +using System; +using System.Linq.Expressions; +using LightInject; + +namespace EveOPreview +{ + // Adapts LighInject to the generic IoC interface + sealed class LightInjectContainer : IIocContainer + { + private readonly ServiceContainer _container; + + public LightInjectContainer() + { + this._container = new ServiceContainer(ContainerOptions.Default); + } + + public bool IsRegistered() + { + return this._container.CanGetInstance(typeof(TService), ""); + } + + public void Register() + { + this._container.Register(); + } + + public void Register() + where TImplementation : TService + { + this._container.Register(); + } + + public void Register(Expression> factory) + { + this._container.Register(f => factory); + } + + public void RegisterInstance(T instance) + { + this._container.RegisterInstance(instance); + } + + public TService Resolve() + { + return this._container.GetInstance(); + } + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/Presenter.cs b/Eve-O-Preview/ApplicationBase/Presenter.cs new file mode 100644 index 0000000..6a42ed3 --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/Presenter.cs @@ -0,0 +1,22 @@ +namespace EveOPreview +{ + public abstract class Presenter : IPresenter + where TView : IView + { + // Properties are used instead of fields so the code remains CLS compliant + // 'protected readonly' fields would result in non-CLS compliant code + protected TView View { get; private set; } + protected IApplicationController Controller { get; private set; } + + protected Presenter(IApplicationController controller, TView view) + { + this.Controller = controller; + this.View = view; + } + + public void Run() + { + this.View.Show(); + } + } +} \ No newline at end of file diff --git a/Eve-O-Preview/ApplicationBase/PresenterGeneric.cs b/Eve-O-Preview/ApplicationBase/PresenterGeneric.cs new file mode 100644 index 0000000..438161b --- /dev/null +++ b/Eve-O-Preview/ApplicationBase/PresenterGeneric.cs @@ -0,0 +1,19 @@ +namespace EveOPreview +{ + public abstract class Presenter : IPresenter + where TView : IView + { + // Properties are used instead of fields so the code remains CLS compliant + // 'protected readonly' fields would result in non-CLS compliant code + protected TView View { get; private set; } + protected IApplicationController Controller { get; private set; } + + protected Presenter(IApplicationController controller, TView view) + { + this.Controller = controller; + this.View = view; + } + + public abstract void Run(TArgument args); + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Configuration/Configuration.cs b/Eve-O-Preview/Configuration/Configuration.cs index 62d40ec..a7fe428 100644 --- a/Eve-O-Preview/Configuration/Configuration.cs +++ b/Eve-O-Preview/Configuration/Configuration.cs @@ -1,4 +1,4 @@ -namespace EveOPreview +namespace EveOPreview.Configuration { public class Configuration { diff --git a/Eve-O-Preview/Configuration/ConfigurationStorage.cs b/Eve-O-Preview/Configuration/ConfigurationStorage.cs index 974930e..e2bf967 100644 --- a/Eve-O-Preview/Configuration/ConfigurationStorage.cs +++ b/Eve-O-Preview/Configuration/ConfigurationStorage.cs @@ -1,4 +1,4 @@ -namespace EveOPreview.Managers +namespace EveOPreview.Configuration { public class ConfigurationStorage { diff --git a/Eve-O-Preview/Configuration/WindowProperties.cs b/Eve-O-Preview/Configuration/WindowProperties.cs new file mode 100644 index 0000000..00df984 --- /dev/null +++ b/Eve-O-Preview/Configuration/WindowProperties.cs @@ -0,0 +1,11 @@ +namespace EveOPreview +{ + public class WindowProperties + { + public int X { get; set; } + public int Y { get; set; } + + public int Width { get; set; } + public int Height { get; set; } + } +} \ No newline at end of file diff --git a/Eve-O-Preview/Eve-O-Preview.csproj b/Eve-O-Preview/Eve-O-Preview.csproj index 99848fb..70e2f42 100644 --- a/Eve-O-Preview/Eve-O-Preview.csproj +++ b/Eve-O-Preview/Eve-O-Preview.csproj @@ -90,10 +90,11 @@ - - + + ..\packages\LightInject.4.0.9\lib\net45\LightInject.dll + True + - @@ -103,39 +104,57 @@ + + + + + + + - - + + + + + + + + + + + + + - - - + + + Form - + MainForm.cs - - - - + + + + Form - + ThumbnailOverlay.cs - + Designer MainForm.cs - + ThumbnailOverlay.cs @@ -143,9 +162,9 @@ Resources.Designer.cs Designer - + Designer - ThumbnailWindow.cs + ThumbnailView.cs True @@ -155,6 +174,7 @@ Designer + SettingsSingleFileGenerator Settings.Designer.cs @@ -164,11 +184,11 @@ Settings.settings True - + Form - - ThumbnailWindow.cs + + ThumbnailView.cs @@ -200,6 +220,9 @@ + + +