예제 #1
0
        static void MoveMessage(Message message, string destinationQueueName, bool leaveCopyInSourceQueue)
        {
            var sourceQueuePath      = message.QueuePath;
            var destinationQueuePath = MsmqUtil.GetFullPath(destinationQueueName);

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    var sourceQueue = new MessageQueue(sourceQueuePath)
                    {
                        MessageReadPropertyFilter = DefaultFilter()
                    };
                    var destinationQueue = new MessageQueue(destinationQueuePath);

                    var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
                    destinationQueue.Send(msmqMessage, transaction);

                    if (leaveCopyInSourceQueue)
                    {
                        sourceQueue.Send(msmqMessage, transaction);
                    }

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath, leaveCopyInSourceQueue));
        }
예제 #2
0
        static void MoveMessage(Message message, string destinationQueueName, bool leaveCopyInSourceQueue)
        {
            var sourceQueuePath = message.QueuePath;
            var destinationQueuePath = MsmqUtil.GetFullPath(destinationQueueName);

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    var sourceQueue = new MessageQueue(sourceQueuePath) { MessageReadPropertyFilter = DefaultFilter() };
                    var destinationQueue = new MessageQueue(destinationQueuePath);

                    var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
                    destinationQueue.Send(msmqMessage, transaction);

                    if (leaveCopyInSourceQueue)
                    {
                        sourceQueue.Send(msmqMessage, transaction);
                    }

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath, leaveCopyInSourceQueue));
        }
예제 #3
0
        void MoveMessage(Message message)
        {
            var sourceQueuePath      = message.QueuePath;
            var destinationQueuePath = MsmqUtil.GetFullPath(message.Headers[Headers.SourceQueue]);

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    var sourceQueue = new MessageQueue(sourceQueuePath)
                    {
                        MessageReadPropertyFilter = DefaultFilter()
                    };
                    var destinationQueue = new MessageQueue(destinationQueuePath);

                    var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
                    destinationQueue.Send(msmqMessage, transaction);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath));
        }
예제 #4
0
 public MessageMoved(Message messageThatWasMoved, string sourceQueuePath, string destinationQueuePath, bool copyWasLeftInSourceQueue)
 {
     this.messageThatWasMoved = messageThatWasMoved;
     this.sourceQueuePath = sourceQueuePath;
     this.destinationQueuePath = destinationQueuePath;
     this.copyWasLeftInSourceQueue = copyWasLeftInSourceQueue;
 }
예제 #5
0
        string FormatMessage(Message message)
        {
            return(string.Format(@"ID: {0}
Headers:
{1}

Body:
{2}", message.Id,
                                 string.Join(Environment.NewLine,
                                             message.Headers.Select(h => string.Format("    {0}: {1}", h.Key, h.Value))),
                                 message.Body));
        }
예제 #6
0
        void EncodeBody(System.Messaging.Message message, Message messageModel)
        {
            var headers = messageModel.Headers;
            var body    = messageModel.Body;

            if (headers.ContainsKey(Headers.ContentType))
            {
                var encoding = headers[Headers.ContentType];
                var encoder  = GetEncoding(encoding);

                message.BodyStream = new MemoryStream(encoder.GetBytes(body));
            }
        }
예제 #7
0
        void DeleteMessage(Message message)
        {
            using (var queue = new MessageQueue(message.QueuePath))
            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    queue.ReceiveById(message.Id, transaction);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageDeleted(message));
        }
예제 #8
0
        void DeleteMessage(Message message)
        {
            using (var queue = new MessageQueue(message.QueuePath))
                using (var transaction = new MessageQueueTransaction())
                {
                    transaction.Begin();
                    try
                    {
                        queue.ReceiveById(message.Id, transaction);

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Abort();
                        throw;
                    }
                }

            Messenger.Default.Send(new MessageDeleted(message));
        }
예제 #9
0
        string GenerateFileName(Message message)
        {
            var fileName = message.Id.Replace("\\", "---");

            return(string.Format("{0}.txt", fileName));
        }
예제 #10
0
        void UpdateMessage(Message message, Queue queueToReload)
        {
            Task.Factory
            .StartNew(() =>
            {
                if (!message.CouldDeserializeBody)
                {
                    throw new InvalidOperationException(
                        string.Format(
                            "Body of message with ID {0} was not properly deserialized, so it's not safe to try to update it...",
                            message.Id));
                }

                using (var queue = new MessageQueue(message.QueuePath))
                {
                    queue.MessageReadPropertyFilter = LosslessFilter();
                    using (var transaction = new MessageQueueTransaction())
                    {
                        transaction.Begin();
                        try
                        {
                            var msmqMessage = queue.ReceiveById(message.Id, transaction);

                            var newMsmqMessage =
                                new System.Messaging.Message
                            {
                                Label     = msmqMessage.Label,
                                Extension = msmqMessage.Extension,

                                TimeToBeReceived   = msmqMessage.TimeToBeReceived,
                                UseDeadLetterQueue = msmqMessage.UseDeadLetterQueue,
                                UseJournalQueue    = msmqMessage.UseJournalQueue,
                            };

                            EncodeBody(newMsmqMessage, message);

                            queue.Send(newMsmqMessage, transaction);

                            transaction.Commit();
                        }
                        catch
                        {
                            transaction.Abort();
                            throw;
                        }
                    }
                }

                return(new
                {
                    Message = message,
                    Queue = queueToReload,
                    Notification =
                        NotificationEvent.Success("Fetched message with ID {0} and put an updated version back in the queue", message.Id),
                });
            })
            .ContinueWith(a =>
            {
                if (a.Exception != null)
                {
                    Messenger.Default.Send(NotificationEvent.Fail(a.Exception.ToString(),
                                                                  "Something went wrong while attempting to update message with ID {0}",
                                                                  message.Id));

                    return;
                }

                var result = a.Result;
                Messenger.Default.Send(new ReloadMessagesRequested(result.Queue));
                Messenger.Default.Send(result.Notification);
            }, Context.UiThread);
        }
