예제 #1
0
 public void OnReceiveEnd(Net.Qiujuer.Blink.Core.ReceivePacket paket)
 {
     if (paket.GetType() == BlinkPacket.Type.STRING)
     {
         Console.WriteLine("Receive->end: String:"
                           + paket.GetId() + " " + paket.GetLength() + " :"
                           + ((StringReceivePacket)paket).GetEntity());
     }
     else if (paket.GetType() == BlinkPacket.Type.BYTES)
     {
         Console.WriteLine("Receive->end: Bytes:"
                           + paket.GetId() + " " + paket.GetLength() + " :"
                           + ((ByteReceivePacket)paket).GetEntity());
     }
     else
     {
         Console.WriteLine("Receive->end: File:"
                           + paket.GetId()
                           + " "
                           + paket.GetLength()
                           + " :"
                           + ((FileReceivePacket)paket).GetEntity()
                           .FullName + " " + paket.GetHashCode());
     }
 }
예제 #2
0
        public ReceivePacket ParseReceive(int type, int len)
        {
            long          id     = ++mId;
            ReceivePacket packet = null;

            switch (type)
            {
            case BlinkPacket.Type.STRING:
                packet = new StringReceivePacket(id, type, len);
                break;

            case BlinkPacket.Type.BYTES:
                packet = new ByteReceivePacket(id, type, len);;
                break;

            case BlinkPacket.Type.FILE:
                String file = mResource.Create(id);
                if (file != null)
                {
                    packet = new FileReceivePacket(id, type, len, file);
                }
                break;
            }
            return(packet);
        }
예제 #3
0
 public void PostReceiveEnd(ReceivePacket entity, bool isSuccess)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null)
     {
         entity.SetSuccess(isSuccess);
         PostBlink(new ReceiveDeliveryRunnable(listener, entity, 0, true));
     }
 }
예제 #4
0
 public void PostReceiveEnd(ReceivePacket entity, bool isSuccess)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         entity.SetSuccess(isSuccess);
         PostQueue(new ReceiveEndDeliveryRunnable(listener, entity));
     }
 }
예제 #5
0
 public void PostReceiveStart(ReceivePacket entity)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         PostQueue(() =>
         {
             listener.OnReceiveStart(entity.GetPacketType(), entity.GetId());
         });
     }
 }
예제 #6
0
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         PostQueue(() =>
         {
             listener.OnReceiveProgress(entity, progress);
         });
     }
 }
예제 #7
0
 public void PostReceiveEnd(ReceivePacket entity, bool isSuccess)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         entity.SetSuccess(isSuccess);
         PostQueue(() =>
         {
             listener.OnReceiveEnd(entity);
         });
     }
 }
예제 #8
0
 public void OnReceiveEnd(ReceivePacket paket)
 {
     if (paket.GetPacketType() == BlinkPacket.PacketType.STRING)
         Console.WriteLine("Receive->end: String:"
                 + paket.GetId() + " " + paket.GetLength() + " :"
                 + ((StringReceivePacket)paket).GetEntity());
     else if (paket.GetPacketType() == BlinkPacket.PacketType.BYTES)
         Console.WriteLine("Receive->end: Bytes:"
                 + paket.GetId() + " " + paket.GetLength() + " :"
                 + ((ByteReceivePacket)paket).GetEntity());
     else
         Console.WriteLine("Receive->end: File:"
                 + paket.GetId()
                 + " "
                 + paket.GetLength()
                 + " "
                 + ((FileReceivePacket)paket).GetEntity().FullName
                 + " "
                 + paket.GetHash());
 }
예제 #9
0
        public new void Dispose()
        {
            if (!IsDisposed())
            {
                mParser = null;

                ReceivePacket packet = mReceivePacket;
                mReceivePacket = null;

                Receiver receiver = mReceiver;
                mReceiver = null;

                ReceiveDelivery receiveDelivery = mReceiveDelivery;
                mReceiveDelivery = null;

                if (packet != null && receiveDelivery != null)
                {
                    if (mSurplusLen > 0)
                    {
                        packet.EndPacket();
                        receiveDelivery.PostReceiveEnd(packet, false);
                    }
                }

                BlinkDelivery blinkDelay = mBlinkDelivery;
                mBlinkDelivery = null;
                if (blinkDelay != null)
                    blinkDelay.PostBlinkDisconnect();

                if (receiver != null)
                    receiver.Dispose();

                SetBuffer(null, 0, 0);

                base.Dispose();
            }
        }
