A:设置集成数据库
This commit is contained in:
1 parent
c999440973
commit
e35eb3e103
8 files changed
+491
-77
No files matched your search
@@ -0,0 +1,88 @@
|
||||
namespace Data.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 应用网络聚合数据基类
|
||||
/// </summary>
|
||||
public abstract class AppNetworkAggregatedBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 软件 ID
|
||||
/// </summary>
|
||||
public string AppId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总上传字节数
|
||||
/// </summary>
|
||||
public long TotalUploadBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总下载字节数
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 连接数量
|
||||
/// </summary>
|
||||
public int ConnectionCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一远程IP数量
|
||||
/// </summary>
|
||||
public int UniqueRemoteIPs { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 唯一远程端口数量
|
||||
/// </summary>
|
||||
public int UniqueRemotePorts { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间戳
|
||||
/// </summary>
|
||||
public long CreatedTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用网络小时聚合数据
|
||||
/// </summary>
|
||||
public class AppNetworkHourly : AppNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 小时时间戳(Unix时间戳,精确到小时)
|
||||
/// </summary>
|
||||
public long HourTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用网络天聚合数据
|
||||
/// </summary>
|
||||
public class AppNetworkDaily : AppNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 天时间戳(Unix时间戳,精确到天)
|
||||
/// </summary>
|
||||
public long DayTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用网络周聚合数据
|
||||
/// </summary>
|
||||
public class AppNetworkWeekly : AppNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 周时间戳(Unix时间戳,精确到周)
|
||||
/// </summary>
|
||||
public long WeekTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用网络月聚合数据
|
||||
/// </summary>
|
||||
public class AppNetworkMonthly : AppNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 月时间戳(Unix时间戳,精确到月)
|
||||
/// </summary>
|
||||
public long MonthTimestamp { get; set; }
|
||||
}
|
||||
@@ -17,17 +17,70 @@ public class AppSetting
|
||||
/// </summary>
|
||||
public int WindowY { get; set; } = 0;
|
||||
|
||||
/*
|
||||
*文本颜色
|
||||
背景颜色
|
||||
透明度
|
||||
速度单位
|
||||
布局方向(横向,纵向)
|
||||
展示单位(true/false)
|
||||
双击动作(1,2,3,)
|
||||
默认以管理员身份启动(true/false)
|
||||
*
|
||||
*/
|
||||
/// <summary>
|
||||
/// 点击穿透功能
|
||||
/// </summary>
|
||||
public bool IsClickThrough { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 位置锁定
|
||||
/// </summary>
|
||||
public bool IsPositionLocked { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 对齐到屏幕
|
||||
/// </summary>
|
||||
public bool SnapToScreen { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 显示详细信息
|
||||
/// </summary>
|
||||
public bool ShowDetailedInfo { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 窗口置顶
|
||||
/// </summary>
|
||||
public bool IsTopmost { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 文本颜色
|
||||
/// </summary>
|
||||
public string TextColor { get; set; } = "#FFFFFF";
|
||||
|
||||
/// <summary>
|
||||
/// 背景颜色
|
||||
/// </summary>
|
||||
public string BackgroundColor { get; set; } = "#000000";
|
||||
|
||||
/// <summary>
|
||||
/// 透明度 (0-100)
|
||||
/// </summary>
|
||||
public int Opacity { get; set; } = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 速度单位 (0: bps, 1: KB/s, 2: MB/s)
|
||||
/// </summary>
|
||||
public int SpeedUnit { get; set; } = 1;
|
||||
|
||||
/// <summary>
|
||||
/// 布局方向 (0: 横向, 1: 纵向)
|
||||
/// </summary>
|
||||
public int LayoutDirection { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 展示单位
|
||||
/// </summary>
|
||||
public bool ShowUnit { get; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// 双击动作 (0: None, 1: TrafficAnalysis, 2: Settings)
|
||||
/// </summary>
|
||||
public int DoubleClickAction { get; set; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 默认以管理员身份启动
|
||||
/// </summary>
|
||||
public bool RunAsAdmin { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 是否开机自启
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
namespace Data.Models;
|
||||
|
||||
/// <summary>
|
||||
/// 全局网络聚合数据基类
|
||||
/// </summary>
|
||||
public abstract class GlobalNetworkAggregatedBase
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 网卡 GUID
|
||||
/// </summary>
|
||||
public string NetworkCardGuid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总上传字节数
|
||||
/// </summary>
|
||||
public long TotalUpload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 总下载字节数
|
||||
/// </summary>
|
||||
public long TotalDownload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 平均上传速度
|
||||
/// </summary>
|
||||
public long AvgUpload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 平均下载速度
|
||||
/// </summary>
|
||||
public long AvgDownload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大上传速度
|
||||
/// </summary>
|
||||
public long MaxUpload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最大下载速度
|
||||
/// </summary>
|
||||
public long MaxDownload { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 记录数量(用于计算平均值)
|
||||
/// </summary>
|
||||
public int RecordCount { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 创建时间戳
|
||||
/// </summary>
|
||||
public long CreatedTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局网络小时聚合数据
|
||||
/// </summary>
|
||||
public class GlobalNetworkHourly : GlobalNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 小时时间戳(Unix时间戳,精确到小时)
|
||||
/// </summary>
|
||||
public long HourTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局网络天聚合数据
|
||||
/// </summary>
|
||||
public class GlobalNetworkDaily : GlobalNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 天时间戳(Unix时间戳,精确到天)
|
||||
/// </summary>
|
||||
public long DayTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局网络周聚合数据
|
||||
/// </summary>
|
||||
public class GlobalNetworkWeekly : GlobalNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 周时间戳(Unix时间戳,精确到周)
|
||||
/// </summary>
|
||||
public long WeekTimestamp { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 全局网络月聚合数据
|
||||
/// </summary>
|
||||
public class GlobalNetworkMonthly : GlobalNetworkAggregatedBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 月时间戳(Unix时间戳,精确到月)
|
||||
/// </summary>
|
||||
public long MonthTimestamp { get; set; }
|
||||
}
|
||||
@@ -62,12 +62,25 @@ public class NetVizorDbContext : IDisposable
|
||||
DeleteTime INTEGER DEFAULT 0
|
||||
)");
|
||||
|
||||
// 创建AppSetting表 - 简化结构
|
||||
// 创建AppSetting表 - 完整结构
|
||||
await connection.ExecuteAsync(@"
|
||||
CREATE TABLE IF NOT EXISTS AppSetting (
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
WindowX INTEGER DEFAULT 0,
|
||||
WindowY INTEGER DEFAULT 0,
|
||||
IsClickThrough INTEGER DEFAULT 0,
|
||||
IsPositionLocked INTEGER DEFAULT 0,
|
||||
SnapToScreen INTEGER DEFAULT 0,
|
||||
ShowDetailedInfo INTEGER DEFAULT 0,
|
||||
IsTopmost INTEGER DEFAULT 0,
|
||||
TextColor TEXT DEFAULT '#FFFFFF',
|
||||
BackgroundColor TEXT DEFAULT '#000000',
|
||||
Opacity INTEGER DEFAULT 100,
|
||||
SpeedUnit INTEGER DEFAULT 1,
|
||||
LayoutDirection INTEGER DEFAULT 0,
|
||||
ShowUnit INTEGER DEFAULT 1,
|
||||
DoubleClickAction INTEGER DEFAULT 0,
|
||||
RunAsAdmin INTEGER DEFAULT 0,
|
||||
AutoStart INTEGER DEFAULT 0,
|
||||
UpdateTime INTEGER NOT NULL
|
||||
)");
|
||||
@@ -268,7 +281,8 @@ public class NetVizorDbContext : IDisposable
|
||||
var columns = await GetTableColumnsAsync("AppSetting");
|
||||
var needsMigration = columns.Contains("WindowWidth") || columns.Contains("WindowHeight") ||
|
||||
columns.Contains("Theme") || columns.Contains("Language") ||
|
||||
columns.Contains("MonitoringEnabled");
|
||||
columns.Contains("MonitoringEnabled") ||
|
||||
!columns.Contains("IsClickThrough") || !columns.Contains("TextColor");
|
||||
|
||||
if (needsMigration)
|
||||
{
|
||||
@@ -287,6 +301,19 @@ public class NetVizorDbContext : IDisposable
|
||||
Id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
WindowX INTEGER DEFAULT 0,
|
||||
WindowY INTEGER DEFAULT 0,
|
||||
IsClickThrough INTEGER DEFAULT 0,
|
||||
IsPositionLocked INTEGER DEFAULT 0,
|
||||
SnapToScreen INTEGER DEFAULT 0,
|
||||
ShowDetailedInfo INTEGER DEFAULT 0,
|
||||
IsTopmost INTEGER DEFAULT 0,
|
||||
TextColor TEXT DEFAULT '#FFFFFF',
|
||||
BackgroundColor TEXT DEFAULT '#000000',
|
||||
Opacity INTEGER DEFAULT 100,
|
||||
SpeedUnit INTEGER DEFAULT 1,
|
||||
LayoutDirection INTEGER DEFAULT 0,
|
||||
ShowUnit INTEGER DEFAULT 1,
|
||||
DoubleClickAction INTEGER DEFAULT 0,
|
||||
RunAsAdmin INTEGER DEFAULT 0,
|
||||
AutoStart INTEGER DEFAULT 0,
|
||||
UpdateTime INTEGER NOT NULL
|
||||
)");
|
||||
|
||||
@@ -30,8 +30,16 @@ public class AppSettingRepository : IAppSettingRepository
|
||||
setting.UpdateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
||||
|
||||
const string sql = @"
|
||||
INSERT INTO AppSetting (WindowX, WindowY, AutoStart, UpdateTime)
|
||||
VALUES (@WindowX, @WindowY, @AutoStart, @UpdateTime)";
|
||||
INSERT INTO AppSetting (
|
||||
WindowX, WindowY, IsClickThrough, IsPositionLocked, SnapToScreen, ShowDetailedInfo,
|
||||
IsTopmost, TextColor, BackgroundColor, Opacity, SpeedUnit, LayoutDirection,
|
||||
ShowUnit, DoubleClickAction, RunAsAdmin, AutoStart, UpdateTime
|
||||
)
|
||||
VALUES (
|
||||
@WindowX, @WindowY, @IsClickThrough, @IsPositionLocked, @SnapToScreen, @ShowDetailedInfo,
|
||||
@IsTopmost, @TextColor, @BackgroundColor, @Opacity, @SpeedUnit, @LayoutDirection,
|
||||
@ShowUnit, @DoubleClickAction, @RunAsAdmin, @AutoStart, @UpdateTime
|
||||
)";
|
||||
|
||||
var result = await _context.Connection.ExecuteAsync(sql, setting);
|
||||
|
||||
@@ -49,7 +57,13 @@ public class AppSettingRepository : IAppSettingRepository
|
||||
|
||||
const string sql = @"
|
||||
UPDATE AppSetting
|
||||
SET WindowX = @WindowX, WindowY = @WindowY, AutoStart = @AutoStart, UpdateTime = @UpdateTime
|
||||
SET WindowX = @WindowX, WindowY = @WindowY, IsClickThrough = @IsClickThrough,
|
||||
IsPositionLocked = @IsPositionLocked, SnapToScreen = @SnapToScreen,
|
||||
ShowDetailedInfo = @ShowDetailedInfo, IsTopmost = @IsTopmost,
|
||||
TextColor = @TextColor, BackgroundColor = @BackgroundColor, Opacity = @Opacity,
|
||||
SpeedUnit = @SpeedUnit, LayoutDirection = @LayoutDirection, ShowUnit = @ShowUnit,
|
||||
DoubleClickAction = @DoubleClickAction, RunAsAdmin = @RunAsAdmin,
|
||||
AutoStart = @AutoStart, UpdateTime = @UpdateTime
|
||||
WHERE Id = @Id";
|
||||
|
||||
return await _context.Connection.ExecuteAsync(sql, setting);
|
||||
|
||||
@@ -59,11 +59,24 @@ public class DataService : IDataService, IDisposable
|
||||
{
|
||||
WindowX = 100,
|
||||
WindowY = 100,
|
||||
IsClickThrough = false,
|
||||
IsPositionLocked = false,
|
||||
SnapToScreen = false,
|
||||
ShowDetailedInfo = false,
|
||||
IsTopmost = false,
|
||||
TextColor = "#FFFFFF",
|
||||
BackgroundColor = "#000000",
|
||||
Opacity = 100,
|
||||
SpeedUnit = 1, // KB/s
|
||||
LayoutDirection = 0, // 横向
|
||||
ShowUnit = true,
|
||||
DoubleClickAction = 0, // None
|
||||
RunAsAdmin = false,
|
||||
AutoStart = false,
|
||||
UpdateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds()
|
||||
};
|
||||
|
||||
setting.Id = await AppSettings.SaveSettingAsync(setting);
|
||||
await AppSettings.SaveSettingAsync(setting);
|
||||
}
|
||||
|
||||
return setting;
|
||||
|
||||
Reference in new issue
Block a user