mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
using System.Threading;
|
|
using ZeroLevel.Services.Serialization;
|
|
|
|
namespace ZeroLevel.Network.FileTransfer
|
|
{
|
|
public sealed class FileStartFrame
|
|
: IBinarySerializable, IFileTransferInfo
|
|
{
|
|
private static long _uploadTaskIdCounter = 0;
|
|
|
|
public FileTransferInfoType TransferInfoType => FileTransferInfoType.Start;
|
|
|
|
public long UploadFileTaskId { get; set; }
|
|
public string FilePath;
|
|
public long Size;
|
|
|
|
public void Serialize(IBinaryWriter writer)
|
|
{
|
|
writer.WriteLong(this.UploadFileTaskId);
|
|
writer.WriteString(this.FilePath);
|
|
writer.WriteLong(this.Size);
|
|
}
|
|
|
|
public void Deserialize(IBinaryReader reader)
|
|
{
|
|
this.UploadFileTaskId = reader.ReadLong();
|
|
this.FilePath = reader.ReadString();
|
|
this.Size = reader.ReadLong();
|
|
}
|
|
|
|
public static FileStartFrame GetTransferFileInfo(string path)
|
|
{
|
|
var fi = new System.IO.FileInfo(path);
|
|
return new FileStartFrame
|
|
{
|
|
FilePath = fi.FullName,
|
|
UploadFileTaskId = Interlocked.Increment(ref _uploadTaskIdCounter),
|
|
Size = fi.Length
|
|
};
|
|
}
|
|
}
|
|
}
|