public IMyCommand DequeueCommand()
        {
            IMyCommand cmd = null;

            m_Commands.TryDequeue(out cmd);
            return(cmd);
        }
Beispiel #2
0
        private static void SendCommand(ISession session, string queue, IMyCommand request)
        {
            request.Time      = DateTime.Now;
            request.Duration  = TimeSpan.FromMinutes(5);
            request.CommandId = Guid.NewGuid();

            var destination = SessionUtil.GetDestination(session, queue);

            using (var producer = session.CreateProducer())
            {
                var message =
                    session.CreateXmlMessage(
                        request);
                message.NMSReplyTo = responseQueue;
                producer.Send(destination, message);
            }
        }
Beispiel #3
0
        public void Start()
        {
            Console.WriteLine("This will send a command Message.");
            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            while (Console.ReadLine() != null)
            {
                IMyCommand myCommand = Bus.CreateInstance <IMyCommand>(m =>
                {
                    m.IdGuid = Guid.NewGuid();
                    m.Name   = "My Name is Demo!";
                });

                Bus.Send(myCommand);

                Console.WriteLine("Send a command message type: {1} with Id {0}."
                                  , myCommand.IdGuid, myCommand.GetType());
                Console.WriteLine("==========================================================================");
            }
        }
 public void HandleCommands(int maxCount)
 {
     try {
         for (int i = 0; i < maxCount; ++i)
         {
             if (m_Commands.Count > 0)
             {
                 IMyCommand cmd = null;
                 if (m_Commands.TryPeek(out cmd))
                 {
                     if (null != cmd)
                     {
                         try {
                             if (!cmd.Execute())
                             {
                                 m_Commands.TryDequeue(out cmd);
                             }
                             else
                             {
                                 break;
                             }
                         } catch (Exception ex) {
                             m_Commands.TryDequeue(out cmd);
                             LogSystem.Error("ClientConcurrentCommandProcessor command() throw exception:{0}\n{1}", ex.Message, ex.StackTrace);
                         }
                     }
                     else
                     {
                         m_Commands.TryDequeue(out cmd);
                     }
                 }
             }
             else
             {
                 break;
             }
         }
     } catch (Exception ex) {
         LogSystem.Error("ClientConcurrentCommandProcessor.HandleCommands throw exception:{0}\n{1}", ex.Message, ex.StackTrace);
     }
 }
Beispiel #5
0
 public void SetCreateMode(IMyCommand command)
 {
     mode = command;
 }
 public void QueueCommand(IMyCommand cmd)
 {
     m_Commands.Enqueue(cmd);
 }
Beispiel #7
0
        public void Start()
        {
            Console.WriteLine("Press 's' to send lots of commands");
            Console.WriteLine("Press 'e' to send a command that will throw an exception.");

            string cmd;

            while ((cmd = Console.ReadKey().Key.ToString().ToLower()) != "q")
            {
                Console.WriteLine(Environment.NewLine);

                switch (cmd)
                {
                case "s":
                    for (int i = 0; i < 30; i++)
                    {
                        _myCommand = Bus.CreateInstance <IMyCommand>(m =>
                        {
                            m.IdGuid = Guid.NewGuid();
                            m.Name   = string.Format("My Name is MyCommand number {0}", i);
                        });

                        Bus.Send(_myCommand);

                        Console.WriteLine("Send a command message number {2} type: {1} with Id {0}."
                                          , _myCommand.IdGuid, _myCommand.GetType(), i);
                        Console.WriteLine("==========================================================================");

                        _myOtherCommand = Bus.CreateInstance <IMyOtherCommand>(m =>
                        {
                            m.IdGuid = Guid.NewGuid();
                            m.Name   = string.Format("My Name is MyOtherCommand number {0}", i);
                        });

                        Bus.Send(_myOtherCommand);

                        Console.WriteLine("Send a MyOtherCommand message number {2} type: {1} with Id {0}."
                                          , _myCommand.IdGuid, _myCommand.GetType(), i);
                        Console.WriteLine("==========================================================================");
                    }
                    break;

                case "e":
                    var exceptionCommand = Bus.CreateInstance <IMyCommand>(m =>
                    {
                        m.IdGuid = Guid.NewGuid();
                        m.Name   = "My Name is Demo!";
                        m.Throw  = true;
                    });

                    Bus.Send(exceptionCommand);

                    Console.WriteLine("Sending a exceptionCommand the will throw, message type: {1} with Id {0}."
                                      , exceptionCommand.IdGuid, exceptionCommand.GetType());
                    Console.WriteLine("==========================================================================");

                    var exceptionOtherCommand = Bus.CreateInstance <IMyOtherCommand>(m =>
                    {
                        m.IdGuid = Guid.NewGuid();
                        m.Name   = "My Name is exceptionOtherCommand!";
                        m.Throw  = true;
                    });

                    Bus.Send(exceptionOtherCommand);

                    Console.WriteLine("Sending a exceptionOtherCommand the will throw, message type: {1} with Id {0}."
                                      , exceptionCommand.IdGuid, exceptionCommand.GetType());
                    Console.WriteLine("==========================================================================");
                    break;
                }
            }
        }
Beispiel #8
0
 public void AddAndExecute(IMyCommand c, object o)
 {
     undoCommands.Add(c);
     undoObjects.Add(o);
 }