Skip to content

Commit

Permalink
Changed MQTT library to MQTTnet (Old one has issues when connecttion …
Browse files Browse the repository at this point in the history
…lost with server)
  • Loading branch information
WebSpiderTeam committed Aug 28, 2022
1 parent cf5f2a2 commit fee688a
Show file tree
Hide file tree
Showing 7 changed files with 224 additions and 202 deletions.
3 changes: 1 addition & 2 deletions BluetoothDMM WPF/BluetoothDMM/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@
</setting>
<setting name="SelectedDataList" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>Time
"Time":"</string>
<string>Device
Expand Down
35 changes: 34 additions & 1 deletion BluetoothDMM WPF/BluetoothDMM/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ public partial class App : Application
{
private const int MINIMUM_SPLASH_TIME = 3000; // Miliseconds
private const int SPLASH_FADE_TIME = 1000; // Miliseconds
private string time;

protected override void OnStartup(StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(AppDispatcherUnhandledException);
//AppDomain.UnhandledException += AppDomain_UnhandledException;
this.Dispatcher.UnhandledException += AppDispatcherUnhandledException;
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
time = DateTime.Now.ToString("dd-MM-yyyy_HH_mm_ss");
//AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
// Step 1 - Load the splash screen
SplashScreen splash = new SplashScreen("Assets/SplashScreen.scale-100.png");
splash.Show(false, true);
Expand All @@ -41,6 +47,33 @@ protected override void OnStartup(StartupEventArgs e)
main.Show();
}

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{

Exception ex = e.ExceptionObject as Exception;
#if DEBUG// In debug mode do not custom-handle the exception, let Visual Studio handle it
//ex.Handled = false;
#else
//ex. Handled = true;
//e.Exception.StackTrace
string errorMessage = string.Format("An application error occurred.\n" +
"Please check whether your data is correct and repeat the action. " +
"If this error occurs again there seems to be a more serious malfunction in the application, and you better close it.\n\n" +
"Error: {0}\n\nDo you want to continue?\n" +
"(if you click Yes you will continue with your work, if you click No the application will close)",
ex.Message + (ex.InnerException != null ? "\n" +
ex.InnerException.Message : null));

File.AppendAllText("Debuglog_" + time + ".txt", "error catch Error: " + ex.ToString() + System.Environment.NewLine);
File.AppendAllText("Debuglog_" + time + ".txt", errorMessage + System.Environment.NewLine);
if (MessageBox.Show(errorMessage, "Application Error", MessageBoxButton.YesNoCancel, MessageBoxImage.Error) == MessageBoxResult.No)
if (MessageBox.Show("WARNING: The application will close. Any changes will not be saved!\nDo you really want to close it?", "Close the application!", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)
{
Application.Current.Shutdown();
}
#endif
}

void AppDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
#if DEBUG// In debug mode do not custom-handle the exception, let Visual Studio handle it
Expand All @@ -54,7 +87,7 @@ void AppDispatcherUnhandledException(object sender, DispatcherUnhandledException
void ShowUnhandledException(DispatcherUnhandledExceptionEventArgs e)
{
e.Handled = true;

//e.Exception.StackTrace
string errorMessage = string.Format("An application error occurred.\n" +
"Please check whether your data is correct and repeat the action. " +
"If this error occurs again there seems to be a more serious malfunction in the application, and you better close it.\n\n" +
Expand Down
4 changes: 2 additions & 2 deletions BluetoothDMM WPF/BluetoothDMM/BluetoothDMM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@
<Reference Include="DotNetProjects.DataVisualization.Toolkit, Version=6.1.94.0, Culture=neutral, PublicKeyToken=79778c5f2eed289b, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetProjects.WpfToolkit.DataVisualization.6.1.94\lib\net40\DotNetProjects.DataVisualization.Toolkit.dll</HintPath>
</Reference>
<Reference Include="M2Mqtt.Net, Version=4.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\M2MqttAutoReconnect.4.4.0.1\lib\net462\M2Mqtt.Net.dll</HintPath>
<Reference Include="MQTTnet, Version=4.1.0.247, Culture=neutral, PublicKeyToken=fdb7629f2e364a63, processorArchitecture=MSIL">
<HintPath>..\packages\MQTTnet.4.1.0.247\lib\net461\MQTTnet.dll</HintPath>
</Reference>
<Reference Include="presentationframework.aero2" />
<Reference Include="ScottPlot, Version=4.1.52.0, Culture=neutral, PublicKeyToken=86698dc10387c39e, processorArchitecture=MSIL">
Expand Down
Loading

0 comments on commit fee688a

Please sign in to comment.