private TransferFileDetails CreateTransferFileDetails(FileDetails file) { TransferFileDetails transferFile = new TransferFileDetails(file.FileName, file.FileSize); foreach (User user in ServerFileList[file]) { transferFile.PeersList.Add(new Peer(user.Ip, user.UpPort)); } return(transferFile); }
private void GetFileDetails() { try { Byte[] receiveBytes = new Byte[256]; do { int bytes = stream.Read(receiveBytes, 0, receiveBytes.Length); }while (stream.DataAvailable); string json = Encoding.UTF8.GetString(receiveBytes); fileDet = JsonConvert.DeserializeObject <FileDetails>(json); } catch (Exception ex) { Console.WriteLine("GetFileDetails Error in ClientObject class"); } }
protected internal void SendFile(FileDetails fd, string fs, string id, string type) { FileStream fstream = File.Open(fs, FileMode.Open, FileAccess.ReadWrite, FileShare.None); foreach (ClientObject x in clients) { if (x.Id != id) { string tmp = fs.Insert(0, "new"); BinaryWriter writer = new BinaryWriter(x.stream); writer.Write(type); //send that it is image writer.Write(tmp); //send filename writer.Write(Convert.ToInt32(fd.FILESIZE)); //send filesize byte[] bites = new byte[fstream.Length]; int size = fstream.Read(bites, 0, bites.Length); writer.Write(bites); // send ImageData } } }
static void SendFileInfo(Socket current) { fileDetails = new FileDetails(); string fullFileName = file.Name; int lastIndex = fullFileName.LastIndexOf(@"\"); string type = fullFileName.Remove(0, lastIndex + 1); fileDetails.FileType = type; fileDetails.Length = file.Length; XmlSerializer xmlSerializer = new XmlSerializer(typeof(FileDetails)); MemoryStream memoryStream = new MemoryStream(); xmlSerializer.Serialize(memoryStream, fileDetails); memoryStream.Position = 0; byte[] buffer = new byte[memoryStream.Length]; memoryStream.Read(buffer, 0, buffer.Length); memoryStream.Close(); current.Send(buffer); Console.WriteLine("Данные о файле отправлены"); }