-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRiskCaptureController.cs
53 lines (47 loc) · 1.67 KB
/
RiskCaptureController.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
namespace AppliedSystems.RiskCapture
{
using System;
using System.Diagnostics;
using AppliedSystems.RiskCapture.Bootstrapping;
using Core;
using Core.Diagnostics;
using Messaging.Infrastructure;
using Messaging.Infrastructure.Receiving;
using Microsoft.Owin.Hosting;
public class RiskCaptureController
{
private static readonly TraceSource Trace = TraceSourceProvider.Provide();
private readonly string address;
private IDisposable webApp;
private readonly IMessageReceiver receiver;
public RiskCaptureController(string address, IMessageReceiver receiver)
{
this.address = address;
this.receiver = receiver;
}
public void Start()
{
Trace.Information("Starting the risk capture service");
receiver.StartReceiving(OnException);
webApp = WebApp.Start<WebAppStartup>(address);
Trace.Information("Listening on {0}", address);
}
private void OnException(Exception exception, NotRequired<Message> message)
{
if (message.HasValue)
{
Trace.Error("Exception occurred whilst receving message {0}. Exception was {1}", message.Value.PayloadType, exception.GetExceptionDetails());
}
else
{
Trace.Error("Exception occurred whilst receving messages. Exception was {0}", exception.GetExceptionDetails());
}
}
public void Stop()
{
webApp.Dispose();
receiver.StopReceiving();
Trace.Information("Stopping the risk capture service");
}
}
}