Пример #1
0
        private void Button1_Click(object sender, RoutedEventArgs e)
        {
            if (idChat != -1 && UserLoger != null)
            {
                Service1Client client = new Service1Client();
                FileDTO        file   = GetFile();
                if (file != null)
                {
                    //MessageBox.Show(file.FileInfo.FullName);
                    using (FileStream stream = new FileStream(file.FileInfo.FullName, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        try
                        {
                            client.UploadFile(file.FileName, file.FileInfo.Length, stream);
                            Button_Click_6(null, null);
                        }
                        catch (Exception error)
                        {
                            MessageBox.Show("error: " + error.Message);
                            //throw;
                        }
                    }
                    //RemoteFileInfo fileInfo = new RemoteFileInfo(file.FileName, file.FileInfo.Length, file.FileStream);
                }
                else
                {
                    file = new FileDTO();
                }

                bool CompleteOparation = client.PushMessage(textBox.Text, UserLoger, idChat, file.FileName);
                client.Close();
                if (CompleteOparation)
                {
                    //UpdateMessages();
                    textBox.Text = "";
                }
                else
                {
                    MessageBox.Show("Error push message");
                }
            }
        }
Пример #2
0
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            if (idChat != -1 && !FileExixt())
            {
                string path;
                System.Windows.Forms.OpenFileDialog openFile = new System.Windows.Forms.OpenFileDialog();
                openFile.Filter = "All files (*.*)|*.*";
                if (openFile.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    path = openFile.FileName;
                    FileInfo info = new FileInfo(path);
                    FileDTO  file;// = new FileDTO(path);
                    using (System.IO.FileStream stream = new System.IO.FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                    {
                        file = new FileDTO {
                            ChatId = idChat, FileName = openFile.SafeFileName, FileInfo = info, FileStream = stream
                        };

                        //MessageBox.Show(info.Name);
                    }
                    if (file.FileStream != null)
                    {
                        files.Add(file);
                    }
                    //MessageBox.Show($"{openFile.SafeFileName} /n{openFile.FileName} /n{openFile.ValidateNames}");
                }
            }
            else if (FileExixt())
            {
                FileDTO tmp = new FileDTO();
                foreach (FileDTO item in files)
                {
                    if (item.ChatId == idChat)
                    {
                        tmp = item;
                    }
                }
                files.Remove(tmp);
            }
        }