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

[Pull Request] 配置系统升级, 自发现逻辑优化, 修复多网络适配器导致的问题 #139

Merged
merged 11 commits into from
Sep 24, 2022
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
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/---bug-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ If applicable, add screenshots to help explain your problem.

**🖥 Desktop (please complete the following information):**
- OS: [e.g. Windows 11 Build xxx]
- Version [e.g. KitX v3.0.0]
- Version: [e.g. KitX v3.0.0]

**📱 Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Version [e.g. KitX Mobile v1.0.0]
- Version: [e.g. KitX Mobile v1.0.0]

**📎 Additional context**
Add any other context about the problem here.
13 changes: 6 additions & 7 deletions KitX Dashboard/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Avalonia.Media;
using BasicHelper.IO;
using BasicHelper.Util;
using FluentAvalonia.UI.Media;
using KitX_Dashboard.Data;
using KitX_Dashboard.Models;
using KitX_Dashboard.ViewModels;
Expand All @@ -24,7 +23,7 @@ public override void Initialize()
{
AvaloniaXamlLoader.Load(this);

string lang = Program.GlobalConfig.App.AppLanguage;
string lang = Program.Config.App.AppLanguage;
try
{
Resources.MergedDictionaries.Clear();
Expand All @@ -38,15 +37,15 @@ public override void Initialize()
{
Log.Warning($"Language File {lang}.axaml not found.");

string backup_lang = Program.GlobalConfig.App.SurpportLanguages.Keys.First();
string backup_lang = Program.Config.App.SurpportLanguages.Keys.First();
Resources.MergedDictionaries.Clear();
Resources.MergedDictionaries.Add(
AvaloniaRuntimeXamlLoader.Load(
FileHelper.ReadAll($"{GlobalInfo.LanguageFilePath}/{backup_lang}.axaml")
) as ResourceDictionary
);

Program.GlobalConfig.App.AppLanguage = backup_lang;
Program.Config.App.AppLanguage = backup_lang;
}
finally
{
Expand All @@ -55,7 +54,7 @@ public override void Initialize()

EventHandlers.Invoke("LanguageChanged");

Color c = Color.Parse(Program.GlobalConfig.App.ThemeColor);
Color c = Color.Parse(Program.Config.App.ThemeColor);

if (Current != null)
{
Expand Down Expand Up @@ -84,10 +83,10 @@ public override void OnFrameworkInitializationCompleted()
};
}

string color = Program.GlobalConfig.App.ThemeColor;
string color = Program.Config.App.ThemeColor;
Resources["ThemePrimaryAccent"] = new SolidColorBrush(Color.Parse(color));

if (Program.GlobalConfig.App.ShowAnnouncementWhenStart)
if (Program.Config.App.ShowAnnouncementWhenStart)
new Thread(async () =>
{
await Services.AnouncementManager.CheckNewAnnouncements();
Expand Down
98 changes: 62 additions & 36 deletions KitX Dashboard/Data/Config.cs → KitX Dashboard/Data/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace KitX_Dashboard.Data
/// <summary>
/// 配置结构
/// </summary>
public class Config
public class AppConfig
{
[JsonInclude]
public Config_App App { get; set; } = new();
Expand All @@ -17,8 +17,14 @@ public class Config
[JsonInclude]
public Config_Pages Pages { get; set; } = new();

[JsonInclude]
public Config_Web Web { get; set; } = new();

[JsonInclude]
public Config_Log Log { get; set; } = new();

/// <summary>
/// AppConfig
/// Config
/// </summary>
public class Config_App
{
Expand Down Expand Up @@ -49,45 +55,11 @@ public class Config_App
[JsonInclude]
public bool DeveloperSetting { get; set; } = false;

[JsonInclude]
public int UDPPortSend { get; set; } = 23404;

[JsonInclude]
public int UDPPortReceive { get; set; } = 24040;

[JsonInclude]
public string APIServer { get; set; } = "api.catrol.cn";

[JsonInclude]
public string APIPath { get; set; } = "/apps/kitx/";

[JsonInclude]
public bool ShowAnnouncementWhenStart { get; set; } = true;

[JsonInclude]
public ulong RanTime { get; set; } = 0;

[JsonInclude]
public string IPFilter { get; set; } = "192.168";

[JsonInclude]
public long LogFileSingleMaxSize { get; set; } = 1024 * 10000; // 10MB

[JsonInclude]
public string LogFilePath { get; set; } = "./Log/";

[JsonInclude]
public string LogTemplate { get; set; } = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] " +
"[{Level:u3}] {Message:lj}{NewLine}{Exception}";

[JsonInclude]
public int LogFileMaxCount { get; set; } = 50;

[JsonInclude]
public int LogFileFlushInterval { get; set; } = 30;

[JsonInclude]
public int SocketBufferSize { get; set; } = 1024 * 100;
}

/// <summary>
Expand Down Expand Up @@ -218,6 +190,60 @@ public class Config_SettingsPage
public bool IsNavigationViewPaneOpened { get; set; } = true;
}
}

/// <summary>
/// WebConfig
/// </summary>
public class Config_Web
{

[JsonInclude]
public string APIServer { get; set; } = "api.catrol.cn";

[JsonInclude]
public string APIPath { get; set; } = "/apps/kitx/";

[JsonInclude]
public int UDPPortSend { get; set; } = 23404;

[JsonInclude]
public int UDPPortReceive { get; set; } = 24040;

[JsonInclude]
public string UDPBroadcastAddress { get; set; } = "224.0.0.0";

[JsonInclude]
public string IPFilter { get; set; } = "192.168";

[JsonInclude]
public int SocketBufferSize { get; set; } = 1024 * 100;

[JsonInclude]
public int DeviceInfoStructTTLSeconds { get; set; } = 5;
}

/// <summary>
/// LogConfig
/// </summary>
public class Config_Log
{

[JsonInclude]
public long LogFileSingleMaxSize { get; set; } = 1024 * 10000; // 10MB

[JsonInclude]
public string LogFilePath { get; set; } = "./Log/";

[JsonInclude]
public string LogTemplate { get; set; } = "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] " +
"[{Level:u3}] {Message:lj}{NewLine}{Exception}";

[JsonInclude]
public int LogFileMaxCount { get; set; } = 50;

[JsonInclude]
public int LogFileFlushInterval { get; set; } = 30;
}
}
}

