Exemplo n.º 1
0
        public void InvalidReceiveMessage_SetProperty()
        {
            GameObject newGameObject = new GameObject("new game object");

            Message setMessage = new Message(newGameObject.Name, MessageAction.Set, "a property name that is wrong or doesn't exist", "a new value", PropType.String);
            Response response = newGameObject.ReceiveMessage(setMessage);
            Assert.IsFalse(response.Status);
            Assert.IsTrue(response.Value == "Property name does not exist");
            Assert.IsTrue(response.PropType == PropType.Error);
        }
Exemplo n.º 2
0
        public void InvalidReceiveMessage_GetProperty()
        {
            GameObject newGameObject = new GameObject("new game object");
            Property newProperty = new Property(PropertyType.String, "new property", "a value");
            newGameObject.AddProperty(newProperty);

            Message getMessage = new Message(newGameObject.Name, MessageAction.Get, "wrong name");
            Response response = newGameObject.ReceiveMessage(getMessage);
            Assert.IsFalse(response.Status);
            Assert.IsTrue(response.Value == "Property name does not exist");
            Assert.IsTrue(response.PropType == PropType.Error );
        }
Exemplo n.º 3
0
        public void InvalidReceiveMessage_AddProperty()
        {
            GameObject newGameObject = new GameObject("new game object");
            Property newProperty = new Property(PropertyType.String, "new property", "a new value");
            newGameObject.AddProperty(newProperty);

            Message newMessage = new Message(newGameObject.Name, MessageAction.Add, "new property", "a value", PropType.String);
            Response response = newGameObject.ReceiveMessage(newMessage);

            Assert.IsFalse(response.Status);
            Assert.IsTrue(response.Value == "Property name already exists");
            Assert.IsTrue(response.Property == newProperty.Name);
            Assert.IsTrue(response.PropType == PropType.Error);
        }
Exemplo n.º 4
0
        public void Run()
        {
            var t1 = rvMessaging.Start();

            var t2 = MsmqLoop();

            // start the piong pong
            var reply = new Messaging.Message {
                Subject = "ping", Body = "hello"
            };

            mqMessaging.Send(reply);

            Task.WaitAll(t1, t2);
        }
Exemplo n.º 5
0
        private void OnMsmqPing(IReadOnlyMessage msg)
        {
            if (++pings % 1000 == 0)
            {
                Console.WriteLine($"{pings} pings of {msg.GetType().Name}");
            }
            msg.Acknowledge();
            msg.Dispose();

            //Thread.Sleep(delay);
            using (var reply = new Messaging.Message {
                Subject = "pong", Body = "world"
            })
                rvMessaging.Send(reply);
        }
Exemplo n.º 6
0
        public void SendMessage(string input, string reciever)
        {
            IMessage msg = new Messaging.Message
            {
                SenderName      = UserName,
                DestinationName = reciever,
                DestinationEP   = $"{Host}{Port}",
                SourceEP        = TcpClient.Client.LocalEndPoint.ToString(),
                Text            = input,
                SendTime        = DateTime.Now
            };

            _bf.Serialize(_stream, msg);
            LogMessage(msg);
        }
Exemplo n.º 7
0
 private void OnMessageReceived(Message <Null, string> val)
 {
     if (MessageReceived != null)
     {
         var data = _serializer.Deserialize(null, _encoding.GetBytes(val.Value));
         Messaging.Message msg = null;
         if (_routes.InboundCommands.Any(c => c.MessageType == data.GetType()))
         {
             msg = new CommandMessage(val.Offset.Value.ToString(), data);
         }
         else if (_routes.InboundEvents.Any(c => c.MessageType == data.GetType()))
         {
             msg = new EventMessage(val.Offset.Value.ToString(), val.Offset.Value, data);
         }
         if (msg != null)
         {
             MessageReceived(msg);
         }
     }
 }
Exemplo n.º 8
0
 public void ReceiveMessage_AddProperty()
 {
     GameObject newGameObject = new GameObject("new game object");
     Message newMessage = new Message(newGameObject.Name,MessageAction.Add, "new property", "a value", PropType.String);
     Response response = newGameObject.ReceiveMessage(newMessage);
     Assert.IsTrue(response.Status);
     Assert.IsTrue(newGameObject.DoesPropertyExist("new property"));
     Assert.IsTrue("a value" == newGameObject.GetProperty("new property").Value);
 }
