Skip to content

Commit

Permalink
Added Extended Accidental Deletion Prevention
Browse files Browse the repository at this point in the history
  • Loading branch information
BruAlcarazUlg committed May 15, 2023
1 parent 747438b commit 33ac24e
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 41 deletions.
2 changes: 2 additions & 0 deletions src/Common/Helpers/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ static MainSettings GetMainSettingsUsingConfiguration(TwoFilesConfiguration conf

resultProperties.DisableAccidentalDeletionPrevention = configuration.GetBoolValue
(ConfigurationParameters.DisableAccidentalDeletionPrevention, currentSettings.DisableAccidentalDeletionPrevention, writeToLog);
resultProperties.DisableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue
(ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention, currentSettings.DisableExtendedAccidentalDeletionPrevention, writeToLog);

resultProperties.ProxyOverrideDefault = configuration.GetBoolValue(ConfigurationParameters.ProxyOverrideDefault, currentSettings.ProxyOverrideDefault, writeToLog);
resultProperties.ProxyUseDefaultCredentials = configuration.GetBoolValue(ConfigurationParameters.ProxyUseDefaultCredentials, currentSettings.ProxyUseDefaultCredentials, writeToLog);
Expand Down
1 change: 1 addition & 0 deletions src/Common/Helpers/ConfigurationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static class ConfigurationParameters
public const string SelectedMessageCountsParameter = "selectedMessageCounts";
public const string MicrosoftServiceBusConnectionString = "Microsoft.ServiceBus.ConnectionString";
public const string DisableAccidentalDeletionPrevention = "disableAccidentalDeletionPrevention";
public const string DisableExtendedAccidentalDeletionPrevention = "disableExtendedAccidentalDeletionPrevention";

public const string ProxyOverrideDefault = "Proxy.OverrideDefault";
public const string ProxyAddress = "Proxy.Address";
Expand Down
4 changes: 4 additions & 0 deletions src/Common/Helpers/MainSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public class MainSettings
public Enums.EncodingType EncodingType { get; set; }

public bool DisableAccidentalDeletionPrevention { get; set; }
public bool DisableExtendedAccidentalDeletionPrevention { get; set; }

public bool ProxyOverrideDefault { get; set; }
public string ProxyAddress { get; set; }
Expand Down Expand Up @@ -290,6 +291,9 @@ public object GetValue(string setting)
case ConfigurationParameters.DisableAccidentalDeletionPrevention:
return DisableAccidentalDeletionPrevention;

case ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention:
return DisableExtendedAccidentalDeletionPrevention;

case ConfigurationParameters.Encoding:
return EncodingType;

Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleConsumerGroupControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ private void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(consumerGroupDescription.Name, ConsumerGroupEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {consumerGroupDescription.Name} {ConsumerGroupEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
serviceBusHelper.DeleteConsumerGroup(consumerGroupDescription);
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleEventHubControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ private void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(eventHubDescription.Path, EventHubEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {eventHubDescription.Path} {EventHubEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
serviceBusHelper.DeleteEventHub(eventHubDescription);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2010,6 +2010,15 @@ private async void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(notificationHubDescription.Path, NotificationHubEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {notificationHubDescription.Path} {NotificationHubEntity.ToLower()}");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteNotificationHub(notificationHubDescription);
Expand Down
9 changes: 9 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleQueueControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
Expand Down Expand Up @@ -2004,6 +2005,14 @@ private async void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(queueDescription.Path, QueueEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {queueDescription.Path} {QueueEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteQueue(queueDescription);
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleRelayControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,14 @@ private async void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(relayDescription.Path, RelayEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {relayDescription.Path} {RelayEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.NamespaceManager.DeleteRelayAsync(relayDescription.Path);
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleRuleControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,14 @@ void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(ruleWrapper.RuleDescription.Name, RuleEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {ruleWrapper.RuleDescription.Name} {RuleEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
serviceBusHelper.RemoveRule(ruleWrapper.SubscriptionDescription, ruleWrapper.RuleDescription);
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleSubscriptionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,14 @@ private async void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(subscriptionWrapper.SubscriptionDescription.Name, SubscriptionEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {subscriptionWrapper.SubscriptionDescription.Name} {SubscriptionEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteSubscription(subscriptionWrapper.SubscriptionDescription);
Expand Down
8 changes: 8 additions & 0 deletions src/ServiceBusExplorer/Controls/HandleTopicControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,14 @@ private async void btnCreateDelete_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(topicDescription.Path, TopicEntity.ToLower()))
{
var configuration = TwoFilesConfiguration.Create(TwoFilesConfiguration.GetCurrentConfigFileUse(), writeToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {topicDescription.Path} {TopicEntity.ToLower()}");
if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteTopic(topicDescription);
Expand Down
25 changes: 25 additions & 0 deletions src/ServiceBusExplorer/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,8 @@ private async void optionsToolStripMenuItem_Click(object sender, EventArgs e)

mainSettings.DisableAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableAccidentalDeletionPrevention, defaultValue: false, WriteToLog);
mainSettings.DisableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention, defaultValue: false, WriteToLog);

var lastConfigFileUse = configFileUse;

Expand Down Expand Up @@ -1947,6 +1949,10 @@ private async void deleteEntity_Click(object sender, EventArgs e)

var configuration = TwoFilesConfiguration.Create(configFileUse, WriteToLog);

bool disableExtendedAccidentalDeletionPrevention = configuration.GetBoolValue(
ConfigurationParameters.DisableExtendedAccidentalDeletionPrevention,
defaultValue: false);

// Root Node
if (serviceBusTreeView.SelectedNode == rootNode)
{
Expand Down Expand Up @@ -2139,6 +2145,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(queueDescription.Path, QueueEntity.ToLower()))
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {queueDescription.Path} {QueueEntity.ToLower()}");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteQueue(queueDescription);
Expand All @@ -2164,6 +2173,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(DeleteAllSubscriptions))
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {subscriptionDescriptions.Count} subscriptions");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteSubscriptions(subscriptionDescriptions);
Expand All @@ -2178,6 +2190,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(topicDescription.Path, TopicEntity.ToLower()))
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {TopicEntity.ToLower()} {topicDescription.Path}");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteTopic(topicDescription);
Expand All @@ -2191,6 +2206,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(relayDescription.Path, RelayEntity.ToLower()))
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {RelayEntity.ToLower()} {relayDescription.Path}");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteRelay(relayDescription.Path);
Expand Down Expand Up @@ -2278,6 +2296,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
if (deleteForm.ShowDialog() == DialogResult.OK)
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {subscriptionDescriptions.Count()} subscriptions");

await serviceBusHelper.DeleteSubscriptions(subscriptionDescriptions);
}
}
Expand All @@ -2293,6 +2314,9 @@ private async void deleteEntity_Click(object sender, EventArgs e)
{
using (var deleteForm = new DeleteForm(subscriptionWrapper.SubscriptionDescription.Name, SubscriptionEntity.ToLower()))
{
if (!disableExtendedAccidentalDeletionPrevention)
deleteForm.ShowAccidentalDeletionPreventionCheck(configuration, $"Delete {SubscriptionEntity.ToLower()} {subscriptionWrapper.SubscriptionDescription.Name}");

if (deleteForm.ShowDialog() == DialogResult.OK)
{
await serviceBusHelper.DeleteSubscription(subscriptionWrapper.SubscriptionDescription);
Expand Down Expand Up @@ -4691,6 +4715,7 @@ private void ShowQueue(QueueDescription queue, string path, bool duplicateQueue

try
{
var configuration = TwoFilesConfiguration.Create(configFileUse, WriteToLog);
panelMain.SuspendDrawing();
foreach (var userControl in panelMain.Controls.OfType<UserControl>())
{
Expand Down
Loading

0 comments on commit 33ac24e

Please sign in to comment.