Ejemplo n.º 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;
 }
Ejemplo n.º 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));
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 4
0
        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");
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
                }
            });
        }
Ejemplo n.º 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)));
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 11
0
 public ClientPacketHandler GetHandler(PacketIdentity packetId)
 {
     return(clientPacketHandlers[(byte)packetId]);
 }
Ejemplo n.º 12
0
 public static void Register(PacketIdentity packetId, Func <IPacket> ctor)
 {
     _dict.Add(packetId, ctor);
 }
Ejemplo n.º 13
0
 public Packet(PacketIdentity packetId, int size)
 {
     this.PacketId = packetId;
     this.Buffer   = new byte[size];
     this.Size     = size;
 }
Ejemplo n.º 14
0
 //public Packet()
 //{
 //    this.PacketId = PacketIdentity.Invalid;
 //    this.Buffer = new byte[Packet.BufferSize];
 //}
 public Packet(PacketIdentity packetId) : this(packetId, Packet.DefaultBufferSize)
 {
 }