Esempio n. 1
0
        public async void SubscribeToMessages(HandleMessageDelegate handler, string Channel, string Group = "", string clientDisplayName = "")
        {
            try
            {
                SubscribeToMessages(new SubscribeRequest()
                {
                    Channel = Channel, Group = Group
                }, clientDisplayName);

                // send messages to end-user
                while (true)
                {
                    // await for message from queue
                    InnerMessage innerMessage = await _RecivedMessages.ReceiveAsync();

                    LogIncomingMessage(innerMessage);

                    // Convert KubeMQ.Grpc.Message to outter Message
                    Message message = new Message(innerMessage);

                    // Activate end-user message handler Delegate
                    handler(message);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "Exception in SubscribeToMessages");
            }
        }
Esempio n. 2
0
 void SketchHandler(string msg)
 {
     if (msg == "Recieved" && nextCommand != sketch.Length)
     {
         if (sketch[nextCommand].StartsWith("sleep"))
         {
             Thread.Sleep(int.Parse(sketch[nextCommand++].Substring(5)));
             if (nextCommand != sketch.Length)
             {
                 SendMessage(sketch[nextCommand++]);
             }
             else
             {
                 MessageHandler = PrintMessage;
             }
         }
         else
         {
             SendMessage(sketch[nextCommand++]);
         }
     }
     else
     {
         MessageHandler = PrintMessage;
     }
 }
Esempio n. 3
0
 private void button7_Click(object sender, EventArgs e)
 {
     MessageHandler = RotateHandler;
     angle          = -180;
     SendMessage($"sp{deviation} {angle}");
     angle += delta;
 }
Esempio n. 4
0
 private void button5_Click(object sender, EventArgs e)
 {
     MessageHandler = SketchHandler;
     sketch         = sketches[sketchBox.SelectedIndex];
     nextCommand    = 0;
     SendMessage(sketch[nextCommand++]);
 }
Esempio n. 5
0
        public async Task <TResponse> RunAsync(TMessage message, IMediationContext mediationContext,
                                               CancellationToken cancellationToken, HandleMessageDelegate <TMessage, TResponse> next)
        {
            Console.WriteLine("Constrained validator hit");
            var result = await next.Invoke(message, mediationContext, cancellationToken);

            return(result);
        }
Esempio n. 6
0
 private void Form1_Load(object sender, EventArgs e)
 {
     F = this;
     legsBox.SelectedIndex = 2;
     MessageHandler        = PrintMessage;
     LoadSketches();
     Connect();
 }
Esempio n. 7
0
        /// <summary>
        /// Check that the object uses the bus to return the appropriate error code.
        /// </summary>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectReturn(ReturnPredicate check)
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToReturn(check)
                );

            delegates.Add(d);
        }
Esempio n. 8
0
        /// <summary>
        /// Check that the object sends a message of the given type complying with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectSend <TMessage>(SendPredicate <TMessage> check)
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSend <TMessage>(
                    msgs => msgs.All(msg => msg is TMessage) && msgs.OfType <TMessage>().All(msg => check(msg))));

            delegates.Add(d);
        }
Esempio n. 9
0
        /// <summary>
        /// Check that the object tells the bus to not dispatch the current message to any other handlers.
        /// </summary>
        /// <returns></returns>
        public void ExpectDoNotContinueDispatchingCurrentMessageToHandlers()
        {
            Delegate d = new HandleMessageDelegate(
                this.ExpectCallToDoNotContinueDispatchingCurrentMessageToHandlers
                );

            delegates.Add(d);
        }
Esempio n. 10
0
        /// <summary>
        /// Check that the object tells the bus to handle the current message later
        /// </summary>
        /// <returns></returns>
        public void ExpectHandleCurrentMessageLater()
        {
            Delegate d = new HandleMessageDelegate(
                this.ExpectCallToHandleCurrentMessageLater
                );

            delegates.Add(d);
        }
        public async Task <TResponse> RunAsync(TMessage message, IMediationContext mediationContext,
                                               CancellationToken cancellationToken, HandleMessageDelegate <TMessage, TResponse> next)
        {
            Console.WriteLine("Message pre logged using middleware 1");
            var result = await next.Invoke(message, mediationContext, cancellationToken);

            Console.WriteLine("Message post logged using middleware 1");

            return(result);
        }
        private Task <TResponse> RunMiddleware(TMessage message, HandleMessageDelegate <TMessage, TResponse> handleMessageHandlerCall,
                                               IMediationContext mediationContext, CancellationToken cancellationToken)
        {
            HandleMessageDelegate <TMessage, TResponse> next = null;

            next = _middlewares.Reverse().Aggregate(handleMessageHandlerCall, (messageDelegate, middleware) =>
                                                    ((req, ctx, ct) => middleware.RunAsync(req, ctx, ct, messageDelegate)));

            return(next.Invoke(message, mediationContext, cancellationToken));
        }
Esempio n. 13
0
        /// <summary>
        /// Check that the object sends a message of the given type complying with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectSend <TMessage>(SendPredicate <TMessage> check)
        {
            MessagingBestPractices.AssertIsValidForSend(typeof(TMessage), MessageIntentEnum.Send);

            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSend <TMessage>(
                    msgs => msgs.All(msg => msg is TMessage) && msgs.OfType <TMessage>().All(msg => check(msg))));

            delegates.Add(d);
        }
        public async Task <TResponse> RunAsync(TMessage message, IMediationContext mediationContext,
                                               CancellationToken cancellationToken, HandleMessageDelegate <TMessage, TResponse> next)
        {
            if (mediationContext.GetType().IsAssignableFrom(typeof(MassTransitSendMediationContext <TMessage, TResponse>)))
            {
                var context = mediationContext as MassTransitSendMediationContext <TMessage, TResponse>;
                return(await context.Client.Request(message, cancellationToken));
            }

            // Pass through
            return(await next.Invoke(message, mediationContext, cancellationToken));
        }