Expand Down
19 changes: 8 additions & 11 deletions KitX Dashboard/Helper.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
using Avalonia;
using Avalonia.Media;
using FluentAvalonia.UI.Media;
using KitX_Dashboard.Data;
using KitX_Dashboard.Data;
using KitX_Dashboard.Models;
using Serilog;
using System;
Expand Down Expand Up @@ -32,7 +29,7 @@ public static void StartUpCheck()

//InitLiteLogger(Program.LocalLogger);

string logdir = Path.GetFullPath(Program.GlobalConfig.App.LogFilePath);
string logdir = Path.GetFullPath(Program.Config.Log.LogFilePath);

if (!Directory.Exists(logdir))
Directory.CreateDirectory(logdir);
Expand All @@ -41,14 +38,14 @@ public static void StartUpCheck()
.MinimumLevel.Information()
.WriteTo.File(
$"{logdir}Log_.log",
outputTemplate: Program.GlobalConfig.App.LogTemplate,
outputTemplate: Program.Config.Log.LogTemplate,
rollingInterval: RollingInterval.Hour,
fileSizeLimitBytes: Program.GlobalConfig.App.LogFileSingleMaxSize,
fileSizeLimitBytes: Program.Config.Log.LogFileSingleMaxSize,
buffered: true,
flushToDiskInterval: new(0, 0, Program.GlobalConfig.App.LogFileFlushInterval),
flushToDiskInterval: new(0, 0, Program.Config.Log.LogFileFlushInterval),
restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information,
rollOnFileSizeLimit: true,
retainedFileCountLimit: Program.GlobalConfig.App.LogFileMaxCount
retainedFileCountLimit: Program.Config.Log.LogFileMaxCount
)
.CreateLogger();

Expand Down Expand Up @@ -90,7 +87,7 @@ public static void SaveConfig()
new Thread(() =>
{
BasicHelper.IO.FileHelper.WriteIn(Path.GetFullPath(GlobalInfo.ConfigFilePath),
JsonSerializer.Serialize(Program.GlobalConfig, options));
JsonSerializer.Serialize(Program.Config, options));
}).Start();
}