예제 #10
0
 public void PostReceiveStart(ReceivePacket entity)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
         PostQueue(new ReceiveStartDeliveryRunnable(listener, entity));
 }
예제 #11
0
 public ReceiveDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress, bool isEnd)
 {
     this.listener = listener;
     this.entity = entity;
     this.progress = progress;
     this.isEnd = isEnd;
 }
예제 #12
0
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
         PostQueue(new ReceiveProgressDeliveryRunnable(listener, entity, progress));
 }
예제 #13
0
 public ReceiveStartDeliveryRunnable(ReceiveListener listener, ReceivePacket entity)
 {
     this.listener = listener;
     this.entity = entity;
 }
예제 #14
0
 public void Run()
 {
     listener.OnReceiveStart(entity.GetPacketType(), entity.GetId());
     entity = null;
     listener = null;
 }
예제 #15
0
 public ReceiveProgressDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress)
 {
     this.listener = listener;
     this.entity = entity;
     this.progress = progress;
 }
예제 #16
0
 public void Run()
 {
     listener.OnReceiveProgress(entity, progress);
     entity = null;
     listener = null;
 }
예제 #17
0
 public void OnReceiveProgress(ReceivePacket paket, float progress)
 {
     Console.WriteLine("Receive->progress:" + paket.GetPacketType() + " " + paket.GetId()
                  + " " + paket.GetLength() + " " + progress);
 }
예제 #18
0
 public void Run()
 {
     listener.OnReceiveEnd(entity);
     entity = null;
     listener = null;
 }
예제 #19
0
 public void Run()
 {
     if (listener != null)
     {
         if (progress > 0)
             listener.OnReceiveProgress(entity, progress);
         else if (isEnd)
             listener.OnReceiveEnd(entity);
         else
             listener.OnReceiveStart(entity.GetPacketType(), entity.GetId());
     }
     entity = null;
     listener = null;
 }
예제 #20
0
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null)
         PostBlink(new ReceiveDeliveryRunnable(listener, entity, progress, false));
 }
예제 #21
0
 public void PostReceiveStart(ReceivePacket entity)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null)
         PostBlink(new ReceiveDeliveryRunnable(listener, entity, 0, false));
 }
예제 #22
0
        private void ReceiveHead(byte[] buffer)
        {
            mSurplusLen = 0;
            mSurplusInfoLen = 0;
            mProgress = 0;

            byte type = buffer[0];
            long len = BitConverter.ToInt64(buffer, 1);
            short info = BitConverter.ToInt16(buffer, HeadSize - 2);

            if (len > 0)
            {
                // Set Length
                mSurplusLen = len;
                mSurplusInfoLen = info;

                // Parse receive packet
                ReceivePacket packet = mParser.ParseReceive(type, len);

                if (packet != null && packet.StartPacket())
                {
                    mReceivePacket = packet;

                    // Notifly
                    ReceiveDelivery delivery = mReceiveDelivery;
                    if (delivery != null)
                        delivery.PostReceiveStart(packet);

                }
                else
                {
                    // Set Null
                    mReceivePacket = null;
                }
            }

            ReceiveAsync(mSurplusInfoLen > 0 ? mSurplusInfoLen : mSurplusLen);
        }
예제 #23
0
        private void ReceiveEntity(byte[] buffer, int offset, int count)
        {
            // Set len
            mSurplusLen -= count;

            ReceivePacket packet = mReceivePacket;

            if (packet != null)
            {
                packet.Write(buffer, offset, count);

                // Notity progress
                float len = packet.GetLength();
                float progress = (len - mSurplusLen) / len;

                // Post Callback
                ReceiveDelivery delivery = mReceiveDelivery;

                if (IsNotifyProgress(progress))
                {
                    // Notify
                    if (delivery != null)
                        delivery.PostReceiveProgress(packet, mProgress);
                }

                if (mSurplusLen <= 0)
                {
                    // End
                    packet.EndPacket();

                    // Notify
                    if (delivery != null)
                        delivery.PostReceiveEnd(packet, mStatus);

                    // Set Null
                    mReceivePacket = null;
                }
            }

            // Receive next entity
            ReceiveAsync(mSurplusLen);
        }