-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEmulatorBootstrapper.cs
More file actions
103 lines (85 loc) · 3.14 KB
/
EmulatorBootstrapper.cs
File metadata and controls
103 lines (85 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Caliburn.Micro;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Reflection;
using Netduino.Core.ViewModels;
using Netduino.Core.Services;
using System.IO;
using Microsoft.SPOT.Tasks;
using System.Xml;
using Netduino.Core.Service;
namespace Netduino.Core
{
/// <summary>
/// The bootstrapper for initializing the application
/// </summary>
public class EmulatorBootstrapper : Bootstrapper<IShellViewModel>
{
private CompositionContainer container;
static EmulatorBootstrapper()
{
LogManager.GetLog = type => new Log4netLogger(type);
}
/// <summary>
/// Configure the IOC Container and get the emulator started
/// </summary>
protected override void Configure()
{
AggregateCatalog catalog = new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());
container = new CompositionContainer(catalog);
var batch = new CompositionBatch();
batch.AddExportedValue<IWindowManager>(new WindowManager());
IEventAggregator aggregator = new EventAggregator();
batch.AddExportedValue<IEventAggregator>(aggregator);
EmulatorService service = new EmulatorService(aggregator);
batch.AddExportedValue<IEmulatorService>(service);
batch.AddExportedValue(container);
container.Compose(batch);
// Start the emulator
service.StartEmulator();
}
/// <summary>
/// Resolve an instance of a contract
/// </summary>
/// <param name="serviceType"></param>
/// <param name="key"></param>
/// <returns></returns>
protected override object GetInstance(Type serviceType, string key)
{
string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
var exports = container.GetExportedValues<object>(contract);
if (exports.Count() > 0)
return exports.First();
throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
}
protected override IEnumerable<object> GetAllInstances(Type serviceType)
{
return container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
}
protected override void BuildUp(object instance)
{
container.SatisfyImportsOnce(instance);
}
/// <summary>
/// Determine what assemblies are part of the application
/// </summary>
/// <returns></returns>
protected override IEnumerable<Assembly> SelectAssemblies()
{
return new Assembly[] { Assembly.GetExecutingAssembly(), Assembly.LoadFrom(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Extensions\NetduinoEmulator.dll")) };
}
/// <summary>
/// Display the main windows
/// </summary>
protected override void DisplayRootView()
{
var viewModel = IoC.Get<IShellViewModel>();
new WindowManager().Show(viewModel);
}
}
}