public ClientPanel() { InitializeComponent(); file = null; //this.tbIP.Text = new WebClient().DownloadString("http://icanhazip.com"); this.tbIP.Text = "127.0.0.1"; }
public static void SerializeToFile(cFile file) { IFormatter f = new BinaryFormatter(); Stream s = new FileStream(Directory.GetCurrentDirectory() + cFile.FileNameOnDir, FileMode.Create, FileAccess.Write); f.Serialize(s, file); s.Close(); }
public void ResetFile(object sender, EventArgs e) { Serializer.Clean(); cFile = null; userFileControl1.progressBar1.BeginInvoke(new MethodInvoker(delegate() { userFileControl1.progressBar1.Value = 0; userFileControl1.ResetBtn.Enabled = true; userFileControl1.StartBtn.Text = "Start"; userFileControl1.StartBtn.Click += new System.EventHandler(this.SendFile_Click); ShowServerMessage("Reset file..."); tbFileDatas.Visible = false; })); }
public void FileIsOpen(FileInfo fiFile) { file = new cFile((long)fiFile.Length, fiFile.Name, fiFile.FullName); btnPause.Visible = true; btnPause.Text = "Запустить"; btnPause.Image = Properties.Resources.play_button; pDown.Visible = true; lFileInfo.Text = "Файл выбран! " + file.PathToFile; btnReset.Visible = true; panel2.BackgroundImage = null; panel2.Paint -= panel2_Paint; btnTakeAFile.Visible = false; panel2.Invalidate(); }
public static byte[] SerializeToByteArray(cFile obj) { if (obj == null) { return(null); } var bf = new BinaryFormatter(); using (var ms = new MemoryStream()) { bf.Serialize(ms, obj); return(ms.ToArray()); } }
public static cFile DeserializeFile(byte[] byteArray) { if (byteArray == null) { return(null); } using (var memStream = new MemoryStream()) { var binForm = new BinaryFormatter(); memStream.Write(byteArray, 0, byteArray.Length); memStream.Seek(0, SeekOrigin.Begin); cFile obj = (cFile)binForm.Deserialize(memStream); return(obj); } }
public void Send(cFile file) { if (handler == null) { this.file = file; handler = new ClientHandler(clientSocket, this); handler.file = file; pointer = 0; } else { handler.file_pointer = file.filePointer; } thread = new Thread(delegate() { handler.ProcessSocketRequest(); }); thread.Start(); }
internal void TakeFile_Click(object sender, EventArgs e) { try { tbFileDatas.Clear(); using (var o = new OpenFileDialog()) { if (o.ShowDialog() == DialogResult.OK) { filename = o.FileName; fiFile = new FileInfo(Path.GetFullPath(o.FileName)); cFile = new cFile((int)fiFile.Length, fiFile.Name, fiFile.FullName); tbFileDatas.Visible = true; tbFileDatas.Text += cFile.ToString(); ShowServerMessage("File loaded..."); } } } catch (Exception) { } }
private void pDragDrop_DragDrop(object sender, DragEventArgs e) { try { string [] file = (string[])e.Data.GetData(DataFormats.FileDrop); tbFileDatas.Clear(); using (var o = new OpenFileDialog()) { fiFile = new FileInfo(Path.GetFullPath(file[0])); cFile = new cFile((int)fiFile.Length, fiFile.Name, fiFile.FullName); tbFileDatas.Visible = true; tbFileDatas.Text += cFile.ToString(); ShowServerMessage("File loaded..."); } } catch (Exception) { tbFileDatas.Visible = false; label1.Text = "Не удалось открыть файл"; } }