private void OnServerVanished()
        {
            CleanUpAfterDisconnection();

            if (!ConnectionWasTerminated)
            {
                ConnectionEventInvoked?.Invoke(ConnectionEvent.ConnectionLost);
            }
        }
 private void ConnectionEndResponseReceived()
 {
     Application.Current.Dispatcher.Invoke(
         () =>
     {
         ConnectionWasTerminated = true;
         ConnectionEventInvoked?.Invoke(ConnectionEvent.Disconnected);
         CleanUpAfterDisconnection();
     });
 }
        public void TryDisconnect(Action dissconnectionSuccessful, Action <string> errorCallback)
        {
            ConnectionEventInvoked?.Invoke(ConnectionEvent.StartedTryDisconnect);

            requestWorkQueue.Put(new EndConnectionRequestHandler(() =>
            {
                ConnectionEndResponseReceived();
                dissconnectionSuccessful?.Invoke();
            },
                                                                 connectionInfoVariable,
                                                                 errorCallback));
        }
        private void DebugConnectionBeginResponeReceived(ConnectionSessionId connectionSessionId)
        {
            Application.Current.Dispatcher.Invoke(
                () =>
            {
                connectionInfoVariable.Value = new ConnectionInfo(connectionSessionId, null);

                RunNotificationThread(connectionSessionId);

                ConnectionEventInvoked?.Invoke(ConnectionEvent.ConnectionEstablished);
            }
                );
        }
        public void TryDisconnect(Action dissconnectionSuccessful, Action <string> errorCallback)
        {
            ConnectionEventInvoked?.Invoke(ConnectionEvent.StartedTryDisconnect);

            if (connectionInfoVariable.Value.SessionId != null)
            {
                requestWorkQueue.Put(new EndConnectionRequestHandler(() =>
                {
                    ConnectionEndResponseReceived();
                    dissconnectionSuccessful?.Invoke();
                },
                                                                     connectionInfoVariable,
                                                                     errorCallback));
            }
            else
            {
                CleanUpAfterDisconnection();
                dissconnectionSuccessful?.Invoke();
            }
        }
        public void TryDebugConnect(Address serverAddress, Address clientAddress,
                                    Action <string> errorCallback)
        {
            ConnectionWasTerminated = false;

            ServerAddress = serverAddress;
            ClientAddress = clientAddress;

            ConnectionEventInvoked?.Invoke(ConnectionEvent.StartedTryConnect);

            RunUserveralRequestThread();

            requestWorkQueue.Put(new BeginDebugConnectionRequestHandler(DebugConnectionBeginResponeReceived,
                                                                        ClientAddress.Identifier,
                                                                        errorMsg =>
            {
                ConnectionEventInvoked?.Invoke(ConnectionEvent.ConAttemptUnsuccessful);
                CleanUpAfterDisconnection();
                errorCallback(errorMsg);
            }));
        }