예제 #11
0
 public UpdateMessageRequested(Message message, Queue queue)
 {
     this.message = message;
     this.queue = queue;
 }
예제 #12
0
        void EncodeBody(System.Messaging.Message message, Message messageModel)
        {
            var headers = messageModel.Headers;
            var body = messageModel.Body;

            if (headers.ContainsKey(Headers.ContentType))
            {
                var encoding = headers[Headers.ContentType];
                var encoder = GetEncoding(encoding);

                message.BodyStream = new MemoryStream(encoder.GetBytes(body));
            }
        }
예제 #13
0
        string GenerateFileName(Message message)
        {
            var fileName = message.Id.Replace("\\", "---");

            return string.Format("{0}.txt", fileName);
        }
예제 #14
0
        void UpdateMessage(Message message, Queue queueToReload)
        {
            Task.Factory
                .StartNew(() =>
                    {
                        if (!message.CouldDeserializeBody)
                        {
                            throw new InvalidOperationException(
                                string.Format(
                                    "Body of message with ID {0} was not properly deserialized, so it's not safe to try to update it...",
                                    message.Id));
                        }

                        using (var queue = new MessageQueue(message.QueuePath))
                        {
                            queue.MessageReadPropertyFilter = LosslessFilter();
                            using (var transaction = new MessageQueueTransaction())
                            {
                                transaction.Begin();
                                try
                                {
                                    var msmqMessage = queue.ReceiveById(message.Id, transaction);

                                    var newMsmqMessage =
                                        new System.Messaging.Message
                                            {
                                                Label = msmqMessage.Label,
                                                Extension = msmqMessage.Extension,

                                                TimeToBeReceived = msmqMessage.TimeToBeReceived,
                                                UseDeadLetterQueue = msmqMessage.UseDeadLetterQueue,
                                                UseJournalQueue = msmqMessage.UseJournalQueue,
                                            };

                                    EncodeBody(newMsmqMessage, message);

                                    queue.Send(newMsmqMessage, transaction);

                                    transaction.Commit();
                                }
                                catch
                                {
                                    transaction.Abort();
                                    throw;
                                }
                            }
                        }

                        return new
                                   {
                                       Message = message,
                                       Queue = queueToReload,
                                       Notification =
                                           NotificationEvent.Success("Fetched message with ID {0} and put an updated version back in the queue", message.Id),
                                   };
                    })
                .ContinueWith(a =>
                    {
                        if (a.Exception != null)
                        {
                            Messenger.Default.Send(NotificationEvent.Fail(a.Exception.ToString(),
                                                                          "Something went wrong while attempting to update message with ID {0}",
                                                                          message.Id));

                            return;
                        }

                        var result = a.Result;
                        Messenger.Default.Send(new ReloadMessagesRequested(result.Queue));
                        Messenger.Default.Send(result.Notification);
                    }, Context.UiThread);
        }
예제 #15
0
        void MoveMessage(Message message)
        {
            var sourceQueuePath = message.QueuePath;
            var destinationQueuePath = MsmqUtil.GetFullPath(message.Headers[Headers.SourceQueue]);

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                try
                {
                    var sourceQueue = new MessageQueue(sourceQueuePath) { MessageReadPropertyFilter = DefaultFilter() };
                    var destinationQueue = new MessageQueue(destinationQueuePath);

                    var msmqMessage = sourceQueue.ReceiveById(message.Id, transaction);
                    destinationQueue.Send(msmqMessage, transaction);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Abort();
                    throw;
                }
            }

            Messenger.Default.Send(new MessageMoved(message, sourceQueuePath, destinationQueuePath));
        }
예제 #16
0
 public MessageDeleted(Message messageThatWasDeleted)
 {
     this.messageThatWasDeleted = messageThatWasDeleted;
 }
예제 #17
0
 void MoveMessageToSourceQueue(Message message)
 {
     MoveMessage(message, message.Headers[Headers.SourceQueue], false);
 }
예제 #18
0
        string FormatMessage(Message message)
        {
            return string.Format(@"ID: {0}
Headers:
{1}

Body:
{2}", message.Id,
                                 string.Join(Environment.NewLine,
                                             message.Headers.Select(h => string.Format("    {0}: {1}", h.Key, h.Value))),
                                 message.Body);
        }
예제 #19
0
 void MoveMessageToSourceQueue(Message message)
 {
     MoveMessage(message, message.Headers[Headers.SourceQueue], false);
 }
예제 #20
0
 public MessageMoved(Message messageThatWasMoved, string sourceQueuePath, string destinationQueuePath)
 {
     this.messageThatWasMoved = messageThatWasMoved;
     this.sourceQueuePath = sourceQueuePath;
     this.destinationQueuePath = destinationQueuePath;
 }