2using System.Collections.Generic;
11 private readonly List<IEndpoint> endpoints =
new List<IEndpoint>();
12 private readonly
object synchObj =
new object();
13 private readonly
string name;
14 private readonly
string type;
15 private DateTime lastConnect = DateTime.MinValue;
16 private DateTime lastDisconnect = DateTime.MinValue;
17 private long sumConnectionTimeMilliseconds = 0;
18 private long nrConnectionTimes = 0;
19 private volatile int connectionCount = 0;
40 if (!this.endpoints.Contains(
Endpoint))
42 if (this.connectionCount == 0)
43 this.lastConnect = DateTime.Now;
46 this.connectionCount++;
62 this.sumConnectionTimeMilliseconds += ConnectionTimeMilliseconds;
63 this.nrConnectionTimes++;
65 if (this.connectionCount > 0)
67 this.connectionCount--;
68 if (this.connectionCount == 0)
69 this.lastDisconnect = DateTime.Now;
78 public string Name => this.name;
83 public string Type => this.type;
94 return this.endpoints.ToArray();
108 if (this.endpoints.Count == 0)
111 return this.endpoints[0];
145 return this.nrConnectionTimes + this.connectionCount;
159 if (this.nrConnectionTimes == 0)
162 double x = this.sumConnectionTimeMilliseconds;
163 x /= this.nrConnectionTimes;
182 return ToStr(d.Value);
186 private static string ToStr(
double x)
189 return x.ToString(
"F0") +
" s";
195 return x.ToString(
"F1") +
" min";
201 return x.ToString(
"F1") +
" h";
205 return x.ToString(
"F1") +
" days";
220 if (this.connectionCount == 0)
223 return (DateTime.Now -
this.lastConnect).TotalSeconds;
239 return ToStr(d.Value);
Mainstains information about connectivity from a specific endpoint.
double? AvgConnectionTimeSeconds
Average connection time, in seconds, if available, null otherwise.
void EndpointConnected(IEndpoint Endpoint)
Call this method when the endpoint connects.
IEndpoint Endpoint
First registered active endpoint, if any, null otherwise.
DateTime LastConnect
When endpoint last connected.
string Type
Type of Endpoint
string CurrentConnectionTime
Average connection time, as a string.
DateTime LastDisconnect
When endpoint last disconnected.
bool Connected
If the endpoint is connected
void EndpointDisconnected(IEndpoint Endpoint, long ConnectionTimeMilliseconds)
Call this method when the endpoint disconnects.
long TotalConnectionCount
Total number of connections made by endpoint.
EndpointStatistics(string Name, string Type)
Mainstains information about connectivity from a specific endpoint.
string Name
Name of Endpoint
int ActiveConnectionCount
Current number of active connections
string AvgConnectionTime
Average connection time, as a string.
double? CurrentConnectionTimeSeconds
Current connection time, in seconds, if available, null otherwise.
IEndpoint[] Endpoints
Registered connection endpoints.
Interface for XMPP endpoints