Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show error message if a config file is incorrect #770

Merged
merged 4 commits into from
Feb 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ServiceBusExplorer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<add key="messageDeferProvider" value="ServiceBusExplorer.Helpers.InMemoryMessageDeferProvider,ServiceBusExplorer.Common" />
<add key="Microsoft.ServiceBus.X509RevocationMode" value="NoCheck" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
Expand Down
8 changes: 7 additions & 1 deletion src/ServiceBusExplorer/Forms/ConnectForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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<string> { "Key" },
new List<string> { key },
Expand All @@ -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
Expand All @@ -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);
Expand Down
9 changes: 8 additions & 1 deletion src/ServiceBusExplorer/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(mainSingletonMainForm != null)
{
mainSingletonMainForm.WriteToLog(message);
}
else
{
MessageBox.Show(message);
}
}
#endregion

Expand Down
11 changes: 10 additions & 1 deletion src/ServiceBusExplorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Loading