using System.Windows; using System.Windows.Controls; using System.Windows.Navigation; using Caliburn.Micro; using Caliburn.Micro.Logging; using Microsoft.Windows.Controls; using Pithos.Client.WPF.Properties; using Pithos.Core; using Pithos.Network; using log4net.Appender; using log4net.Config; using log4net.Filter; using log4net.Layout; namespace Pithos.Client.WPF { using System; using System.Collections.Generic; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.ComponentModel.Composition.Primitives; using System.Linq; using Caliburn.Micro; public class AppBootstrapper : Bootstrapper { CompositionContainer container; public AppBootstrapper() { LogManager.GetLog = type => new log4netLogger(type); UpgradeSettings(); } private void UpgradeSettings() { if (Settings.Default.MustUpgrade) { Settings.Default.Upgrade(); Settings.Default.MustUpgrade = false; Settings.Default.Save(); } } /// /// By default, we are configured to use MEF /// protected override void Configure() { var catalog = new AggregateCatalog( AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType() ); Type[] types = { typeof(PithosMonitor), typeof(CloudFilesClient) }; foreach (var type in types) { catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly)); } container = new CompositionContainer(catalog); var batch = new CompositionBatch(); batch.AddExportedValue(new WindowManager()); batch.AddExportedValue(new EventAggregator()); batch.AddExportedValue(container); batch.AddExportedValue(catalog); container.Compose(batch); ConventionManager.AddElementConvention(ItemsControl.ItemsSourceProperty, "DataContext", "Click"); ConventionManager.AddElementConvention(IntegerUpDown.ValueProperty, "Value", "ValueChanged"); } protected override object GetInstance(Type serviceType, string key) { string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key; var exports = container.GetExportedValues(contract); if (exports.Any()) return exports.First(); throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract)); } protected override IEnumerable GetAllInstances(Type serviceType) { return container.GetExportedValues(AttributedModelServices.GetContractName(serviceType)); } protected override void BuildUp(object instance) { container.SatisfyImportsOnce(instance); } } }