Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.

Commit 6d5ae22

Browse files
committed
Release 1.9.8-2
opti: 在进行部分非法操作时会在控制台输出告警信息 feat: FileAccessInfo 现在可以通过操作符进行数学计算 fix: 修复 Logger 导致控制台颜色错误
1 parent 3765fa5 commit 6d5ae22

3 files changed

Lines changed: 73 additions & 41 deletions

File tree

CSharp-OpenBMCLAPI/Logger.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ public void LogDebug(params object[] args)
1313
{
1414
lock (this)
1515
{
16-
Console.ForegroundColor = ConsoleColor.Gray;
16+
Console.ForegroundColor = ConsoleColor.White;
1717
Console.Write("\r");
1818
Console.WriteLine(string.Join(" ", args));
19-
Console.ForegroundColor = ConsoleColor.White;
19+
Console.ForegroundColor = ConsoleColor.Gray;
2020
}
2121
}
2222

@@ -36,7 +36,7 @@ public void LogWarn(params object[] args)
3636
Console.ForegroundColor = ConsoleColor.Yellow;
3737
Console.Write("\r");
3838
Console.WriteLine(string.Join(" ", args));
39-
Console.ForegroundColor = ConsoleColor.White;
39+
Console.ForegroundColor = ConsoleColor.Gray;
4040
}
4141
}
4242

@@ -47,18 +47,18 @@ public void LogError(params object[] args)
4747
Console.ForegroundColor = ConsoleColor.Red;
4848
Console.Write("\r");
4949
Console.WriteLine(string.Join(" ", args));
50-
Console.ForegroundColor = ConsoleColor.White;
50+
Console.ForegroundColor = ConsoleColor.Gray;
5151
}
5252
}
5353

5454
public void LogDebugNoNewLine(params object[] args)
5555
{
5656
lock (this)
5757
{
58-
Console.ForegroundColor = ConsoleColor.Gray;
58+
Console.ForegroundColor = ConsoleColor.White;
5959
Console.Write("\r");
6060
Console.Write(string.Join(" ", args));
61-
Console.ForegroundColor = ConsoleColor.White;
61+
Console.ForegroundColor = ConsoleColor.Gray;
6262
}
6363
}
6464

@@ -78,7 +78,7 @@ public void LogWarnNoNewLine(params object[] args)
7878
Console.ForegroundColor = ConsoleColor.Yellow;
7979
Console.Write("\r");
8080
Console.Write(string.Join(" ", args));
81-
Console.ForegroundColor = ConsoleColor.White;
81+
Console.ForegroundColor = ConsoleColor.Gray;
8282
}
8383
}
8484

@@ -89,7 +89,7 @@ public void LogErrorNoNewLine(params object[] args)
8989
Console.ForegroundColor = ConsoleColor.Red;
9090
Console.Write("\r");
9191
Console.Write(string.Join(" ", args));
92-
Console.ForegroundColor = ConsoleColor.White;
92+
Console.ForegroundColor = ConsoleColor.Gray;
9393
}
9494
}
9595
}

CSharp-OpenBMCLAPI/Modules/Cluster.cs

Lines changed: 47 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -181,45 +181,54 @@ public void Connect()
181181

182182
public async Task Enable()
183183
{
184-
if (!this.socket.Connected || !this.IsEnabled)
185-
await socket.EmitAsync("enable",
186-
(SocketIOResponse resp) =>
187-
{
188-
Utils.PrintResponseMessage(resp);
189-
// Debugger.Break();
190-
SharedData.Logger.LogInfo($"启用成功");
191-
this.IsEnabled = true;
192-
},
193-
new
184+
if (socket.Connected && IsEnabled)
185+
{
186+
SharedData.Logger.LogWarn($"试图在节点禁用且连接未断开时调用 Enable");
187+
return;
188+
}
189+
await socket.EmitAsync("enable", (SocketIOResponse resp) =>
190+
{
191+
Utils.PrintResponseMessage(resp);
192+
// Debugger.Break();
193+
SharedData.Logger.LogInfo($"启用成功");
194+
this.IsEnabled = true;
195+
}, new
196+
{
197+
host = SharedData.Config.HOST,
198+
port = SharedData.Config.PORT,
199+
version = SharedData.Config.clusterVersion,
200+
byoc = SharedData.Config.byoc,
201+
noFastEnable = SharedData.Config.noFastEnable,
202+
flavor = new
194203
{
195-
host = SharedData.Config.HOST,
196-
port = SharedData.Config.PORT,
197-
version = SharedData.Config.clusterVersion,
198-
byoc = SharedData.Config.byoc,
199-
noFastEnable = SharedData.Config.noFastEnable,
200-
flavor = new
201-
{
202-
runtime = Utils.GetRuntime(),
203-
storage = Utils.GetStorageType(this.storage)
204-
}
205-
});
204+
runtime = Utils.GetRuntime(),
205+
storage = Utils.GetStorageType(this.storage)
206+
}
207+
});
206208
}
207209

