// This is a handler for IEC104 connection events
        private static void ConnectionEventHandler(
            object parameter,
            ClientConnection connection,
            ClientConnectionEvent conEvent
            )
        {
            var srv        = IEC10Xconns[(int)parameter];
            var conNameStr = srv.name + " - ";

            if (conEvent == ClientConnectionEvent.OPENED)
            {
                srv.clientConnections.Add(connection);
            }
            else if (conEvent == ClientConnectionEvent.CLOSED)
            {
                srv.clientConnections.Remove(connection);
            }
            Log(conNameStr + "Connection event " +
                connection.RemoteEndpoint.Address.ToString() + ":" +
                connection.RemoteEndpoint.Port + " - " +
                conEvent.ToString());

            var Client     = ConnectMongoClient(JSConfig);
            var DB         = Client.GetDatabase(JSConfig.mongoDatabaseName);
            var collection = DB.GetCollection <IEC10X_connection>(ProtocolConnectionsCollectionName);
            // update stats
            var filter =
                new BsonDocument(new BsonDocument("protocolConnectionNumber",
                                                  srv.protocolConnectionNumber));
            var update =
                new BsonDocument("$set",
                                 new BsonDocument {
                { "stats", new BsonDocument {
                      { "nodeName", JSConfig.nodeName },
                      { "timeTag", BsonDateTime.Create(DateTime.Now) },
                      { "openConnections", BsonValue.Create(srv.server.OpenConnections) },
                      { "clientConnections", BsonValue.Create(srv.clientConnections.Count) },
                      { "endpoint." +
                                connection.RemoteEndpoint.Address.ToString(),
                                new BsonDocument {
                                    { "timeTag", BsonDateTime.Create(DateTime.Now) },
                                    { "connectionState", BsonValue.Create(conEvent.ToString()) },
                                } },
                  } },
            });
            var res = collection.UpdateOneAsync(filter, update);

            Log("Mongo protocolConnections Matched " + res.Result.MatchedCount + " Updated " + res.Result.ModifiedCount);
        }
Beispiel #2
0
        // This is a handler for IEC104 connection events
        private static void ConnectionEventHandler(
            object parameter,
            ClientConnection connection,
            ClientConnectionEvent conEvent
            )
        {
            var srv        = IEC10Xconns[(int)parameter];
            var conNameStr = srv.name + " - ";

            if (conEvent == ClientConnectionEvent.OPENED)
            {
                srv.clientConnections.Add(connection);
            }
            else if (conEvent == ClientConnectionEvent.CLOSED)
            {
                srv.clientConnections.Remove(connection);
            }
            Log(conNameStr + "Connection event " +
                connection.RemoteEndpoint.Address.ToString() + ":" +
                connection.RemoteEndpoint.Port + " - " +
                conEvent.ToString());
        }
Beispiel #3
0
 private static void connectionEventHandler(object parameter, ClientConnection connection, ClientConnectionEvent conEvent)
 {
     Console.WriteLine("Connection {0}:{1} - {2}", connection.RemoteEndpoint.Address.ToString(),
                       connection.RemoteEndpoint.Port, conEvent.ToString());
 }
 private static void OnConnectionEvent(object parameter, ClientConnection connection, ClientConnectionEvent eventType)
 {
     SmprMonitoringService.Log("connection event " + eventType.ToString() + " " + connection.RemoteEndpoint);
 }