2 using System.Windows.Controls;
3 using System.Windows.Navigation;
5 using Caliburn.Micro.Logging;
6 using Microsoft.Windows.Controls;
7 using Pithos.Client.WPF.Properties;
10 using log4net.Appender;
15 namespace Pithos.Client.WPF
18 using System.Collections.Generic;
19 using System.ComponentModel.Composition;
20 using System.ComponentModel.Composition.Hosting;
21 using System.ComponentModel.Composition.Primitives;
25 public class AppBootstrapper : Bootstrapper<IShell>
27 CompositionContainer container;
29 public AppBootstrapper()
31 LogManager.GetLog = type => new log4netLogger(type);
36 private void UpgradeSettings()
38 if (Settings.Default.MustUpgrade)
40 Settings.Default.Upgrade();
41 Settings.Default.MustUpgrade = false;
42 Settings.Default.Save();
47 /// By default, we are configured to use MEF
49 protected override void Configure() {
50 var catalog = new AggregateCatalog(
51 AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
54 Type[] types = { typeof(PithosMonitor), typeof(CloudFilesClient) };
55 foreach (var type in types)
57 catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly));
60 container = new CompositionContainer(catalog);
62 var batch = new CompositionBatch();
64 batch.AddExportedValue<IWindowManager>(new WindowManager());
65 batch.AddExportedValue<IEventAggregator>(new EventAggregator());
66 batch.AddExportedValue(container);
67 batch.AddExportedValue(catalog);
70 container.Compose(batch);
72 ConventionManager.AddElementConvention<MenuItem>(ItemsControl.ItemsSourceProperty, "DataContext", "Click");
73 ConventionManager.AddElementConvention<IntegerUpDown>(IntegerUpDown.ValueProperty, "Value", "ValueChanged");
76 protected override object GetInstance(Type serviceType, string key)
78 string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
79 var exports = container.GetExportedValues<object>(contract);
81 if (exports.Count() > 0)
82 return exports.First();
84 throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
87 protected override IEnumerable<object> GetAllInstances(Type serviceType)
89 return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
92 protected override void BuildUp(object instance)
94 container.SatisfyImportsOnce(instance);