コード例 #1
0
ファイル: Client.cs プロジェクト: killerwife/ACMadness
 /// <summary>
 /// This method encrypts the message we want to send
 /// and sends it either to one recipient (whisper)
 /// or all online chat clients
 /// </summary>
 public void Send()
 {
     if (_channel != null && _viewModel.ChatInputText != "")
     {
         if (_channel.State == CommunicationState.Faulted)
         {
             HandleProxy();
         }
         else
         {
             //Create message, assign its properties
             //encrypt message
             string temp = "";
             switch (_viewModel.SelectedCypher)
             {
                 case (int)Cyphers.SimpleEncryption:
                     var cypher1 = new SimpleEncryption();
                     temp = cypher1.EncryptMessage(_viewModel.ChatInputText, _viewModel.Key);
                     break;
                 case (int)Cyphers.Rijndael:
                     var cypher2 = new Rijndael();
                     temp = cypher2.EncryptMessage(_viewModel.ChatInputText, _viewModel.Key);
                     break;
             }
             Message msg = new Message
             {
                 Sender = _localClient.Name,
                 Time = DateTime.Now,
                 Content = temp
             };
             //If whisper mode is checked and an item is
             //selected in the list box of clients, it will
             //arrange a client object called receiver
             //to whisper
             if (_viewModel.WhisperBox)
             {
                 if (_receiver != null)
                 {
                     _channel.WhisperAsync(msg, _receiver);
                     _viewModel.ChatInputText = "";
                 }
             }
             else
             {
                 _channel.SayAsync(msg);
                 _viewModel.ChatInputText = "";
             }
             //Tell the service to tell back all clients that this client
             //has just finished typing..
             _channel.IsWritingAsync(null);
         }
     }
 }