Example #1
0
 public IAsyncResult BeginReceiveWhisper(Message msg, SharedComponents.Client receiver, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }
Example #2
0
        /// <summary>
        /// Opens progress windows, opens http channel, sends request for file download, saves file and tidies up.
        /// </summary>
        /// <param name="client">Client that sent the file.</param>
        /// <param name="filename">File that will be downloaded from service.</param>
        public void PrepareForFile(SharedComponents.Client client, string filename)
        {
            _viewModel.OpenProgressWindow();
            _viewModel.FileWindowModel.FileNameLabel = filename;
            Thread thread = new Thread(() =>
            {
                string[] address = _viewModel.ConnectionIP.Split(':');
                string fileServicePath = "/WPFHost/http";
                var fileEndAdd = new EndpointAddress("http://" + address[0] + ":" + (int.Parse(address[1]) + 1111) + fileServicePath);
                var fileBinding = new BasicHttpBinding("httpBinding");
                _fileChannel = new FileTransferWcfClient(fileBinding, fileEndAdd);
                try
                {
                    // start service client
                    _fileChannel.Open();
                    _fileChannel.SetProxy(_fileChannel.ChannelFactory.CreateChannel());
                    // kill target file, if already exists
                    // get stream from server

                    Stream inputStream;
                    long length = _fileChannel.DownloadFile(ref filename, out inputStream);
                    string filePath = Path.Combine("Download", filename);
                    // write server stream to disk
                    using (FileStream writeStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
                    {
                        int chunkSize = 2048;
                        byte[] buffer = new byte[chunkSize];
                        _viewModel.FileWindowModel.ProgressMax = length;
                        do
                        {
                            // read bytes from input stream
                            int bytesRead = inputStream.Read(buffer, 0, chunkSize);
                            if (bytesRead == 0) break;

                            // write bytes to output stream
                            writeStream.Write(buffer, 0, bytesRead);

                            // report progress from time to time
                            _viewModel.FileWindowModel.Progress = writeStream.Position;
                        } while (true);

                        writeStream.Close();
                        Thread threadClose = new Thread(() =>
                        {
                            _viewModel.FileWindowModel.DoneLabel = "Done";
                           // _viewModel.CloseProgressWindow();
                        });
                        threadClose.SetApartmentState(ApartmentState.STA);
                        threadClose.Start();
                    }

                    // close service client
                    //inputStream.Close();
                    _fileChannel.Close();
                    _channel.DeleteFileAsync(client, Path.Combine("Upload", filename));
                }
                catch (Exception ex)
                {
                    _viewModel.Name = ex.ToString();
                }
            });
            thread.Start();
        }
Example #3
0
 public IAsyncResult BeginIsWritingCallback(SharedComponents.Client client, AsyncCallback callback, object asyncState)
 {
     throw new NotImplementedException();
 }
Example #4
0
 /// <summary>
 /// Shows user left message when a user leaves
 /// </summary>
 /// <param name="client"></param>
 public void UserLeave(SharedComponents.Client client)
 {
     ListBoxItem item = MakeItem(client.AvatarID,
         "------------ " + client.Name + " left chat ------------");
     _viewModel.ChatMsgs.Add(item);
     _messages.Add("------------ " + client.Name + " left chat ------------");
     _msgIds.Add("bla");
     _viewModel.ScrollDown();
 }
Example #5
0
 /// <summary>
 /// Shows is writing a message message
 /// </summary>
 /// <param name="client"></param>
 public void IsWritingCallback(SharedComponents.Client client)
 {
     if (client == null)
     {
         _viewModel.LabelWritingMsg = "";
     }
     else
     {
         _viewModel.LabelWritingMsg += client.Name + " is writing a message.., ";
     }
 }
Example #6
0
 /// <summary>
 /// Receives a whisper and decrypts it
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="receiver"></param>
 public void ReceiveWhisper(Message msg, SharedComponents.Client receiver)
 {
     foreach (SharedComponents.Client c in _onlineClients.Values)
     {
         if (c.Name == msg.Sender)
         {
             string output = "";
             switch (_viewModel.SelectedCypher)
             {
                 case (int)Cyphers.SimpleEncryption:
                     var cypher1 = new SimpleEncryption();
                     output = cypher1.DecryptMessage(msg.Content, _viewModel.Key);
                     break;
                 case (int)Cyphers.Rijndael:
                     var cypher2 = new Rijndael();
                     output = cypher2.DecryptMessage(msg.Content, _viewModel.Key);
                     break;
             }
             ListBoxItem item = MakeItem(c.AvatarID,
                 msg.Sender + " whispers " + receiver.Name + " : " + output);
             _viewModel.ChatMsgs.Add(item);
             _messages.Add(msg.Content);
             _msgIds.Add(msg.Sender + " whispers " + receiver.Name);
         }
     }
     _viewModel.ScrollDown();
 }
Example #7
0
 private void Awake()
 {
     sharedComponents = GetComponent <SharedComponents>();
     InitializeUnit();
 }
Example #8
0
 private void InitializeApp()
 {
     SharedComponents.AutoConnect(this);
     SharedComponents.ShownMovies = WaitForItBLL.Singleton.GetPopularMoviesList();
 }