Exemple #1
0
        private void CloseConnection(ConnectionEntry entry)
        {
            NetGraph graph = entry.Graph;

            lock (entry)
            {
                if (!graph.IsDisposed)
                {
                    ConnectionHistoryEntry history = new ConnectionHistoryEntry(graph.NetworkDescription, graph.Uuid, graph.Created, DateTime.Now);
                    bool noConnections             = false;

                    foreach (KeyValuePair <string, object> pair in graph.ConnectionProperties)
                    {
                        history.Properties[pair.Key] = pair.Value;
                    }

                    try
                    {
                        entry.Dispose();
                    }
                    catch
                    {
                        // Shouldn't throw but just in case
                    }

                    lock (_history)
                    {
                        _history.Add(history);
                    }

                    lock (_connections)
                    {
                        _connections.Remove(entry);
                        if (_connections.Count == 0)
                        {
                            noConnections = true;
                        }
                    }

                    CloseConnectionEvent?.Invoke(this, new ConnectionEventArgs(graph));

                    if (_logger != null)
                    {
                        _logger.LogVerbose(CANAPE.Net.Properties.Resources.NetworkServiceBase_ConnectionClosed, graph.NetworkDescription);
                    }

                    if ((_state == (int)ServiceState.StopPending) && noConnections)
                    {
                        CompleteStop();
                    }
                }
            }
        }
Exemple #2
0
 private void service_CloseConnectionEvent(object sender, ConnectionEventArgs e)
 {
     CloseConnectionEvent?.Invoke(sender, e);
 }