-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFivetService.cs
105 lines (75 loc) · 2.74 KB
/
FivetService.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
using System;
using System.Threading;
using System.Threading.Tasks;
using Fivet.ZeroIce.model;
using Ice;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Fivet.Server
{
internal class FivetService : IHostedService, IDisposable
{
///<summary>
/// The Logger.
///</summary>
private readonly ILogger<FivetService> _logger;
///<summary>
/// The Port.
///</summary>
private readonly int _port = 8080;
///<summary>
/// The Communicator.
///</summary>
private readonly Communicator _communicator;
private readonly TheSystemDisp_ _theSystem;
private readonly ContratosDisp_ _contratos;
///<summary>
/// The FivetService.
///</summary>
public FivetService(ILogger<FivetService> logger, TheSystemDisp_ theSystem, ContratosDisp_ contratos)
{
_logger = logger;
_logger.LogDebug("Building FivetService ...");
_theSystem = theSystem;
_contratos = contratos;
_communicator = buildCommunicator();
}
///<summary>
/// Triggered when the application host is ready to start the service
///</summary>
public Task StartAsync(CancellationToken cancellationToken)
{
_logger.LogDebug("Starting the FivetService ... ");
var adapter = _communicator.createObjectAdapterWithEndpoints("TheAdapter", "tcp -z -t 15000 -p " + _port);
// Register in the communicator
adapter.add(_theSystem, Util.stringToIdentity("TheSystem"));
// Activation
adapter.activate();
_theSystem.getDelay(0);
//All ok
return Task.CompletedTask;
}
///<summary>
/// Triggered when the application host is performing a graceful shutdown
///</summary>
public Task StopAsync(CancellationToken cancellationToken)
{
_logger.LogInformation("Stopping the FivetService ... ");
_communicator.shutdown();
_logger.LogDebug("Communication Stopped!");
return Task.CompletedTask;
}
private Communicator buildCommunicator()
{
_logger.LogDebug("Initializing Communicator v{0} ({1}) ..", Ice.Util.stringVersion(), Ice.Util.intVersion());
Properties properties = Util.createProperties();
InitializationData initializationData = new InitializationData();
initializationData.properties = properties;
return Ice.Util.initialize(initializationData);
}
public void Dispose()
{
_communicator.destroy();
}
}
}