Compare commits

...

3 Commits

5 changed files with 51 additions and 37 deletions

View File

@ -691,13 +691,17 @@ public class MachineInfo : IExtend
if (dic.TryGetValue("MemTotal", out var str) && !str.IsNullOrEmpty())
Memory = (UInt64)str.TrimEnd(" kB").ToInt() * 1024;
if (dic.TryGetValue("MemAvailable", out str) && !str.IsNullOrEmpty())
AvailableMemory = (UInt64)str.TrimEnd(" kB").ToInt() * 1024;
else if (dic.TryGetValue("MemFree", out str) && !str.IsNullOrEmpty())
AvailableMemory =
(UInt64)(str.TrimEnd(" kB").ToInt() +
dic["Buffers"]?.TrimEnd(" kB").ToInt() ?? 0 +
dic["Cached"]?.TrimEnd(" kB").ToInt() ?? 0) * 1024;
// MemAvailable是系统内核预测的可用内存过低则认为不能安全分配给新进程可能过于悲观
// MemFree是完全空闲的内存未被使用的物理内存页但内核不敢用
var ma = (UInt64)(dic["MemAvailable"]?.TrimEnd(" kB").ToInt() ?? 0) * 1024;
var mf = (UInt64)(dic["MemFree"]?.TrimEnd(" kB").ToInt() ?? 0) * 1024;
var mc = (UInt64)(dic["Cached"]?.TrimEnd(" kB").ToInt() ?? 0) * 1024;
// 空闲内存 100% 可用,缓存内存 40% 可快速回收(保守估计)
mf += (UInt64)(mc * 0.4);
if (mf > 5ul * 1024 * 1024 * 1024) mf = 5ul * 1024 * 1024 * 1024;
AvailableMemory = ma > mf ? ma : mf;
}
// A2/A4温度获取BuildrootCPU温度和主板温度

View File

@ -130,15 +130,22 @@ public abstract class FileConfigProvider : ConfigProvider
if (str != null && str != old)
{
// 如果文件内容有变化,输出差异
var i = 0;
while (i < str.Length && i < old.Length && str[i] == old[i]) i++;
if (old.IsNullOrEmpty())
XTrace.WriteLine("新建配置:{0}", fileName);
else
{
// 如果文件内容有变化,输出差异
var i = 0;
while (i < str.Length && i < old.Length && str[i] == old[i]) i++;
var s = i > 16 ? i - 16 : 0;
var e = i + 16 < str.Length ? i + 16 : str.Length;
var diff = str.Substring(s, e - s).Replace("\r", "\\r").Replace("\n", "\\n");
var s = i > 16 ? i - 16 : 0;
var e = i + 32 < old.Length ? i + 32 : old.Length;
var ori = old.Substring(s, e - s).Replace("\r", "\\r").Replace("\n", "\\n");
var e2 = i + 32 < str.Length ? i + 32 : str.Length;
var diff = str.Substring(s, e2 - s).Replace("\r", "\\r").Replace("\n", "\\n");
XTrace.WriteLine("保存配置:{0},差异:\"...{1}...\"", fileName, diff);
XTrace.WriteLine("更新配置:{0},原:\"{1}\",新:\"{2}\"", fileName, ori, diff);
}
File.WriteAllText(fileName, str);
}

View File

