配置表接入和升级服务器框架到最新版

This commit is contained in:
2025-10-10 17:57:01 +08:00
parent 520d4f37bd
commit 8a302754d6
250 changed files with 6356 additions and 4135 deletions

View File

@@ -6,10 +6,8 @@ public class AppConfig
public string ExcelPath { get; set; }
public string ClientPath { get; set; }
public string ClientJsonPath { get; set; }
public string ClientNamespace { get; set; }
public string ServerPath { get; set; }
public string ServerJsonPath { get; set; }
public string ServerNamespace { get; set; }
public bool GenClient { get; set; }
public bool GenServer { get; set; }

View File

@@ -635,12 +635,6 @@ public sealed class ExcelExporter
var colInfos = isServer ? table.ServerColInfos : table.ClientColInfos;
var exportPath = isServer ? App.Config.ServerPath : App.Config.ClientPath;
var csNamespace = isServer ? App.Config.ServerNamespace : App.Config.ClientNamespace;
if (string.IsNullOrEmpty(csNamespace))
{
csNamespace = "NB";
}
if (colInfos.Count <= 0)
{
return;
@@ -720,7 +714,7 @@ public sealed class ExcelExporter
}
}
var template = ExcelTemplate.Template;
var template = GetTemplate(isServer);
if (fileBuilder.Length > 0)
{
@@ -729,8 +723,7 @@ public sealed class ExcelExporter
FileHelper.CreateDirectory(exportPath);
}
var content = template.Replace("(namespace)", csNamespace)
.Replace("(ConfigName)", csName)
var content = template.Replace("(ConfigName)", csName)
.Replace("(Fields)", fileBuilder.ToString());
File.WriteAllText(Path.Combine(exportPath, $"{csName}.cs"), content);
}
@@ -748,4 +741,10 @@ public sealed class ExcelExporter
return index >= 0;
}
private string GetTemplate(bool isServer)
{
var fileName = isServer ? "TemplateServer.txt" : "TemplateClient.txt";
return File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, fileName));
}
}

View File

@@ -1,103 +0,0 @@
namespace NBConfigBuilder;
public static class ExcelTemplate
{
public static readonly string Template = """
using System;
using ProtoBuf;
using Fantasy;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Concurrent;
#if FANTASY_NET
using Fantasy.ConfigTable;
using Fantasy.Serialize;
#else
using NBC;
using NBC.Serialize;
#endif
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace (namespace)
{
[ProtoContract]
public sealed partial class (ConfigName)Data : ASerialize, IConfigTable, IProto
{
[ProtoMember(1)]
public List<(ConfigName)> List { get; set; } = new List<(ConfigName)>();
#if FANTASY_NET
[ProtoIgnore]
private readonly ConcurrentDictionary<uint, (ConfigName)> _configs = new ConcurrentDictionary<uint, (ConfigName)>();
#else
[ProtoIgnore]
private readonly Dictionary<uint, (ConfigName)> _configs = new Dictionary<uint, (ConfigName)>();
#endif
private static (ConfigName)Data _instance = null;
public static (ConfigName)Data Instance
{
get { return _instance ??= ConfigTableHelper.Load<(ConfigName)Data>(); }
private set => _instance = value;
}
public (ConfigName) Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"(ConfigName) not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out (ConfigName) config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
foreach (var config in List)
{
#if FANTASY_NET
_configs.TryAdd(config.Id, config);
#else
_configs.Add(config.Id, config);
#endif
config.AfterDeserialization();
}
EndInit();
}
public override void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class (ConfigName) : ASerialize, IProto
{(Fields)
}
}
""";
}

View File

