Repository navigation
Expand file tree
/
Copy pathFireWatchService.Main.cs
More file actions
108 lines (92 loc) · 4.06 KB
/
Copy pathFireWatchService.Main.cs
File metadata and controls
108 lines (92 loc) · 4.06 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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Threading;
using Microsoft.Extensions.Configuration;
using Genetec.Sdk;
// Inside your FireWatchService initialization block:
string aegisUrl = "https://api.revolutionary.technology/univac-aegis/ingest";
// Initialize the core tools
var protocolEncoder = new EdwardsProtocolEncoder();
var aegisBridge = new UnivacAegisBridge(aegisUrl);
// Instantiate the Edwards Node bridging the two
var edwardsNode = new EdwardsAegisNode(aegisBridge, protocolEncoder);
// When data arrives from FireWatchService.Network.cs, route it:
// await edwardsNode.ProcessEdwardsStreamAsync(incomingBytes);
namespace GenetecEdwardsBridge
{
public partial class FireWatchService : ServiceBase
{
// Thread synchronization lock object
private readonly object _lockObject = new object();
// Configuration Properties
private IConfigurationRoot _configuration;
private GenetecSettings _genetecConfig;
private EdwardsSettings _edwardsConfig;
private Dictionary<string, CameraMapping> _lookupMap = new Dictionary<string, CameraMapping>();
// System Services & Timers
private Engine _genetecEngine;
private System.Timers.Timer _heartbeatTimer;
private Guid _kiwiFireEventGuid;
public FireWatchService()
{
ServiceName = "GenetecEdwardsFireWatch";
CanHandlePowerEvent = true;
CanShutdown = true;
CanStop = true;
}
protected override void OnStart(string[] args)
{
try
{
// 1. Initialize Configuration and Hot-Swap Listeners
InitializeAndWatchConfiguration();
// 2. Instantiate and Initialize the Genetec SDK Engine
_genetecEngine = new Engine();
_genetecEngine.LoginManager.LoggedOn += OnGenetecLoggedOn;
_genetecEngine.LoginManager.LoggedOff += OnGenetecLoggedOff;
// 3. Initiate Non-Blocking Async Authentication to Genetec Server
_genetecEngine.LoginManager.LogonAsync(
_genetecConfig.DirectoryServer,
_genetecConfig.ServiceUser,
_genetecConfig.ServicePassword
);
// 4. Initialize and Start the Supervision Watchdog Heartbeat
int heartbeatMs = _edwardsConfig.HeartbeatIntervalSeconds * 1000;
_heartbeatTimer = new System.Timers.Timer(heartbeatMs);
_heartbeatTimer.Elapsed += OnHeartbeatTimerElapsed;
_heartbeatTimer.Start();
EventLog.WriteEntry(ServiceName, "FireWatch service initialized and running successfully.", EventLogEntryType.Information);
}
catch (Exception ex)
{
EventLog.WriteEntry(ServiceName, $"Critical failure during service startup: {ex.Message}", EventLogEntryType.Error);
throw; // Stop service execution immediately if initialization fails
}
}
protected override void OnStop()
{
try
{
_heartbeatTimer?.Stop();
if (_genetecEngine != null)
{
if (_genetecEngine.LoginManager.IsLoggedOn)
{
_genetecEngine.ActionManager.UnregisterAction(EventType.VideoAnalyticsEvent, OnAnalyticsEventReceived);
_genetecEngine.LoginManager.Logoff();
}
_genetecEngine.Dispose();
}
EventLog.WriteEntry(ServiceName, "FireWatch service cleanly shut down and detached from system tasks.", EventLogEntryType.Information);
}
catch (Exception ex)
{
EventLog.WriteEntry(ServiceName, $"Uncaught exception handling service termination routines: {ex.Message}", EventLogEntryType.Error);
}
}
}
}