@ -29,20 +29,20 @@
private void InitializeComponent()
{
groupBox1 = new GroupBox();
btnDownloadPlugin = new Button();
btnOpenAsync = new Button();
txtServer = new TextBox();
btnOpen = new Button();
label1 = new Label();
groupBox2 = new GroupBox();
btnCallAsync = new Button();
textBox2 = new TextBox();
txtArgument = new TextBox();
label3 = new Label();
btnCall = new Button();
cbApi = new ComboBox();
label2 = new Label();
groupBox3 = new GroupBox();
richTextBox1 = new RichTextBox();
btnDownloadPlugin = new Button();
groupBox1.SuspendLayout();
groupBox2.SuspendLayout();
groupBox3.SuspendLayout();
@ -65,6 +65,17 @@
groupBox1.TabStop = false;
groupBox1.Text = "数据库连接";
//
// btnDownloadPlugin
//
btnDownloadPlugin.Location = new Point(766, 19);
btnDownloadPlugin.Margin = new Padding(3, 2, 3, 2);
btnDownloadPlugin.Name = "btnDownloadPlugin";
btnDownloadPlugin.Size = new Size(106, 45);
btnDownloadPlugin.TabIndex = 5;
btnDownloadPlugin.Text = "插件下载";
btnDownloadPlugin.UseVisualStyleBackColor = true;
btnDownloadPlugin.Click += btnDownloadPlugin_Click;
//
// btnOpenAsync
//
btnOpenAsync.Location = new Point(630, 19);
@ -108,7 +119,7 @@
//
groupBox2.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
groupBox2.Controls.Add(btnCallAsync);
groupBox2.Controls.Add(textBox2);
groupBox2.Controls.Add(txtArgument);
groupBox2.Controls.Add(label3);
groupBox2.Controls.Add(btnCall);
groupBox2.Controls.Add(cbApi);
@ -133,12 +144,12 @@
btnCallAsync.UseVisualStyleBackColor = true;
btnCallAsync.Click += btnCallAsync_Click;
//
// textBox2
// txtArgument
//
textBox2.Location = new Point(96, 79);
textBox2.Name = "textBox2";
textBox2.Size = new Size(346, 26);
textBox2.TabIndex = 4;
txtArgument.Location = new Point(96, 79);
txtArgument.Name = "txtArgument";
txtArgument.Size = new Size(346, 26);
txtArgument.TabIndex = 4;
//
// label3
//
@ -199,17 +210,6 @@
richTextBox1.TabIndex = 0;
richTextBox1.Text = "";
//
// btnDownloadPlugin
//
btnDownloadPlugin.Location = new Point(766, 19);
btnDownloadPlugin.Margin = new Padding(3, 2, 3, 2);
btnDownloadPlugin.Name = "btnDownloadPlugin";
btnDownloadPlugin.Size = new Size(106, 45);
btnDownloadPlugin.TabIndex = 5;
btnDownloadPlugin.Text = "插件下载";
btnDownloadPlugin.UseVisualStyleBackColor = true;
btnDownloadPlugin.Click += btnDownloadPlugin_Click;
//
// FrmMain
//
AutoScaleDimensions = new SizeF(10F, 20F);
@ -243,7 +243,7 @@
private Button btnCall;
private ComboBox cbApi;
private Label label2;
private TextBox textBox2;
private TextBox txtArgument;
private Label label3;
private Button btnOpenAsync;
private Button btnCallAsync;

View File

@ -3,6 +3,7 @@ using NewLife;
using NewLife.Log;
using NewLife.Reflection;
using NewLife.Remoting;
using NewLife.Serialization;
using NewLife.Threading;
using NewLife.Web;
@ -129,13 +130,15 @@ public partial class FrmMain : Form
private void btnCall_Click(object sender, EventArgs e)
{
var act = cbApi.Text.Substring(" ", "(");
var rs = _client.Invoke<String>(act, null);
var args = txtArgument.Text.Trim().DecodeJson();
var rs = _client.Invoke<String>(act, args);
}
private async void btnCallAsync_Click(object sender, EventArgs e)
{
var act = cbApi.Text.Substring(" ", "(");
var rs = await _client.InvokeAsync<String>(act, null);
var args = txtArgument.Text.Trim().DecodeJson();
var rs = await _client.InvokeAsync<String>(act, args);
}
private void btnDownloadPlugin_Click(object sender, EventArgs e)

View File

@ -42,6 +42,6 @@ star?.Service?.Register("EchoServer", () => $"tcp://*:{server.Port},udp://*:{ser
// 阻塞,等待友好退出
var host = services.BuildHost();
(host as Host).MaxTime = 5_000;
//(host as Host).MaxTime = 5_000;
await host.RunAsync();
server.Stop("stop");