diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index 5ddb9b2..47f82dd 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -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); diff --git a/Esiur/Proxy/ResourceProxy.cs b/Esiur/Proxy/ResourceProxy.cs index 30962c2..35e4e74 100644 --- a/Esiur/Proxy/ResourceProxy.cs +++ b/Esiur/Proxy/ResourceProxy.cs @@ -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 diff --git a/Esiur/Proxy/TemplateGenerator.cs b/Esiur/Proxy/TemplateGenerator.cs index c7d35aa..78e8888 100644 --- a/Esiur/Proxy/TemplateGenerator.cs +++ b/Esiur/Proxy/TemplateGenerator.cs @@ -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};"); } diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Resource/Template/TypeTemplate.cs index ad71e79..9298929 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Resource/Template/TypeTemplate.cs @@ -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}"; } diff --git a/Esiur/Resource/Warehouse.cs b/Esiur/Resource/Warehouse.cs index 9d0b37d..4a7f839 100644 --- a/Esiur/Resource/Warehouse.cs +++ b/Esiur/Resource/Warehouse.cs @@ -767,11 +767,11 @@ public static class Warehouse /// Resource template. 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; }