Ejemplo n.º 1
0
        //Запрос на загрузку файла
        protected internal void LoadFile()
        {
            InfoFile info = new InfoFile();

            info.FileName = view.GetUser.Message;
            if (string.IsNullOrEmpty(info.FileName))
            {
                return;
            }
            byte[] data = info.Serialize();
            streamSharing.Write(data, 0, data.Length);
        }
Ejemplo n.º 2
0
        private void SendFile(InfoFile info)
        {
            try
            {
                FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
                info.FileLenght = fs.Length;

                byte[] data = info.Serialize();
                streamSharing.Write(data, 0, data.Length);
                data = new byte[fs.Length];
                fs.Read(data, 0, (int)fs.Length);
                fs.Close();
                streamSharing.Write(data, 0, data.Length);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "SendFile");
            }
        }
Ejemplo n.º 3
0
 protected internal void SendFile(bool flag)
 {
     try
     {
         InfoFile       info   = new InfoFile();
         OpenFileDialog dialog = new OpenFileDialog();
         if (dialog.ShowDialog() == true)
         {
             info.FileName = dialog.SafeFileName;
             filePath      = dialog.FileName;
             if (flag)
             {
                 info.PrivateName = view.SelectUser;
             }
             SendFile(info);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message + "SendFile");
     }
 }
Ejemplo n.º 4
0
        protected internal void ReceiveSharing()
        {
            try
            {
                while (true)
                {
                    byte[]   data = new byte[256];
                    InfoFile info = new InfoFile();

                    do
                    {
                        streamSharing.Read(data, 0, data.Length);
                        info.Desserialize(data);
                        int        len  = (int)info.FileLenght;
                        int        size = 0;
                        FileStream fs   = new FileStream(info.FileName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite, len);
                        do
                        {
                            data = new byte[1024000];
                            size = streamSharing.Read(data, 0, data.Length);
                            fs.Write(data, 0, size);
                            if (fs.Length == len)
                            {
                                break;
                            }
                        } while (size > 0);
                        fs.Close();
                        streamSharing.Flush();
                    } while (streamSharing.DataAvailable);
                }
            }
            catch (Exception ex)
            {
                Close();
            }
        }