【重构】为与LubanAssistant共享代码而略微调整了一些.net5与.net 4.7 之间不兼容的代码
parent
2f9c970730
commit
8288591827
|
|
@ -23,13 +23,21 @@ namespace Luban.Common.Utils
|
||||||
public static string GetFileName(string path)
|
public static string GetFileName(string path)
|
||||||
{
|
{
|
||||||
int index = path.Replace('\\', '/').LastIndexOf('/');
|
int index = path.Replace('\\', '/').LastIndexOf('/');
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
return index >= 0 ? path[(index + 1)..] : path;
|
return index >= 0 ? path[(index + 1)..] : path;
|
||||||
|
#else
|
||||||
|
return index >= 0 ? path.Substring(index + 1, path.Length - index - 1) : path;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetParent(string path)
|
public static string GetParent(string path)
|
||||||
{
|
{
|
||||||
int index = path.Replace('\\', '/').LastIndexOf('/');
|
int index = path.Replace('\\', '/').LastIndexOf('/');
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
return index >= 0 ? path[..index] : ".";
|
return index >= 0 ? path[..index] : ".";
|
||||||
|
#else
|
||||||
|
return index >= 0 ? path.Substring(0, index) : ".";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFileNameWithoutExt(string file)
|
public static string GetFileNameWithoutExt(string file)
|
||||||
|
|
@ -62,7 +70,11 @@ namespace Luban.Common.Utils
|
||||||
}
|
}
|
||||||
var f = new FileInfo(file);
|
var f = new FileInfo(file);
|
||||||
string fname = f.Name;
|
string fname = f.Name;
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
return !fname.StartsWith('.') && !fname.StartsWith('_') && !fname.StartsWith('~');
|
return !fname.StartsWith('.') && !fname.StartsWith('_') && !fname.StartsWith('~');
|
||||||
|
#else
|
||||||
|
return !fname.StartsWith(".") && !fname.StartsWith("_") && !fname.StartsWith("~");
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
[ThreadStatic]
|
[ThreadStatic]
|
||||||
|
|
@ -100,6 +112,45 @@ namespace Luban.Common.Utils
|
||||||
return Standardize(Path.Combine(parent, sub));
|
return Standardize(Path.Combine(parent, sub));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool IsExcelFile(string fullName)
|
||||||
|
{
|
||||||
|
return fullName.EndsWith(".csv", StringComparison.Ordinal)
|
||||||
|
|| fullName.EndsWith(".xls", StringComparison.Ordinal)
|
||||||
|
|| fullName.EndsWith(".xlsx", StringComparison.Ordinal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (string, string) SplitFileAndSheetName(string url)
|
||||||
|
{
|
||||||
|
int sheetSepIndex = url.IndexOf('@');
|
||||||
|
if (sheetSepIndex < 0)
|
||||||
|
{
|
||||||
|
return (url, null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int lastPathSep = url.LastIndexOf('/', sheetSepIndex);
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
|
if (lastPathSep >= 0)
|
||||||
|
{
|
||||||
|
return (url[0..(lastPathSep + 1)] + url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (lastPathSep >= 0)
|
||||||
|
{
|
||||||
|
return (url.Substring(0, lastPathSep + 1) + url.Substring(sheetSepIndex + 1), url.Substring(lastPathSep + 1, sheetSepIndex - lastPathSep - 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return (url.Substring(sheetSepIndex + 1), url.Substring(lastPathSep + 1, sheetSepIndex - lastPathSep - 1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task SaveFileAsync(string relateDir, string filePath, byte[] content)
|
public static async Task SaveFileAsync(string relateDir, string filePath, byte[] content)
|
||||||
{
|
{
|
||||||
// 调用此接口时,已保证 文件必然是改变的,不用再检查对比文件
|
// 调用此接口时,已保证 文件必然是改变的,不用再检查对比文件
|
||||||
|
|
@ -131,7 +182,12 @@ namespace Luban.Common.Utils
|
||||||
s_logger.Info("[new] {file}", outputPath);
|
s_logger.Info("[new] {file}", outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
await File.WriteAllBytesAsync(outputPath, content);
|
await File.WriteAllBytesAsync(outputPath, content);
|
||||||
|
#else
|
||||||
|
await Task.Run(() => File.WriteAllBytes(outputPath, content));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<byte[]> ReadAllBytesAsync(string file)
|
public static async Task<byte[]> ReadAllBytesAsync(string file)
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ namespace Luban.Job.Cfg.Cache
|
||||||
cacheList.Sort((a, b) => a.Value.LastAccessTime - b.Value.LastAccessTime);
|
cacheList.Sort((a, b) => a.Value.LastAccessTime - b.Value.LastAccessTime);
|
||||||
for (int i = 0; i < CACHE_FILE_HIGH_WATER_MARK - CACHE_FILE_LOW_WATER_MARK; i++)
|
for (int i = 0; i < CACHE_FILE_HIGH_WATER_MARK - CACHE_FILE_LOW_WATER_MARK; i++)
|
||||||
{
|
{
|
||||||
_caches.Remove(cacheList[i].Key, out _);
|
_caches.TryRemove(cacheList[i].Key, out _);
|
||||||
}
|
}
|
||||||
s_logger.Info("ShrinkCaches. after shrink, cache file num:{}", _caches.Count);
|
s_logger.Info("ShrinkCaches. after shrink, cache file num:{}", _caches.Count);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.DataSources.Excel;
|
using Luban.Job.Cfg.DataSources.Excel;
|
||||||
|
|
|
||||||
|
|
@ -317,11 +317,11 @@ namespace Luban.Job.Cfg.DataCreators
|
||||||
public DType Accept(TMap type, Sheet.NamedRow x, bool multirow, bool nullable)
|
public DType Accept(TMap type, Sheet.NamedRow x, bool multirow, bool nullable)
|
||||||
{
|
{
|
||||||
var map = new Dictionary<DType, DType>();
|
var map = new Dictionary<DType, DType>();
|
||||||
foreach (var (key, keyTitle) in x.Titles)
|
foreach (var e in x.Titles)
|
||||||
{
|
{
|
||||||
if (TryCreateColumnStream(x, keyTitle, out var stream))
|
if (TryCreateColumnStream(x, e.Value, out var stream))
|
||||||
{
|
{
|
||||||
var keyData = type.KeyType.Apply(StringDataCreator.Ins, key);
|
var keyData = type.KeyType.Apply(StringDataCreator.Ins, e.Key);
|
||||||
var valueData = type.ValueType.Apply(ExcelDataCreator.Ins, null, stream, DefAssembly.LocalAssebmly);
|
var valueData = type.ValueType.Apply(ExcelDataCreator.Ins, null, stream, DefAssembly.LocalAssebmly);
|
||||||
map.Add(keyData, valueData);
|
map.Add(keyData, valueData);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
|
|
|
||||||
|
|
@ -18,19 +18,7 @@ namespace Luban.Job.Cfg.DataSources.Excel
|
||||||
|
|
||||||
private System.Text.Encoding DetectCsvEncoding(Stream fs)
|
private System.Text.Encoding DetectCsvEncoding(Stream fs)
|
||||||
{
|
{
|
||||||
Ude.CharsetDetector cdet = new Ude.CharsetDetector();
|
return System.Text.Encoding.Default;
|
||||||
cdet.Feed(fs);
|
|
||||||
cdet.DataEnd();
|
|
||||||
fs.Seek(0, SeekOrigin.Begin);
|
|
||||||
if (cdet.Charset != null)
|
|
||||||
{
|
|
||||||
s_logger.Debug("Charset: {}, confidence: {}", cdet.Charset, cdet.Confidence);
|
|
||||||
return System.Text.Encoding.GetEncoding(cdet.Charset) ?? System.Text.Encoding.Default;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return System.Text.Encoding.Default;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Load(string rawUrl, string sheetName, Stream stream)
|
public override void Load(string rawUrl, string sheetName, Stream stream)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using ExcelDataReader;
|
using ExcelDataReader;
|
||||||
using Luban.Job.Cfg.DataCreators;
|
using Luban.Job.Cfg.DataCreators;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
using Luban.Job.Cfg.Utils;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace Luban.Job.Cfg.Datas
|
namespace Luban.Job.Cfg.Datas
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Common.Utils;
|
using Luban.Common.Utils;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.DataSources.Excel;
|
using Luban.Job.Cfg.DataSources.Excel;
|
||||||
|
|
@ -36,7 +37,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
private readonly List<string> _defaultGroups = new List<string>();
|
private readonly List<string> _defaultGroups = new List<string>();
|
||||||
|
|
||||||
public CfgDefLoader(RemoteAgent agent) : base(agent)
|
public CfgDefLoader(IAgent agent) : base(agent)
|
||||||
{
|
{
|
||||||
RegisterRootDefineHandler("importexcel", AddImportExcel);
|
RegisterRootDefineHandler("importexcel", AddImportExcel);
|
||||||
RegisterRootDefineHandler("patch", AddPatch);
|
RegisterRootDefineHandler("patch", AddPatch);
|
||||||
|
|
@ -139,14 +140,22 @@ namespace Luban.Job.Cfg.Defs
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrWhiteSpace(attr))
|
if (!string.IsNullOrWhiteSpace(attr))
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
foreach (var validatorStr in attr.Split('#', StringSplitOptions.RemoveEmptyEntries))
|
foreach (var validatorStr in attr.Split('#', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
#else
|
||||||
|
foreach (var validatorStr in attr.Split('#'))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
var sepIndex = validatorStr.IndexOf(':');
|
var sepIndex = validatorStr.IndexOf(':');
|
||||||
if (sepIndex < 0)
|
if (sepIndex <= 0)
|
||||||
{
|
{
|
||||||
throw new Exception($"定义文件:{defineFile} key:'{key}' attr:'{attr}' 不是合法的 validator 定义 (key1:value1#key2:value2 ...)");
|
throw new Exception($"定义文件:{defineFile} key:'{key}' attr:'{attr}' 不是合法的 validator 定义 (key1:value1#key2:value2 ...)");
|
||||||
}
|
}
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
result.Add(new Validator() { Type = validatorStr[..sepIndex], Rule = validatorStr[(sepIndex + 1)..] });
|
result.Add(new Validator() { Type = validatorStr[..sepIndex], Rule = validatorStr[(sepIndex + 1)..] });
|
||||||
|
#else
|
||||||
|
result.Add(new Validator() { Type = validatorStr.Substring(0, sepIndex), Rule = validatorStr.Substring(sepIndex + 1, validatorStr.Length - sepIndex - 1) });
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -356,7 +365,11 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
for (int i = 1; i < attrs.Length; i++)
|
for (int i = 1; i < attrs.Length; i++)
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
var pair = attrs[i].Split('=', 2);
|
var pair = attrs[i].Split('=', 2);
|
||||||
|
#else
|
||||||
|
var pair = attrs[i].Split(new char[] { '=' }, 2);
|
||||||
|
#endif
|
||||||
if (pair.Length != 2)
|
if (pair.Length != 2)
|
||||||
{
|
{
|
||||||
throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' attr:'{attrs[i]}' is invalid!");
|
throw new Exception($"table:'{table.Name}' file:{file.OriginFile} title:'{f.Name}' attr:'{attrs[i]}' is invalid!");
|
||||||
|
|
|
||||||
|
|
@ -7,24 +7,5 @@ namespace Luban.Job.Cfg.Defs
|
||||||
public abstract class CfgDefTypeBase : DefTypeBase
|
public abstract class CfgDefTypeBase : DefTypeBase
|
||||||
{
|
{
|
||||||
public DefAssembly Assembly => (DefAssembly)AssemblyBase;
|
public DefAssembly Assembly => (DefAssembly)AssemblyBase;
|
||||||
|
|
||||||
public virtual string UeBpName => "U" + Name;
|
|
||||||
|
|
||||||
public virtual string UeBpFullName => TypeUtil.MakeCppJoinedFullName("U" + Namespace, Name);
|
|
||||||
|
|
||||||
public string UeBpHeaderFileName => "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName);
|
|
||||||
|
|
||||||
public string UeBpHeaderFileNameWithoutSuffix => "bp_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePathWithoutSuffix(FullName);
|
|
||||||
|
|
||||||
public string EditorUeFullName => TypeUtil.MakeCppFullName(Namespace, Name);
|
|
||||||
|
|
||||||
public string UeFname => "F" + Name;
|
|
||||||
|
|
||||||
public string UeFfullName => TypeUtil.MakeCppFullName(Namespace, UeFname);
|
|
||||||
|
|
||||||
public string UeHeaderFileName => RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName);
|
|
||||||
|
|
||||||
public string UeEditorHeaderFileName => "editor_" + RenderFileUtil.GetUeCppDefTypeHeaderFilePath(FullName);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Job.Cfg.Datas;
|
using Luban.Job.Cfg.Datas;
|
||||||
using Luban.Job.Cfg.l10n;
|
using Luban.Job.Cfg.l10n;
|
||||||
using Luban.Job.Cfg.RawDefs;
|
using Luban.Job.Cfg.RawDefs;
|
||||||
|
|
@ -43,7 +44,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
|
|
||||||
public TimeZoneInfo TimeZone { get; }
|
public TimeZoneInfo TimeZone { get; }
|
||||||
|
|
||||||
public DefAssembly(string patchName, TimeZoneInfo timezone, List<string> excludeTags, RemoteAgent agent)
|
public DefAssembly(string patchName, TimeZoneInfo timezone, List<string> excludeTags, IAgent agent)
|
||||||
{
|
{
|
||||||
this._patchName = patchName;
|
this._patchName = patchName;
|
||||||
this.TimeZone = timezone;
|
this.TimeZone = timezone;
|
||||||
|
|
@ -153,11 +154,11 @@ namespace Luban.Job.Cfg.Defs
|
||||||
throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 重复引用");
|
throw new Exception($"service:'{targetService.Name}' ref:'{refType}' 重复引用");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach ((var fullTypeName, var type) in this.Types)
|
foreach (var e in this.Types)
|
||||||
{
|
{
|
||||||
if (!refTypes.ContainsKey(fullTypeName) && (type is DefEnum))
|
if (!refTypes.ContainsKey(e.Key) && (e.Value is DefEnum))
|
||||||
{
|
{
|
||||||
refTypes.Add(fullTypeName, type);
|
refTypes.Add(e.Key, e.Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
return DeepCompareTypeDefine.Ins.Compare(this, b, new Dictionary<DefTypeBase, bool>(), new HashSet<DefTypeBase>());
|
return DeepCompareTypeDefine.Ins.Compare(this, b, new Dictionary<DefTypeBase, bool>(), new HashSet<DefTypeBase>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
public string GoBinImport
|
public string GoBinImport
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
@ -129,6 +130,7 @@ namespace Luban.Job.Cfg.Defs
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
public DefBean(CfgBean b) : base(b)
|
public DefBean(CfgBean b) : base(b)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Job.Cfg.RawDefs;
|
using Luban.Job.Cfg.RawDefs;
|
||||||
using Luban.Job.Common.Types;
|
using Luban.Job.Common.Types;
|
||||||
using Luban.Job.Common.Utils;
|
using Luban.Job.Common.Utils;
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ namespace Luban.Job.Cfg.Generate
|
||||||
postContent?.Invoke(fileContent);
|
postContent?.Invoke(fileContent);
|
||||||
|
|
||||||
var file = outputFile;
|
var file = outputFile;
|
||||||
var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join('\n', fileContent));
|
var md5 = CacheFileUtil.GenMd5AndAddCache(file, string.Join("\n", fileContent));
|
||||||
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
ctx.GenCodeFilesInOutputCodeDir.Add(new FileInfo() { FilePath = file, MD5 = md5 });
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,9 @@ namespace Luban.Job.Cfg.TypeVisitors
|
||||||
|| f1.NeedExport != f2.NeedExport
|
|| f1.NeedExport != f2.NeedExport
|
||||||
|| f1.Index != f2.Index
|
|| f1.Index != f2.Index
|
||||||
|| f1.Sep != f2.Sep
|
|| f1.Sep != f2.Sep
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
|| f1.ResourceTag != f2.ResourceTag
|
|| f1.ResourceTag != f2.ResourceTag
|
||||||
|
#endif
|
||||||
|| f1.IsMultiRow != f2.IsMultiRow
|
|| f1.IsMultiRow != f2.IsMultiRow
|
||||||
|| f1.CType.IsNullable != f2.CType.IsNullable
|
|| f1.CType.IsNullable != f2.CType.IsNullable
|
||||||
|| f1.CType.GetType() != f2.CType.GetType()
|
|| f1.CType.GetType() != f2.CType.GetType()
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
using Bright.Collections;
|
||||||
using Luban.Job.Cfg.Defs;
|
using Luban.Job.Cfg.Defs;
|
||||||
using Luban.Job.Common.Defs;
|
using Luban.Job.Common.Defs;
|
||||||
using Luban.Job.Common.Types;
|
using Luban.Job.Common.Types;
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@ namespace Luban.Job.Cfg.Utils
|
||||||
public string SheetName { get; set; }
|
public string SheetName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task<List<InputFileInfo>> CollectInputFilesAsync(RemoteAgent agent, IEnumerable<string> files, string dataDir)
|
public static async Task<List<InputFileInfo>> CollectInputFilesAsync(IAgent agent, IEnumerable<string> files, string dataDir)
|
||||||
{
|
{
|
||||||
var collectTasks = new List<Task<List<InputFileInfo>>>();
|
var collectTasks = new List<Task<List<InputFileInfo>>>();
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
(var actualFile, var sheetName) = RenderFileUtil.SplitFileAndSheetName(FileUtil.Standardize(file));
|
(var actualFile, var sheetName) = FileUtil.SplitFileAndSheetName(FileUtil.Standardize(file));
|
||||||
var actualFullPath = FileUtil.Combine(dataDir, actualFile);
|
var actualFullPath = FileUtil.Combine(dataDir, actualFile);
|
||||||
var originFullPath = FileUtil.Combine(dataDir, file);
|
var originFullPath = FileUtil.Combine(dataDir, file);
|
||||||
//s_logger.Info("== get input file:{file} actualFile:{actual}", file, actualFile);
|
//s_logger.Info("== get input file:{file} actualFile:{actual}", file, actualFile);
|
||||||
|
|
@ -71,7 +71,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
// return CollectInputFilesAsync(agent, table.InputFiles, dataDir)
|
// return CollectInputFilesAsync(agent, table.InputFiles, dataDir)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static async Task GenerateLoadRecordFromFileTasksAsync(RemoteAgent agent, DefTable table, string dataDir, List<string> inputFiles2, List<Task<List<Record>>> tasks)
|
public static async Task GenerateLoadRecordFromFileTasksAsync(IAgent agent, DefTable table, string dataDir, List<string> inputFiles2, List<Task<List<Record>>> tasks)
|
||||||
{
|
{
|
||||||
var inputFileInfos = await CollectInputFilesAsync(agent, inputFiles2, dataDir);
|
var inputFileInfos = await CollectInputFilesAsync(agent, inputFiles2, dataDir);
|
||||||
|
|
||||||
|
|
@ -93,7 +93,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
file.OriginFile,
|
file.OriginFile,
|
||||||
file.SheetName,
|
file.SheetName,
|
||||||
await agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5),
|
await agent.GetFromCacheOrReadAllBytesAsync(file.ActualFile, file.MD5),
|
||||||
RenderFileUtil.IsExcelFile(file.ActualFile));
|
FileUtil.IsExcelFile(file.ActualFile));
|
||||||
|
|
||||||
FileRecordCacheManager.Ins.AddCacheLoadedRecords(table, file.MD5, file.SheetName, res);
|
FileRecordCacheManager.Ins.AddCacheLoadedRecords(table, file.MD5, file.SheetName, res);
|
||||||
|
|
||||||
|
|
@ -102,7 +102,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadTableAsync(RemoteAgent agent, DefTable table, string dataDir, string patchName, string patchDataDir)
|
public static async Task LoadTableAsync(IAgent agent, DefTable table, string dataDir, string patchName, string patchDataDir)
|
||||||
{
|
{
|
||||||
var mainLoadTasks = new List<Task<List<Record>>>();
|
var mainLoadTasks = new List<Task<List<Record>>>();
|
||||||
var mainGenerateTask = GenerateLoadRecordFromFileTasksAsync(agent, table, dataDir, table.InputFiles, mainLoadTasks);
|
var mainGenerateTask = GenerateLoadRecordFromFileTasksAsync(agent, table, dataDir, table.InputFiles, mainLoadTasks);
|
||||||
|
|
@ -145,7 +145,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
s_logger.Trace("table:{name} record num:{num}", table.FullName, mainRecords.Count);
|
s_logger.Trace("table:{name} record num:{num}", table.FullName, mainRecords.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadCfgDataAsync(RemoteAgent agent, DefAssembly ass, string dataDir, string patchName, string patchDataDir)
|
public static async Task LoadCfgDataAsync(IAgent agent, DefAssembly ass, string dataDir, string patchName, string patchDataDir)
|
||||||
{
|
{
|
||||||
var ctx = agent;
|
var ctx = agent;
|
||||||
List<DefTable> exportTables = ass.Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList();
|
List<DefTable> exportTables = ass.Types.Values.Where(t => t is DefTable ct && ct.NeedExport).Select(t => (DefTable)t).ToList();
|
||||||
|
|
@ -200,7 +200,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadTextTablesAsync(RemoteAgent agent, DefAssembly ass, string baseDir, string textTableFiles)
|
public static async Task LoadTextTablesAsync(IAgent agent, DefAssembly ass, string baseDir, string textTableFiles)
|
||||||
{
|
{
|
||||||
var tasks = new List<Task<byte[]>>();
|
var tasks = new List<Task<byte[]>>();
|
||||||
var files = textTableFiles.Split(',');
|
var files = textTableFiles.Split(',');
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ namespace Luban.Job.Cfg.Utils
|
||||||
};
|
};
|
||||||
public static DDateTime CreateDateTime(string x)
|
public static DDateTime CreateDateTime(string x)
|
||||||
{
|
{
|
||||||
DateTime dateTime = DateTime.ParseExact(x, dateTimeFormats, System.Globalization.CultureInfo.InvariantCulture);
|
DateTime dateTime = DateTime.ParseExact(x, dateTimeFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None);
|
||||||
return new DDateTime(dateTime);
|
return new DDateTime(dateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,11 @@ namespace Luban.Job.Cfg.Validators
|
||||||
|
|
||||||
public static string GetActualTableName(string table)
|
public static string GetActualTableName(string table)
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
return table.EndsWith("?") ? table[0..^1] : table;
|
return table.EndsWith("?") ? table[0..^1] : table;
|
||||||
|
#else
|
||||||
|
return table.EndsWith("?") ? table.Substring(0, table.Length - 1) : table;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefValidator(List<string> tables)
|
public RefValidator(List<string> tables)
|
||||||
|
|
@ -40,7 +44,11 @@ namespace Luban.Job.Cfg.Validators
|
||||||
if (table.EndsWith("?"))
|
if (table.EndsWith("?"))
|
||||||
{
|
{
|
||||||
zeroAble = true;
|
zeroAble = true;
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
actualTable = table[0..^1];
|
actualTable = table[0..^1];
|
||||||
|
#else
|
||||||
|
actualTable = table.Substring(0, table.Length - 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +72,11 @@ namespace Luban.Job.Cfg.Validators
|
||||||
string actualTable;
|
string actualTable;
|
||||||
if (table.EndsWith("?"))
|
if (table.EndsWith("?"))
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
actualTable = table[0..^1];
|
actualTable = table[0..^1];
|
||||||
|
#else
|
||||||
|
actualTable = table.Substring(0, table.Length - 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -85,7 +97,11 @@ namespace Luban.Job.Cfg.Validators
|
||||||
|
|
||||||
foreach (var table in Tables)
|
foreach (var table in Tables)
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
string actualTable = table.EndsWith("?") ? table[0..^1] : table;
|
string actualTable = table.EndsWith("?") ? table[0..^1] : table;
|
||||||
|
#else
|
||||||
|
string actualTable = table.EndsWith("?") ? table.Substring(0, table.Length - 1) : table;
|
||||||
|
#endif
|
||||||
var ct = def.Assembly.GetCfgTable(actualTable);
|
var ct = def.Assembly.GetCfgTable(actualTable);
|
||||||
if (ct == null)
|
if (ct == null)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Luban.Job.Common.Defs
|
||||||
{
|
{
|
||||||
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
private static readonly NLog.Logger s_logger = NLog.LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
protected RemoteAgent Agent { get; }
|
protected IAgent Agent { get; }
|
||||||
|
|
||||||
public string RootDir { get; private set; }
|
public string RootDir { get; private set; }
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ namespace Luban.Job.Common.Defs
|
||||||
protected readonly List<PEnum> _enums = new List<PEnum>();
|
protected readonly List<PEnum> _enums = new List<PEnum>();
|
||||||
protected readonly List<Bean> _beans = new List<Bean>();
|
protected readonly List<Bean> _beans = new List<Bean>();
|
||||||
|
|
||||||
protected CommonDefLoader(RemoteAgent agent)
|
protected CommonDefLoader(IAgent agent)
|
||||||
{
|
{
|
||||||
Agent = agent;
|
Agent = agent;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ namespace Luban.Job.Common.Defs
|
||||||
|
|
||||||
public Dictionary<string, DefTypeBase> Types { get; } = new Dictionary<string, DefTypeBase>();
|
public Dictionary<string, DefTypeBase> Types { get; } = new Dictionary<string, DefTypeBase>();
|
||||||
|
|
||||||
public RemoteAgent Agent { get; protected set; }
|
public IAgent Agent { get; protected set; }
|
||||||
|
|
||||||
public string TopModule { get; protected set; }
|
public string TopModule { get; protected set; }
|
||||||
|
|
||||||
|
|
@ -117,7 +117,11 @@ namespace Luban.Job.Common.Defs
|
||||||
|
|
||||||
public TType CreateType(string module, string type)
|
public TType CreateType(string module, string type)
|
||||||
{
|
{
|
||||||
|
#if LUBAN_ASSISTANT
|
||||||
|
int sepIndex = type.IndexOf(',');
|
||||||
|
#else
|
||||||
int sepIndex = type.IndexOf(',', System.StringComparison.Ordinal);
|
int sepIndex = type.IndexOf(',', System.StringComparison.Ordinal);
|
||||||
|
#endif
|
||||||
if (sepIndex > 0)
|
if (sepIndex > 0)
|
||||||
{
|
{
|
||||||
string containerType = type.Substring(0, sepIndex).Trim();
|
string containerType = type.Substring(0, sepIndex).Trim();
|
||||||
|
|
@ -134,14 +138,22 @@ namespace Luban.Job.Common.Defs
|
||||||
bool nullable;
|
bool nullable;
|
||||||
var (type, tags) = DefUtil.ParseType(rawType);
|
var (type, tags) = DefUtil.ParseType(rawType);
|
||||||
|
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
if (type.EndsWith('?'))
|
if (type.EndsWith('?'))
|
||||||
|
#else
|
||||||
|
if (type.EndsWith("?"))
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
if (!SupportNullable)
|
if (!SupportNullable)
|
||||||
{
|
{
|
||||||
throw new Exception($"not support nullable type:'{module}.{type}'");
|
throw new Exception($"not support nullable type:'{module}.{type}'");
|
||||||
}
|
}
|
||||||
nullable = true;
|
nullable = true;
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
type = type[0..^1];
|
type = type[0..^1];
|
||||||
|
#else
|
||||||
|
type = type.Substring(0, type.Length - 1);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ using Luban.Job.Common.Utils;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Bright.Collections;
|
||||||
|
|
||||||
namespace Luban.Job.Common.Defs
|
namespace Luban.Job.Common.Defs
|
||||||
{
|
{
|
||||||
|
|
@ -11,19 +12,19 @@ namespace Luban.Job.Common.Defs
|
||||||
{
|
{
|
||||||
public class Item
|
public class Item
|
||||||
{
|
{
|
||||||
public string Name { get; init; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
public string Value { get; set; }
|
public string Value { get; set; }
|
||||||
|
|
||||||
public string Alias { get; init; }
|
public string Alias { get; set; }
|
||||||
|
|
||||||
public string AliasOrName => string.IsNullOrWhiteSpace(Alias) ? Name : Alias;
|
public string AliasOrName => string.IsNullOrWhiteSpace(Alias) ? Name : Alias;
|
||||||
|
|
||||||
public int IntValue { get; set; }
|
public int IntValue { get; set; }
|
||||||
|
|
||||||
public string Comment { get; init; }
|
public string Comment { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, string> Tags { get; init; }
|
public Dictionary<string, string> Tags { get; set; }
|
||||||
|
|
||||||
public bool HasTag(string attrName)
|
public bool HasTag(string attrName)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ namespace Luban.Job.Common.Defs
|
||||||
|
|
||||||
public string TopModule => AssemblyBase.TopModule;
|
public string TopModule => AssemblyBase.TopModule;
|
||||||
|
|
||||||
public RemoteAgent Agent => AssemblyBase.Agent;
|
public IAgent Agent => AssemblyBase.Agent;
|
||||||
|
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,11 @@ namespace Luban.Job.Common.Utils
|
||||||
int sepIndex = pair.IndexOfAny(s_attrKeyValueSep);
|
int sepIndex = pair.IndexOfAny(s_attrKeyValueSep);
|
||||||
if (sepIndex >= 0)
|
if (sepIndex >= 0)
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
am.Add(pair[..sepIndex].Trim(), pair[(sepIndex + 1)..].Trim());
|
am.Add(pair[..sepIndex].Trim(), pair[(sepIndex + 1)..].Trim());
|
||||||
|
#else
|
||||||
|
am.Add(pair.Substring(0, sepIndex).Trim(), pair.Substring(sepIndex + 1).Trim());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +44,11 @@ namespace Luban.Job.Common.Utils
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#if !LUBAN_ASSISTANT
|
||||||
return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..]));
|
return (s[..sepIndex], ParseAttrs(s[(sepIndex + 1)..]));
|
||||||
|
#else
|
||||||
|
return (s.Substring(0, sepIndex), ParseAttrs(s.Substring(sepIndex + 1)));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,34 +59,6 @@ namespace Luban.Job.Common.Utils
|
||||||
return fullName + ".bin";
|
return fullName + ".bin";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsExcelFile(string fullName)
|
|
||||||
{
|
|
||||||
return fullName.EndsWith(".csv", StringComparison.Ordinal)
|
|
||||||
|| fullName.EndsWith(".xls", StringComparison.Ordinal)
|
|
||||||
|| fullName.EndsWith(".xlsx", StringComparison.Ordinal);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static (string, string) SplitFileAndSheetName(string url)
|
|
||||||
{
|
|
||||||
int sheetSepIndex = url.IndexOf('@');
|
|
||||||
if (sheetSepIndex < 0)
|
|
||||||
{
|
|
||||||
return (url, null);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int lastPathSep = url.LastIndexOf('/', sheetSepIndex);
|
|
||||||
if (lastPathSep >= 0)
|
|
||||||
{
|
|
||||||
return (url[0..(lastPathSep + 1)] + url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return (url[(sheetSepIndex + 1)..], url[(lastPathSep + 1)..sheetSepIndex]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly static Dictionary<string, ELanguage> s_name2Lans = new()
|
private readonly static Dictionary<string, ELanguage> s_name2Lans = new()
|
||||||
{
|
{
|
||||||
{ "cs", ELanguage.CS },
|
{ "cs", ELanguage.CS },
|
||||||
|
|
|
||||||
|
|
@ -126,7 +126,7 @@ namespace Luban.Server.Common
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
_caches.Remove(c.MD5, out var _);
|
_caches.Remove(c.MD5);
|
||||||
TotalBytes -= c.Content.Length;
|
TotalBytes -= c.Content.Length;
|
||||||
s_logger.Info("remove cache. file:{file} md5:{md5} size:{size}, total bytes:{bytes} after remove.", c.FileName, c.MD5, c.Content.Length, TotalBytes);
|
s_logger.Info("remove cache. file:{file} md5:{md5} size:{size}, total bytes:{bytes} after remove.", c.FileName, c.MD5, c.Content.Length, TotalBytes);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue