From 04ee5fed6fe3d21f3413c6de9067d8d990d11a80 Mon Sep 17 00:00:00 2001 From: Erik Mogensen Date: Fri, 23 Feb 2024 19:13:18 +0100 Subject: [PATCH 1/4] Only formatting --- src/Common/Helpers/ConfigurationHelper.cs | 2 +- src/ServiceBusExplorer/App.config | 2 +- src/ServiceBusExplorer/Forms/ConnectForm.cs | 8 +++++++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Common/Helpers/ConfigurationHelper.cs b/src/Common/Helpers/ConfigurationHelper.cs index b26bee93..7f2d04af 100644 --- a/src/Common/Helpers/ConfigurationHelper.cs +++ b/src/Common/Helpers/ConfigurationHelper.cs @@ -46,7 +46,7 @@ public static void UpdateServiceBusNamespace(ConfigFileUse configFileUse, string configuration.UpdateEntryInDictionarySection(SERVICEBUS_SECTION_NAME, key, newKey, newValue, writeToLog); } - public static void AddServiceBusNamespace(ConfigFileUse configFileUse, string key, string value, WriteToLogDelegate writeToLog) + public static void F(ConfigFileUse configFileUse, string key, string value, WriteToLogDelegate writeToLog) { var configuration = TwoFilesConfiguration.Create(configFileUse, writeToLog); diff --git a/src/ServiceBusExplorer/App.config b/src/ServiceBusExplorer/App.config index b957634f..19c74d8b 100644 --- a/src/ServiceBusExplorer/App.config +++ b/src/ServiceBusExplorer/App.config @@ -55,7 +55,7 @@ - + diff --git a/src/ServiceBusExplorer/Forms/ConnectForm.cs b/src/ServiceBusExplorer/Forms/ConnectForm.cs index d239867b..6d141e37 100644 --- a/src/ServiceBusExplorer/Forms/ConnectForm.cs +++ b/src/ServiceBusExplorer/Forms/ConnectForm.cs @@ -593,15 +593,19 @@ private void btnSave_Click(object sender, EventArgs e) { var key = cboServiceBusNamespace.Text; var isNewServiceBusNamespace = (key == EnterConnectionString); + ServiceBusConnectionStringBuilder serviceBusConnectionStringBuilder; + try { BuildCurrentConnectionString(); + if (string.IsNullOrWhiteSpace(ConnectionString)) { MainForm.StaticWriteToLog(ConnectionStringCannotBeNull); return; } + serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder(ConnectionString); } catch (Exception) @@ -621,10 +625,10 @@ private void btnSave_Click(object sender, EventArgs e) var index = host.IndexOf(".", StringComparison.Ordinal); - if (isNewServiceBusNamespace) { key = index > 0 ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(host.Substring(0, index)) : "MyNamespace"; + using (var parameterForm = new ParameterForm("Enter the key for the Service Bus namespace", new List { "Key" }, new List { key }, @@ -644,6 +648,7 @@ private void btnSave_Click(object sender, EventArgs e) MainForm.StaticWriteToLog("The key of the Service Bus namespace cannot be null."); return; } + var value = ConnectionString; try @@ -663,6 +668,7 @@ private void btnSave_Click(object sender, EventArgs e) } serviceBusHelper.ServiceBusNamespaces[key] = ServiceBusNamespace.GetServiceBusNamespace(key, value, MainForm.StaticWriteToLog); + cboServiceBusNamespace.Items.Clear(); cboServiceBusNamespace.Items.Add(SelectServiceBusNamespace); cboServiceBusNamespace.Items.Add(EnterConnectionString); From d0f13c5f78f92a329ab84cd31efe6b0b86f37be6 Mon Sep 17 00:00:00 2001 From: Erik Mogensen Date: Sun, 25 Feb 2024 11:19:27 +0100 Subject: [PATCH 2/4] Give helping error message if the application does not start --- src/Common/Helpers/ConfigurationHelper.cs | 2 +- src/ServiceBusExplorer/Forms/MainForm.cs | 9 ++++++++- src/ServiceBusExplorer/Program.cs | 11 ++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Common/Helpers/ConfigurationHelper.cs b/src/Common/Helpers/ConfigurationHelper.cs index 7f2d04af..b26bee93 100644 --- a/src/Common/Helpers/ConfigurationHelper.cs +++ b/src/Common/Helpers/ConfigurationHelper.cs @@ -46,7 +46,7 @@ public static void UpdateServiceBusNamespace(ConfigFileUse configFileUse, string configuration.UpdateEntryInDictionarySection(SERVICEBUS_SECTION_NAME, key, newKey, newValue, writeToLog); } - public static void F(ConfigFileUse configFileUse, string key, string value, WriteToLogDelegate writeToLog) + public static void AddServiceBusNamespace(ConfigFileUse configFileUse, string key, string value, WriteToLogDelegate writeToLog) { var configuration = TwoFilesConfiguration.Create(configFileUse, writeToLog); diff --git a/src/ServiceBusExplorer/Forms/MainForm.cs b/src/ServiceBusExplorer/Forms/MainForm.cs index 2c2d3e83..9223fd32 100644 --- a/src/ServiceBusExplorer/Forms/MainForm.cs +++ b/src/ServiceBusExplorer/Forms/MainForm.cs @@ -4041,7 +4041,14 @@ private void SetTitle(string prefix) #region Public Static Methods public static void StaticWriteToLog(string message, bool async = true) { - mainSingletonMainForm.WriteToLog(message); + if(null != mainSingletonMainForm) + { + mainSingletonMainForm.WriteToLog(message); + } + else + { + MessageBox.Show(message); + } } #endregion diff --git a/src/ServiceBusExplorer/Program.cs b/src/ServiceBusExplorer/Program.cs index 9d4caf03..045a3311 100644 --- a/src/ServiceBusExplorer/Program.cs +++ b/src/ServiceBusExplorer/Program.cs @@ -97,7 +97,16 @@ static void HandleException(Exception ex) { if (ex != null && !string.IsNullOrWhiteSpace(ex.Message)) { - MainForm.StaticWriteToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, ex.Message)); + var message = ex.Message; + + if (ex.GetType() == typeof(TypeInitializationException)) + { + message += Environment.NewLine + Environment.NewLine + + "This may be due to an invalid configuration file."; + } + + MainForm.StaticWriteToLog(string.Format(CultureInfo.CurrentCulture, ExceptionFormat, message)); + if (ex.InnerException != null && !string.IsNullOrWhiteSpace(ex.InnerException.Message)) { MainForm.StaticWriteToLog(string.Format(CultureInfo.CurrentCulture, InnerExceptionFormat, ex.InnerException.Message)); From 5062b8245cd116c4491de073e57972de25ce6137 Mon Sep 17 00:00:00 2001 From: Erik Mogensen Date: Sun, 25 Feb 2024 17:43:23 +0100 Subject: [PATCH 3/4] Update src/ServiceBusExplorer/Forms/MainForm.cs Co-authored-by: Sean Feldman --- src/ServiceBusExplorer/Forms/MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceBusExplorer/Forms/MainForm.cs b/src/ServiceBusExplorer/Forms/MainForm.cs index 9223fd32..5a74eb76 100644 --- a/src/ServiceBusExplorer/Forms/MainForm.cs +++ b/src/ServiceBusExplorer/Forms/MainForm.cs @@ -4041,7 +4041,7 @@ private void SetTitle(string prefix) #region Public Static Methods public static void StaticWriteToLog(string message, bool async = true) { - if(null != mainSingletonMainForm) + if(mainSingletonMainForm is not null) { mainSingletonMainForm.WriteToLog(message); } From 2127ee498201e815b5cb619c1080eea5d7694abf Mon Sep 17 00:00:00 2001 From: Erik Mogensen Date: Sun, 25 Feb 2024 18:01:08 +0100 Subject: [PATCH 4/4] Changed null comparison --- src/ServiceBusExplorer/Forms/MainForm.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceBusExplorer/Forms/MainForm.cs b/src/ServiceBusExplorer/Forms/MainForm.cs index 5a74eb76..6c4d0563 100644 --- a/src/ServiceBusExplorer/Forms/MainForm.cs +++ b/src/ServiceBusExplorer/Forms/MainForm.cs @@ -4041,7 +4041,7 @@ private void SetTitle(string prefix) #region Public Static Methods public static void StaticWriteToLog(string message, bool async = true) { - if(mainSingletonMainForm is not null) + if(mainSingletonMainForm != null) { mainSingletonMainForm.WriteToLog(message); }