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)); }
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)); }
public MessageMoved(Message messageThatWasMoved, string sourceQueuePath, string destinationQueuePath, bool copyWasLeftInSourceQueue) { this.messageThatWasMoved = messageThatWasMoved; this.sourceQueuePath = sourceQueuePath; this.destinationQueuePath = destinationQueuePath; this.copyWasLeftInSourceQueue = copyWasLeftInSourceQueue; }
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)); }
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)); } }
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)); }
string GenerateFileName(Message message) { var fileName = message.Id.Replace("\\", "---"); return(string.Format("{0}.txt", fileName)); }
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); }
public UpdateMessageRequested(Message message, Queue queue) { this.message = message; this.queue = queue; }
string GenerateFileName(Message message) { var fileName = message.Id.Replace("\\", "---"); return string.Format("{0}.txt", fileName); }
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); }
public MessageDeleted(Message messageThatWasDeleted) { this.messageThatWasDeleted = messageThatWasDeleted; }
void MoveMessageToSourceQueue(Message message) { MoveMessage(message, message.Headers[Headers.SourceQueue], false); }
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); }
public MessageMoved(Message messageThatWasMoved, string sourceQueuePath, string destinationQueuePath) { this.messageThatWasMoved = messageThatWasMoved; this.sourceQueuePath = sourceQueuePath; this.destinationQueuePath = destinationQueuePath; }