【修复】修复LubanAssistant的编译错误

main
walon 2021-11-30 18:07:16 +08:00
parent ca8e5035ba
commit 57867bc14b
7 changed files with 229 additions and 9 deletions

View File

@ -99,7 +99,7 @@ namespace Luban.Client.Common.Net
private async Task OnGetImportFileOrDirectoryAsync(GetImportFileOrDirectory rpc) private async Task OnGetImportFileOrDirectoryAsync(GetImportFileOrDirectory rpc)
{ {
long t1 = TimeUtil.NowMillis; long t1 = Bright.Time.TimeUtil.NowMillis;
var file = rpc.Arg.FileOrDirName; var file = rpc.Arg.FileOrDirName;
var suffixes = rpc.Arg.InclusiveSuffixs; var suffixes = rpc.Arg.InclusiveSuffixs;
var re = new GetImportFileOrDirectoryRes() var re = new GetImportFileOrDirectoryRes()
@ -139,14 +139,14 @@ namespace Luban.Client.Common.Net
s_logger.Error(e); s_logger.Error(e);
} }
s_logger.Trace(" GetImportFileOrDirectory file:{file} err:{err} cost:{time}", file, re.Err, TimeUtil.NowMillis - t1); s_logger.Trace(" GetImportFileOrDirectory file:{file} err:{err} cost:{time}", file, re.Err, Bright.Time.TimeUtil.NowMillis - t1);
Session.ReplyRpc<GetImportFileOrDirectory, GetImportFileOrDirectoryArg, GetImportFileOrDirectoryRes>(rpc, re); Session.ReplyRpc<GetImportFileOrDirectory, GetImportFileOrDirectoryArg, GetImportFileOrDirectoryRes>(rpc, re);
} }
private async Task OnGetInputFileAsync(GetInputFile rpc) private async Task OnGetInputFileAsync(GetInputFile rpc)
{ {
long t1 = TimeUtil.NowMillis; long t1 = Bright.Time.TimeUtil.NowMillis;
var res = new GetInputFileRes() { Err = Luban.Common.EErrorCode.OK }; var res = new GetInputFileRes() { Err = Luban.Common.EErrorCode.OK };
try try
{ {
@ -158,7 +158,7 @@ namespace Luban.Client.Common.Net
{ {
res.Err = Luban.Common.EErrorCode.READ_FILE_FAIL; res.Err = Luban.Common.EErrorCode.READ_FILE_FAIL;
} }
s_logger.Info(" get input file:{file} err:{err} cost:{time}", rpc.Arg.File, res.Err, TimeUtil.NowMillis - t1); s_logger.Info(" get input file:{file} err:{err} cost:{time}", rpc.Arg.File, res.Err, Bright.Time.TimeUtil.NowMillis - t1);
Session.ReplyRpc<GetInputFile, GetInputFileArg, GetInputFileRes>(rpc, res); Session.ReplyRpc<GetInputFile, GetInputFileArg, GetInputFileRes>(rpc, res);
} }

View File

@ -22,13 +22,13 @@ namespace Luban.Common.Utils
public void StartPhase(string name) public void StartPhase(string name)
{ {
phaseStack.Push(new Phase() { Name = name, StartTime = TimeUtil.NowMillis }); phaseStack.Push(new Phase() { Name = name, StartTime = Bright.Time.TimeUtil.NowMillis });
} }
private Phase EndPhase() private Phase EndPhase()
{ {
var phase = phaseStack.Pop(); var phase = phaseStack.Pop();
phase.EndTime = TimeUtil.NowMillis; phase.EndTime = Bright.Time.TimeUtil.NowMillis;
phase.ElapseTime = phase.EndTime - phase.StartTime; phase.ElapseTime = phase.EndTime - phase.StartTime;
return phase; return phase;
} }

View File

@ -1,3 +1,4 @@
using Bright.Collections;
using Luban.Common.Utils; using Luban.Common.Utils;
using Luban.Job.Cfg.Cache; using Luban.Job.Cfg.Cache;
using Luban.Job.Cfg.Datas; using Luban.Job.Cfg.Datas;

View File

@ -170,16 +170,16 @@ namespace Luban.Job.Cfg.Utils
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();
var genDataTasks = new List<Task>(); var genDataTasks = new List<Task>();
var outputDataFiles = new ConcurrentBag<FileInfo>(); var outputDataFiles = new ConcurrentBag<FileInfo>();
long genDataStartTime = TimeUtil.NowMillis; long genDataStartTime = Bright.Time.TimeUtil.NowMillis;
foreach (DefTable c in exportTables) foreach (DefTable c in exportTables)
{ {
var table = c; var table = c;
genDataTasks.Add(Task.Run(async () => genDataTasks.Add(Task.Run(async () =>
{ {
long beginTime = TimeUtil.NowMillis; long beginTime = Bright.Time.TimeUtil.NowMillis;
await LoadTableAsync(agent, table, dataDir, patchName, patchDataDir, inputConvertDataDir); await LoadTableAsync(agent, table, dataDir, patchName, patchDataDir, inputConvertDataDir);
long endTime = TimeUtil.NowMillis; long endTime = Bright.Time.TimeUtil.NowMillis;
if (endTime - beginTime > 100) if (endTime - beginTime > 100)
{ {
ctx.Info("====== load {0} cost {1} ms ======", table.FullName, (endTime - beginTime)); ctx.Info("====== load {0} cost {1} ms ======", table.FullName, (endTime - beginTime));

View File

@ -243,12 +243,18 @@
<Compile Include="..\Luban.Common\Source\Utils\LogUtil.cs"> <Compile Include="..\Luban.Common\Source\Utils\LogUtil.cs">
<Link>Source\Utils\LogUtil.cs</Link> <Link>Source\Utils\LogUtil.cs</Link>
</Compile> </Compile>
<Compile Include="..\Luban.Common\Source\Utils\TimeZoneUtil.cs">
<Link>Source\Common\TimeZoneUtil.cs</Link>
</Compile>
<Compile Include="..\Luban.Common\Source\Utils\TypeUtil.cs"> <Compile Include="..\Luban.Common\Source\Utils\TypeUtil.cs">
<Link>Source\Utils\TypeUtil.cs</Link> <Link>Source\Utils\TypeUtil.cs</Link>
</Compile> </Compile>
<Compile Include="..\Luban.Common\Source\Utils\XmlUtil.cs"> <Compile Include="..\Luban.Common\Source\Utils\XmlUtil.cs">
<Link>Source\Utils\XmlUtil.cs</Link> <Link>Source\Utils\XmlUtil.cs</Link>
</Compile> </Compile>
<Compile Include="..\Luban.Job.Cfg\Source\Cache\ExcelTableValueTypeDefInfoCacheManager.cs">
<Link>Source\Cache\ExcelTableValueTypeDefInfoCacheManager.cs</Link>
</Compile>
<Compile Include="..\Luban.Job.Cfg\Source\DataConverts\FillSheetVisitor.cs"> <Compile Include="..\Luban.Job.Cfg\Source\DataConverts\FillSheetVisitor.cs">
<Link>Source\DataConverters\FillSheetVisitor.cs</Link> <Link>Source\DataConverters\FillSheetVisitor.cs</Link>
</Compile> </Compile>
@ -501,6 +507,9 @@
<Compile Include="..\Luban.Job.Cfg\Source\Validators\RefValidator.cs"> <Compile Include="..\Luban.Job.Cfg\Source\Validators\RefValidator.cs">
<Link>Source\Validators\RefValidator.cs</Link> <Link>Source\Validators\RefValidator.cs</Link>
</Compile> </Compile>
<Compile Include="..\Luban.Job.Cfg\Source\Validators\ValidatorAttribute.cs">
<Link>Source\Validators\ValidatorAttribute.cs</Link>
</Compile>
<Compile Include="..\Luban.Job.Cfg\Source\Validators\ValidatorFactory.cs"> <Compile Include="..\Luban.Job.Cfg\Source\Validators\ValidatorFactory.cs">
<Link>Source\Validators\ValidatorFactory.cs</Link> <Link>Source\Validators\ValidatorFactory.cs</Link>
</Compile> </Compile>
@ -630,6 +639,9 @@
<Compile Include="..\Luban.Job.Common\Source\TypeVisitors\ITypeFuncVisitor.cs"> <Compile Include="..\Luban.Job.Common\Source\TypeVisitors\ITypeFuncVisitor.cs">
<Link>Source\TypeVisitors\ITypeFuncVisitor.cs</Link> <Link>Source\TypeVisitors\ITypeFuncVisitor.cs</Link>
</Compile> </Compile>
<Compile Include="..\Luban.Job.Common\Source\TypeVisitors\TypeActionVisitorAdaptor.cs">
<Link>Source\TypeVisitors\TypeActionVisitorAdaptor.cs</Link>
</Compile>
<Compile Include="..\Luban.Job.Common\Source\Utils\DefUtil.cs"> <Compile Include="..\Luban.Job.Common\Source\Utils\DefUtil.cs">
<Link>Source\Utils\DefUtil.cs</Link> <Link>Source\Utils\DefUtil.cs</Link>
</Compile> </Compile>
@ -659,6 +671,7 @@
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="app.config" /> <None Include="app.config" />
<None Include="focus_creative_games.pfx" />
<None Include="packages.config" /> <None Include="packages.config" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>
@ -669,6 +682,7 @@
<DependentUpon>Settings.settings</DependentUpon> <DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput> <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile> </Compile>
<Compile Include="Source\Common\ReflectionUtil.cs" />
<Compile Include="Source\Utils\AtomicLong.cs" /> <Compile Include="Source\Utils\AtomicLong.cs" />
<Compile Include="Source\Utils\CacheFileUtil.cs" /> <Compile Include="Source\Utils\CacheFileUtil.cs" />
<Compile Include="Source\Collections\CollectionExtension.cs" /> <Compile Include="Source\Collections\CollectionExtension.cs" />

View File

@ -0,0 +1,205 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
namespace Bright.Common
{
public class ParamInfo
{
public Type Type { get; set; }
public bool ChildType { get; set; }
}
public class SignatureInfo
{
public Type ReturnType { get; set; }
#pragma warning disable CA2227 // 集合属性应为只读
public List<ParamInfo> Params { get; set; }
#pragma warning restore CA2227 // 集合属性应为只读
public Action<Delegate, Attribute> Callback { get; set; }
public bool CanBeStatic { get; set; }
}
public class ReflectionException : Exception
{
public ReflectionException()
{
}
public ReflectionException(string message) : base(message)
{
}
public ReflectionException(string message, Exception innerException) : base(message, innerException)
{
}
protected ReflectionException(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
}
public static class ReflectionUtil
{
public static Type GetType(string name)
{
foreach (var a in AppDomain.CurrentDomain.GetAssemblies())
{
var type = a.GetType(name);
if (type != null)
{
return type;
}
}
return null;
}
public static Type[] GetSubTypes(Assembly assembly, Type type)
{
return assembly.GetTypes().Where(t => type.IsAssignableFrom(t) && !t.IsAbstract).ToArray();
}
public static Type[] GetTypesByAttr(Assembly assembly, Type attr)
{
return assembly.GetTypes().Where(t => t.GetCustomAttribute(attr) != null).ToArray();
}
public static MethodInfo[] GetMethodsByAttr(Type type, Type attr, bool includeStatic = false)
{
var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
if (includeStatic)
{
flags |= BindingFlags.Static;
}
return type.GetMethods(flags).Where(m => m.GetCustomAttribute(attr) != null).ToArray();
}
public static Type[] GetCallingSubTypes(Type type)
{
return GetSubTypes(Assembly.GetCallingAssembly(), type);
}
public static Type[] GetCallingTypesByAttr(Type attr)
{
return GetTypesByAttr(Assembly.GetCallingAssembly(), attr);
}
public static Type MakeGenericActionFromMethod(MethodInfo method)
{
var argTypes = method.GetParameters().Select(p => p.ParameterType).ToArray();
return argTypes.Length switch
{
0 => typeof(Action),
1 => typeof(Action<>).MakeGenericType(argTypes),
2 => typeof(Action<,>).MakeGenericType(argTypes),
3 => typeof(Action<,,>).MakeGenericType(argTypes),
4 => typeof(Action<,,,>).MakeGenericType(argTypes),
5 => typeof(Action<,,,,>).MakeGenericType(argTypes),
_ => throw new NotImplementedException(),
};
}
public static Type MakeGenericFuncFromMethod(MethodInfo method)
{
var returnType = method.ReturnType;
var argTypes = method.GetParameters().Select(p => p.ParameterType).Concat(new Type[] { returnType }).ToArray();
return argTypes.Length switch
{
1 => typeof(Func<>).MakeGenericType(argTypes),
2 => typeof(Func<,>).MakeGenericType(argTypes),
3 => typeof(Func<,,>).MakeGenericType(argTypes),
4 => typeof(Func<,,,>).MakeGenericType(argTypes),
5 => typeof(Func<,,,,>).MakeGenericType(argTypes),
6 => typeof(Func<,,,,,>).MakeGenericType(argTypes),
_ => throw new NotImplementedException(),
};
}
public static void ScanHandler(Type type, object self, Type attr, params SignatureInfo[] signatures)
{
foreach (var method in GetMethodsByAttr(type, attr, true))
{
bool match = false;
foreach (var s in signatures)
{
var ps = method.GetParameters();
if (method.ReturnType == s.ReturnType && ps.Length == s.Params.Count)
{
bool allMatch = true;
for (int i = 0; i < ps.Length; i++)
{
var p = s.Params[i];
if ((p.ChildType ? !p.Type.IsAssignableFrom(ps[i].ParameterType) : p.Type != ps[i].ParameterType))
{
allMatch = false;
break;
}
}
if (!allMatch)
{
continue;
}
if (allMatch && method.IsStatic && !s.CanBeStatic)
{
throw new ReflectionException($"type:{type} method:{method} can't be static");
}
match = true;
var del = Delegate.CreateDelegate((method.ReturnType == typeof(void) ? MakeGenericActionFromMethod(method) : MakeGenericFuncFromMethod(method)),
method.IsStatic ? null : self, method);
s.Callback(del, method.GetCustomAttribute(attr));
break;
}
}
if (!match)
{
throw new ReflectionException($"type{type} method:{method} invalid signature");
}
}
}
public static Action<TR> CastAction<TS, TR>(Delegate del) where TS : TR
{
var action = (Action<TS>)del;
return (TR a) => action((TS)a);
}
//public static Action<TR> CastAction<TR>(Delegate del, Type sourceType)
//{
// var castAction = typeof(ReflectionUtil).GetMethod(nameof(CastAction), 2, new Type[] { typeof(Delegate) });
// return (Action<TR>)castAction.MakeGenericMethod(sourceType, typeof(TR)).Invoke(null, new object[] { del });
//}
public static Action<TR1, TR2> CastAction<TS1, TR1, TS2, TR2>(Delegate del) where TS1 : TR1 where TS2 : TR2
{
var action = (Action<TS1, TS2>)del;
return (TR1 a, TR2 b) => action((TS1)a, (TS2)b);
}
public static Action<TR1, TR2, TR3> CastAction<TS1, TR1, TS2, TR2, TS3, TR3>(Delegate del) where TS1 : TR1 where TS2 : TR2 where TS3 : TR3
{
var action = (Action<TS1, TS2, TS3>)del;
return (TR1 a, TR2 b, TR3 c) => action((TS1)a, (TS2)b, (TS3)c);
}
//public static void RegisterProtoHandler(Assembly assembly, HandlerDispatcher dispatcher)
//{
// foreach (var type in GetTypesByAttr(assembly, typeof(ProtoHandlerAttribute)))
// {
// var handler = (ProtoHandler)Activator.CreateInstance(type);
// s_logger.ConditionalDebug("RegisterProtoHandler {0} {1}", type, handler);
// dispatcher.Register(type.BaseType.GetGenericArguments()[0], handler.Process);
// }
//}
}
}