Expand All @@ -117,7 +114,7 @@ public static void SavePluginsListConfig()
/// </summary>
public static void LoadConfig()
{
Program.GlobalConfig = JsonSerializer.Deserialize<Config>(
Program.Config = JsonSerializer.Deserialize<AppConfig>(
BasicHelper.IO.FileHelper.ReadAll(Path.GetFullPath(GlobalInfo.ConfigFilePath)));
}

Expand Down
10 changes: 5 additions & 5 deletions KitX Dashboard/Models/GreetingTextGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ internal static int GenerateRandomIndex(Step step)
switch (step)
{
case Step.Morning:
result = random.Next(1, Program.GlobalConfig.Windows
result = random.Next(1, Program.Config.Windows
.MainWindow.GreetingTextCount_Morning + 1);
break;
case Step.Noon:
result = random.Next(1, Program.GlobalConfig.Windows
result = random.Next(1, Program.Config.Windows
.MainWindow.GreetingTextCount_Noon + 1);
break;
case Step.AfterNoon:
result = random.Next(1, Program.GlobalConfig.Windows
result = random.Next(1, Program.Config.Windows
.MainWindow.GreetingTextCount_AfterNoon + 1);
break;
case Step.Evening:
result = random.Next(1, Program.GlobalConfig.Windows
result = random.Next(1, Program.Config.Windows
.MainWindow.GreetingTextCount_Evening + 1);
break;
case Step.Night:
result = random.Next(1, Program.GlobalConfig.Windows
result = random.Next(1, Program.Config.Windows
.MainWindow.GreetingTextCount_Night + 1);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions KitX Dashboard/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class Program
{
//internal static LoggerManager LocalLogger = new();

internal static Config GlobalConfig = new();
internal static AppConfig Config = new();

internal static WebServer? LocalWebServer;

Expand Down Expand Up @@ -87,7 +87,7 @@ public static void Main(string[] args)

#endregion

GlobalConfig.App.RanTime++;
Config.App.RanTime++;

#region ����Ӧ����������ѭ��

Expand Down
6 changes: 3 additions & 3 deletions KitX Dashboard/Services/AnouncementManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public static async Task CheckNewAnnouncements()

// 链接头部
string linkBase = $"http://" +
$"{Program.GlobalConfig.App.APIServer}" +
$"{Program.GlobalConfig.App.APIPath}";
$"{Program.Config.Web.APIServer}" +
$"{Program.Config.Web.APIPath}";

// 获取公告列表的api链接
string link = $"{linkBase}{GlobalInfo.Api_Get_Announcements}";
Expand Down Expand Up @@ -66,7 +66,7 @@ await FileHelper.ReadAllAsync(confPath)
// 获取单个公告的链接
string apiLink = $"{linkBase}{GlobalInfo.Api_Get_Announcement}" +
$"?" +
$"lang={Program.GlobalConfig.App.AppLanguage}" +
$"lang={Program.Config.App.AppLanguage}" +
$"&" +
$"date={item:yyyy-MM-dd HH-mm}";
string? md = JsonSerializer.Deserialize<string>(await client.GetStringAsync(apiLink));
Expand Down
3 changes: 2 additions & 1 deletion KitX Dashboard/Services/DevicesManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ internal static void KeepCheckAndRemove()
continue;
}
MacAddressVisited.Add(item.viewModel.DeviceInfo.DeviceMacAddress);
if (DateTime.Now - item.viewModel.DeviceInfo.SendTime > new TimeSpan(0, 0, 5))
if (DateTime.Now - item.viewModel.DeviceInfo.SendTime
> new TimeSpan(0, 0, Program.Config.Web.DeviceInfoStructTTLSeconds))
DevicesNeed2BeRemoved.Add(item);
}
foreach (var item in DevicesNeed2BeRemoved)
Expand Down
2 changes: 2 additions & 0 deletions KitX Dashboard/Services/LoadersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@
{
internal class LoadersManager
{


}
}
8 changes: 4 additions & 4 deletions KitX Dashboard/Services/PluginsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ internal static void ImportPlugin(string[] kxpfiles, bool inGraphic = false)
Directory.Delete(releaseDir, true);
LoaderStruct loaderStruct = JsonSerializer.Deserialize<LoaderStruct>(rst.Item1);
PluginStruct pluginStruct = JsonSerializer.Deserialize<PluginStruct>(rst.Item2);
Config? config = null;
if (inGraphic) config = Program.GlobalConfig;
else config = JsonSerializer.Deserialize<Config>(File.ReadAllText(
AppConfig? config = null;
if (inGraphic) config = Program.Config;
else config = JsonSerializer.Deserialize<AppConfig>(File.ReadAllText(
Path.GetFullPath($"{GlobalInfo.ConfigPath}config.json")
));
if (config == null)
Expand Down Expand Up @@ -242,7 +242,7 @@ internal static void KeepCheckAndRemoveOrDelete()
Plugin pg = pluginsToDelete.Dequeue();
Program.PluginsList.Plugins.Remove(pg);
string pgfiledir = Path.GetFullPath(
$"{Program.GlobalConfig.App.LocalPluginsFileDirectory}/" +
$"{Program.Config.App.LocalPluginsFileDirectory}/" +
$"{pg.PluginDetails.PublisherName}_{pg.PluginDetails.AuthorName}/" +
$"{pg.PluginDetails.Name}/{pg.PluginDetails.Version}/"
);
Expand Down
Loading