Exemplo n.º 9
0
        public void ReceiveMessage_SetProperty()
        {
            GameObject newGameObject = new GameObject("new game object");
            Property newProperty = new Property(PropertyType.String, "new property", "a value");
            newGameObject.AddProperty(newProperty);

            Message setMessage = new Message(newGameObject.Name, MessageAction.Set, newProperty.Name,"a new value", PropType.String);
            Response response = newGameObject.ReceiveMessage(setMessage);
            Assert.IsTrue(response.Status);
            Assert.IsTrue(response.Property == newProperty.Name);
            Assert.IsTrue(response.Value != newProperty.Value);
            Assert.IsTrue(response.Value == newGameObject.GetProperty(newProperty.Name).Value);
        }
Exemplo n.º 10
0
        public void ReceiveMessage_RemoveProperty()
        {
            GameObject newGameObject = new GameObject("new game object");
            Property newProperty = new Property(PropertyType.String, "new property", "a value");
            newGameObject.AddProperty(newProperty);

            Message removeMessage = new Message(newGameObject.Name,MessageAction.Remove, newProperty.Name);
            Response response = newGameObject.ReceiveMessage(removeMessage);
            Assert.IsTrue(response.Status);
            Assert.IsTrue(response.Property == newProperty.Name);
            Assert.IsTrue(response.Value == "none");
            Assert.IsFalse(newGameObject.DoesPropertyExist(newProperty.Name));
        }
Exemplo n.º 11
0
 public SuccessMessage(Message wrappedMessage)
 {
     Message = wrappedMessage;
 }
Exemplo n.º 12
0
 public FutureMessage(Message message, DateTimeOffset retryAt)
 {
     Message = message;
     RetryAt = retryAt;
 }
Exemplo n.º 13
0
        public Response ReceiveMessage(Message newMessage)
        {
            bool doesPropertyExist = DoesPropertyExist(newMessage.Property);
            PropertyType messageType = PropertyType.String;
            switch (newMessage.PropType)
            {
                case PropType.Bool:
                    messageType = PropertyType.Bool;
                    break;
                case PropType.Number:
                    messageType = PropertyType.Number;
                    break;
                case PropType.String:
                    messageType = PropertyType.String;
                    break;
            }

            switch (newMessage.Action)
            {
                case MessageAction.Add:
                    return doesPropertyExist ? new Response(false, newMessage.Property, "Property name already exists",PropType.Error, Name) : new Response(AddProperty(new Property(messageType, newMessage.Property, newMessage.Value)), newMessage.Property, newMessage.Value, newMessage.PropType, Name);

                case MessageAction.Get:
                    if (!doesPropertyExist)
                    {
                        return new Response(false, newMessage.Property, "Property name does not exist",PropType.Error, Name);
                    }
                    Property getProperty = GetProperty(newMessage.Property);

                    return new Response(true, getProperty.Name,getProperty.Value,ConvertPropertyType(getProperty.Type), Name);

                case MessageAction.Set:
                    return !doesPropertyExist ? new Response(false, newMessage.Property, "Property name does not exist", PropType.Error, Name) : new Response(SetProperty(newMessage.Property, newMessage.Value, messageType), newMessage.Property, newMessage.Value, newMessage.PropType, Name);

                case MessageAction.Remove:
                    return !doesPropertyExist ? new Response(false, newMessage.Property, "Property name does not exist", PropType.Error, Name) : new Response(RemoveProperty(newMessage.Property), newMessage.Property, "none", PropType.Bool, Name);
            }
            return new Response(false, "Error", "Error", PropType.Error, Name);
        }
Exemplo n.º 14
0
 public RetryMessage(Message message)
 {
     Message = message;
 }
 public RetryLimitExceededException(Message message)
 {
     _message = message;
 }
Exemplo n.º 16
0
 public Response SendMessage(Message newMessage)
 {
     return !_objectList.ContainsKey(newMessage.Receiver) ? new Response(false, "GameObject is not being observed", "GameObject is not being observed", PropType.Error, "GameObject is not being observed") : _objectList[newMessage.Receiver].ReceiveMessage(newMessage);
 }