Ejemplo n.º 1
0
        private void InitMessages()
        {
            if (this.messages == null)
            {
                try
                {
                    using (var messageQueue = new MessageQueue(this.path))
                    {
                        messageQueue.MessageReadPropertyFilter.ClearAll();
                        messageQueue.MessageReadPropertyFilter.Id = true;
                        messageQueue.MessageReadPropertyFilter.Label = true;
                        messageQueue.MessageReadPropertyFilter.SentTime = true;
                        messageQueue.MessageReadPropertyFilter.ResponseQueue = true;
                        messageQueue.MessageReadPropertyFilter.CorrelationId = true;

                        this.messages = messageQueue
                            .Cast<Message>()
                            .Reverse()
                            .Select(m => new MessageModel(
                                this.path,
                                m.Id,
                                m.Label,
                                m.SentTime,
                                m.ResponseQueue != null ? GetFriendlyName(m.ResponseQueue) : string.Empty,
                                m.CorrelationId))
                            .ToList();
                    }
                }
                catch (Exception ex)
                {
                    this.messages = new List<MessageModel>();

                    MessageBox.Show(
                        "Error during reading messages. Try refreshing queues list.\n"
                        + "\n"
                        + "Details:\n"
                        + ex.ToString(),
                        "Error during reading messages",
                        MessageBoxButton.OK,
                        MessageBoxImage.Error);
                }
            }
        }