-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootStrapper.cs
More file actions
135 lines (115 loc) · 5.43 KB
/
BootStrapper.cs
File metadata and controls
135 lines (115 loc) · 5.43 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//using BigBin;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Media.Imaging;
using System.Windows.Threading;
using Caliburn.Micro;
using DBF.AudioServices;
using DBF.DataModel;
using DBF.Helpers;
using DBF.ViewModels;
using DBF.Views;
using Microsoft.DotNet.DesignTools.ViewModels;
namespace DBF
{
//[TraceOn()]
public class Bootstrapper : BootstrapperBase
{
public Bootstrapper()
{
Encoding.RegisterProvider( CodePagesEncodingProvider.Instance);
FrameworkElement.LanguageProperty
.OverrideMetadata( typeof(FrameworkElement)
, new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
Thread.CurrentThread.CurrentCulture = Global.DkCulture;
//setupLogging();
Initialize();
}
//[Conditional("DEBUG")] //private static void setupLogging()
//{
// Console.SetOut(new ToDebugWriter());
//}
#region SimpleContainer Overrides and Configuration.
private readonly SimpleContainer _container = new();
//[DebuggerStepThrough]
protected override void Configure()
{
SyncFusion.FindandRegisterLicenseKey();
_container.Instance<IWindowManager>(new WindowManager());
_container.Singleton<IEventAggregator, EventAggregator>();
_container.Singleton<Configuration>();
_container.Singleton<BridgeMate>();
_container.Singleton<IAudioService, WindowsAudioService>();
foreach (var viewModel in SelectViewModels())
if (_container.HasHandler(viewModel, null) == false)
if (viewModel.Name == "ConfigurationViewModel"
|| viewModel.Name == "TimerSettingsViewModel"
|| viewModel.Name == "PresetNameViewModel")
_container.RegisterPerRequest(viewModel, null, viewModel);
else
_container.RegisterSingleton(viewModel, null, viewModel);
var defaultLocateTypeForModelType = ViewLocator.LocateTypeForModelType;
ViewLocator.LocateTypeForModelType = FindTypeForModelType(defaultLocateTypeForModelType);
}
[DebuggerStepThrough]
private static Func<Type, DependencyObject, object, Type> FindTypeForModelType(Func<Type, DependencyObject, object, Type> defaultLocateTypeForModelType)
{
return (Type modelType, DependencyObject displayLocation, object context) =>
{
if (modelType == typeof(ControlViewModel))
if (context is string viewName
&& viewName == "ProjectorView")
return typeof(ProjectorView);
return defaultLocateTypeForModelType(modelType, displayLocation, context);
};
}
[DebuggerStepThrough]
protected override object GetInstance(Type service, string key)
{
var instance = _container.GetInstance(service, key);
if (instance != null)
return instance;
throw new InvalidOperationException("Could not locate any instances.");
}
protected override IEnumerable<object> GetAllInstances(Type service) => _container.GetAllInstances(service);
protected override void BuildUp(object instance)
{
_container.BuildUp(instance);
}
protected override IEnumerable<Assembly> SelectAssemblies()
{
// We pick one type from each assembly to get to the assemblies
yield return Assembly.GetAssembly(typeof(Bootstrapper));
}
protected IEnumerable<Type> SelectViewModels() => SelectAssemblies().SelectMany(a => a.GetTypes())
.Where(t => t.Name.EndsWith("ViewModel", StringComparison.Ordinal));
#endregion
protected override void OnUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
//Logger.Error(e.Exception.Message, "Fatal Error");
//if (e.Exception.InnerException is not null)
// Logger.Error(e.Exception.InnerException.Message, "Inner Exception");
base.OnUnhandledException(sender, e);
}
protected override void OnStartup(object sender, StartupEventArgs e)
{
#if false
DisplayRootViewForAsync<TimerSettingsViewModel>();
var screen = IoC.Get<TimerSettingsViewModel>();
#else
// Show screen at startup
DisplayRootViewForAsync<ShellViewModel>();
var screen = IoC.Get<ShellViewModel>();
//var view = screen.GetView() as ShellView;
screen.OpenControlView();
#endif
// Restore Taskbar Icon.
Application.MainWindow.Icon = BitmapFrame.Create(new Uri("pack://application:,,,/Images/DBF_Tools.ico", UriKind.Absolute));
}
}
}