@@ -46,17 +46,13 @@
textBoxServerGenJsonPath = new TextBox();
label5 = new Label();
buttonSelectServerJsonPath = new Button();
textBoxClientNamespce = new TextBox();
textBoxServerNamespace = new TextBox();
label6 = new Label();
label7 = new Label();
SuspendLayout();
//
// textBoxExcelPath
//
textBoxExcelPath.Location = new Point(105, 13);
textBoxExcelPath.Location = new Point(81, 13);
textBoxExcelPath.Name = "textBoxExcelPath";
textBoxExcelPath.Size = new Size(301, 23);
textBoxExcelPath.Size = new Size(325, 23);
textBoxExcelPath.TabIndex = 0;
//
// buttonSelectExcelPath
@@ -80,9 +76,9 @@
//
// textBoxClientGenPath
//
textBoxClientGenPath.Location = new Point(105, 42);
textBoxClientGenPath.Location = new Point(81, 42);
textBoxClientGenPath.Name = "textBoxClientGenPath";
textBoxClientGenPath.Size = new Size(301, 23);
textBoxClientGenPath.Size = new Size(325, 23);
textBoxClientGenPath.TabIndex = 3;
//
// buttonSelectClientPath
@@ -100,7 +96,7 @@
checkBoxGenClient.AutoSize = true;
checkBoxGenClient.Checked = true;
checkBoxGenClient.CheckState = CheckState.Checked;
checkBoxGenClient.Location = new Point(412, 160);
checkBoxGenClient.Location = new Point(504, 13);
checkBoxGenClient.Name = "checkBoxGenClient";
checkBoxGenClient.Size = new Size(87, 21);
checkBoxGenClient.TabIndex = 5;
@@ -118,9 +114,9 @@
//
// textBoxServerGenPath
//
textBoxServerGenPath.Location = new Point(105, 100);
textBoxServerGenPath.Location = new Point(81, 100);
textBoxServerGenPath.Name = "textBoxServerGenPath";
textBoxServerGenPath.Size = new Size(301, 23);
textBoxServerGenPath.Size = new Size(325, 23);
textBoxServerGenPath.TabIndex = 7;
//
// label3
@@ -137,7 +133,7 @@
checkBoxGenServer.AutoSize = true;
checkBoxGenServer.Checked = true;
checkBoxGenServer.CheckState = CheckState.Checked;
checkBoxGenServer.Location = new Point(412, 189);
checkBoxGenServer.Location = new Point(504, 42);
checkBoxGenServer.Name = "checkBoxGenServer";
checkBoxGenServer.Size = new Size(87, 21);
checkBoxGenServer.TabIndex = 9;
@@ -157,9 +153,9 @@
//
// buttonRun
//
buttonRun.Location = new Point(504, 13);
buttonRun.Location = new Point(504, 77);
buttonRun.Name = "buttonRun";
buttonRun.Size = new Size(82, 195);
buttonRun.Size = new Size(87, 77);
buttonRun.TabIndex = 12;
buttonRun.Text = "执行";
buttonRun.UseVisualStyleBackColor = true;
@@ -167,9 +163,9 @@
//
// textBoxClientGenJsonPath
//
textBoxClientGenJsonPath.Location = new Point(105, 71);
textBoxClientGenJsonPath.Location = new Point(81, 71);
textBoxClientGenJsonPath.Name = "textBoxClientGenJsonPath";
textBoxClientGenJsonPath.Size = new Size(301, 23);
textBoxClientGenJsonPath.Size = new Size(325, 23);
textBoxClientGenJsonPath.TabIndex = 13;
//
// label4
@@ -193,9 +189,9 @@
//
// textBoxServerGenJsonPath
//
textBoxServerGenJsonPath.Location = new Point(105, 131);
textBoxServerGenJsonPath.Location = new Point(81, 131);
textBoxServerGenJsonPath.Name = "textBoxServerGenJsonPath";
textBoxServerGenJsonPath.Size = new Size(301, 23);
textBoxServerGenJsonPath.Size = new Size(325, 23);
textBoxServerGenJsonPath.TabIndex = 16;
//
// label5
@@ -217,47 +213,11 @@
buttonSelectServerJsonPath.UseVisualStyleBackColor = true;
buttonSelectServerJsonPath.Click += buttonSelectServerJsonPath_Click;
//
// textBoxClientNamespce
//
textBoxClientNamespce.Location = new Point(105, 160);
textBoxClientNamespce.Name = "textBoxClientNamespce";
textBoxClientNamespce.Size = new Size(301, 23);
textBoxClientNamespce.TabIndex = 19;
//
// textBoxServerNamespace
//
textBoxServerNamespace.Location = new Point(105, 189);
textBoxServerNamespace.Name = "textBoxServerNamespace";
textBoxServerNamespace.Size = new Size(301, 23);
textBoxServerNamespace.TabIndex = 20;
//
// label6
//
label6.AutoSize = true;
label6.Location = new Point(7, 161);
label6.Name = "label6";
label6.Size = new Size(92, 17);
label6.TabIndex = 21;
label6.Text = "客户端命名空间";
//
// label7
//
label7.AutoSize = true;
label7.Location = new Point(7, 192);
label7.Name = "label7";
label7.Size = new Size(92, 17);
label7.TabIndex = 22;
label7.Text = "服务端命名空间";
//
// Form1
//
AutoScaleDimensions = new SizeF(7F, 17F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(596, 216);
Controls.Add(label7);
Controls.Add(label6);
Controls.Add(textBoxServerNamespace);
Controls.Add(textBoxClientNamespce);
ClientSize = new Size(599, 165);
Controls.Add(buttonSelectServerJsonPath);
Controls.Add(label5);
Controls.Add(textBoxServerGenJsonPath);
@@ -302,9 +262,5 @@
private TextBox textBoxServerGenJsonPath;
private Label label5;
private Button buttonSelectServerJsonPath;
private TextBox textBoxClientNamespce;
private TextBox textBoxServerNamespace;
private Label label6;
private Label label7;
}
}

