From 46ccf6868bd57948c05350b08a98a34485fcc82f Mon Sep 17 00:00:00 2001 From: walon Date: Tue, 30 Nov 2021 20:14:57 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=9C=A8=E6=9F=90=E4=BA=9B=E6=9C=BA=E5=99=A8=E4=B8=8A?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=89=BE=E5=88=B0"Asia/Shanghai"=EF=BC=8C?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E5=90=AF=E5=8A=A8=E5=A4=B1=E8=B4=A5=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82=E6=96=B0=E5=A2=9E=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=90=8E=E5=B0=9D=E8=AF=95"China=20Standard=20Time"=20?= =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE=E5=A4=8DLuban.Cli?= =?UTF-8?q?entServer=E6=9C=AA=E5=88=9D=E5=A7=8B=E5=8C=96DefaultTimeZone?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E8=87=B4=E9=BB=98=E8=AE=A4=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E4=B8=BAUtc=E7=9A=84bug=EF=BC=8C=E4=B8=A5=E9=87=8D=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 59 +++++++++++++++++++ src/Luban.ClientServer/Program.cs | 2 + src/Luban.Common/Source/Utils/TimeZoneUtil.cs | 39 ++++++++++++ src/Luban.Server/Source/Program.cs | 6 +- 4 files changed, 103 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f421b83..76ed3f9 100644 --- a/README.md +++ b/README.md @@ -325,6 +325,44 @@ xml中定义如下 +或者可以用多级标题头对每个元素单独限定 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
##idnamerewards
##typeintstringlist,Reward
##+012
##+ + + item_idnumdescitem_idnumdescitem_idnumdesc
1task1110desc1212desc2313desc3
2task1330desc3440desc4
3task1550desc5
### 多行结构列表 有时候列表结构的每个结构字段较多,如果水平展开则占据太多列,不方便编辑,如果拆表,无论程序还是策划都不方便,此时可以使用多行模式。支持任意层次的多行结构列表(也即多行结构中的每个元素也可以是多行), name&multi_rows=1或者 *name 都可以表达一个多行解析的字段。 @@ -579,6 +617,27 @@ xml中定义如下 + + ##+ + + + 0 + 1 + 2 + + + ##+ + + + item_idnumdesc + item_idnumdesc + item_idnumdesc + + +1task1110desc1212desc2313desc3 +2task1330desc3440desc4 +3task1550desc5 + ### 可空数据类型 配置数据中经常有空值的语义需求,实际项目中往往混杂地使用0或-1表达空值,既不自然清晰也不统一。luban借鉴了c#中的可空变量的概念,特地提供可空数据支持。所有原生数据类型,以及enum、bean、和多态bean类型都有相应的可空数据类型。定义方式为 <类型名>?,与c#里的Nullable类型定义方式相同。例如 bool?,int?,long?,double?, EColor?, DemoType? diff --git a/src/Luban.ClientServer/Program.cs b/src/Luban.ClientServer/Program.cs index e6b91ab..efff373 100644 --- a/src/Luban.ClientServer/Program.cs +++ b/src/Luban.ClientServer/Program.cs @@ -219,6 +219,8 @@ Options: LogUtil.InitSimpleNLogConfigure(NLog.LogLevel.FromString(options.LogLevel)); s_logger = NLog.LogManager.GetCurrentClassLogger(); + TimeZoneUtil.InitDefaultTimeZone(""); + int processorCount = System.Environment.ProcessorCount; ThreadPool.SetMinThreads(Math.Max(4, processorCount), 5); ThreadPool.SetMaxThreads(Math.Max(16, processorCount * 4), 10); diff --git a/src/Luban.Common/Source/Utils/TimeZoneUtil.cs b/src/Luban.Common/Source/Utils/TimeZoneUtil.cs index 739b759..83518ce 100644 --- a/src/Luban.Common/Source/Utils/TimeZoneUtil.cs +++ b/src/Luban.Common/Source/Utils/TimeZoneUtil.cs @@ -8,6 +8,45 @@ namespace Luban.Common.Utils { public static class TimeZoneUtil { + private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger(); + + public static void InitDefaultTimeZone(string timeZoneName) + { + if (timeZoneName?.ToLower() == "local") + { + DefaultTimeZone = TimeZoneInfo.Local; + return; + } + if (timeZoneName?.ToLower() == "utc") + { + DefaultTimeZone = TimeZoneInfo.Utc; + return; + } + if (string.IsNullOrEmpty(timeZoneName)) + { + try + { + DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Asia/Shanghai"); + } + catch (Exception) + { + try + { + DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById("China Standard Time"); + } + catch (Exception ex) + { + s_logger.Error(ex); + throw new ArgumentException("The default timezone ID 'Asia/Shanghai' and 'China Standard Time' was not found on local computer. please set valid timezone manually."); + } + } + } + else + { + DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName); + } + } + public static TimeZoneInfo DefaultTimeZone { get; set; } = TimeZoneInfo.Utc; } } diff --git a/src/Luban.Server/Source/Program.cs b/src/Luban.Server/Source/Program.cs index 08579b2..b4106d7 100644 --- a/src/Luban.Server/Source/Program.cs +++ b/src/Luban.Server/Source/Program.cs @@ -26,8 +26,8 @@ namespace Luban.Server [Option("disable_cache", Required = false, HelpText = "disable generation cache")] public bool DisableCache { get; set; } - [Option("i10n:default_timezone", Required = false, HelpText = "default timezone")] - public string L10nDefaultTimeZone { get; set; } = "Asia/Shanghai"; + [Option("i10n:default_timezone", Required = false, HelpText = "default timezone id. 'Asia/Shanghai', 'China Standard Time' eg. you can also use two special values: local,utc")] + public string L10nDefaultTimeZone { get; set; } } static void Main(string[] args) @@ -50,7 +50,7 @@ namespace Luban.Server System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); - TimeZoneUtil.DefaultTimeZone = TimeZoneInfo.FindSystemTimeZoneById(options.L10nDefaultTimeZone); + TimeZoneUtil.InitDefaultTimeZone(options.L10nDefaultTimeZone); GenServer.Ins.Start(false, options.Port, ProtocolStub.Factories);