-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStationServer.cs
More file actions
114 lines (99 loc) · 4.56 KB
/
Copy pathStationServer.cs
File metadata and controls
114 lines (99 loc) · 4.56 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
109
110
111
112
113
114
using Opc.Ua;
using Opc.Ua.Server;
using System.Collections.Generic;
using System.Reflection;
using System.Threading;
namespace CfStation
{
public partial class StationServer : StandardServer
{
/// <summary>
/// Creates the node managers for the server.
/// </summary>
/// <remarks>
/// This method allows the sub-class create any additional node managers which it uses. The SDK
/// always creates a CoreNodeManager which handles the built-in nodes defined by the specification.
/// Any additional NodeManagers are expected to handle application specific nodes.
/// </remarks>
protected override MasterNodeManager CreateMasterNodeManager(IServerInternal server, ApplicationConfiguration configuration)
{
List<INodeManager> nodeManagers = new List<INodeManager>
{
new StationNodeManager(server, configuration)
};
return new MasterNodeManager(server, configuration, null, nodeManagers.ToArray());
}
/// <summary>
/// Loads the non-configurable properties for the application.
/// </summary>
/// <remarks>
/// These properties are exposed by the server but cannot be changed by administrators.
/// </remarks>
protected override ServerProperties LoadServerProperties()
{
ServerProperties properties = new ServerProperties
{
ManufacturerName = "Microsoft",
ProductName = "IoT Edge OPC Connectedfactory Station",
ProductUri = "https://github.com/Azure/azure-iot-connected-factory-cfstation.git",
SoftwareVersion = Utils.GetAssemblySoftwareVersion(),
BuildNumber = Utils.GetAssemblyBuildNumber(),
BuildDate = Utils.GetAssemblyTimestamp()
};
return properties;
}
/// <summary>
/// Creates the resource manager for the server.
/// </summary>
protected override ResourceManager CreateResourceManager(IServerInternal server, ApplicationConfiguration configuration)
{
ResourceManager resourceManager = new ResourceManager(server, configuration);
System.Reflection.FieldInfo[] fields = typeof(StatusCodes).GetFields(BindingFlags.Public | System.Reflection.BindingFlags.Static);
foreach (System.Reflection.FieldInfo field in fields)
{
uint? id = field.GetValue(typeof(StatusCodes)) as uint?;
if (id != null)
{
resourceManager.Add(id.Value, "en-US", field.Name);
}
}
return resourceManager;
}
/// <summary>
/// Cleans up before the server shuts down.
/// </summary>
/// <remarks>
/// This method is called before any shutdown processing occurs.
/// </remarks>
protected override void OnServerStopping()
{
try
{
// check for connected clients
IList<Session> currentessions = this.ServerInternal.SessionManager.GetSessions();
if (currentessions.Count > 0)
{
// provide some time for the connected clients to detect the shutdown state.
ServerInternal.Status.Value.ShutdownReason = new LocalizedText("en-US", "Application closed.");
ServerInternal.Status.Variable.ShutdownReason.Value = new LocalizedText("en-US", "Application closed.");
ServerInternal.Status.Value.State = ServerState.Shutdown;
ServerInternal.Status.Variable.State.Value = ServerState.Shutdown;
ServerInternal.Status.Variable.ClearChangeMasks(ServerInternal.DefaultSystemContext, true);
for (uint timeTillShutdown = _stationShutdownWaitPeriod; timeTillShutdown > 0; timeTillShutdown--)
{
ServerInternal.Status.Value.SecondsTillShutdown = timeTillShutdown;
ServerInternal.Status.Variable.SecondsTillShutdown.Value = timeTillShutdown;
ServerInternal.Status.Variable.ClearChangeMasks(ServerInternal.DefaultSystemContext, true);
Thread.Sleep(1000);
}
}
}
catch
{
// ignore error during shutdown procedure.
}
base.OnServerStopping();
}
private static uint _stationShutdownWaitPeriod = 10;
}
}