-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMintySenorMonitor.cs
More file actions
51 lines (42 loc) · 1.46 KB
/
Copy pathMintySenorMonitor.cs
File metadata and controls
51 lines (42 loc) · 1.46 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
using System;
using System.Diagnostics;
namespace mintymods {
public class MintySenorMonitor {
static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
readonly MsmMonitorRequest request;
MsmMonitorResponse response;
public MintySenorMonitor(MsmMonitorRequest request) {
this.request = request;
this.response = new MsmMonitorResponse();
log.Debug("Created new MintySensorMonitor");
}
public string getSensorInfoAsJSON() {
var timer = Stopwatch.StartNew();
var controller = new MsmServiceController();
MsmServiceInterface monitor = controller.getMonitorForRequest(request);
log.Debug("@Created monitor#" + monitor);
string json = "";
try {
response = monitor.poll();
timer.Stop();
response.time_taken = timer.Elapsed;
json = Newtonsoft.Json.JsonConvert.SerializeObject(response);
log.Debug("@JSON#" + json);
} catch (MsmException e) {
if (response.exception == null) {
response.exception = e;
}
timer.Stop();
response.time_taken = timer.Elapsed;
json = Newtonsoft.Json.JsonConvert.SerializeObject(response);
} finally {
monitor.dispose();
}
if (request.debug) {
log.Debug(json);
Debug.WriteLine(json);
}
return json;
}
}
}