-
Notifications
You must be signed in to change notification settings - Fork 2
/
Program.cs
124 lines (108 loc) · 4.8 KB
/
Program.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using console = System.Console;
using System.Reflection;
using System.Diagnostics;
using MARC.HI.EHRS.SVC.Core;
using MARC.HI.EHRS.SVC.Core.Services;
using System.Runtime.InteropServices;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Xml.Serialization;
namespace MARC.EHRS.Audit
{
[GuidAttribute("1D5016E2-56E1-4a33-B263-B9CDBAC30F9C")]
class Program
{
/// <summary>
/// Entry point for the console presentation layer
/// </summary>
static void Main(string[] args)
{
if (args.Length > 0 && args[0] == "c")
Console();
else
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new VisualizationService() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
}
}
static void Console()
{
ShowCopyright();
Trace.CorrelationManager.ActivityId = typeof(Program).GUID;
Trace.TraceInformation("Starting host context on Console Presentation System at {0}", DateTime.Now);
// Detect platform
if (System.Environment.OSVersion.Platform != PlatformID.Win32NT)
Trace.TraceWarning("Not running on WindowsNT, some features may not function correctly");
// Do this because loading stuff is tricky ;)
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
console.Write("Starting MARC-HI Service Framework...");
// Start the message handler service
IMessageHandlerService messageHandlerService = null;
try
{
// Initialize
HostContext context = new HostContext();
Trace.TraceInformation("Getting default message handler service.");
messageHandlerService = context.GetService(typeof(IMessageHandlerService)) as IMessageHandlerService;
console.WriteLine("ok");
console.Write("Starting default MessageHandler...");
if (messageHandlerService == null)
Trace.TraceError("PANIC! Can't find a default message handler service: {0}", "No IMessageHandlerService classes are registered with this host context");
else
{
Trace.TraceInformation("Starting message handler service {0}", messageHandlerService);
if (messageHandlerService.Start())
{
console.WriteLine("ok\r\nService host console started succesfully, press any key to terminate...");
console.ReadKey();
}
else
{
console.WriteLine("fail");
Trace.TraceError("No message handler service started. Terminating program");
}
}
}
catch(Exception e)
{
Trace.TraceError("Fatal exception occurred: {0}", e.ToString());
}
finally
{
if (messageHandlerService != null)
{
console.Write("Stopping listeners...");
Trace.TraceInformation("Stopping message handler service {0}", messageHandlerService);
messageHandlerService.Stop();
console.WriteLine("ok");
}
}
console.WriteLine("Service Terminated, press any key to close...");
console.ReadKey();
}
internal static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
if (args.Name == asm.FullName)
return asm;
/// Try for an non-same number Version
foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
if (args.Name.Substring(0, args.Name.IndexOf(",")) == asm.GetName().Name)
return asm;
return null;
}
/// <summary>
/// Show copyright information on screen
/// </summary>
private static void ShowCopyright()
{
console.WriteLine("MARC-HI Service Host Console v{0}", Assembly.GetEntryAssembly().GetName().Version);
console.WriteLine("Copyright (C) 2010, Mohawk College of Applied Arts and Technology");
}
}
}