summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrakeWPF/Startup
diff options
context:
space:
mode:
Diffstat (limited to 'win/CS/HandBrakeWPF/Startup')
-rw-r--r--win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs169
-rw-r--r--win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs165
2 files changed, 169 insertions, 165 deletions
diff --git a/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs
new file mode 100644
index 000000000..c4ddeb1ad
--- /dev/null
+++ b/win/CS/HandBrakeWPF/Startup/AppBootstrapper.cs
@@ -0,0 +1,169 @@
+// --------------------------------------------------------------------------------------------------------------------
+// <copyright file="AppBootstrapper.cs" company="HandBrake Project (http://handbrake.fr)">
+// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
+// </copyright>
+// <summary>
+// The Castle Bootstrapper
+// </summary>
+// --------------------------------------------------------------------------------------------------------------------
+
+namespace HandBrakeWPF.Startup
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Reflection;
+
+ using Caliburn.Micro;
+
+ using HandBrake.ApplicationServices.Services.Encode;
+ using HandBrake.ApplicationServices.Services.Encode.Interfaces;
+ using HandBrake.ApplicationServices.Services.Scan;
+ using HandBrake.ApplicationServices.Services.Scan.Interfaces;
+
+ using HandBrakeWPF.Commands;
+ using HandBrakeWPF.Commands.Interfaces;
+ using HandBrakeWPF.Services;
+ using HandBrakeWPF.Services.Interfaces;
+ using HandBrakeWPF.Services.Presets;
+ using HandBrakeWPF.Services.Presets.Interfaces;
+ using HandBrakeWPF.Services.Queue;
+ using HandBrakeWPF.Services.Queue.Interfaces;
+ using HandBrakeWPF.ViewModels;
+ using HandBrakeWPF.ViewModels.Interfaces;
+
+ /// <summary>
+ /// The Castle Bootstrapper
+ /// </summary>
+ public class AppBootstrapper : Bootstrapper<IShellViewModel>
+ {
+ private SimpleContainer container;
+
+ /// <summary>
+ /// Configure Castle Windsor
+ /// </summary>
+ protected override void Configure()
+ {
+ this.container = new SimpleContainer();
+
+ this.container.Singleton<IWindowManager, WindowManager>();
+ this.container.Singleton<IEventAggregator, EventAggregator>();
+
+ // Services
+ this.container.Singleton<IUpdateService, UpdateService>();
+ this.container.Singleton<IScan, LibScan>();
+ this.container.Singleton<IEncode, LibEncode>();
+ this.container.Singleton<INotificationService, NotificationService>();
+ this.container.Singleton<IPrePostActionService, PrePostActionService>();
+ this.container.Singleton<IUserSettingService, UserSettingService>();
+ this.container.Singleton<IPresetService, PresetService>();
+ this.container.Singleton<IQueueProcessor, QueueProcessor>();
+
+ // Commands
+ this.container.Singleton<IAdvancedEncoderOptionsCommand, AdvancedEncoderOptionsCommand>();
+
+ // Services and Shell Components
+ this.container.Singleton<IErrorService, ErrorService>();
+ this.container.Singleton<IErrorViewModel, ErrorViewModel>();
+ this.container.Singleton<IMainViewModel, MainViewModel>();
+ this.container.Singleton<IQueueViewModel, QueueViewModel>();
+ this.container.PerRequest<IAddPresetViewModel, AddPresetViewModel>();
+ this.container.Singleton<ILogViewModel, LogViewModel>();
+ this.container.Singleton<IAboutViewModel, AboutViewModel>();
+ this.container.Singleton<IOptionsViewModel, OptionsViewModel>();
+ this.container.Singleton<ITitleSpecificViewModel, TitleSpecificViewModel>();
+ this.container.Singleton<IQueueSelectionViewModel, QueueSelectionViewModel>();
+ this.container.Singleton<ICountdownAlertViewModel, CountdownAlertViewModel>();
+ this.container.Singleton<IMiniViewModel, MiniViewModel>();
+ this.container.Singleton<IStaticPreviewViewModel, StaticPreviewViewModel>();
+
+
+ // Tab Components
+ this.container.Singleton<IAudioViewModel, AudioViewModel>();
+ this.container.Singleton<IX264ViewModel, X264ViewModel>();
+ this.container.Singleton<IAdvancedViewModel, AdvancedViewModel>();
+ this.container.Singleton<IPictureSettingsViewModel, PictureSettingsViewModel>();
+ this.container.Singleton<IChaptersViewModel, ChaptersViewModel>();
+ this.container.Singleton<ISubtitlesViewModel, SubtitlesViewModel>();
+ this.container.Singleton<IFiltersViewModel, FiltersViewModel>();
+ this.container.Singleton<IVideoViewModel, VideoViewModel>();
+
+ // Shell
+ this.container.Singleton<IShellViewModel, ShellViewModel>();
+
+ base.Configure();
+ }
+
+ /// <summary>
+ /// Select Assemblies
+ /// </summary>
+ /// <returns>
+ /// A List of Assembly objects
+ /// </returns>
+ protected override IEnumerable<Assembly> SelectAssemblies()
+ {
+ return AppDomain.CurrentDomain.GetAssemblies();
+ }
+
+ /// <summary>
+ /// Get an Instance of a service
+ /// </summary>
+ /// <param name="service">
+ /// The service.
+ /// </param>
+ /// <param name="key">
+ /// The key.
+ /// </param>
+ /// <returns>
+ /// The Service Requested
+ /// </returns>
+ protected override object GetInstance(Type service, string key)
+ {
+ var instance = container.GetInstance(service, key);
+ if (instance != null)
+ {
+ // this.BuildUp(instance);
+ return instance;
+ }
+
+ throw new InvalidOperationException("Could not locate any instances for: " + key);
+ }
+
+ /// <summary>
+ /// Get all instances of a service
+ /// </summary>
+ /// <param name="service">
+ /// The service.
+ /// </param>
+ /// <returns>
+ /// A collection of instances of the requested service type.
+ /// </returns>
+ protected override IEnumerable<object> GetAllInstances(Type service)
+ {
+ IEnumerable<object> instances = this.container.GetAllInstances(service);
+ if (instances != null)
+ {
+ foreach (var item in instances)
+ {
+ // this.BuildUp(item);
+ }
+ }
+
+ return instances;
+ }
+
+ /// <summary>
+ /// Build Up
+ /// </summary>
+ /// <param name="instance">
+ /// The instance.
+ /// </param>
+ protected override void BuildUp(object instance)
+ {
+ //instance.GetType().GetProperties()
+ // .Where(property => property.CanWrite && property.PropertyType.IsPublic)
+ // .ForEach(property => property.SetValue(instance, this.container.GetInstance(property.PropertyType, property.Name), null));
+
+ this.container.BuildUp(instance);
+ }
+ }
+}
diff --git a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs b/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
deleted file mode 100644
index 4bb0a0cda..000000000
--- a/win/CS/HandBrakeWPF/Startup/CastleBootstrapper.cs
+++ /dev/null
@@ -1,165 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="CastleBootstrapper.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// The Castle Bootstrapper
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrakeWPF.Startup
-{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Reflection;
-
- using Caliburn.Micro;
-
- using Castle.Core;
- using Castle.MicroKernel.Registration;
- using Castle.Windsor;
-
- using HandBrake.ApplicationServices.Services.Encode;
- using HandBrake.ApplicationServices.Services.Encode.Interfaces;
- using HandBrake.ApplicationServices.Services.Logging;
- using HandBrake.ApplicationServices.Services.Scan;
- using HandBrake.ApplicationServices.Services.Scan.Interfaces;
-
- using HandBrakeWPF.Commands;
- using HandBrakeWPF.Commands.Interfaces;
- using HandBrakeWPF.Services.Presets;
- using HandBrakeWPF.Services.Presets.Interfaces;
-
- using ViewModels;
- using ViewModels.Interfaces;
-
- using HandBrakeWPF.Services;
- using HandBrakeWPF.Services.Interfaces;
- using HandBrakeWPF.Services.Queue;
- using HandBrakeWPF.Services.Queue.Interfaces;
-
- /// <summary>
- /// The Castle Bootstrapper
- /// </summary>
- public class CastleBootstrapper : Bootstrapper<IShellViewModel>
- {
- /// <summary>
- /// The Windsor Container
- /// </summary>
- private IWindsorContainer windsorContainer;
-
- /// <summary>
- /// Configure Castle Windsor
- /// </summary>
- protected override void Configure()
- {
- this.windsorContainer = new WindsorContainer();
- this.windsorContainer.Register(Component.For<IWindowManager>().ImplementedBy<WindowManager>());
- this.windsorContainer.Register(Component.For<IEventAggregator>().ImplementedBy<EventAggregator>());
-
- // Initialise the ApplicationServices IWindsorInstaller
- // this.windsorContainer.Register(Component.For<IWindsorInstaller>().ImplementedBy<ServicesWindsorInstaller>());
- // this.windsorContainer.Install(windsorContainer.ResolveAll<IWindsorInstaller>());
-
- // Services
- this.windsorContainer.Register(Component.For<IUpdateService>().ImplementedBy<UpdateService>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IScan>().ImplementedBy<LibScan>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IEncode>().ImplementedBy<LibEncode>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<INotificationService>().ImplementedBy<NotificationService>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IPrePostActionService>().ImplementedBy<PrePostActionService>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IUserSettingService>().ImplementedBy<UserSettingService>());
- this.windsorContainer.Register(Component.For<IPresetService>().ImplementedBy<PresetService>());
- this.windsorContainer.Register(Component.For<IQueueProcessor>().ImplementedBy<QueueProcessor>());
-
- // Commands
- this.windsorContainer.Register(Component.For<IAdvancedEncoderOptionsCommand>().ImplementedBy<AdvancedEncoderOptionsCommand>().LifeStyle.Is(LifestyleType.Singleton));
-
- // Shell
- this.windsorContainer.Register(Component.For<IErrorService>().ImplementedBy<ErrorService>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IErrorViewModel>().ImplementedBy<ErrorViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IMainViewModel>().ImplementedBy<MainViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IShellViewModel>().ImplementedBy<ShellViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IQueueViewModel>().ImplementedBy<QueueViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IAddPresetViewModel>().ImplementedBy<AddPresetViewModel>().LifeStyle.Is(LifestyleType.Transient));
- this.windsorContainer.Register(Component.For<ILogViewModel>().ImplementedBy<LogViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IAboutViewModel>().ImplementedBy<AboutViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IOptionsViewModel>().ImplementedBy<OptionsViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<ITitleSpecificViewModel>().ImplementedBy<TitleSpecificViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IQueueSelectionViewModel>().ImplementedBy<QueueSelectionViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<ICountdownAlertViewModel>().ImplementedBy<CountdownAlertViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IMiniViewModel>().ImplementedBy<MiniViewModel>().LifeStyle.Is(LifestyleType.Singleton));
-
- // Experimental Services and Windows.
- this.windsorContainer.Register(Component.For<IStaticPreviewViewModel>().ImplementedBy<StaticPreviewViewModel>().LifeStyle.Is(LifestyleType.Singleton));
-
- // Tab Components
- this.windsorContainer.Register(Component.For<IAudioViewModel>().ImplementedBy<AudioViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IX264ViewModel>().ImplementedBy<X264ViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IAdvancedViewModel>().ImplementedBy<AdvancedViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IPictureSettingsViewModel>().ImplementedBy<PictureSettingsViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IChaptersViewModel>().ImplementedBy<ChaptersViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<ISubtitlesViewModel>().ImplementedBy<SubtitlesViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IFiltersViewModel>().ImplementedBy<FiltersViewModel>().LifeStyle.Is(LifestyleType.Singleton));
- this.windsorContainer.Register(Component.For<IVideoViewModel>().ImplementedBy<VideoViewModel>().LifeStyle.Is(LifestyleType.Singleton));
-
- // Overlay Panels
- }
-
- /// <summary>
- /// Select Assemblies
- /// </summary>
- /// <returns>
- /// A List of Assembly objects
- /// </returns>
- protected override IEnumerable<Assembly> SelectAssemblies()
- {
- return AppDomain.CurrentDomain.GetAssemblies();
- }
-
- /// <summary>
- /// Get an Instance of a service
- /// </summary>
- /// <param name="service">
- /// The service.
- /// </param>
- /// <param name="key">
- /// The key.
- /// </param>
- /// <returns>
- /// The Service Requested
- /// </returns>
- protected override object GetInstance(Type service, string key)
- {
- return string.IsNullOrWhiteSpace(key) ? this.windsorContainer.Resolve(service) : this.windsorContainer.Resolve(key, new { });
- }
-
- /// <summary>
- /// Get all instances of a service
- /// </summary>
- /// <param name="service">
- /// The service.
- /// </param>
- /// <returns>
- /// A collection of instances of the requested service type.
- /// </returns>
- protected override IEnumerable<object> GetAllInstances(Type service)
- {
- return this.windsorContainer.ResolveAll(service).Cast<object>();
- }
-
- /// <summary>
- /// Build Up
- /// </summary>
- /// <param name="instance">
- /// The instance.
- /// </param>
- protected override void BuildUp(object instance)
- {
- instance.GetType().GetProperties()
- .Where(property => property.CanWrite && property.PropertyType.IsPublic)
- .Where(property => this.windsorContainer.Kernel.HasComponent(property.PropertyType))
- .ForEach(property => property.SetValue(instance, this.windsorContainer.Resolve(property.PropertyType), null));
- }
- }
-}