Skip to content

Commit

Permalink
Moved delete button to MessageDetail window (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
armannaj authored Sep 29, 2020
1 parent f397a0e commit 4ae6877
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 33 deletions.
26 changes: 0 additions & 26 deletions PurpleExplorer/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,32 +231,6 @@ public async void AddMessage()
}
}

public async void DeleteMessage()
{
LoggingService.Log("DANGER NOTE: Deleting requires receiving all the messages up to the selected message to perform this action and this increases the DeliveryCount of the messages");
var buttonResult = await MessageBoxHelper.ShowConfirmation(
$"Deleting message from {_currentTopic.Name}/{_currentSubscription.Name}",
$"DANGER!!! READ CAREFULLY \n" +
$"Deleting requires receiving all the messages up to the selected message to perform this action and this increases the DeliveryCount of the messages. \n" +
$"There can be consequences to other messages in this subscription, Are you sure? \n \n" +
$"Are you sure you would like to delete the message with ID: {_currentMessage.MessageId} AND increase the delivery count of ALL the messages before it?");

// Because buttonResult can be None or No
if (buttonResult != ButtonResult.Yes)
{
CurrentMessage = null;
return;
}

LoggingService.Log($"User accepted to receive messages in order to delete message {_currentMessage.MessageId}. This is going to increases the DeliveryCount of the messages before it.");
LoggingService.Log($"Deleting message {_currentMessage.MessageId}... (might take some seconds)");
var connectionString = CurrentTopic.ServiceBus.ConnectionString;
await _serviceBusHelper.DeleteMessage(connectionString, _currentTopic.Name, _currentSubscription.Name,
_currentMessage, _currentMessage.IsDlq);
LoggingService.Log($"Message deleted, MessageId: {_currentMessage.MessageId}");
CurrentMessage = null;
}

public async void PurgeMessages(string isDlqText)
{
var isDlq = Convert.ToBoolean(isDlqText);
Expand Down
27 changes: 27 additions & 0 deletions PurpleExplorer/ViewModels/MessageDetailsWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Threading.Tasks;
using Avalonia.Controls;
using MessageBox.Avalonia.Enums;
using Microsoft.Azure.Amqp.Framing;
using PurpleExplorer.Helpers;
using PurpleExplorer.Models;
using PurpleExplorer.Services;
Expand All @@ -23,6 +25,31 @@ public MessageDetailsWindowViewModel(IServiceBusHelper serviceBusHelper = null,
_serviceBusHelper = serviceBusHelper ?? Locator.Current.GetService<IServiceBusHelper>();
}

public async void DeleteMessage(Window window)
{
_loggingService.Log("DANGER NOTE: Deleting requires receiving all the messages up to the selected message to perform this action and this increases the DeliveryCount of the messages");
var buttonResult = await MessageBoxHelper.ShowConfirmation(
$"Deleting message from {Subscription.Topic.Name}/{Subscription.Name}",
$"DANGER!!! READ CAREFULLY \n" +
$"Deleting requires receiving all the messages up to the selected message to perform this action and this increases the DeliveryCount of the messages. \n" +
$"There can be consequences to other messages in this subscription, Are you sure? \n \n" +
$"Are you sure you would like to delete the message with ID: {Message.MessageId} AND increase the delivery count of ALL the messages before it?");

// Because buttonResult can be None or No
if (buttonResult != ButtonResult.Yes)
{
return;
}

_loggingService.Log($"User accepted to receive messages in order to delete message {Message.MessageId}. This is going to increases the DeliveryCount of the messages before it.");
_loggingService.Log($"Deleting message {Message.MessageId}... (might take some seconds)");
var connectionString = Subscription.Topic.ServiceBus.ConnectionString;
await _serviceBusHelper.DeleteMessage(connectionString, Subscription.Topic.Name, Subscription.Name,
Message, Message.IsDlq);
_loggingService.Log($"Message deleted, MessageId: {Message.MessageId}");
window.Close();
}

public async Task ResubmitMessage()
{
_loggingService.Log($"Resending DLQ message: {Message.MessageId}");
Expand Down
7 changes: 0 additions & 7 deletions PurpleExplorer/Views/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@
<TextBlock VerticalAlignment="Center">New message</TextBlock>
</StackPanel>
</Button>
<Button Name="MinusButton" Classes="topButton" IsEnabled="{Binding !!CurrentMessage}"
Command="{Binding DeleteMessage}">
<StackPanel Orientation="Horizontal">
<DrawingPresenter Drawing="{DynamicResource Material.Delete}" />
<TextBlock VerticalAlignment="Center">Delete message</TextBlock>
</StackPanel>
</Button>
<Button Name="btnPurgeActiveMessages" Classes="topButton" IsEnabled="{Binding !!CurrentSubscription}"
Command="{Binding PurgeMessages}" CommandParameter="false">
<StackPanel Orientation="Horizontal">
Expand Down
8 changes: 8 additions & 0 deletions PurpleExplorer/Views/MessageDetailsWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

<StackPanel Orientation="Vertical">
<DockPanel Background="#380f14" Height="30" LastChildFill="False">
<Button Name="MinusButton" Classes="topButton" IsEnabled="{Binding !!CurrentMessage}"
Command="{Binding DeleteMessage}"
CommandParameter="{Binding $parent[Window]}">
<StackPanel Orientation="Horizontal">
<DrawingPresenter Drawing="{DynamicResource Material.Delete}" />
<TextBlock VerticalAlignment="Center">Delete message</TextBlock>
</StackPanel>
</Button>
<Button Command="{Binding DeadletterMessage}"
IsVisible="{Binding !Message.IsDlq}"
Classes="topButton">
Expand Down

0 comments on commit 4ae6877

Please sign in to comment.