public void OnMessageReceived(NetworkBusEnvelope envelope) { if (messageHandlers.ContainsKey(envelope.PayloadType)) { var payLoad = envelope.Open <object>(); messageHandlers[envelope.PayloadType](payLoad); } else { HandleUnHandledMessage(envelope); } }
private void EnqueueSubMessage(NetworkBusEnvelope sub) { if (!subBox.ContainsKey(sub.GroupId)) { subBox.Add(sub.GroupId, new List <NetworkBusEnvelope>()); } var group = subBox[sub.GroupId]; group.Add(sub); if (group.Count == sub.GroupTotal) { RebuildSubGroup(sub.GroupId); } }
private void SplitOutgoingEnvelope(OutgoingNetworkBusEnvelope outgoingNetworkBusEnvelope, byte[] data) { var splitSize = MaxBufferSize / 2; var groupId = Guid.NewGuid(); var groupSize = (int)Math.Ceiling((float)data.Length / splitSize); for (var i = 0; i < groupSize; i++) { var payload = data.Skip(i * splitSize).Take(splitSize).ToArray(); var subEnveloppe = new NetworkBusEnvelope( groupId, i, groupSize, payload); outbox.Enqueue( new OutgoingNetworkBusEnvelope { Envelope = subEnveloppe, SendToSelf = outgoingNetworkBusEnvelope.SendToSelf }); } }
protected virtual void HandleUnHandledMessage(NetworkBusEnvelope envelope) { }