예제 #1
0
 public void OnMessageReceived(NetworkBusEnvelope envelope)
 {
     if (messageHandlers.ContainsKey(envelope.PayloadType))
     {
         var payLoad = envelope.Open <object>();
         messageHandlers[envelope.PayloadType](payLoad);
     }
     else
     {
         HandleUnHandledMessage(envelope);
     }
 }
예제 #2
0
        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);
            }
        }
예제 #3
0
        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
                });
            }
        }
예제 #4
0
 protected virtual void HandleUnHandledMessage(NetworkBusEnvelope envelope)
 {
 }