mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 11:32:59 +00:00
fix
This commit is contained in:
parent
c1b9af9e9e
commit
8e17a5b677
@ -1013,7 +1013,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
if (this.Instance == null)
|
||||
{
|
||||
Warehouse.Put(this.RemoteUsername, this, null, Server).Then(x =>
|
||||
Warehouse.Put(this.RemoteUsername.Replace("/", "_"), this, null, Server).Then(x =>
|
||||
{
|
||||
ready = true;
|
||||
Status = ConnectionStatus.Connected;
|
||||
@ -1136,7 +1136,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
|
||||
if (this.Instance == null)
|
||||
{
|
||||
Warehouse.Put(this.LocalUsername, this, null, Server).Then(x =>
|
||||
Warehouse.Put(this.LocalUsername.Replace("/", "_"), this, null, Server).Then(x =>
|
||||
{
|
||||
openReply?.Trigger(true);
|
||||
OnReady?.Invoke(this);
|
||||
|
@ -28,6 +28,9 @@ public static class ResourceProxy
|
||||
|
||||
public static Type GetBaseType(Type type)
|
||||
{
|
||||
if (type == null)
|
||||
throw new NullReferenceException("Type can't be null.");
|
||||
|
||||
if (type.Assembly.IsDynamic)
|
||||
return type.GetTypeInfo().BaseType;
|
||||
else
|
||||
|
@ -22,6 +22,8 @@ public static class TemplateGenerator
|
||||
|
||||
static string ToLiteral(string input)
|
||||
{
|
||||
if (input == null) return "null";
|
||||
|
||||
var literal = new StringBuilder();
|
||||
literal.Append("\"");
|
||||
foreach (var c in input)
|
||||
@ -82,6 +84,7 @@ public static class TemplateGenerator
|
||||
foreach (var p in template.Properties)
|
||||
{
|
||||
var ptTypeName = GetTypeName(p.ValueType, templates);
|
||||
rt.AppendLine($"[Annotation[{ToLiteral(p.ReadAnnotation)}]");
|
||||
rt.AppendLine($"public {ptTypeName} {p.Name} {{ get; set; }}");
|
||||
rt.AppendLine();
|
||||
}
|
||||
@ -294,9 +297,11 @@ public static class TemplateGenerator
|
||||
var positionalArgs = f.Arguments.Where((x) => !x.Optional).ToArray();
|
||||
var optionalArgs = f.Arguments.Where((x) => x.Optional).ToArray();
|
||||
|
||||
rt.AppendLine($"[Annotation[{ToLiteral(f.Annotation)}]");
|
||||
|
||||
if (f.IsStatic)
|
||||
{
|
||||
|
||||
rt.Append($"[Public] public static AsyncReply<{rtTypeName}> {f.Name}(DistributedConnection connection");
|
||||
|
||||
if (positionalArgs.Length > 0)
|
||||
@ -356,6 +361,8 @@ public static class TemplateGenerator
|
||||
if (p.Inherited)
|
||||
continue;
|
||||
|
||||
rt.AppendLine($"[Annotation[{ToLiteral(p.ReadAnnotation)}]");
|
||||
|
||||
var ptTypeName = GetTypeName(p.ValueType, templates);
|
||||
rt.AppendLine($"[Public] public {ptTypeName} {p.Name} {{");
|
||||
rt.AppendLine($"get => ({ptTypeName})properties[{p.Index}];");
|
||||
@ -371,6 +378,8 @@ public static class TemplateGenerator
|
||||
if (c.Inherited)
|
||||
continue;
|
||||
|
||||
rt.AppendLine($"[Annotation[{ToLiteral(c.Annotation)}]");
|
||||
|
||||
var ctTypeName = GetTypeName(c.ValueType, templates);
|
||||
rt.AppendLine($"[Public] public const {ctTypeName} {c.Name} = {c.Value};");
|
||||
}
|
||||
@ -388,6 +397,8 @@ public static class TemplateGenerator
|
||||
{
|
||||
var etTypeName = GetTypeName(e.ArgumentType, templates);
|
||||
rt.AppendLine($"case {e.Index}: {e.Name}?.Invoke(({etTypeName})args); break;");
|
||||
|
||||
eventsList.AppendLine($"[Annotation[{ToLiteral(e.Annotation)}]");
|
||||
eventsList.AppendLine($"[Public] public event ResourceEventHandler<{etTypeName}> {e.Name};");
|
||||
}
|
||||
|
||||
|
@ -354,7 +354,7 @@ public class TypeTemplate
|
||||
}
|
||||
|
||||
|
||||
public static string GetTypeClassName(Type type, string separator = ".")
|
||||
public static string GetTypeClassName(Type type, char separator = '.')
|
||||
{
|
||||
|
||||
if (type.IsGenericType)
|
||||
@ -362,12 +362,12 @@ public class TypeTemplate
|
||||
var index = type.Name.IndexOf("`");
|
||||
var name = $"{type.Namespace}{separator}{((index > -1) ? type.Name.Substring(0, index) : type.Name)}Of";
|
||||
foreach (var t in type.GenericTypeArguments)
|
||||
name += GetTypeClassName(t, "_");
|
||||
name += GetTypeClassName(t, '_');
|
||||
|
||||
return name;
|
||||
}
|
||||
else
|
||||
return $"{type.Namespace}{separator}{type.Name}";
|
||||
return $"{type.Namespace.Replace('.', separator)}{separator}{type.Name}";
|
||||
}
|
||||
|
||||
|
||||
|
@ -767,11 +767,11 @@ public static class Warehouse
|
||||
/// <returns>Resource template.</returns>
|
||||
public static TypeTemplate GetTemplateByType(Type type)
|
||||
{
|
||||
var baseType = ResourceProxy.GetBaseType(type);
|
||||
|
||||
//TemplateType templateType = TemplateType.Unspecified;
|
||||
|
||||
//if (Codec.InheritsClass(type, typeof(DistributedResource)))
|
||||
// templateType = TemplateType.Wrapper;
|
||||
if (baseType == typeof(IResource)
|
||||
|| baseType == typeof(IRecord))
|
||||
return null;
|
||||
|
||||
TemplateType templateType;
|
||||
if (Codec.ImplementsInterface(type, typeof(IResource)))
|
||||
@ -783,20 +783,13 @@ public static class Warehouse
|
||||
else
|
||||
return null;
|
||||
|
||||
var baseType = ResourceProxy.GetBaseType(type);
|
||||
var template = templates[templateType].Values.FirstOrDefault(x => x.DefinedType == baseType);
|
||||
if (template != null)
|
||||
return template;
|
||||
|
||||
if (baseType == typeof(IResource)
|
||||
|| baseType == typeof(IRecord))
|
||||
return null;
|
||||
|
||||
var template = templates[templateType].Values.FirstOrDefault(x => x.DefinedType == type);
|
||||
|
||||
// loaded ?
|
||||
if (template == null)
|
||||
{
|
||||
template = new TypeTemplate(baseType, true);
|
||||
TypeTemplate.GetDependencies(template);
|
||||
}
|
||||
// create new template for type
|
||||
template = new TypeTemplate(baseType, true);
|
||||
TypeTemplate.GetDependencies(template);
|
||||
|
||||
return template;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user