Exemplo n.º 1
0
        internal void Send(QueuedMessage send)
        {
            if (clients.Count == 0)
            {
                return;
            }

            Client[] clientsTo = send.sendTo;

            if (clientsTo == null || clientsTo.Count() == 0)
            {
                clientsTo = new Client[] { clients[0] }
            }
            ;

            send.sendTo = clientsTo;

            string payload = GetPayload(send);

            foreach (Client client in clientsTo)
            {
                if (send.SendReliable)
                {
                    NetworkChannel.SetReliable();
                }
                else
                {
                    NetworkChannel.SetUnreliable();
                }

                NetworkChannel.Send(client, payload);
            }
        }
Exemplo n.º 2
0
        private void CheckExecuteReplyAction(ReceivedMessage message, Type receivedObjectType, string token, object receivedObject)
        {
            Delegate replyFunction = ReceiveHandle[receivedObjectType].ReplyFunction;

            if (replyFunction != null)
            {
                object result;
                if (replyFunction.GetMethodInfo().GetParameters().Count() > 1)
                {
                    result = replyFunction.DynamicInvoke(message.From, receivedObject);
                }
                else
                {
                    result = replyFunction.DynamicInvoke(receivedObject);
                }

                if (result == null)
                {
                    return;
                }

                QueuedMessage queueMessage = new QueuedMessage();
                queueMessage.ObjectToSend = result;
                queueMessage.sendTo       = new Client[] { message.From };
                queueMessage.SendReliable = SendReliable;
                queueMessage.Token        = token;
                Send(queueMessage);
            }
        }
Exemplo n.º 3
0
        private string GetPayload(QueuedMessage send)
        {
            object objectToSend = send.ObjectToSend;
            Type   objectType   = objectToSend.GetType();

            string object_AssemblyQualifiedName = objectType.AssemblyQualifiedName;
            string serialized_object            = Serializer.Serialize(objectToSend);

            string token = send.Token;

            //If this queued message is waiting for a response eg (Send().Response())
            if (send.resonseType_to_actionMatch.Count > 0)
            {
                token = GenerateToken();

                MessageResponseHandle responseHandle = new MessageResponseHandle(send);
                responseHandle.ClientsToRespond.AddRange(send.sendTo);
                ResponseHandle.TryAdd(token, responseHandle);
            }

            string payload = string.Empty;

            if (token == null)
            {
                payload = string.Format("{0}::{1}", object_AssemblyQualifiedName, serialized_object);
            }
            else
            {
                payload = string.Format("{0}::{1}::{2}", object_AssemblyQualifiedName, token, serialized_object);
            }

            return(payload);
        }
 public MessageResponseHandle(QueuedMessage sent)
 {
     sentMessage = sent;
 }