Esempio n. 15
0
        public void ExpectForwardCurrentMessageTo(string destination)
        {
            string dest = string.Empty;

            Delegate del = new HandleMessageDelegate(
                () => Expect.Call(() => bus.ForwardCurrentMessageTo(dest))
                .IgnoreArguments()
                .Callback((string d) => d == destination)
                );

            delegates.Add(del);
        }
Esempio n. 16
0
 void RotateHandler(string msg)
 {
     if (msg == "Recieved" && angle <= 180)
     {
         SendMessage($"sp{deviation} {angle}");
         angle += delta;
     }
     else
     {
         MessageHandler = PrintMessage;
         SendMessage("sp0 0");
     }
 }
Esempio n. 17
0
        /// <summary>
        /// Check that the object replies with the given message type complying with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectReply <TMessage>(SendPredicate <TMessage> check)
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToReply(
                    delegate(object[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 18
0
        /// <summary>
        /// Check that the object does not publish any messages of the given type complying with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectNotPublish <TMessage>(PublishPredicate <TMessage> check)
        {
            Delegate d = new HandleMessageDelegate(
                () => DoNotExpectCallToPublish <TMessage>(
                    delegate(TMessage[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 19
0
        /// <summary>
        /// Check that the object sends the given message type to its local queue
        /// and that the message complies with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectSendLocal <TMessage>(SendPredicate <TMessage> check) where TMessage : IMessage
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSendLocal(
                    delegate(IMessage[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 20
0
        /// <summary>
        /// Check that the object sends the given message type to the appropriate destination.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectSendToDestination <TMessage>(SendToDestinationPredicate <TMessage> check) where TMessage : IMessage
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSend(
                    delegate(string destination, IMessage[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(destination, msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 21
0
        /// <summary>
        /// Check that the object replies to the originator with the given message type.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectReplyToOrginator <TMessage>(SendPredicate <TMessage> check) where TMessage : IMessage
        {
            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSend(
                    delegate(string destination, string correlationId, IMessage[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 22
0
        /// <summary>
        /// Check that the object publishes a message of the given type complying with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectPublish <TMessage>(PublishPredicate <TMessage> check)
        {
            MessagingBestPractices.AssertIsValidForPubSub(typeof(TMessage));

            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToPublish(
                    delegate(TMessage[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 23
0
        /// <summary>
        /// Check that the object sends the given message type to its local queue
        /// and that the message complies with the given predicate.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectSendLocal <TMessage>(SendPredicate <TMessage> check)
        {
            MessagingBestPractices.AssertIsValidForSend(typeof(TMessage), MessageIntentEnum.Send);

            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSendLocal <TMessage>(
                    delegate(object[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 24
0
        /// <summary>
        /// Check that the object replies to the originator with the given message type.
        /// </summary>
        /// <typeparam name="TMessage"></typeparam>
        /// <param name="check"></param>
        /// <returns></returns>
        public void ExpectReplyToOrginator <TMessage>(SendPredicate <TMessage> check)
        {
            MessagingBestPractices.AssertIsValidForReply(typeof(TMessage));

            Delegate d = new HandleMessageDelegate(
                () => ExpectCallToSend <TMessage>(
                    delegate(string destination, string correlationId, object[] msgs)
            {
                foreach (TMessage msg in msgs)
                {
                    if (!check(msg))
                    {
                        return(false);
                    }
                }

                return(true);
            }
                    )
                );

            delegates.Add(d);
        }
Esempio n. 25
0
 public ClientMessageBuilder(HandleMessageDelegate _delegate)
 {
     this._delegate = _delegate;
 }
 public ClientMessageBuilder(HandleMessageDelegate _delegate)
 {
     this._delegate = _delegate;
 }
Esempio n. 27
0
 public void RegisterCommandHandler(int cmdID, HandleMessageDelegate <byte[]> handler)
 {
     throw new NotImplementedException();
 }
Esempio n. 28
0
 public void RegisterMessage(int message, HandleMessageDelegate targetHandler)
 {
     HandleMessageDelegate handlers;
     if (messageHandlers.TryGetValue(message, out handlers))
     {
         messageHandlers[message] = handlers + targetHandler;
     }
     else
     {
         messageHandlers[message] = targetHandler;
     }
 }
Esempio n. 29
0
 public void RegisterEventHandler(int channelID, int eventID, HandleMessageDelegate <byte[]> handler)
 {
     throw new NotImplementedException();
 }
Esempio n. 30
0
 private void button6_Click(object sender, EventArgs e)
 {
     MessageHandler = PrintMessage;
 }
Esempio n. 31
0
 /// <summary>
 /// The unregister message handler.
 /// </summary>
 /// <param name="messageHandler">
 /// The message handler.
 /// </param>
 public void UnregisterMessageHandler(HandleMessageDelegate messageHandler)
 {
     this.MessageReceivedEvent -= messageHandler;
 }
Esempio n. 32
0
        public async Task <TResponse> RunAsync(TMessage message, IMediationContext mediationContext, CancellationToken cancellationToken, HandleMessageDelegate <TMessage, TResponse> next)
        {
            var gameContext = mediationContext as GameContext;

            if (gameContext != null)
            {
                gameContext.Game = gameContext.GameCode != null?_gameManager.GetGame(gameContext.GameCode) : null;
            }

            return(await next.Invoke(message, mediationContext, cancellationToken));
        }