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()); } }
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); }
public void PostReceiveEnd(ReceivePacket entity, bool isSuccess) { ReceiveListener listener = mReceiveListener; if (listener != null) { entity.SetSuccess(isSuccess); PostBlink(new ReceiveDeliveryRunnable(listener, entity, 0, true)); } }
public void PostReceiveEnd(ReceivePacket entity, bool isSuccess) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) { entity.SetSuccess(isSuccess); PostQueue(new ReceiveEndDeliveryRunnable(listener, entity)); } }
public void PostReceiveStart(ReceivePacket entity) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) { PostQueue(() => { listener.OnReceiveStart(entity.GetPacketType(), entity.GetId()); }); } }
public void PostReceiveProgress(ReceivePacket entity, float progress) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) { PostQueue(() => { listener.OnReceiveProgress(entity, progress); }); } }
public void PostReceiveEnd(ReceivePacket entity, bool isSuccess) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) { entity.SetSuccess(isSuccess); PostQueue(() => { listener.OnReceiveEnd(entity); }); } }
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()); }
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(); } }
public void PostReceiveStart(ReceivePacket entity) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) PostQueue(new ReceiveStartDeliveryRunnable(listener, entity)); }
public ReceiveDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress, bool isEnd) { this.listener = listener; this.entity = entity; this.progress = progress; this.isEnd = isEnd; }
public void PostReceiveProgress(ReceivePacket entity, float progress) { ReceiveListener listener = mReceiveListener; if (listener != null && entity != null) PostQueue(new ReceiveProgressDeliveryRunnable(listener, entity, progress)); }
public ReceiveStartDeliveryRunnable(ReceiveListener listener, ReceivePacket entity) { this.listener = listener; this.entity = entity; }
public void Run() { listener.OnReceiveStart(entity.GetPacketType(), entity.GetId()); entity = null; listener = null; }
public ReceiveProgressDeliveryRunnable(ReceiveListener listener, ReceivePacket entity, float progress) { this.listener = listener; this.entity = entity; this.progress = progress; }
public void Run() { listener.OnReceiveProgress(entity, progress); entity = null; listener = null; }
public void OnReceiveProgress(ReceivePacket paket, float progress) { Console.WriteLine("Receive->progress:" + paket.GetPacketType() + " " + paket.GetId() + " " + paket.GetLength() + " " + progress); }
public void Run() { listener.OnReceiveEnd(entity); entity = null; listener = null; }
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; }
public void PostReceiveProgress(ReceivePacket entity, float progress) { ReceiveListener listener = mReceiveListener; if (listener != null) PostBlink(new ReceiveDeliveryRunnable(listener, entity, progress, false)); }
public void PostReceiveStart(ReceivePacket entity) { ReceiveListener listener = mReceiveListener; if (listener != null) PostBlink(new ReceiveDeliveryRunnable(listener, entity, 0, false)); }
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); }
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); }