Exemple #1
0
        void LoadQueues(Machine machine)
        {
            Task.Factory
                .StartNew(() =>
                    {
                        var queues = MessageQueue
                            .GetPrivateQueuesByMachine(machine.MachineName)
                            .Concat(new[]
                                        {
                                            // don't add non-transactional dead letter queue - wouldn't be safe!
                                            //new MessageQueue(string.Format(@"FormatName:DIRECT=OS:{0}\SYSTEM$;DeadLetter", machine.MachineName)),

                                            new MessageQueue(string.Format(@"FormatName:DIRECT=OS:{0}\SYSTEM$;DeadXact", machine.MachineName)),
                                        })
                            .ToArray();

                        return queues;
                    })
                .ContinueWith(t =>
                                  {
                                      if (!t.IsFaulted)
                                      {
                                          try
                                          {
                                              var queues = t.Result
                                                            .Select(queue =>
                                                                {
                                                                    try
                                                                    {
                                                                        return new Queue(queue);
                                                                    }
                                                                    catch (Exception e)
                                                                    {
                                                                        throw new ApplicationException(string.Format("An error occurred while loading message queue {0}", queue.Path), e);
                                                                    }
                                                                });

                                              machine.SetQueues(queues);

                                              return NotificationEvent.Success("{0} queues loaded from {1}",
                                                                               t.Result.Length,
                                                                               machine.MachineName);
                                          }
                                          catch (Exception e)
                                          {
                                              return NotificationEvent.Fail(e.ToString(), "Could not load queues from {0}: {1}",
                                                                           machine.MachineName, e.Message);
                                          }
                                      }

                                      return NotificationEvent.Fail(t.Exception.ToString(), "Could not load queues from {0}: {1}",
                                                                   machine.MachineName, t.Exception.Message);
                                  }, Context.UiThread)
                .ContinueWith(t => Messenger.Default.Send(t.Result), Context.UiThread);
        }
Exemple #2
0
        void LoadQueues(Machine machine)
        {
            Task.Factory
                .StartNew(() =>
                              {
                                  var privateQueues = MessageQueue.GetPrivateQueuesByMachine(machine.MachineName);

                                  return privateQueues;
                              })
                .ContinueWith(t =>
                                  {
                                      if (!t.IsFaulted)
                                      {
                                          var queues = t.Result
                                              .Select(queue => new Queue(queue));

                                          machine.SetQueues(queues);

                                          return NotificationEvent.Success("{0} queues loaded from {1}",
                                                                       t.Result.Length,
                                                                       machine.MachineName);
                                      }

                                      var details = t.Exception.ToString();
                                      return NotificationEvent.Fail(details, "Could not load queues from {0}: {1}",
                                                                   machine.MachineName, t.Exception.Message);
                                  }, Context.UiThread)
                .ContinueWith(t => Messenger.Default.Send(t.Result), Context.UiThread);
        }