Beispiel #1
0
 public TransportPacketInfo(string providerKey, PacketIdentity identity, int length, Func <Stream> streamFactory)
 {
     this.Identity      = identity;
     this.ProviderKey   = providerKey;
     this.Length        = length;
     this.streamFactory = streamFactory;
 }
Beispiel #2
0
        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));
        }
Beispiel #3
0
        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");
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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);
                }
            });
        }
Beispiel #7
0
 private string GetPacketFilePath(string providerKey, PacketIdentity packetId)
 {
     return(Path.Combine(this.GetProviderStoreDir(providerKey), string.Concat(packetId.PacketId.ToString(), packetFileIdOrderDelimeter, packetId.OrderValue, this.packetExt)));
 }
Beispiel #8
0
 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;
 }
Beispiel #11
0
 public ClientPacketHandler GetHandler(PacketIdentity packetId)
 {
     return(clientPacketHandlers[(byte)packetId]);
 }
 public static void Register(PacketIdentity packetId, Func <IPacket> ctor)
 {
     _dict.Add(packetId, ctor);
 }
Beispiel #13
0
 public Packet(PacketIdentity packetId, int size)
 {
     this.PacketId = packetId;
     this.Buffer   = new byte[size];
     this.Size     = size;
 }
Beispiel #14
0
 //public Packet()
 //{
 //    this.PacketId = PacketIdentity.Invalid;
 //    this.Buffer = new byte[Packet.BufferSize];
 //}
 public Packet(PacketIdentity packetId) : this(packetId, Packet.DefaultBufferSize)
 {
 }