From 27ba8a6ae145d4889219b5a74691209ea2395a83 Mon Sep 17 00:00:00 2001 From: Erik Mogensen Date: Tue, 13 Feb 2024 08:09:50 +0100 Subject: [PATCH] Add selective delete to Transfer deadletter subqueues and fix the context menus for the Transfer Deadletter grid view (#768) * Added support for deleting transfer DLQ messages --- .../Helpers/DeadLetterMessageHandler.cs | 20 +- .../Controls/HandleQueueControl.Designer.cs | 248 +++--- .../Controls/HandleQueueControl.cs | 725 ++++++------------ .../Controls/HandleQueueControl.resx | 5 +- .../HandleSubscriptionControl.Designer.cs | 16 +- .../Controls/HandleSubscriptionControl.cs | 2 +- src/ServiceBusExplorer/Forms/MessageForm.cs | 25 +- .../UIHelpers/DataGridViewHelper.cs | 41 + 8 files changed, 428 insertions(+), 654 deletions(-) create mode 100644 src/ServiceBusExplorer/UIHelpers/DataGridViewHelper.cs diff --git a/src/Common/Helpers/DeadLetterMessageHandler.cs b/src/Common/Helpers/DeadLetterMessageHandler.cs index a86cfd5e..1330ad20 100644 --- a/src/Common/Helpers/DeadLetterMessageHandler.cs +++ b/src/Common/Helpers/DeadLetterMessageHandler.cs @@ -87,7 +87,8 @@ public DeadLetterMessageHandler(WriteToLogDelegate writeToLog, ServiceBusHelper #endregion #region Public methods - public async Task DeleteMessages(List sequenceNumbers) + public async Task DeleteMessages(List sequenceNumbers, + bool TransferDLQ) { var sequenceNumbersToDeleteList = new List(); foreach (var number in sequenceNumbers) @@ -96,7 +97,7 @@ public async Task DeleteMessages(List sequenceN } var timedOut = false; - var dlqEntityPath = GetDlqEntityPath(); + var dlqEntityPath = TransferDLQ ? GetTransferDlqEntityPath() : GetDlqEntityPath(); var messageReceiver = await serviceBusHelper.MessagingFactory.CreateMessageReceiverAsync( dlqEntityPath, @@ -185,7 +186,7 @@ public async Task DeleteMessages(List sequenceN public async Task MoveMessages(MessageSender messageSender, - List sequenceNumbers, List messagesToSend = null) + List sequenceNumbers, bool transferDLQ, List messagesToSend = null) { if (messagesToSend != null) { @@ -196,7 +197,7 @@ public async Task MoveMessages(MessageSender messageSe } } - var dlqEntityPath = GetDlqEntityPath(); + var dlqEntityPath = transferDLQ ? GetTransferDlqEntityPath() : GetDlqEntityPath(); var messageReceiver = serviceBusHelper.MessagingFactory.CreateMessageReceiver( dlqEntityPath, @@ -368,6 +369,17 @@ string GetDlqEntityPath() sourceSubscriptionWrapper.SubscriptionDescription.TopicPath, sourceSubscriptionWrapper.SubscriptionDescription.Name); } + + string GetTransferDlqEntityPath() + { + if (sourceQueueDescription != null) + { + return QueueClient.FormatTransferDeadLetterPath(sourceQueueDescription.Path); + } + + throw new Exception("It is currently not supported getting a Transfer Dead-letter queue for a subscription."); + } + void WriteToLog(string message) { if (writeToLog != null && !string.IsNullOrWhiteSpace(message)) diff --git a/src/ServiceBusExplorer/Controls/HandleQueueControl.Designer.cs b/src/ServiceBusExplorer/Controls/HandleQueueControl.Designer.cs index 0d950d7e..f486679c 100644 --- a/src/ServiceBusExplorer/Controls/HandleQueueControl.Designer.cs +++ b/src/ServiceBusExplorer/Controls/HandleQueueControl.Designer.cs @@ -123,17 +123,17 @@ private void InitializeComponent() this.saveSelectedMessageBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveSelectedMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveSelectedMessagesBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deadletterContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); - this.repairAndResubmitDeadletterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.resubmitDeadletterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.sharedDeadletterContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); + this.repairAndResubmitSharedDeadletterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.resubmitSharedDeadletterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); - this.saveSelectedDeadletteredMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedDeadletteredMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteSelectedMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.deleteSelectedMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.messagesBindingSource = new System.Windows.Forms.BindingSource(this.components); this.sessionsBindingSource = new System.Windows.Forms.BindingSource(this.components); this.deadletterBindingSource = new System.Windows.Forms.BindingSource(this.components); @@ -141,14 +141,6 @@ private void InitializeComponent() this.saveFileDialog = new System.Windows.Forms.SaveFileDialog(); this.btnPurgeMessages = new System.Windows.Forms.Button(); this.transferDeadletterBindingSource = new System.Windows.Forms.BindingSource(this.components); - this.transferDeadletterContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components); - this.repairAndResubmitTransferDeadletterToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator(); - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.mainTabControl.SuspendLayout(); this.tabPageDescription.SuspendLayout(); this.grouperAutoDeleteOnIdle.SuspendLayout(); @@ -238,13 +230,12 @@ private void InitializeComponent() this.grouperSessionState.SuspendLayout(); this.grouperSessionProperties.SuspendLayout(); this.messagesContextMenuStrip.SuspendLayout(); - this.deadletterContextMenuStrip.SuspendLayout(); + this.sharedDeadletterContextMenuStrip.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.messagesBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.sessionsBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.deadletterBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.authorizationRulesBindingSource)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.transferDeadletterBindingSource)).BeginInit(); - this.transferDeadletterContextMenuStrip.SuspendLayout(); this.SuspendLayout(); // // btnPurgeDeadletterQueueMessages @@ -1156,6 +1147,7 @@ private void InitializeComponent() this.txtMessageText.CharWidth = 8; this.txtMessageText.Cursor = System.Windows.Forms.Cursors.IBeam; this.txtMessageText.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); + this.txtMessageText.Font = new System.Drawing.Font("Courier New", 9.75F); this.txtMessageText.ForeColor = System.Drawing.SystemColors.ControlText; this.txtMessageText.IsReplaceMode = false; this.txtMessageText.Location = new System.Drawing.Point(16, 32); @@ -1454,6 +1446,7 @@ private void InitializeComponent() this.txtDeadletterText.CharWidth = 8; this.txtDeadletterText.Cursor = System.Windows.Forms.Cursors.IBeam; this.txtDeadletterText.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); + this.txtDeadletterText.Font = new System.Drawing.Font("Courier New", 9.75F); this.txtDeadletterText.ForeColor = System.Drawing.SystemColors.ControlText; this.txtDeadletterText.IsReplaceMode = false; this.txtDeadletterText.Location = new System.Drawing.Point(16, 32); @@ -1735,6 +1728,7 @@ private void InitializeComponent() this.txtTransferDeadletterText.CharWidth = 8; this.txtTransferDeadletterText.Cursor = System.Windows.Forms.Cursors.IBeam; this.txtTransferDeadletterText.DisabledColor = System.Drawing.Color.FromArgb(((int)(((byte)(100)))), ((int)(((byte)(180)))), ((int)(((byte)(180)))), ((int)(((byte)(180))))); + this.txtTransferDeadletterText.Font = new System.Drawing.Font("Courier New", 9.75F); this.txtTransferDeadletterText.ForeColor = System.Drawing.SystemColors.ControlText; this.txtTransferDeadletterText.IsReplaceMode = false; this.txtTransferDeadletterText.Location = new System.Drawing.Point(16, 32); @@ -2098,7 +2092,7 @@ private void InitializeComponent() this.saveSelectedMessagesToolStripMenuItem, this.saveSelectedMessagesBodyAsFileToolStripMenuItem}); this.messagesContextMenuStrip.Name = "registrationContextMenuStrip"; - this.messagesContextMenuStrip.Size = new System.Drawing.Size(306, 186); + this.messagesContextMenuStrip.Size = new System.Drawing.Size(306, 164); // // repairAndResubmitMessageToolStripMenuItem // @@ -2155,91 +2149,91 @@ private void InitializeComponent() this.saveSelectedMessagesBodyAsFileToolStripMenuItem.Text = "Save Selected Messages Text as File"; this.saveSelectedMessagesBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedMessagesBodyAsFileToolStripMenuItem_Click); // - // deadletterContextMenuStrip + // sharedDeadletterContextMenuStrip // - this.deadletterContextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.deadletterContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.repairAndResubmitDeadletterToolStripMenuItem, - this.resubmitDeadletterToolStripMenuItem, - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem, + this.sharedDeadletterContextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); + this.sharedDeadletterContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.repairAndResubmitSharedDeadletterToolStripMenuItem, + this.resubmitSharedDeadletterToolStripMenuItem, + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem, this.toolStripSeparator2, - this.saveSelectedDeadletteredMessageToolStripMenuItem, - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem, - this.saveSelectedDeadletteredMessagesToolStripMenuItem, - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem, - this.deleteSelectedMessageToolStripMenuItem, - this.deleteSelectedMessagesToolStripMenuItem}); - this.deadletterContextMenuStrip.Name = "registrationContextMenuStrip"; - this.deadletterContextMenuStrip.Size = new System.Drawing.Size(306, 208); + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem, + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem, + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem, + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem, + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem, + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem}); + this.sharedDeadletterContextMenuStrip.Name = "registrationContextMenuStrip"; + this.sharedDeadletterContextMenuStrip.Size = new System.Drawing.Size(306, 230); // - // repairAndResubmitDeadletterToolStripMenuItem + // repairAndResubmitSharedDeadletterToolStripMenuItem // - this.repairAndResubmitDeadletterToolStripMenuItem.Name = "repairAndResubmitDeadletterToolStripMenuItem"; - this.repairAndResubmitDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.repairAndResubmitDeadletterToolStripMenuItem.Text = "Repair And Resubmit Selected Message"; - this.repairAndResubmitDeadletterToolStripMenuItem.Click += new System.EventHandler(this.repairAndResubmitDeadletterMessageToolStripMenuItem_Click); + this.repairAndResubmitSharedDeadletterToolStripMenuItem.Name = "repairAndResubmitSharedDeadletterToolStripMenuItem"; + this.repairAndResubmitSharedDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.repairAndResubmitSharedDeadletterToolStripMenuItem.Text = "Repair And Resubmit Selected Message"; + this.repairAndResubmitSharedDeadletterToolStripMenuItem.Click += new System.EventHandler(this.repairAndResubmitSharedDeadletterMessageToolStripMenuItem_Click); // - // resubmitDeadletterToolStripMenuItem + // resubmitSharedDeadletterToolStripMenuItem // - this.resubmitDeadletterToolStripMenuItem.Name = "resubmitDeadletterToolStripMenuItem"; - this.resubmitDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.resubmitDeadletterToolStripMenuItem.Text = "Resubmit Selected Message"; - this.resubmitDeadletterToolStripMenuItem.ToolTipText = "Resubmits the deadletter message with unchanged body."; - this.resubmitDeadletterToolStripMenuItem.Click += new System.EventHandler(this.resubmitDeadletterMessageToolStripMenuItem_Click); + this.resubmitSharedDeadletterToolStripMenuItem.Name = "resubmitSharedDeadletterToolStripMenuItem"; + this.resubmitSharedDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.resubmitSharedDeadletterToolStripMenuItem.Text = "Resubmit Selected Message"; + this.resubmitSharedDeadletterToolStripMenuItem.ToolTipText = "Resubmits the deadletter message with unchanged body."; + this.resubmitSharedDeadletterToolStripMenuItem.Click += new System.EventHandler(this.resubmitSharedDeadletterMessageToolStripMenuItem_Click); // - // resubmitSelectedDeadletterInBatchModeToolStripMenuItem + // resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem // - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Name = "resubmitSelectedDeadletterInBatchModeToolStripMenuItem"; - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Text = "Resubmit Selected Messages In Batch Mode"; - this.resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Click += new System.EventHandler(this.resubmitSelectedDeadletterMessagesInBatchModeToolStripMenuItem_Click); + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem.Name = "resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem"; + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem.Text = "Resubmit Selected Messages In Batch Mode"; + this.resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem.Click += new System.EventHandler(this.resubmitSelectedSharedDeadletterMessagesInBatchModeToolStripMenuItem_Click); // // toolStripSeparator2 // this.toolStripSeparator2.Name = "toolStripSeparator2"; this.toolStripSeparator2.Size = new System.Drawing.Size(302, 6); // - // saveSelectedDeadletteredMessageToolStripMenuItem + // saveSelectedSharedDeadletteredMessageToolStripMenuItem // - this.saveSelectedDeadletteredMessageToolStripMenuItem.Name = "saveSelectedDeadletteredMessageToolStripMenuItem"; - this.saveSelectedDeadletteredMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedDeadletteredMessageToolStripMenuItem.Text = "Save Selected Message"; - this.saveSelectedDeadletteredMessageToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedDeadletteredMessageToolStripMenuItem_Click); + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem.Name = "saveSelectedSharedDeadletteredMessageToolStripMenuItem"; + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem.Text = "Save Selected Message"; + this.saveSelectedSharedDeadletteredMessageToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedSharedDeadletteredMessageToolStripMenuItem_Click); // - // saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem + // saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem // - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Name = "saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem"; - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Text = "Save Selected Message Text as File"; - this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem_Click); + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem.Name = "saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem"; + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem.Text = "Save Selected Message Text as File"; + this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem_Click); // - // saveSelectedDeadletteredMessagesToolStripMenuItem + // saveSelectedSharedDeadletteredMessagesToolStripMenuItem // - this.saveSelectedDeadletteredMessagesToolStripMenuItem.Name = "saveSelectedDeadletteredMessagesToolStripMenuItem"; - this.saveSelectedDeadletteredMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedDeadletteredMessagesToolStripMenuItem.Text = "Save Selected Messages"; - this.saveSelectedDeadletteredMessagesToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedDeadletteredMessagesToolStripMenuItem_Click); + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem.Name = "saveSelectedSharedDeadletteredMessagesToolStripMenuItem"; + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem.Text = "Save Selected Messages"; + this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedSharedDeadletteredMessagesToolStripMenuItem_Click); // - // saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem + // saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem // - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Name = "saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem"; - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Text = "Save Selected Messages Text as File"; - this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem_Click); + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem.Name = "saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem"; + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem.Text = "Save Selected Messages Text as File"; + this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem_Click); // - // deleteSelectedMessageToolStripMenuItem + // deleteSelectedSharedDeadletterMessageToolStripMenuItem // - this.deleteSelectedMessageToolStripMenuItem.Name = "deleteSelectedMessageToolStripMenuItem"; - this.deleteSelectedMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.deleteSelectedMessageToolStripMenuItem.Text = "Delete Selected Message"; - this.deleteSelectedMessageToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedMessageToolStripMenuItem_Click); + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem.Name = "deleteSelectedSharedDeadletterMessageToolStripMenuItem"; + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem.Text = "Delete Selected Message"; + this.deleteSelectedSharedDeadletterMessageToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedSharedDeadLetterMessageToolStripMenuItem_Click); // - // deleteSelectedMessagesToolStripMenuItem + // deleteSelectedSharedDeadletterMessagesToolStripMenuItem // - this.deleteSelectedMessagesToolStripMenuItem.Name = "deleteSelectedMessagesToolStripMenuItem"; - this.deleteSelectedMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.deleteSelectedMessagesToolStripMenuItem.Text = "Delete Selected Messages"; - this.deleteSelectedMessagesToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedMessagesToolStripMenuItem_Click); + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem.Name = "deleteSelectedSharedDeadletterMessagesToolStripMenuItem"; + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem.Text = "Delete Selected Messages"; + this.deleteSelectedSharedDeadletterMessagesToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedSharedDeadLetterMessagesToolStripMenuItem_Click); // // btnPurgeMessages // @@ -2260,67 +2254,6 @@ private void InitializeComponent() this.btnPurgeMessages.MouseEnter += new System.EventHandler(this.button_MouseEnter); this.btnPurgeMessages.MouseLeave += new System.EventHandler(this.button_MouseLeave); // - // transferDeadletterContextMenuStrip - // - this.transferDeadletterContextMenuStrip.ImageScalingSize = new System.Drawing.Size(20, 20); - this.transferDeadletterContextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.repairAndResubmitTransferDeadletterToolStripMenuItem, - this.resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem, - this.toolStripSeparator3, - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem, - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem, - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem, - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem}); - this.transferDeadletterContextMenuStrip.Name = "registrationContextMenuStrip"; - this.transferDeadletterContextMenuStrip.Size = new System.Drawing.Size(306, 142); - this.transferDeadletterContextMenuStrip.Click += new System.EventHandler(this.resubmitSelectedTransferDeadletterMessagesInBatchModeToolStripMenuItem_Click); - // - // repairAndResubmitTransferDeadletterToolStripMenuItem - // - this.repairAndResubmitTransferDeadletterToolStripMenuItem.Name = "repairAndResubmitTransferDeadletterToolStripMenuItem"; - this.repairAndResubmitTransferDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.repairAndResubmitTransferDeadletterToolStripMenuItem.Text = "Repair and Resubmit Selected Message"; - this.repairAndResubmitTransferDeadletterToolStripMenuItem.Click += new System.EventHandler(this.repairAndResubmitTransferDeadletterMessageToolStripMenuItem_Click); - // - // resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem - // - this.resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem.Name = "resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem"; - this.resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem.Text = "Resubmit Selected Messages In Batch Mode"; - // - // toolStripSeparator3 - // - this.toolStripSeparator3.Name = "toolStripSeparator3"; - this.toolStripSeparator3.Size = new System.Drawing.Size(302, 6); - // - // saveSelectedTransferDeadletteredMessageToolStripMenuItem - // - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem.Name = "saveSelectedTransferDeadletteredMessageToolStripMenuItem"; - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem.Text = "Save Selected Message"; - this.saveSelectedTransferDeadletteredMessageToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedTransferDeadletteredMessageToolStripMenuItem_Click); - // - // saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem - // - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem.Name = "saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem"; - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem.Text = "Save Selected Message Text as File"; - this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem_Click); - // - // saveSelectedTransferDeadletteredMessagesToolStripMenuItem - // - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem.Name = "saveSelectedTransferDeadletteredMessagesToolStripMenuItem"; - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem.Text = "Save Selected Messages"; - this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedTransferDeadletteredMessagesToolStripMenuItem_Click); - // - // saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem - // - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem.Name = "saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem"; - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem.Size = new System.Drawing.Size(305, 22); - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem.Text = "Save Selected Messages Text as File"; - this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem_Click); - // // HandleQueueControl // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -2431,13 +2364,12 @@ private void InitializeComponent() this.grouperSessionState.PerformLayout(); this.grouperSessionProperties.ResumeLayout(false); this.messagesContextMenuStrip.ResumeLayout(false); - this.deadletterContextMenuStrip.ResumeLayout(false); + this.sharedDeadletterContextMenuStrip.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.messagesBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.sessionsBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.deadletterBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.authorizationRulesBindingSource)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.transferDeadletterBindingSource)).EndInit(); - this.transferDeadletterContextMenuStrip.ResumeLayout(false); this.ResumeLayout(false); } @@ -2508,9 +2440,9 @@ private void InitializeComponent() private System.Windows.Forms.ContextMenuStrip messagesContextMenuStrip; private System.Windows.Forms.ToolStripMenuItem repairAndResubmitMessageToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem resubmitSelectedMessagesInBatchModeToolStripMenuItem; - private System.Windows.Forms.ContextMenuStrip deadletterContextMenuStrip; - private System.Windows.Forms.ToolStripMenuItem repairAndResubmitDeadletterToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem resubmitSelectedDeadletterInBatchModeToolStripMenuItem; + private System.Windows.Forms.ContextMenuStrip sharedDeadletterContextMenuStrip; + private System.Windows.Forms.ToolStripMenuItem repairAndResubmitSharedDeadletterToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem; private System.Windows.Forms.PictureBox pictFindMessages; private System.Windows.Forms.PictureBox pictFindDeadletter; private System.Windows.Forms.PictureBox pictFindMessagesByDate; @@ -2523,8 +2455,8 @@ private void InitializeComponent() private System.Windows.Forms.SaveFileDialog saveFileDialog; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; - private System.Windows.Forms.ToolStripMenuItem saveSelectedDeadletteredMessageToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedDeadletteredMessagesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveSelectedSharedDeadletteredMessageToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveSelectedSharedDeadletteredMessagesToolStripMenuItem; private System.Windows.Forms.Button btnPurgeDeadletterQueueMessages; private System.Windows.Forms.Button btnPurgeMessages; private System.Windows.Forms.TabPage tabPageTransferDeadletter; @@ -2535,14 +2467,8 @@ private void InitializeComponent() private System.Windows.Forms.PictureBox pictureBox1; private System.Windows.Forms.DataGridView transferDeadletterDataGridView; private System.Windows.Forms.BindingSource transferDeadletterBindingSource; - private System.Windows.Forms.ContextMenuStrip transferDeadletterContextMenuStrip; - private System.Windows.Forms.ToolStripMenuItem repairAndResubmitTransferDeadletterToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem resubmitSelectedTransferDeadletterInBatchModeToolStripMenuItem; - private System.Windows.Forms.ToolStripSeparator toolStripSeparator3; - private System.Windows.Forms.ToolStripMenuItem saveSelectedTransferDeadletteredMessageToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedTransferDeadletteredMessagesToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem deleteSelectedMessageToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem deleteSelectedMessagesToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteSelectedSharedDeadletterMessageToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem deleteSelectedSharedDeadletterMessagesToolStripMenuItem; private Grouper grouperMessageText; private FastColoredTextBoxNS.FastColoredTextBox txtMessageText; private System.Windows.Forms.SplitContainer messagePropertiesSplitContainer; @@ -2563,10 +2489,8 @@ private void InitializeComponent() private Grouper grouperTransferDeadletterCustomProperties; private System.Windows.Forms.ToolStripMenuItem saveSelectedMessageBodyAsFileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem saveSelectedMessagesBodyAsFileToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem; - private System.Windows.Forms.ToolStripMenuItem saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem; private TimeSpanControl tsAutoDeleteOnIdle; private TimeSpanControl tsDefaultMessageTimeToLive; private TimeSpanControl tsLockDuration; @@ -2574,7 +2498,7 @@ private void InitializeComponent() private System.Windows.Forms.PropertyGrid messageCustomPropertyGrid; private System.Windows.Forms.PropertyGrid deadletterCustomPropertyGrid; private System.Windows.Forms.PropertyGrid transferDeadletterCustomPropertyGrid; - private System.Windows.Forms.ToolStripMenuItem resubmitDeadletterToolStripMenuItem; + private System.Windows.Forms.ToolStripMenuItem resubmitSharedDeadletterToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem resubmitMessageToolStripMenuItem; } } diff --git a/src/ServiceBusExplorer/Controls/HandleQueueControl.cs b/src/ServiceBusExplorer/Controls/HandleQueueControl.cs index 48c644fe..216fa77e 100644 --- a/src/ServiceBusExplorer/Controls/HandleQueueControl.cs +++ b/src/ServiceBusExplorer/Controls/HandleQueueControl.cs @@ -24,18 +24,9 @@ #region Using Directives #nullable enable -using Microsoft.ServiceBus.Messaging; - -using ServiceBusExplorer.Forms; -using ServiceBusExplorer.Helpers; -using ServiceBusExplorer.ServiceBus.Helpers; -using ServiceBusExplorer.UIHelpers; -using ServiceBusExplorer.Utilities.Helpers; - using System; using System.Collections.Generic; using System.ComponentModel; -using System.Configuration; using System.Diagnostics; using System.Drawing; using System.Globalization; @@ -44,6 +35,14 @@ using System.Threading.Tasks; using System.Windows.Forms; +using Microsoft.ServiceBus.Messaging; + +using ServiceBusExplorer.Forms; +using ServiceBusExplorer.Helpers; +using ServiceBusExplorer.ServiceBus.Helpers; +using ServiceBusExplorer.UIHelpers; +using ServiceBusExplorer.Utilities.Helpers; + #endregion // ReSharper disable once CheckNamespace @@ -681,14 +680,14 @@ private void InitializeControls(bool initialCall) if (queueDescription != null) { - if (duplicateQueue) - { - ConfigureDuplicateUserInterface(); - } - else - { - ConfigureReadUserInterface(); - } + if (duplicateQueue) + { + ConfigureDuplicateUserInterface(); + } + else + { + ConfigureReadUserInterface(); + } } else { @@ -1049,7 +1048,7 @@ private void ConfigureDuplicateUserInterface() // special handling for max size if partitioning is enabled trackBarMaxQueueSize.Maximum = serviceBusHelper.IsCloudNamespace ? 5 : 11; - trackBarMaxQueueSize.Value = queueDescription.EnablePartitioning ? queueDescription.MaxSizeInGigabytes() / 16 + trackBarMaxQueueSize.Value = queueDescription.EnablePartitioning ? queueDescription.MaxSizeInGigabytes() / 16 : queueDescription.MaxSizeInGigabytes(); ConfigureCreateUserInterface(); @@ -1090,8 +1089,6 @@ private void ConfigureCreateUserInterface() txtPath.Focus(); } - - private void bindingList_ListChanged(object sender, ListChangedEventArgs e) { if (e.ListChangedType == ListChangedType.ItemDeleted) @@ -1467,7 +1464,7 @@ private void ReadMessagesOneAtTheTime(bool peek, bool all, int count, IBrokeredM else { var messageReceiver = BuildMessageReceiver(ReceiveMode.ReceiveAndDelete, fromSession); - + var totalRetrieved = 0; int retrieved; do @@ -1755,7 +1752,7 @@ private void GetTransferDeadletterMessages(bool peek, bool all, int count, IBrok { AllowEdit = false, AllowNew = false, - AllowRemove = false + AllowRemove = true }; transferDeadletterBindingSource.DataSource = transferDeadletterBindingList; @@ -3171,7 +3168,8 @@ private void messagesDataGridView_CellDoubleClick(object sender, DataGridViewCel { return; } - using (var messageForm = new MessageForm(queueDescription, bindingList[e.RowIndex], serviceBusHelper, writeToLog)) + using (var messageForm = new MessageForm(queueDescription, + MessageForm.QueueType.PrimaryQueue, bindingList[e.RowIndex], serviceBusHelper, writeToLog)) { messageForm.ShowDialog(); } @@ -3179,49 +3177,12 @@ private void messagesDataGridView_CellDoubleClick(object sender, DataGridViewCel private void deadletterDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex < 0) - { - return; - } - var bindingList = deadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } - using (var messageForm = new MessageForm(queueDescription, bindingList[e.RowIndex], serviceBusHelper, writeToLog)) - { - messageForm.ShowDialog(); - - Application.UseWaitCursor = true; - try - { - if (messageForm.RemovedSequenceNumbers != null && messageForm.RemovedSequenceNumbers.Any()) - { - RemoveDeadletterDataGridRows(messageForm.RemovedSequenceNumbers); - } - } - finally - { - Application.UseWaitCursor = false; - } - } + RepairAndResubmitSharedDeadletterMessage(e); } private void transferDeadletterDataGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { - if (e.RowIndex < 0) - { - return; - } - var bindingList = transferDeadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } - using (var messageForm = new MessageForm(queueDescription, bindingList[e.RowIndex], serviceBusHelper, writeToLog)) - { - messageForm.ShowDialog(); - } + RepairAndResubmitSharedDeadletterMessage(e); } private void messagesDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e) @@ -3355,51 +3316,51 @@ private void resubmitSelectedMessagesInBatchModeToolStripMenuItem_Click(object s private void ResubmitSelectedMessages() { - try + if (messagesDataGridView.SelectedRows.Count <= 0) { - if (messagesDataGridView.SelectedRows.Count <= 0) - { - return; - } - - using (var form = new MessageForm(queueDescription, messagesDataGridView.SelectedRows.Cast() - .Select(r => (BrokeredMessage)r.DataBoundItem), serviceBusHelper, writeToLog)) - { - form.ShowDialog(); - } + return; } - catch (Exception ex) + + using (var form = new MessageForm( + queueDescription, + MessageForm.QueueType.PrimaryQueue, + messagesDataGridView.SelectedRows.Cast() + .Select(r => (BrokeredMessage)r.DataBoundItem), + serviceBusHelper, writeToLog)) { - HandleException(ex); + form.ShowDialog(); } } - void deleteSelectedMessageToolStripMenuItem_Click(object sender, EventArgs e) + void deleteSelectedSharedDeadLetterMessageToolStripMenuItem_Click(object sender, EventArgs e) { - deleteSelectedMessagesToolStripMenuItem_Click(sender, e); + deleteSelectedSharedDeadLetterMessagesToolStripMenuItem_Click(sender, e); } - async void deleteSelectedMessagesToolStripMenuItem_Click(object sender, EventArgs e) + async void deleteSelectedSharedDeadLetterMessagesToolStripMenuItem_Click(object sender, EventArgs e) { - if (deadletterDataGridView.SelectedRows.Count <= 0) + var dataGridView = GetActiveDeadletterGridView(); + + if (dataGridView.SelectedRows.Count <= 0) { return; } - var messages = deadletterDataGridView.SelectedRows.Cast() + var messages = dataGridView.SelectedRows.Cast() .Select(r => r.DataBoundItem as BrokeredMessage); string confirmationText; + var transferText = dataGridView == transferDeadletterDataGridView ? "transfer " : string.Empty; if (messages.Count() == 1) { confirmationText = "Are you sure you want to delete the selected message from the " + - $"dead-letter subqueue for the {queueDescription.Path} queue?"; + $"{transferText}dead-letter subqueue for the {queueDescription.Path} queue?"; } else { confirmationText = $"Are you sure you want to delete {messages.Count()} messages from the " + - $"dead-letter subqueue for {queueDescription.Path} queue?"; + $"{transferText}dead-letter subqueue for {queueDescription.Path} queue?"; } using (var deleteForm = new DeleteForm(confirmationText)) @@ -3421,8 +3382,10 @@ async void deleteSelectedMessagesToolStripMenuItem_Click(object sender, EventArg stopwatch.Start(); var messagesDeleteCount = sequenceNumbersToDelete.Count; - var result = await deadLetterMessageHandler.DeleteMessages(sequenceNumbersToDelete); - RemoveDeadletterDataGridRows(result.DeletedSequenceNumbers); + var result = await deadLetterMessageHandler.DeleteMessages(sequenceNumbersToDelete, + TransferDLQ : dataGridView == transferDeadletterDataGridView ? true : false); + + DataGridViewHelper.RemoveDataGridRowsUsingSequenceNumbers(dataGridView, result.DeletedSequenceNumbers); if (messagesDeleteCount > result.DeletedSequenceNumbers.Count) { @@ -3447,78 +3410,59 @@ async void deleteSelectedMessagesToolStripMenuItem_Click(object sender, EventArg } private void deadletterDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) - { - if (e.Button != MouseButtons.Right || e.RowIndex == -1) - { - return; - } - deadletterDataGridView.Rows[e.RowIndex].Selected = true; - var multipleSelectedRows = deadletterDataGridView.SelectedRows.Count > 1; - - repairAndResubmitDeadletterToolStripMenuItem.Visible = !multipleSelectedRows; - resubmitDeadletterToolStripMenuItem.Visible = !multipleSelectedRows; - saveSelectedDeadletteredMessageToolStripMenuItem.Visible = !multipleSelectedRows; - saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Visible = !multipleSelectedRows; - deleteSelectedMessageToolStripMenuItem.Visible = !multipleSelectedRows; - - resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Visible = multipleSelectedRows; - saveSelectedDeadletteredMessagesToolStripMenuItem.Visible = multipleSelectedRows; - saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Visible = multipleSelectedRows; - deleteSelectedMessagesToolStripMenuItem.Visible = multipleSelectedRows; - - deadletterContextMenuStrip.Show(Cursor.Position); + { + ShowAppropriateSharedDeadletterMenuItems(e); } private void transferDeadletterDataGridView_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) { - if (e.Button != MouseButtons.Right || e.RowIndex == -1) - { - return; - } - transferDeadletterDataGridView.Rows[e.RowIndex].Selected = true; - var multipleSelectedRows = transferDeadletterDataGridView.SelectedRows.Count > 1; - repairAndResubmitDeadletterToolStripMenuItem.Visible = !multipleSelectedRows; - saveSelectedDeadletteredMessageToolStripMenuItem.Visible = !multipleSelectedRows; - saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem.Visible = !multipleSelectedRows; - resubmitSelectedDeadletterInBatchModeToolStripMenuItem.Visible = multipleSelectedRows; - saveSelectedDeadletteredMessagesToolStripMenuItem.Visible = multipleSelectedRows; - saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem.Visible = multipleSelectedRows; - transferDeadletterContextMenuStrip.Show(Cursor.Position); + ShowAppropriateSharedDeadletterMenuItems(e); } - private void repairAndResubmitDeadletterMessageToolStripMenuItem_Click(object sender, EventArgs e) + private void repairAndResubmitSharedDeadletterMessageToolStripMenuItem_Click(object sender, EventArgs e) { - deadletterDataGridView_CellDoubleClick(deadletterDataGridView, - new DataGridViewCellEventArgs(0, currentDeadletterMessageRowIndex)); + var dataGridView = GetActiveDeadletterGridView(); + + var currentRowIndex = dataGridView == deadletterDataGridView + ? currentDeadletterMessageRowIndex + : currentTransferDeadletterMessageRowIndex; + + RepairAndResubmitSharedDeadletterMessage(new DataGridViewCellEventArgs(0, currentRowIndex)); } - private async void resubmitDeadletterMessageToolStripMenuItem_Click(object sender, EventArgs e) + private async void resubmitSharedDeadletterMessageToolStripMenuItem_Click(object sender, EventArgs e) { - await ResubmitSelectedDeadletterMessages(); + await ResubmitSelectedDeadletterMessages(GetActiveDeadletterGridView()); } - private async void resubmitSelectedDeadletterMessagesInBatchModeToolStripMenuItem_Click(object sender, + private async void resubmitSelectedSharedDeadletterMessagesInBatchModeToolStripMenuItem_Click(object sender, EventArgs e) { - await ResubmitSelectedDeadletterMessages(); + await ResubmitSelectedDeadletterMessages(GetActiveDeadletterGridView()); } - async Task ResubmitSelectedDeadletterMessages() + async Task ResubmitSelectedDeadletterMessages(DataGridView dataGridView) { try { - if (deadletterDataGridView.SelectedRows.Count <= 0) + if (dataGridView.SelectedRows.Count <= 0) { return; } - using (var form = new MessageForm(queueDescription, deadletterDataGridView.SelectedRows.Cast() - .Select(r => (BrokeredMessage)r.DataBoundItem), serviceBusHelper, writeToLog)) + using (var form = new MessageForm( + queueDescription, + dataGridView == deadletterDataGridView + ? MessageForm.QueueType.Deadletter + : MessageForm.QueueType.TransferDeadletter, + dataGridView.SelectedRows.Cast() + .Select(r => (BrokeredMessage)r.DataBoundItem), + serviceBusHelper, writeToLog)) { form.ShowDialog(); if (form.RemovedSequenceNumbers != null && form.RemovedSequenceNumbers.Any()) { - RemoveDeadletterDataGridRows(form.RemovedSequenceNumbers); + DataGridViewHelper.RemoveDataGridRowsUsingSequenceNumbers(dataGridView, form.RemovedSequenceNumbers); } } } @@ -3533,33 +3477,6 @@ async Task ResubmitSelectedDeadletterMessages() await MainForm.SingletonMainForm.RefreshTopics(); } - private void repairAndResubmitTransferDeadletterMessageToolStripMenuItem_Click(object sender, EventArgs e) - { - transferDeadletterDataGridView_CellDoubleClick(transferDeadletterDataGridView, - new DataGridViewCellEventArgs(0, currentTransferDeadletterMessageRowIndex)); - } - - private void resubmitSelectedTransferDeadletterMessagesInBatchModeToolStripMenuItem_Click(object sender, - EventArgs e) - { - try - { - if (transferDeadletterDataGridView.SelectedRows.Count <= 0) - { - return; - } - using (var form = new MessageForm(queueDescription, transferDeadletterDataGridView.SelectedRows.Cast() - .Select(r => (BrokeredMessage)r.DataBoundItem), serviceBusHelper, writeToLog)) - { - form.ShowDialog(); - } - } - catch (Exception ex) - { - HandleException(ex); - } - } - private void pictFindMessages_Click(object sender, EventArgs e) { try @@ -3942,7 +3859,7 @@ protected override void Dispose(bool disposing) #region Save Messages - private void saveSelectedMessageToolStripMenuItem_Click(object sender, EventArgs e) + void saveSelectedMessageToolStripMenuItem_Click(object sender, EventArgs e) { try { @@ -4031,8 +3948,7 @@ void saveSelectedMessageBodyAsFileToolStripMenuItem_Click(object sender, EventAr } } - - private void saveSelectedMessagesToolStripMenuItem_Click(object sender, EventArgs e) + void saveSelectedMessagesToolStripMenuItem_Click(object sender, EventArgs e) { try { @@ -4132,312 +4048,151 @@ void saveSelectedMessagesBodyAsFileToolStripMenuItem_Click(object sender, EventA } } - private void saveSelectedDeadletteredMessageToolStripMenuItem_Click(object sender, EventArgs e) + void saveSelectedSharedDeadletteredMessageToolStripMenuItem_Click(object sender, EventArgs e) { - try - { - if (currentDeadletterMessageRowIndex < 0) - { - return; - } - var bindingList = deadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } - if (string.IsNullOrWhiteSpace(txtDeadletterText.Text)) - { - return; - } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; - saveFileDialog.DefaultExt = JsonExtension; - saveFileDialog.Filter = JsonFilter; - saveFileDialog.FileName = CreateFileName(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } - using (var writer = new StreamWriter(saveFileDialog.FileName)) - { - writer.Write(MessageSerializationHelper.Serialize(bindingList[currentDeadletterMessageRowIndex], txtDeadletterText.Text)); - } - } - catch (Exception ex) - { - HandleException(ex); - } + SaveSelectedMessage(SaveInJsonFormat: true); } - void saveSelectedDeadletteredMessageBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) + void saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) { - try - { - if (currentDeadletterMessageRowIndex < 0) - { - return; - } + SaveSelectedMessage(SaveInJsonFormat: false); + } - var bindingList = deadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } + void saveSelectedSharedDeadletteredMessagesToolStripMenuItem_Click(object sender, EventArgs e) + { + SaveSelectedMessages(SaveInJsonFormat: true); + } - if (string.IsNullOrWhiteSpace(txtDeadletterText.Text)) - { - return; - } + void saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) + { + SaveSelectedMessages(SaveInJsonFormat: false); + } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; - saveFileDialog.DefaultExt = TxtExtension; - saveFileDialog.Filter = AllFilesFilter; - saveFileDialog.FileName = CreateFileNameAutoRecognize(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } + void SaveSelectedMessage(bool SaveInJsonFormat) + { + var activeGridView = GetActiveDeadletterGridView(); - using (var writer = new StreamWriter(saveFileDialog.FileName)) - { - writer.Write(txtDeadletterText.Text); - } + var currentRowIndex = activeGridView == deadletterDataGridView + ? currentDeadletterMessageRowIndex + : currentTransferDeadletterMessageRowIndex; + + if (currentRowIndex < 0) + { + return; } - catch (Exception ex) + + var bindingSource = activeGridView == deadletterDataGridView + ? deadletterBindingSource + : transferDeadletterBindingSource; + + var bindingList = bindingSource.DataSource as BindingList; + + if (bindingList == null) { - HandleException(ex); + return; } - } - private void saveSelectedDeadletteredMessagesToolStripMenuItem_Click(object sender, EventArgs e) - { - try + var text = activeGridView == deadletterDataGridView + ? txtDeadletterText.Text + : txtTransferDeadletterText.Text; + + if (string.IsNullOrWhiteSpace(text)) + { + return; + } + + saveFileDialog.RestoreDirectory = true; + saveFileDialog.Title = SaveAsTitle; + + if (SaveInJsonFormat) { - if (deadletterDataGridView.SelectedRows.Count <= 0) - { - return; - } - var messages = deadletterDataGridView.SelectedRows.Cast() - .Select(r => r.DataBoundItem as BrokeredMessage); - IEnumerable brokeredMessages = messages as BrokeredMessage[] ?? messages.ToArray(); - if (!brokeredMessages.Any()) - { - return; - } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; saveFileDialog.DefaultExt = JsonExtension; saveFileDialog.Filter = JsonFilter; saveFileDialog.FileName = CreateFileName(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } - using (var writer = new StreamWriter(saveFileDialog.FileName)) - { - var bodies = brokeredMessages.Select(bm => serviceBusHelper.GetMessageText(bm, - MainForm.SingletonMainForm.UseAscii, out _)); - writer.Write(MessageSerializationHelper.Serialize(brokeredMessages, bodies, doNotSerializeBody: true)); - } - } - catch (Exception ex) - { - HandleException(ex); } - } - - void saveSelectedDeadletteredMessagesBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) - { - try + else { - if (deadletterDataGridView.SelectedRows.Count <= 0) - { - return; - } - - var messages = deadletterDataGridView.SelectedRows.Cast() - .Select(r => r.DataBoundItem as BrokeredMessage); - IEnumerable brokeredMessages = messages as BrokeredMessage[] ?? messages.ToArray(); - if (!brokeredMessages.Any()) - { - return; - } - - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; saveFileDialog.DefaultExt = TxtExtension; saveFileDialog.Filter = AllFilesFilter; saveFileDialog.FileName = CreateFileNameAutoRecognize(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - - var bodies = brokeredMessages.Select(bm => serviceBusHelper.GetMessageText(bm, - MainForm.SingletonMainForm.UseAscii, out _)); - var count = 0; - foreach (var body in bodies) - { - count++; - var fileNameParts = saveFileDialog.FileName.Split('.').ToList(); - var fileExtension = fileNameParts.Last(); - fileNameParts.RemoveAt(fileNameParts.IndexOf(fileExtension)); - fileNameParts.Add($"({count}).{fileExtension}"); - var fileName = string.Join(".", fileNameParts); - if (File.Exists(fileName)) - { - File.Delete(fileName); - } + } - using (var writer = new StreamWriter(fileName)) - { - writer.Write(body); - } - } + if (saveFileDialog.ShowDialog() != DialogResult.OK || + string.IsNullOrWhiteSpace(saveFileDialog.FileName)) + { + return; } - catch (Exception ex) + + if (File.Exists(saveFileDialog.FileName)) { - HandleException(ex); + File.Delete(saveFileDialog.FileName); } - } - private void saveSelectedTransferDeadletteredMessageToolStripMenuItem_Click(object sender, EventArgs e) - { - try + using (var writer = new StreamWriter(saveFileDialog.FileName)) { - if (currentTransferDeadletterMessageRowIndex < 0) - { - return; - } - var bindingList = transferDeadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } - if (string.IsNullOrWhiteSpace(txtTransferDeadletterText.Text)) - { - return; - } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; - saveFileDialog.DefaultExt = JsonExtension; - saveFileDialog.Filter = JsonFilter; - saveFileDialog.FileName = CreateFileName(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) + if (SaveInJsonFormat) { - return; + writer.Write(MessageSerializationHelper.Serialize(bindingList[currentRowIndex], text)); } - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } - using (var writer = new StreamWriter(saveFileDialog.FileName)) + else { - writer.Write(MessageSerializationHelper.Serialize(bindingList[currentTransferDeadletterMessageRowIndex], - txtTransferDeadletterText.Text)); + writer.Write(txtDeadletterText.Text); } } - catch (Exception ex) - { - HandleException(ex); - } } - void saveSelectedTransferDeadletteredMessageBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) + void SaveSelectedMessages(bool SaveInJsonFormat) { - try + var activeGridView = GetActiveDeadletterGridView(); + + var currentRowIndex = activeGridView == deadletterDataGridView + ? currentDeadletterMessageRowIndex + : currentTransferDeadletterMessageRowIndex; + + if (activeGridView.SelectedRows.Count <= 0) { - if (currentTransferDeadletterMessageRowIndex < 0) - { - return; - } + return; + } - var bindingList = transferDeadletterBindingSource.DataSource as BindingList; - if (bindingList == null) - { - return; - } + var messages = activeGridView.SelectedRows.Cast() + .Select(r => r.DataBoundItem as BrokeredMessage); + IEnumerable brokeredMessages = messages as BrokeredMessage[] ?? messages.ToArray(); - if (string.IsNullOrWhiteSpace(txtTransferDeadletterText.Text)) - { - return; - } + if (!brokeredMessages.Any()) + { + return; + } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; + saveFileDialog.RestoreDirectory = true; + saveFileDialog.Title = SaveAsTitle; + + if (SaveInJsonFormat) + { + saveFileDialog.DefaultExt = JsonExtension; + saveFileDialog.Filter = JsonFilter; + saveFileDialog.FileName = CreateFileName(); + } + else + { saveFileDialog.DefaultExt = TxtExtension; saveFileDialog.Filter = AllFilesFilter; saveFileDialog.FileName = CreateFileNameAutoRecognize(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } + } - using (var writer = new StreamWriter(saveFileDialog.FileName)) - { - writer.Write(txtTransferDeadletterText.Text); - } + if (saveFileDialog.ShowDialog() != DialogResult.OK || + string.IsNullOrWhiteSpace(saveFileDialog.FileName)) + { + return; } - catch (Exception ex) + + if (File.Exists(saveFileDialog.FileName)) { - HandleException(ex); + File.Delete(saveFileDialog.FileName); } - } - private void saveSelectedTransferDeadletteredMessagesToolStripMenuItem_Click(object sender, EventArgs e) - { - try + if (SaveInJsonFormat) { - if (transferDeadletterDataGridView.SelectedRows.Count <= 0) - { - return; - } - var messages = transferDeadletterDataGridView.SelectedRows.Cast() - .Select(r => r.DataBoundItem as BrokeredMessage); - IEnumerable brokeredMessages = messages as BrokeredMessage[] ?? messages.ToArray(); - if (!brokeredMessages.Any()) - { - return; - } - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; - saveFileDialog.DefaultExt = JsonExtension; - saveFileDialog.Filter = JsonFilter; - saveFileDialog.FileName = CreateFileName(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - if (File.Exists(saveFileDialog.FileName)) - { - File.Delete(saveFileDialog.FileName); - } using (var writer = new StreamWriter(saveFileDialog.FileName)) { var bodies = brokeredMessages.Select(bm => serviceBusHelper.GetMessageText(bm, @@ -4445,43 +4200,12 @@ private void saveSelectedTransferDeadletteredMessagesToolStripMenuItem_Click(obj writer.Write(MessageSerializationHelper.Serialize(brokeredMessages, bodies, doNotSerializeBody: true)); } } - catch (Exception ex) - { - HandleException(ex); - } - } - - void saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem_Click(object sender, EventArgs e) - { - try + else { - if (transferDeadletterDataGridView.SelectedRows.Count <= 0) - { - return; - } - - var messages = transferDeadletterDataGridView.SelectedRows.Cast() - .Select(r => r.DataBoundItem as BrokeredMessage); - IEnumerable brokeredMessages = messages as BrokeredMessage[] ?? messages.ToArray(); - if (!brokeredMessages.Any()) - { - return; - } - - saveFileDialog.RestoreDirectory = true; - saveFileDialog.Title = SaveAsTitle; - saveFileDialog.DefaultExt = TxtExtension; - saveFileDialog.Filter = AllFilesFilter; - saveFileDialog.FileName = CreateFileNameAutoRecognize(); - if (saveFileDialog.ShowDialog() != DialogResult.OK || - string.IsNullOrWhiteSpace(saveFileDialog.FileName)) - { - return; - } - var bodies = brokeredMessages.Select(bm => serviceBusHelper.GetMessageText(bm, MainForm.SingletonMainForm.UseAscii, out _)); var count = 0; + foreach (var body in bodies) { count++; @@ -4501,14 +4225,8 @@ void saveSelectedTransferDeadletteredMessagesBodyAsFileToolStripMenuItem_Click(o } } } - catch (Exception ex) - { - HandleException(ex); - } } - #endregion Save Messages - private string CreateFileName() { return string.Format(MessageFileFormat, @@ -4522,6 +4240,7 @@ private string CreateFileNameAutoRecognize() CultureInfo.CurrentCulture.TextInfo.ToTitleCase(serviceBusHelper.Namespace), DateTime.Now.ToString(CultureInfo.InvariantCulture).Replace('/', '-').Replace(':', '-')); } + #endregion Save Messages private async void btnPurgeMessages_Click(object sender, EventArgs e) { @@ -4533,32 +4252,94 @@ private async void btnPurgeDeadletterQueueMessages_Click(object sender, EventArg await PurgeDeadletterQueueMessagesAsync(); } - void RemoveDeadletterDataGridRows(IEnumerable sequenceNumbersToRemove) + // Returns either the plain deadletter grid view or the transfer deadletter grid view, + // depending on which tab is selected. + DataGridView GetActiveDeadletterGridView() { - var rowsToRemove = new List(sequenceNumbersToRemove.Count()); + if (mainTabControl.SelectedTab == mainTabControl.TabPages[DeadletterTabPage]) + { + return deadletterDataGridView; + } + else if (mainTabControl.SelectedTab == mainTabControl.TabPages[TransferDeadletterTabPage]) + { + return transferDeadletterDataGridView; + } + else + { + throw new InvalidOperationException("Unexpected tab selected."); + } + } - foreach (DataGridViewRow row in deadletterDataGridView.Rows) + void ShowAppropriateSharedDeadletterMenuItems(DataGridViewCellMouseEventArgs e) + { + if (e.Button != MouseButtons.Right || e.RowIndex == -1) { - var message = (BrokeredMessage)row.DataBoundItem; + return; + } - if (sequenceNumbersToRemove.Contains(message.SequenceNumber)) - { - rowsToRemove.Add(row); - if (rowsToRemove.Count >= sequenceNumbersToRemove.Count()) - { - break; - } - } + var activeGridView = GetActiveDeadletterGridView(); + + activeGridView.Rows[e.RowIndex].Selected = true; + var multipleSelectedRows = activeGridView.SelectedRows.Count > 1; + + repairAndResubmitSharedDeadletterToolStripMenuItem.Visible = !multipleSelectedRows; + resubmitSharedDeadletterToolStripMenuItem.Visible = !multipleSelectedRows; + saveSelectedSharedDeadletteredMessageToolStripMenuItem.Visible = !multipleSelectedRows; + saveSelectedSharedDeadletteredMessageBodyAsFileToolStripMenuItem.Visible = !multipleSelectedRows; + deleteSelectedSharedDeadletterMessageToolStripMenuItem.Visible = !multipleSelectedRows; + + + resubmitSelectedSharedDeadletterInBatchModeToolStripMenuItem.Visible = multipleSelectedRows; + saveSelectedSharedDeadletteredMessagesToolStripMenuItem.Visible = multipleSelectedRows; + saveSelectedSharedDeadletteredMessagesBodyAsFileToolStripMenuItem.Visible = multipleSelectedRows; + deleteSelectedSharedDeadletterMessagesToolStripMenuItem.Visible = multipleSelectedRows; + + sharedDeadletterContextMenuStrip.Show(Cursor.Position); + } + + void RepairAndResubmitSharedDeadletterMessage(DataGridViewCellEventArgs e) + { + if (e.RowIndex < 0) + { + return; } - for (var rowIndex = rowsToRemove.Count - 1; rowIndex >= 0; --rowIndex) + var activeGridView = GetActiveDeadletterGridView(); + + var bindingList = activeGridView == deadletterDataGridView + ? deadletterBindingSource.DataSource as BindingList + : transferDeadletterBindingSource.DataSource as BindingList; + + if (bindingList == null) { - var row = rowsToRemove[rowIndex]; - deadletterDataGridView.Rows.Remove(row); + return; } - deadletterDataGridView.ClearSelection(); + using (var messageForm = new MessageForm(queueDescription, + activeGridView == deadletterDataGridView + ? MessageForm.QueueType.Deadletter + : MessageForm.QueueType.TransferDeadletter, + bindingList[e.RowIndex], + serviceBusHelper, + writeToLog)) + { + messageForm.ShowDialog(); + + Application.UseWaitCursor = true; + + try + { + if (messageForm.RemovedSequenceNumbers != null && messageForm.RemovedSequenceNumbers.Any()) + { + DataGridViewHelper.RemoveDataGridRowsUsingSequenceNumbers(activeGridView, messageForm.RemovedSequenceNumbers); + } + } + finally + { + Application.UseWaitCursor = false; + } + } } - #endregion } + #endregion } diff --git a/src/ServiceBusExplorer/Controls/HandleQueueControl.resx b/src/ServiceBusExplorer/Controls/HandleQueueControl.resx index 8f7aada8..3b5394d7 100644 --- a/src/ServiceBusExplorer/Controls/HandleQueueControl.resx +++ b/src/ServiceBusExplorer/Controls/HandleQueueControl.resx @@ -235,7 +235,7 @@ 975, 17 - + 646, 58 @@ -256,9 +256,6 @@ 146, 58 - - 390, 57 - 116 diff --git a/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.Designer.cs b/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.Designer.cs index db3918b1..2e2b04d2 100644 --- a/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.Designer.cs +++ b/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.Designer.cs @@ -1699,16 +1699,16 @@ private void InitializeComponent() this.deadletterContextMenuStrip.Name = "registrationContextMenuStrip"; this.deadletterContextMenuStrip.Size = new System.Drawing.Size(306, 186); // - // repairAndResubmitDeadletterToolStripMenuItem + // repairAndResubmitSharedDeadletterToolStripMenuItem // - this.repairAndResubmitDeadletterToolStripMenuItem.Name = "repairAndResubmitDeadletterToolStripMenuItem"; + this.repairAndResubmitDeadletterToolStripMenuItem.Name = "repairAndResubmitSharedDeadletterToolStripMenuItem"; this.repairAndResubmitDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); this.repairAndResubmitDeadletterToolStripMenuItem.Text = "Repair And Resubmit Selected Message"; this.repairAndResubmitDeadletterToolStripMenuItem.Click += new System.EventHandler(this.repairAndResubmitDeadletterMessageToolStripMenuItem_Click); // - // resubmitDeadletterToolStripMenuItem + // resubmitSharedDeadletterToolStripMenuItem // - this.resubmitDeadletterToolStripMenuItem.Name = "resubmitDeadletterToolStripMenuItem"; + this.resubmitDeadletterToolStripMenuItem.Name = "resubmitSharedDeadletterToolStripMenuItem"; this.resubmitDeadletterToolStripMenuItem.Size = new System.Drawing.Size(305, 22); this.resubmitDeadletterToolStripMenuItem.Text = "Resubmit Selected Message"; this.resubmitDeadletterToolStripMenuItem.ToolTipText = "Resubmits the deadletter message with unchanged body."; @@ -1740,16 +1740,16 @@ private void InitializeComponent() this.saveSelectedDeadletteredMessagesToolStripMenuItem.Text = "Save Selected Messages"; this.saveSelectedDeadletteredMessagesToolStripMenuItem.Click += new System.EventHandler(this.saveSelectedDeadletteredMessagesToolStripMenuItem_Click); // - // deleteSelectedMessageToolStripMenuItem + // deleteSelectedSharedDeadletterMessageToolStripMenuItem // - this.deleteSelectedMessageToolStripMenuItem.Name = "deleteSelectedMessageToolStripMenuItem"; + this.deleteSelectedMessageToolStripMenuItem.Name = "deleteSelectedSharedDeadletterMessageToolStripMenuItem"; this.deleteSelectedMessageToolStripMenuItem.Size = new System.Drawing.Size(305, 22); this.deleteSelectedMessageToolStripMenuItem.Text = "Delete Selected Message"; this.deleteSelectedMessageToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedMessageToolStripMenuItem_Click); // - // deleteSelectedMessagesToolStripMenuItem + // deleteSelectedSharedDeadletterMessagesToolStripMenuItem // - this.deleteSelectedMessagesToolStripMenuItem.Name = "deleteSelectedMessagesToolStripMenuItem"; + this.deleteSelectedMessagesToolStripMenuItem.Name = "deleteSelectedSharedDeadletterMessagesToolStripMenuItem"; this.deleteSelectedMessagesToolStripMenuItem.Size = new System.Drawing.Size(305, 22); this.deleteSelectedMessagesToolStripMenuItem.Text = "Delete Selected Messages"; this.deleteSelectedMessagesToolStripMenuItem.Click += new System.EventHandler(this.deleteSelectedMessagesToolStripMenuItem_Click); diff --git a/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.cs b/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.cs index c1c5c1fd..3c20a5a2 100644 --- a/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.cs +++ b/src/ServiceBusExplorer/Controls/HandleSubscriptionControl.cs @@ -2383,7 +2383,7 @@ async void deleteSelectedMessagesToolStripMenuItem_Click(object sender, EventArg stopwatch.Start(); var messagesDeleteCount = sequenceNumbersToDelete.Count; - var result = await deadLetterMessageHandler.DeleteMessages(sequenceNumbersToDelete); + var result = await deadLetterMessageHandler.DeleteMessages(sequenceNumbersToDelete, TransferDLQ: false); RemoveDeadletterDataGridRows(result.DeletedSequenceNumbers); if (messagesDeleteCount > result.DeletedSequenceNumbers.Count) diff --git a/src/ServiceBusExplorer/Forms/MessageForm.cs b/src/ServiceBusExplorer/Forms/MessageForm.cs index 0a7ff931..40a15d12 100644 --- a/src/ServiceBusExplorer/Forms/MessageForm.cs +++ b/src/ServiceBusExplorer/Forms/MessageForm.cs @@ -82,6 +82,8 @@ public partial class MessageForm : Form #endregion #region Private Instance Fields + QueueType queueType = QueueType.NotSet; + readonly IEnumerable brokeredMessages; readonly BrokeredMessage brokeredMessage; readonly ServiceBusHelper serviceBusHelper; @@ -115,6 +117,16 @@ public partial class MessageForm : Form }; #endregion + #region Public Enums + public enum QueueType + { + NotSet, + PrimaryQueue, + Deadletter, + TransferDeadletter + } + #endregion + #region Public Properties public List RemovedSequenceNumbers { @@ -209,11 +221,12 @@ public MessageForm(BrokeredMessage brokeredMessage, ServiceBusHelper serviceBusH } } - public MessageForm(QueueDescription queueDescription, BrokeredMessage brokeredMessage, + public MessageForm(QueueDescription queueDescription, QueueType queueType, BrokeredMessage brokeredMessage, ServiceBusHelper serviceBusHelper, WriteToLogDelegate writeToLog) : this(brokeredMessage, serviceBusHelper, writeToLog) { this.queueDescription = queueDescription; + this.queueType = queueType; } public MessageForm(SubscriptionWrapper subscriptionWrapper, BrokeredMessage brokeredMessage, @@ -260,11 +273,12 @@ public MessageForm(IEnumerable brokeredMessages, ServiceBusHelp } } - public MessageForm(QueueDescription queueDescription, IEnumerable brokeredMessages, + public MessageForm(QueueDescription queueDescription, QueueType queueType, IEnumerable brokeredMessages, ServiceBusHelper serviceBusHelper, WriteToLogDelegate writeToLog) : this(brokeredMessages, serviceBusHelper, writeToLog) { this.queueDescription = queueDescription; + this.queueType = queueType; } public MessageForm(SubscriptionWrapper subscriptionWrapper, IEnumerable brokeredMessages, @@ -482,6 +496,7 @@ private async void btnSubmit_Click(object sender, EventArgs e) var sent = outboundMessages.Count; var stopwatch = new Stopwatch(); + stopwatch.Start(); if (chkRemove.Checked) @@ -489,8 +504,12 @@ private async void btnSubmit_Click(object sender, EventArgs e) var messageHandler = CreateDeadLetterMessageHandler(); var result = await messageHandler.MoveMessages(messageSender, - sequenceNumbers, outboundMessages); + sequenceNumbers, + transferDLQ: queueType == QueueType.TransferDeadletter, + outboundMessages); + RemovedSequenceNumbers = result.DeletedSequenceNumbers; + stopwatch.Stop(); if (result.TimedOut) diff --git a/src/ServiceBusExplorer/UIHelpers/DataGridViewHelper.cs b/src/ServiceBusExplorer/UIHelpers/DataGridViewHelper.cs new file mode 100644 index 00000000..3c275a7d --- /dev/null +++ b/src/ServiceBusExplorer/UIHelpers/DataGridViewHelper.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Windows.Forms; + +using Microsoft.ServiceBus.Messaging; + +namespace ServiceBusExplorer.UIHelpers +{ + internal static class DataGridViewHelper + { + static public void RemoveDataGridRowsUsingSequenceNumbers(DataGridView dataGridView, + IEnumerable sequenceNumbersToRemove) + { + var rowsToRemove = new List(sequenceNumbersToRemove.Count()); + + foreach (DataGridViewRow row in dataGridView.Rows) + { + var message = (BrokeredMessage)row.DataBoundItem; + + if (sequenceNumbersToRemove.Contains(message.SequenceNumber)) + { + rowsToRemove.Add(row); + + if (rowsToRemove.Count >= sequenceNumbersToRemove.Count()) + { + break; + } + } + } + + for (var rowIndex = rowsToRemove.Count - 1; rowIndex >= 0; --rowIndex) + { + var row = rowsToRemove[rowIndex]; + dataGridView.Rows.Remove(row); + } + + dataGridView.ClearSelection(); + } + } +}