-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathAppBootstrapper.cs
More file actions
105 lines (91 loc) · 3.72 KB
/
Copy pathAppBootstrapper.cs
File metadata and controls
105 lines (91 loc) · 3.72 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
104
105
namespace ServiceControl.Config
{
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Windows;
using System.Windows.Markup;
using Autofac;
using Caliburn.Micro;
using FluentValidation;
using ReactiveUI;
using ServiceControl.Config.Framework;
using ServiceControlInstaller.Engine.Validation;
using UI.Shell;
public class AppBootstrapper : BootstrapperBase
{
public AppBootstrapper()
{
Initialize();
}
void CreateContainer()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterAssemblyModules(typeof(AppBootstrapper).Assembly);
container = containerBuilder.Build();
}
void ApplyBindingCulture()
{
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
}
protected override void Configure()
{
CreateContainer();
ApplyBindingCulture();
DisableRxUIDebuggerBreak();
}
void DisableRxUIDebuggerBreak()
{
RxApp.DefaultExceptionHandler = Observer.Create(delegate (Exception ex)
{
RxApp.MainThreadScheduler.Schedule(() =>
{
throw new Exception(
"An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects",
ex);
});
});
}
protected override object GetInstance(Type service, string key)
{
if (string.IsNullOrWhiteSpace(key))
{
if (container.TryResolve(service, out var result))
{
return result;
}
}
else
{
if (container.TryResolveNamed(key, service, out var result))
{
return result;
}
}
throw new Exception($"Could not locate any instances of contract {key ?? service.Name}.");
}
protected override IEnumerable<object> GetAllInstances(Type service)
{
return container.Resolve(typeof(IEnumerable<>).MakeGenericType(service)) as IEnumerable<object>;
}
protected override void BuildUp(object instance)
{
container.InjectProperties(instance);
}
protected override async void OnStartup(object sender, StartupEventArgs e)
{
ValidatorOptions.Global.DefaultRuleLevelCascadeMode = CascadeMode.Stop;
await DisplayRootViewForAsync<ShellViewModel>();
var windowManager = GetInstance(typeof(IServiceControlWindowManager), null) as IServiceControlWindowManager;
if (OldScmuCheck.OldVersionOfServiceControlInstalled(out var installedVersion))
{
var message = $"An old version {installedVersion} of ServiceControl Management is installed, which will not work after installing new instances. Before installing ServiceControl 5 instances, you must either uninstall the {installedVersion} instance or update it to a 4.x version at least {OldScmuCheck.MinimumScmuVersion}.";
await windowManager.ShowMessage("Outdated Version Installed", message, acceptText: "I understand", hideCancel: true);
Application.Current.Shutdown(-1);
}
}
IContainer container;
}
}