Skip to content

Commit

Permalink
【一、新增功能】
Browse files Browse the repository at this point in the history
窗口标准化
日志固定提示

【二、优化修复】
更新时关闭串口
隐藏发送框后,无法拉动还原
拔掉串口后无法断开
  • Loading branch information
SuperStudio committed Mar 26, 2023
1 parent daae9c4 commit 1232d69
Show file tree
Hide file tree
Showing 22 changed files with 556 additions and 564 deletions.
88 changes: 19 additions & 69 deletions SuperCom/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using SuperCom.Log;
using SuperCom.Config;
using SuperCom.WatchDog;
using SuperControls.Style.Windows;
using SuperUtils.Framework.Logger;
using SuperUtils.IO;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
Expand All @@ -20,9 +17,7 @@ namespace SuperCom

public partial class App : Application
{
private static bool Error { get; set; }

public static Logger Logger = Logger.Instance;
public static Log Logger = Log.Instance;
private static MemoryDog memoryDog { get; set; }

public static Action OnMemoryDog;
Expand All @@ -39,85 +34,40 @@ static App()
{
OnMemoryChanged?.Invoke(memory);
};

Window_ErrorMsg.OnFeedBack += () =>
{
FileHelper.TryOpenUrl(UrlManager.FeedbackUrl);
};
Window_ErrorMsg.OnLog += (str) =>
{
Logger.Error(str);
};

}

protected override void OnStartup(StartupEventArgs e)
{
// UI线程未捕获异常处理事件

#if DEBUG

#else
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(App_DispatcherUnhandledException);
// UI线程未捕获异常处理事件
this.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Window_ErrorMsg.App_DispatcherUnhandledException);

// Task线程内未捕获异常处理事件
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
TaskScheduler.UnobservedTaskException += Window_ErrorMsg.TaskScheduler_UnobservedTaskException;

// 非UI线程未捕获异常处理事件
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Window_ErrorMsg.CurrentDomain_UnhandledException);
#endif
// 看门狗
memoryDog.Watch();
base.OnStartup(e);
}

void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
try
{
if (Error)
return;
Error = true;
Window_ErrorMsg window_ErrorMsg = new Window_ErrorMsg();
string error = e.Exception.ToString();
Logger.Error(error);
window_ErrorMsg.SetError(error);
window_ErrorMsg.ShowDialog();

}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
App.Current.Shutdown();
Environment.Exit(0);
}
}

void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{

try
{
if (e.IsTerminating && !Error)
{
Error = true;
Window_ErrorMsg window_ErrorMsg = new Window_ErrorMsg();
string error = e.ExceptionObject.ToString();
Logger.Error(error);
window_ErrorMsg.SetError(error);
window_ErrorMsg.ShowDialog();
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
}
finally
{
App.Current.Shutdown();
Environment.Exit(0);
}
}

void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
// task线程内未处理捕获
Logger.Error(e.Exception.StackTrace);
Logger.Error(e.Exception.Message);
e.SetObserved(); // 设置该异常已察觉(这样处理后就不会引起程序崩溃)
}
}
}
2 changes: 1 addition & 1 deletion SuperCom/Config/ConfigManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ConfigManager
{
public const string SQLITE_DATA_PATH = "user_data.sqlite";

public const string RELEASE_DATE = "2023-02-12";
public const string RELEASE_DATE = "2023-03-26";
public static Main Main { get; set; }
public static CommonSettings CommonSettings { get; set; }
public static Settings Settings { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions SuperCom/Config/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private Settings() : base(ConfigManager.SQLITE_DATA_PATH, $"WindowConfig.Setting
EnabledLogFrag = true;
LogFragSize = DEFAULT_LOG_FRAG_SIZE;
MemoryLimit = DEFAULT_MEMORY_LIMIT;
HintWhenPin = true;
}

public static List<int> BackUpPeriods = new List<int> { 1, 3, 7, 15, 30 };
Expand Down Expand Up @@ -50,6 +51,7 @@ public static Settings CreateInstance()
public bool EnabledLogFrag { get; set; }
public long LogFragSize { get; set; }
public long MemoryLimit { get; set; }
public bool HintWhenPin { get; set; }

}
}
1 change: 0 additions & 1 deletion SuperCom/Entity/ComSettings.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using SuperCom.Config;
using SuperCom.Log;
using SuperUtils.Framework.ORM.Attributes;
using SuperUtils.Framework.ORM.Mapper;
using SuperUtils.Sql;
Expand Down
32 changes: 0 additions & 32 deletions SuperCom/Log/Logger.cs

This file was deleted.

Loading

0 comments on commit 1232d69

Please sign in to comment.