public TransportPacketInfo(string providerKey, PacketIdentity identity, int length, Func <Stream> streamFactory) { this.Identity = identity; this.ProviderKey = providerKey; this.Length = length; this.streamFactory = streamFactory; }
private bool ExistsSendStats(string providerKey, PacketIdentity packetId) { var packetFilePath = this.GetPacketFilePath(providerKey, packetId); var packetStatsFilePath = packetFilePath + this.packetStatsExt; var packetStatsTempFilePath = packetStatsFilePath + sendStatsOptions.TempFileSuffix; return(File.Exists(packetStatsFilePath) || File.Exists(packetStatsTempFilePath)); }
public TransportPacket(PacketIdentity id, Stream stream, Action saveDataAction, int?length = null) { this.Identity = id; this.stream = stream; this.saveDataAction = saveDataAction; if (length != null) { this.Length = length.Value; } else if (stream.CanSeek) { this.Length = this.stream.Length; } }
private static IPacket Create(PacketIdentity packetId) { if (packetId == PacketIdentity.Invalid) { return(new Packet(packetId)); } Func <IPacket> constructor = null; if (_dict.TryGetValue(packetId, out constructor)) { return(constructor()); } throw new ArgumentException("No type registered for this id"); }
private SendStats ReadSendStatsInternal(string providerKey, PacketIdentity packetId, bool useLock) { var packetFilePath = this.GetPacketFilePath(providerKey, packetId); var packetStatsFilePath = packetFilePath + this.packetStatsExt; var packetStatsTempFilePath = packetStatsFilePath + sendStatsOptions.TempFileSuffix; if (File.Exists(packetStatsFilePath)) { return(this.ReadSendStatsFromFileWithOrWithoutLocks(providerKey, packetStatsFilePath, useLock)); } if (File.Exists(packetStatsTempFilePath)) { return(this.ReadSendStatsFromFileWithOrWithoutLocks(providerKey, packetStatsTempFilePath, useLock)); } return(null); }
public void SaveSendStats(string providerKey, PacketIdentity packetId, SendStats stats) { var packetFilePath = this.GetPacketFilePath(providerKey, packetId); var packetStatsFilePath = packetFilePath + this.packetStatsExt; this.RunInWriteLock(providerKey, () => { if (stats.TransferCompleted) { FileSystemHelper.DeleteFile(packetStatsFilePath); FileSystemHelper.DeleteFile(packetFilePath); } else { AtomicFileWriteHelper.WriteToFile(packetStatsFilePath, JsonConvert.SerializeObject(stats), sendStatsEncoding, sendStatsOptions); } }); }
private string GetPacketFilePath(string providerKey, PacketIdentity packetId) { return(Path.Combine(this.GetProviderStoreDir(providerKey), string.Concat(packetId.PacketId.ToString(), packetFileIdOrderDelimeter, packetId.OrderValue, this.packetExt))); }
public SendStats ReadSendStats(string providerKey, PacketIdentity packetId) { return(this.ReadSendStatsInternal(providerKey, packetId, true)); }
public static ServerPacketHandler GetHandler(PacketIdentity packetID) { return(Handlers[(byte)packetID]); }
public static void Register(PacketIdentity packetID, ServerPacketHandler packetHandler) { Handlers[(byte)packetID] = packetHandler; }
public ClientPacketHandler GetHandler(PacketIdentity packetId) { return(clientPacketHandlers[(byte)packetId]); }
public static void Register(PacketIdentity packetId, Func <IPacket> ctor) { _dict.Add(packetId, ctor); }
public Packet(PacketIdentity packetId, int size) { this.PacketId = packetId; this.Buffer = new byte[size]; this.Size = size; }
//public Packet() //{ // this.PacketId = PacketIdentity.Invalid; // this.Buffer = new byte[Packet.BufferSize]; //} public Packet(PacketIdentity packetId) : this(packetId, Packet.DefaultBufferSize) { }