mirror of
https://github.com/esiur/esiur-dotnet.git
synced 2025-05-06 03:32:57 +00:00
ClassId Attribute
This commit is contained in:
parent
2cf0d59e6b
commit
620dbaf653
@ -464,7 +464,7 @@ public static class DC // Data Converter
|
||||
public static string ToHex(this byte[] ba)
|
||||
{
|
||||
if (ba == null)
|
||||
return "NULL";
|
||||
return "";
|
||||
return ToHex(ba, 0, (uint)ba.Length);
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<Copyright>Ahmed Kh. Zamil</Copyright>
|
||||
<PackageProjectUrl>http://www.esiur.com</PackageProjectUrl>
|
||||
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||
<Version>2.3.4</Version>
|
||||
<Version>2.3.6</Version>
|
||||
<RepositoryUrl>https://github.com/esiur/esiur-dotnet</RepositoryUrl>
|
||||
<Authors>Ahmed Kh. Zamil</Authors>
|
||||
<AssemblyVersion></AssemblyVersion>
|
||||
|
@ -1342,7 +1342,7 @@ public partial class DistributedConnection : NetworkConnection, IStore
|
||||
{
|
||||
if (AutoReconnect)
|
||||
{
|
||||
Console.Write("Reconnecting socket...");
|
||||
Global.Log("DistributedConnection", LogType.Debug, "Reconnecting socket...");
|
||||
Task.Delay((int)ReconnectInterval).ContinueWith((x) => connectSocket(socket));
|
||||
}
|
||||
else
|
||||
|
@ -115,14 +115,14 @@ public class HTTPResponsePacket : Packet
|
||||
}
|
||||
}
|
||||
|
||||
public StringKeyList Headers = new StringKeyList(true);
|
||||
public string Version = "HTTP/1.1";
|
||||
public StringKeyList Headers { get; } = new StringKeyList(true);
|
||||
public string Version { get; set; } = "HTTP/1.1";
|
||||
|
||||
public byte[] Message;
|
||||
public ResponseCode Number;
|
||||
public ResponseCode Number { get; set; } = ResponseCode.OK;
|
||||
public string Text;
|
||||
|
||||
public List<HTTPCookie> Cookies = new List<HTTPCookie>();
|
||||
public List<HTTPCookie> Cookies { get; } = new List<HTTPCookie>();
|
||||
public bool Handled;
|
||||
|
||||
public override string ToString()
|
||||
@ -206,8 +206,6 @@ public class HTTPResponsePacket : Packet
|
||||
if (headerSize == 0)
|
||||
return -1;
|
||||
|
||||
//Cookies = new DStringDictionary();
|
||||
//Headers = new DStringDictionary(true);
|
||||
|
||||
sMethod = sLines[0].Split(' ');
|
||||
|
||||
|
@ -74,6 +74,8 @@ public static class TemplateGenerator
|
||||
if (template.Annotation != null)
|
||||
rt.AppendLine($"[Annotation({ToLiteral(template.Annotation)})]");
|
||||
|
||||
|
||||
rt.AppendLine($"[ClassId(\"{template.ClassId.ToByteArray().ToHex(0, 16, null)}\")]");
|
||||
rt.AppendLine($"[Public] public class {className} : IRecord {{");
|
||||
|
||||
|
||||
@ -104,6 +106,7 @@ public static class TemplateGenerator
|
||||
if (template.Annotation != null)
|
||||
rt.AppendLine($"[Annotation({ToLiteral(template.Annotation)})]");
|
||||
|
||||
rt.AppendLine($"[ClassId(\"{template.ClassId.ToByteArray().ToHex(0, 16, null)}\")]");
|
||||
rt.AppendLine($"[Public] public enum {className} {{");
|
||||
|
||||
rt.AppendLine(String.Join(",\r\n", template.Constants.Select(x => $"{x.Name}={x.Value}")));
|
||||
@ -268,6 +271,9 @@ public static class TemplateGenerator
|
||||
if (template.Annotation != null)
|
||||
rt.AppendLine($"[Annotation({ToLiteral(template.Annotation)})]");
|
||||
|
||||
|
||||
rt.AppendLine($"[ClassId(\"{template.ClassId.ToByteArray().ToHex(0, 16, null)}\")]");
|
||||
|
||||
// extends
|
||||
if (template.ParentId == null)
|
||||
rt.AppendLine($"public class {className} : DistributedResource {{");
|
||||
|
19
Esiur/Resource/ClassIdAttribute.cs
Normal file
19
Esiur/Resource/ClassIdAttribute.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using Esiur.Data;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Esiur.Resource
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Enum)]
|
||||
public class ClassIdAttribute : Attribute
|
||||
{
|
||||
public Guid ClassId { get; private set; }
|
||||
|
||||
public ClassIdAttribute(string classId)
|
||||
{
|
||||
var data = DC.FromHex(classId, null);
|
||||
ClassId = new Guid(data);
|
||||
}
|
||||
}
|
||||
}
|
@ -159,16 +159,18 @@ public class TypeTemplate
|
||||
|
||||
}
|
||||
|
||||
public static Guid GetTypeGuid(Type type) => GetTypeGuid(GetTypeClassName(type));
|
||||
|
||||
public static Guid GetTypeGuid(string typeName)
|
||||
public static Guid GetTypeGuid(Type type)
|
||||
{
|
||||
var tn = Encoding.UTF8.GetBytes(typeName);
|
||||
var attr = type.GetCustomAttribute<ClassIdAttribute>();
|
||||
if (attr != null)
|
||||
return attr.ClassId;
|
||||
|
||||
var tn = Encoding.UTF8.GetBytes(GetTypeClassName(type));
|
||||
var hash = SHA256.Create().ComputeHash(tn).Clip(0, 16);
|
||||
|
||||
return new Guid(hash);
|
||||
var rt = new Guid(hash);
|
||||
return rt;
|
||||
}
|
||||
|
||||
|
||||
static Type[] GetDistributedTypes(Type type)
|
||||
{
|
||||
if (type.IsArray)
|
||||
@ -419,7 +421,7 @@ public class TypeTemplate
|
||||
className = GetTypeClassName(type);
|
||||
|
||||
// set guid
|
||||
classId = GetTypeGuid(className);
|
||||
classId = GetTypeGuid(type);
|
||||
|
||||
if (addToWarehouse)
|
||||
Warehouse.PutTemplate(this);
|
||||
|
@ -43,17 +43,16 @@ using Esiur.Proxy;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Test
|
||||
{
|
||||
|
||||
|
||||
|
||||
class Program
|
||||
{
|
||||
|
||||
static async Task Main(string[] args)
|
||||
{
|
||||
{
|
||||
|
||||
// Create stores to keep objects.
|
||||
var system = await Warehouse.Put("sys", new MemoryStore());
|
||||
|
Loading…
x
Reference in New Issue
Block a user