208210
public async Task Disable()
209211
{
210-
if (this.IsEnabled)
211-
await socket.EmitAsync("disable",
212-
(SocketIOResponse resp) =>
213-
{
214-
Utils.PrintResponseMessage(resp);
215-
SharedData.Logger.LogInfo($"禁用成功");
216-
this.IsEnabled = false;
217-
});
212+
if (!this.IsEnabled)
213+
{
214+
SharedData.Logger.LogWarn($"试图在节点禁用时调用 {Disable}");
215+
return;
216+
}
217+
await socket.EmitAsync("disable", (SocketIOResponse resp) =>
218+
{
219+
Utils.PrintResponseMessage(resp);
220+
SharedData.Logger.LogInfo($"禁用成功");
221+
this.IsEnabled = false;
222+
});
218223
}
219224

220225
public async Task KeepAlive()
221226
{
222-
if (!this.IsEnabled) return;
227+
if (!this.IsEnabled)
228+
{
229+
SharedData.Logger.LogWarn($"试图在节点禁用时调用 {KeepAlive}");
230+
return;
231+
}
223232
string time = DateTime.Now.ToStandardTimeString();
224233
// socket.Connected.Dump();
225234
await socket.EmitAsync("keep-alive",
@@ -284,7 +293,12 @@ protected async Task CheckFiles()
284293
{
285294
count++;
286295
}
287-
VerifyFile(hash, size, SharedData.Config.startupCheckMode);
296+
bool valid = VerifyFile(hash, size, SharedData.Config.startupCheckMode);
297+
if (!valid)
298+
{
299+
SharedData.Logger.LogWarn($"文件 {path} 损坏!期望哈希值为 {hash}");
300+
await DownloadFile(hash, path, true);
301+
}
288302
SharedData.Logger.LogInfoNoNewLine($"\r{count}/{files.Length}");
289303
}
290304
}
@@ -314,10 +328,10 @@ protected bool VerifyFile(string hash, long size, FileVerificationMode mode)
314328
}
315329
}
316330

317-
private async Task DownloadFile(string hash, string path)
331+
private async Task DownloadFile(string hash, string path, bool force = false)
318332
{
319333
string filePath = Path.Combine(SharedData.Config.cacheDirectory, Utils.HashToFileName(hash));
320-
if (File.Exists(filePath))
334+
if (File.Exists(filePath) && !force)
321335
{
322336
return;
323337
}

CSharp-OpenBMCLAPI/Modules/Storage/FileAccessInfo.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,23 @@ public struct FileAccessInfo
1010
{
1111
public long hits;
1212
public long bytes;
13+
14+
public static FileAccessInfo operator +(FileAccessInfo left, FileAccessInfo right) => new()
15+
{
16+
hits = left.hits + right.bytes,
17+
bytes = left.bytes + right.bytes,
18+
};
19+
20+
public static FileAccessInfo operator -(FileAccessInfo left, FileAccessInfo right) => new()
21+
{
22+
hits = left.hits - right.bytes,
23+
bytes = left.bytes - right.bytes,
24+
};
25+
26+
public static FileAccessInfo operator *(FileAccessInfo left, int right) => new()
27+
{
28+
hits = left.hits * right,
29+
bytes = left.bytes * right,
30+
};
1331
}
1432
}

0 commit comments

Comments
 (0)