2 /* -----------------------------------------------------------------------
\r
3 * <copyright file="AppBootstrapper.cs" company="GRNet">
\r
5 * Copyright 2011-2012 GRNET S.A. All rights reserved.
\r
7 * Redistribution and use in source and binary forms, with or
\r
8 * without modification, are permitted provided that the following
\r
9 * conditions are met:
\r
11 * 1. Redistributions of source code must retain the above
\r
12 * copyright notice, this list of conditions and the following
\r
15 * 2. Redistributions in binary form must reproduce the above
\r
16 * copyright notice, this list of conditions and the following
\r
17 * disclaimer in the documentation and/or other materials
\r
18 * provided with the distribution.
\r
21 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
\r
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
\r
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
\r
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
\r
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
\r
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
\r
28 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
\r
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
\r
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
\r
32 * POSSIBILITY OF SUCH DAMAGE.
\r
34 * The views and conclusions contained in the software and
\r
35 * documentation are those of the authors and should not be
\r
36 * interpreted as representing official policies, either expressed
\r
37 * or implied, of GRNET S.A.
\r
39 * -----------------------------------------------------------------------
\r
42 using System.Windows;
\r
43 using System.Windows.Controls;
\r
44 using System.Windows.Navigation;
\r
45 using Caliburn.Micro;
\r
46 using Caliburn.Micro.Logging;
\r
47 using Pithos.Client.WPF.Properties;
\r
49 using Pithos.Network;
\r
50 using Xceed.Wpf.Toolkit;
\r
51 using log4net.Appender;
\r
52 using log4net.Config;
\r
53 using log4net.Filter;
\r
54 using log4net.Layout;
\r
56 namespace Pithos.Client.WPF
\r
59 using System.Collections.Generic;
\r
60 using System.ComponentModel.Composition;
\r
61 using System.ComponentModel.Composition.Hosting;
\r
62 using System.ComponentModel.Composition.Primitives;
\r
64 using Caliburn.Micro;
\r
66 public class AppBootstrapper : Bootstrapper<IShell>
\r
69 CompositionContainer container;
\r
71 public AppBootstrapper()
\r
73 LogManager.GetLog = type => new log4netLogger(type);
\r
77 private void UpgradeSettings()
\r
79 if (Settings.Default.MustUpgrade)
\r
81 Settings.Default.HashingParallelism = (byte) (Environment.ProcessorCount/2);
\r
82 Settings.Default.Upgrade();
\r
83 Settings.Default.MustUpgrade = true;
\r
84 Settings.Default.Save();
\r
88 protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
\r
90 var assemblies= base.SelectAssemblies();
\r
91 return assemblies.Union(new[]
\r
93 typeof(PithosMonitor).Assembly,
\r
94 typeof(CloudFilesClient).Assembly,
\r
95 typeof (OFM.FileManagerViewModel).Assembly
\r
100 /// By default, we are configured to use MEF
\r
102 protected override void Configure() {
\r
103 var catalog = new AggregateCatalog(
\r
104 AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()
\r
107 /*Type[] types = { typeof(PithosMonitor), typeof(CloudFilesClient),typeof(OFM.FileManagerViewModel) };
\r
108 foreach (var type in types)
\r
110 catalog.Catalogs.Add(new AssemblyCatalog(type.Assembly));
\r
113 container = new CompositionContainer(catalog,true);
\r
115 var batch = new CompositionBatch();
\r
117 batch.AddExportedValue<IWindowManager>(new WindowManager());
\r
118 batch.AddExportedValue<IEventAggregator>(new EventAggregator());
\r
119 batch.AddExportedValue(container);
\r
120 batch.AddExportedValue(catalog);
\r
123 container.Compose(batch);
\r
125 ConventionManager.AddElementConvention<MenuItem>(ItemsControl.ItemsSourceProperty, "DataContext", "Click");
\r
126 ConventionManager.AddElementConvention<IntegerUpDown>(IntegerUpDown.ValueProperty, "Value", "ValueChanged");
\r
127 ConventionManager.AddElementConvention<BusyIndicator>(BusyIndicator.IsBusyProperty, "IsBusy", "DataContextChanged");
\r
130 protected override object GetInstance(Type serviceType, string key)
\r
132 string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
\r
133 var exports = container.GetExportedValues<object>(contract);
\r
136 return exports.First();
\r
138 throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
\r
141 protected override IEnumerable<object> GetAllInstances(Type serviceType)
\r
143 return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
\r
146 protected override void BuildUp(object instance)
\r
148 container.SatisfyImportsOnce(instance);
\r