コード例 #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
ファイル: EventDelivery.cs プロジェクト: guogongjun/Blink
 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
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 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
ファイル: DelegateDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveStart(ReceivePacket entity)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         PostQueue(() =>
         {
             listener.OnReceiveStart(entity.GetPacketType(), entity.GetId());
         });
     }
 }
コード例 #6
0
ファイル: DelegateDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         PostQueue(() =>
         {
             listener.OnReceiveProgress(entity, progress);
         });
     }
 }
コード例 #7
0
ファイル: DelegateDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveEnd(ReceivePacket entity, bool isSuccess)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
     {
         entity.SetSuccess(isSuccess);
         PostQueue(() =>
         {
             listener.OnReceiveEnd(entity);
         });
     }
 }
コード例 #8
0
ファイル: BlinkCallBack.cs プロジェクト: guogongjun/Blink
 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
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveStart(ReceivePacket entity)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
         PostQueue(new ReceiveStartDeliveryRunnable(listener, entity));
 }
コード例 #11
0
ファイル: EventDelivery.cs プロジェクト: guogongjun/Blink
 public ReceiveDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress, bool isEnd)
 {
     this.listener = listener;
     this.entity = entity;
     this.progress = progress;
     this.isEnd = isEnd;
 }
コード例 #12
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null && entity != null)
         PostQueue(new ReceiveProgressDeliveryRunnable(listener, entity, progress));
 }
コード例 #13
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public ReceiveStartDeliveryRunnable(ReceiveListener listener, ReceivePacket entity)
 {
     this.listener = listener;
     this.entity = entity;
 }
コード例 #14
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public void Run()
 {
     listener.OnReceiveStart(entity.GetPacketType(), entity.GetId());
     entity = null;
     listener = null;
 }
コード例 #15
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public ReceiveProgressDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress)
 {
     this.listener = listener;
     this.entity = entity;
     this.progress = progress;
 }
コード例 #16
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public void Run()
 {
     listener.OnReceiveProgress(entity, progress);
     entity = null;
     listener = null;
 }
コード例 #17
0
ファイル: BlinkCallBack.cs プロジェクト: guogongjun/Blink
 public void OnReceiveProgress(ReceivePacket paket, float progress)
 {
     Console.WriteLine("Receive->progress:" + paket.GetPacketType() + " " + paket.GetId()
                  + " " + paket.GetLength() + " " + progress);
 }
コード例 #18
0
ファイル: CallBackDelivery.cs プロジェクト: guogongjun/Blink
 public void Run()
 {
     listener.OnReceiveEnd(entity);
     entity = null;
     listener = null;
 }
コード例 #19
0
ファイル: EventDelivery.cs プロジェクト: guogongjun/Blink
 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
ファイル: EventDelivery.cs プロジェクト: guogongjun/Blink
 public void PostReceiveProgress(ReceivePacket entity, float progress)
 {
     ReceiveListener listener = mReceiveListener;
     if (listener != null)
         PostBlink(new ReceiveDeliveryRunnable(listener, entity, progress, false));
 }
コード例 #21
0
ファイル: EventDelivery.cs プロジェクト: guogongjun/Blink
 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);
        }