Exemplo n.º 1
0
        public AsyncReceiveDispatcher(Receiver receiver, BlinkParser parser, ReceiveDelivery receiveDelivery, BlinkDelivery blinkDelivery, float progressPrecision)
            : base(progressPrecision)
        {
            mReceiver        = receiver;
            mBufferSize      = receiver.GetBufferSize();
            mParser          = parser;
            mReceiveDelivery = receiveDelivery;
            mBlinkDelivery   = blinkDelivery;

            // Set Buffer
            SetBuffer(new byte[mBufferSize], 0, mBufferSize);

            // Start
            ReceiveAsync(0);
        }
Exemplo n.º 2
0
        public AsyncReceiveDispatcher(Receiver receiver, BlinkParser parser, ReceiveDelivery receiveDelivery, BlinkDelivery blinkDelivery, float progressPrecision)
            : base(progressPrecision)
        {
            mReceiver = receiver;
            mBufferSize = receiver.GetBufferSize();
            mParser = parser;
            mReceiveDelivery = receiveDelivery;
            mBlinkDelivery = blinkDelivery;

            // Set Buffer
            SetBuffer(new byte[mBufferSize], 0, mBufferSize);

            // Start
            ReceiveAsync(0);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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();
            }
        }
Exemplo n.º 5
0
        public BlinkConn(Sender sender,
                         Receiver receiver,
                         SendDelivery sendDelivery,
                         ReceiveDelivery receiveDelivery,
                         BlinkDelivery blinkDelivery,
                         Resource resource,
                         BlinkParser parser,
                         float progressPrecision)
        {
            mSender   = sender;
            mReceiver = receiver;
            mResource = resource;

            mSendDelivery    = sendDelivery;
            mReceiveDelivery = receiveDelivery;
            mBlinkDelivery   = blinkDelivery;

            mParser = parser;

            // Init this
            Init(progressPrecision);
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        public BlinkConn(Sender sender,
            Receiver receiver,
            SendDelivery sendDelivery,
            ReceiveDelivery receiveDelivery,
            BlinkDelivery blinkDelivery,
            Resource resource,
            BlinkParser parser,
            float progressPrecision)
        {
            mSender = sender;
            mReceiver = receiver;
            mResource = resource;

            mSendDelivery = sendDelivery;
            mReceiveDelivery = receiveDelivery;
            mBlinkDelivery = blinkDelivery;

            mParser = parser;

            // Init this
            Init(progressPrecision);
        }
Exemplo n.º 8
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();
            }
        }