View File

@@ -149,9 +149,7 @@ namespace NBConfigBuilder
ServerPath = textBoxServerGenPath.Text,
ServerJsonPath = textBoxServerGenJsonPath.Text,
GenClient = checkBoxGenClient.Checked,
GenServer = checkBoxGenServer.Checked,
ClientNamespace = textBoxClientNamespce.Text,
ServerNamespace = textBoxServerNamespace.Text
GenServer = checkBoxGenServer.Checked
};
App.Config = config;
try
@@ -184,8 +182,6 @@ namespace NBConfigBuilder
checkBoxGenServer.Checked = config.GenServer;
textBoxClientGenJsonPath.Text = config.ClientJsonPath ?? "";
textBoxServerGenJsonPath.Text = config.ServerJsonPath ?? "";
textBoxClientNamespce.Text = config.ClientNamespace ?? "NB";
textBoxServerNamespace.Text = config.ServerNamespace ?? "NB";
}
}
catch (Exception ex)

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Microsoft ResX Schema
Version 2.0
@@ -48,7 +48,7 @@
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter

View File

@@ -21,5 +21,14 @@
<None Update="NLog.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TemplateClient.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TemplateBack.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TemplateServer.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,96 @@
using System;
using ProtoBuf;
using Fantasy;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Concurrent;
#if FANTASY_NET
using Fantasy.ConfigTable;
using Fantasy.Serialize;
#else
using NBC;
using NBC.Serialize;
#endif
// ReSharper disable CollectionNeverUpdated.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
#pragma warning disable CS0169
#pragma warning disable CS8618
#pragma warning disable CS8625
#pragma warning disable CS8603
namespace (namespace)
{
[ProtoContract]
public sealed partial class (ConfigName)Data : ASerialize, IConfigTable, IProto
{
[ProtoMember(1)]
public List<(ConfigName)> List { get; set; } = new List<(ConfigName)>();
#if FANTASY_NET
[ProtoIgnore]
private readonly ConcurrentDictionary<uint, (ConfigName)> _configs = new ConcurrentDictionary<uint, (ConfigName)>();
#else
[ProtoIgnore]
private readonly Dictionary<uint, (ConfigName)> _configs = new Dictionary<uint, (ConfigName)>();
#endif
private static (ConfigName)Data _instance = null;
public static (ConfigName)Data Instance
{
get { return _instance ??= ConfigTableHelper.Load<(ConfigName)Data>(); }
private set => _instance = value;
}
public (ConfigName) Get(uint id, bool check = true)
{
if (_configs.ContainsKey(id))
{
return _configs[id];
}
if (check)
{
throw new Exception($"(ConfigName) not find {id} Id");
}
return null;
}
public bool TryGet(uint id, out (ConfigName) config)
{
config = null;
if (!_configs.ContainsKey(id))
{
return false;
}
config = _configs[id];
return true;
}
public override void AfterDeserialization()
{
foreach (var config in List)
{
#if FANTASY_NET
_configs.TryAdd(config.Id, config);
#else
_configs.Add(config.Id, config);
#endif
config.AfterDeserialization();
}
EndInit();
}
public override void Dispose()
{
Instance = null;
}
}
[ProtoContract]
public sealed partial class (ConfigName) : ASerialize, IProto
{(Fields)
}
}

