Esempio n. 1
0
 public void Disconnect()
 {
     try {
         client.Disconnect();
     } catch (Exception exception) {
         // Ignore any error
         client.Abort();
         TriggerConnectionFailed(exception);
     }
 }
Esempio n. 2
0
        private void HandleProxy()
        {
            if (chatClient == null)
            {
                return;
            }

            switch (chatClient.State)
            {
            case CommunicationState.Closed:
                chatClient = null;
                //chatListBoxMsgs.Items.Clear();
                //chatListBoxNames.Items.Clear();
                //loginLabelStatus.Content = "Disconnected";
                //ShowChat(false);
                //ShowLogin(true);
                //loginButtonConnect.IsEnabled = true;
                break;

            case CommunicationState.Closing:
                break;

            case CommunicationState.Created:
                break;

            case CommunicationState.Faulted:
                chatClient.Abort();
                chatClient = null;
                //chatListBoxMsgs.Items.Clear();
                //chatListBoxNames.Items.Clear();
                //ShowChat(false);
                //ShowLogin(true);
                //loginLabelStatus.Content = "Disconnected";
                //loginButtonConnect.IsEnabled = true;
                break;

            case CommunicationState.Opened:
                //ShowLogin(false);
                //ShowChat(true);

                //chatLabelCurrentStatus.Content = "online";
                //chatLabelCurrentUName.Content = localClient.Name;

                //Dictionary<int, Image> images = GetImages();
                //Image img = images[loginComboBoxImgs.SelectedIndex];
                //chatCurrentImage.Source = img.Source;
                break;

            case CommunicationState.Opening:
                break;
            }
        }
Esempio n. 3
0
        private T Call <T>(Func <ChatServiceClient, T> f)
        {
            var chatClient = new ChatServiceClient();

            try
            {
                var result = f(chatClient);
                chatClient.Close();

                return(result);
            }
            catch (Exception)
            {
                chatClient.Abort();
                throw;
            }
        }
Esempio n. 4
0
        private void CloseClient()
        {
            try
            {
                if (_callback != null)
                {
                    _callback.MessagePost     -= callback_MessagePost;
                    _callback.UsersListChange -= callback_UsersListChange;

                    _callback = null;
                }

                if (_client != null)
                {
                    _client.InnerDuplexChannel.Closing -= InnerChannel_Closed;
                    _client.InnerDuplexChannel.Closed  -= InnerChannel_Closed;
                    _client.InnerDuplexChannel.Faulted -= InnerChannel_Closed;

                    switch (_client.State)
                    {
                    case CommunicationState.Opened:
                    case CommunicationState.Opening:
                    case CommunicationState.Created:
                        _client.Abort();
                        break;
                    }

                    _client = null;
                }
            }
            catch
            {
                _callback = null;
                _client   = null;
            }
            finally
            {
                _username   = null;
                IsAdmin     = false;
                IsConnected = false;
            }
        }