View File

@@ -0,0 +1,79 @@
using System;
using ProtoBuf;
using Fantasy;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Concurrent;
using NBC;
using NBC.Serialize;
namespace NBF
{
[ProtoContract]
public sealed partial class (ConfigName) : ASerialize, IProto, IConfigTable
{
(Fields)
[ProtoIgnore]
public uint Key => Id;
#region Static
private static ConfigContext<(ConfigName)> Context => ConfigTableHelper.Table<(ConfigName)>();
public static (ConfigName) Get(uint key)
{
return Context.Get(key);
}
public static (ConfigName) Get(Predicate<(ConfigName)> match)
{
return Context.Get(match);
}
public static (ConfigName) Fist()
{
return Context.Fist();
}
public static (ConfigName) Last()
{
return Context.Last();
}
public static (ConfigName) Fist(Predicate<(ConfigName)> match)
{
return Context.Fist(match);
}
public static (ConfigName) Last(Predicate<(ConfigName)> match)
{
return Context.Last(match);
}
public static int Count()
{
return Context.Count();
}
public static int Count(Func<(ConfigName), bool> predicate)
{
return Context.Count(predicate);
}
public static List<(ConfigName)> GetList()
{
return Context.GetList();
}
public static List<(ConfigName)> GetList(Predicate<(ConfigName)> match)
{
return Context.GetList(match);
}
public static void ParseJson(Newtonsoft.Json.Linq.JArray arr)
{
ConfigTableHelper.ParseLine<(ConfigName)>(arr);
}
#endregion
}
}

View File

@@ -0,0 +1,79 @@
using System;
using ProtoBuf;
using Fantasy;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;
using System.Collections.Concurrent;
using Fantasy.Serialize;
using Fantasy.ConfigTable;
namespace NBF
{
[ProtoContract]
public sealed partial class (ConfigName) : ASerialize, IProto, IConfigTable
{
(Fields)
[ProtoIgnore]
public uint Key => Id;
#region Static
private static ConfigContext<(ConfigName)> Context => ConfigTableHelper.Table<(ConfigName)>();
public static (ConfigName) Get(uint key)
{
return Context.Get(key);
}
public static (ConfigName) Get(Predicate<(ConfigName)> match)
{
return Context.Get(match);
}
public static (ConfigName) Fist()
{
return Context.Fist();
}
public static (ConfigName) Last()
{
return Context.Last();
}
public static (ConfigName) Fist(Predicate<(ConfigName)> match)
{
return Context.Fist(match);
}
public static (ConfigName) Last(Predicate<(ConfigName)> match)
{
return Context.Last(match);
}
public static int Count()
{
return Context.Count();
}
public static int Count(Func<(ConfigName), bool> predicate)
{
return Context.Count(predicate);
}
public static List<(ConfigName)> GetList()
{
return Context.GetList();
}
public static List<(ConfigName)> GetList(Predicate<(ConfigName)> match)
{
return Context.GetList(match);
}
public static void ParseJson(Newtonsoft.Json.Linq.JArray arr)
{
ConfigTableHelper.ParseLine<(ConfigName)>(arr);
}
#endregion
}
}