2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2026-03-31 10:28:21 +00:00

renaming 2

This commit is contained in:
2026-03-17 22:15:43 +03:00
parent 9d936c0812
commit e22e0d952d
88 changed files with 1685 additions and 1866 deletions

View File

@@ -27,7 +27,7 @@ SOFTWARE.
using Esiur.AspNetCore;
using Esiur.AspNetCore.Example;
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Net.EP;
using Esiur.Net.Sockets;
using Esiur.Resource;
using Esiur.Stores;

View File

@@ -24,8 +24,8 @@ SOFTWARE.
*/
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Esiur.Protocol;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@@ -35,7 +35,7 @@ namespace Esiur.AspNetCore
{
public class EsiurMiddleware
{
readonly DistributedServer server;
readonly EpServer server;
readonly RequestDelegate next;
readonly ILoggerFactory loggerFactory;
@@ -44,13 +44,13 @@ namespace Esiur.AspNetCore
var buffer = new ArraySegment<byte>(new byte[10240]);
if (context.WebSockets.IsWebSocketRequest
&& context.WebSockets.WebSocketRequestedProtocols.Contains("iip"))
&& context.WebSockets.WebSocketRequestedProtocols.Contains("EP"))
{
var webSocket = await context.WebSockets.AcceptWebSocketAsync("iip");
var webSocket = await context.WebSockets.AcceptWebSocketAsync("EP");
var socket = new FrameworkWebSocket(webSocket);
var iipConnection = new DistributedConnection();
server.Add(iipConnection);
iipConnection.Assign(socket);
var EPConnection = new EpConnection();
server.Add(EPConnection);
EPConnection.Assign(socket);
socket.Begin();
// @TODO: Change this

View File

@@ -24,12 +24,13 @@ SOFTWARE.
*/
using Esiur.Net.IIP;
using Esiur.Protocol;
namespace Esiur.AspNetCore
{
public class EsiurOptions
{
public required DistributedServer Server { get; set; }
public required EpServer Server { get; set; }
}
}

View File

@@ -46,6 +46,6 @@ To access the shell
Now you can simply test the running service typing
```javascript
let x = await wh.get("iip://localhost:8080/sys/service", {secure: false});
let x = await wh.get("EP://localhost:8080/sys/service", {secure: false});
await x.Hello();
```

View File

@@ -47,7 +47,7 @@ if (args.Length > 0)
{
try
{
var path = Esiur.Proxy.TemplateGenerator.GetTemplate(url, o.Dir, false, o.Username, o.Password, o.AsyncSetters);
var path = Esiur.Proxy.TypeDefGenerator.GetTemplate(url, o.Dir, false, o.Username, o.Password, o.AsyncSetters);
Console.WriteLine($"Generated successfully: {path}");
}
catch (Exception ex)
@@ -83,7 +83,7 @@ static void PrintHelp()
Console.WriteLine("Usage: <command> [arguments]");
Console.WriteLine("");
Console.WriteLine("Available commands:");
Console.WriteLine("\tget-template\tGet a template from an IIP link.");
Console.WriteLine("\tget-template\tGet a template from an EP link.");
Console.WriteLine("\tversion\t\tPrint Esiur version.");
Console.WriteLine("");
Console.WriteLine("Global options:");

View File

@@ -2,7 +2,7 @@
"profiles": {
"Esiur.CLI": {
"commandName": "Project",
"commandLineArgs": "get-template iip://phase.delta.iq/sys/phase --dir c:\\temp\\an"
"commandLineArgs": "get-template EP://phase.delta.iq/sys/phase --dir c:\\temp\\an"
}
}
}

View File

@@ -9,7 +9,7 @@ A command-line utility to generate
# Usage
```
Available commands:
get-template Get a template from an IIP link.
get-template Get a template from an EP link.
version Print Esiur version.
Global options:
@@ -23,7 +23,7 @@ Global options:
## Example
```
dotnet run esiur get-template iip://localhost/sys/service
dotnet run esiur get-template EP://localhost/sys/service
```

View File

@@ -1,7 +1,7 @@
using Esiur.Examples.StandaloneWebServerDemo;
using Esiur.Net.HTTP;
using Esiur.Net.IIP;
using Esiur.Protocol;
using Esiur.Resource;
using Esiur.Stores;
using Microsoft.AspNetCore.StaticFiles;
@@ -18,7 +18,7 @@ internal class Program
// Create a store to keep objects.
var system = await wh.Put("sys", new MemoryStore());
// Create a distibuted server
var esiurServer = await wh.Put("sys/server", new DistributedServer());
var esiurServer = await wh.Put("sys/server", new EpServer());
// Add your object to the store
var service = await wh.Put("sys/demo", new Demo());

View File

@@ -1,7 +1,7 @@
async function init() {
try {
connection = await wh.get(`iip://${window.location.hostname}`, {
connection = await wh.get(`EP://${window.location.hostname}`, {
autoReconnect: true
});

View File

@@ -34,7 +34,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using System.Reflection;
using Esiur.Security.Authority;
using System.Collections;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Stores.EntityCore;
public class EntityStore : IStore
@@ -179,7 +179,7 @@ public class EntityStore : IStore
//throw new NotImplementedException();
}
public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
public bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime)
{
return true;
//throw new NotImplementedException();
@@ -216,7 +216,7 @@ public class EntityStore : IStore
throw new NotImplementedException();
}
public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
public AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{
throw new NotImplementedException();
}

View File

@@ -35,7 +35,7 @@ using System.Threading.Tasks;
using System.Linq;
using Esiur.Security.Permissions;
using Esiur.Proxy;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Stores.MongoDB;
@@ -342,7 +342,7 @@ public class MongoDBStore : IStore
var parents = new BsonArray();
var children = new BsonArray();
var schema = resource.Instance.Schema;
var typeDef = resource.Instance.Definition;
// setup attributes
resource.Instance.Variables["children"] = new string[0];
@@ -381,7 +381,7 @@ public class MongoDBStore : IStore
var values = new BsonDocument();
foreach (var pt in schema.Properties)
foreach (var pt in typeDef.Properties)
{
var rt = pt.PropertyInfo.GetValue(resource, null);
@@ -594,7 +594,7 @@ public class MongoDBStore : IStore
var parents = new BsonArray();
var children = new BsonArray();
var schema = resource.Instance.Schema;
var typeDef = resource.Instance.Definition;
//foreach (IResource c in resource.Instance.Children)
// children.Add(c.Instance.Link);
@@ -607,7 +607,7 @@ public class MongoDBStore : IStore
var values = new BsonDocument();
foreach (var pt in schema.Properties)
foreach (var pt in typeDef.Properties)
{
/*
#if NETSTANDARD1_5
@@ -728,11 +728,11 @@ public class MongoDBStore : IStore
return reply;
}
AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecordByAge(IResource resource, ulong fromAge, ulong toAge)
AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecordByAge(IResource resource, ulong fromAge, ulong toAge)
{
var properties = resource.Instance.Schema.Properties.Where(x => x.Recordable).ToList();
var properties = resource.Instance.Definition.Properties.Where(x => x.HasHistory).ToList();
var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
var reply = new AsyncReply<KeyList<PropertyDef, PropertyValue[]>>();
AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>();
@@ -743,7 +743,7 @@ public class MongoDBStore : IStore
bag.Then(x =>
{
var list = new KeyList<PropertyDefinition, PropertyValue[]>();
var list = new KeyList<PropertyDef, PropertyValue[]>();
for (var i = 0; i < x.Length; i++)
list.Add(properties[i], x[i]);
@@ -754,11 +754,11 @@ public class MongoDBStore : IStore
return reply;
}
public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
public AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{
var properties = resource.Instance.Schema.Properties.Where(x => x.Recordable).ToList();
var properties = resource.Instance.Definition.Properties.Where(x => x.HasHistory).ToList();
var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
var reply = new AsyncReply<KeyList<PropertyDef, PropertyValue[]>>();
AsyncBag<PropertyValue[]> bag = new AsyncBag<PropertyValue[]>();
@@ -769,7 +769,7 @@ public class MongoDBStore : IStore
bag.Then(x =>
{
var list = new KeyList<PropertyDefinition, PropertyValue[]>();
var list = new KeyList<PropertyDef, PropertyValue[]>();
for (var i = 0; i < x.Length; i++)
list.Add(properties[i], x[i]);
@@ -780,7 +780,7 @@ public class MongoDBStore : IStore
return reply;
}
public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
public bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime)
{
if (resource == this)
@@ -790,7 +790,7 @@ public class MongoDBStore : IStore
var filter = Builders<BsonDocument>.Filter.Eq("_id", new BsonObjectId(new ObjectId(objectId)));
var update = Builders<BsonDocument>.Update
.Set("values." + propertyName, new BsonDocument { { "age", BsonValue.Create(age) },
.Set("values." + propertyDef.Name, new BsonDocument { { "age", BsonValue.Create(age) },
{ "modification", dateTime },
{ "value", Compose(value) } });

View File

@@ -1,4 +1,4 @@
using Esiur.Net.IIP;
using Esiur.Protocol;
using System;
using System.Collections.Generic;
using System.Text;
@@ -36,10 +36,10 @@ namespace Esiur.Core
Connection.SendWarning(CallbackId, level, message);
}
public DistributedConnection Connection { get; internal set; }
public EpConnection Connection { get; internal set; }
internal InvocationContext(DistributedConnection connection, uint callbackId)
internal InvocationContext(EpConnection connection, uint callbackId)
{
Connection = connection;
CallbackId = callbackId;

View File

@@ -25,12 +25,12 @@ SOFTWARE.
using System;
using System.Collections.Generic;
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Resource;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Collections;
using Esiur.Protocol;
namespace Esiur.Data;
@@ -39,9 +39,9 @@ namespace Esiur.Data;
public static class Codec
{
//delegate AsyncReply AsyncParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence);
//delegate AsyncReply AsyncParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence);
delegate object AsyncParser(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence);
delegate object AsyncParser(ParsedTDU tdu, EpConnection connection, uint[] requestSequence);
delegate object SyncParser(ParsedTDU tdu, Warehouse warehouse);
static AsyncParser[][] FixedAsyncParsers = new AsyncParser[][]
@@ -189,10 +189,10 @@ public static class Codec
/// <param name="data">Bytes array</param>
/// <param name="offset">Zero-indexed offset.</param>
/// <param name="size">Output the number of bytes parsed</param>
/// <param name="connection">DistributedConnection is required in case a structure in the array holds items at the other end.</param>
/// <param name="connection">EpConnection is required in case a structure in the array holds items at the other end.</param>
/// <param name="dataType">DataType, in case the data is not prepended with DataType</param>
/// <returns>Value</returns>
public static (uint, object) ParseAsync(byte[] data, uint offset, DistributedConnection connection, uint[] requestSequence)
public static (uint, object) ParseAsync(byte[] data, uint offset, EpConnection connection, uint[] requestSequence)
{
var tdu = ParsedTDU.Parse(data, offset, (uint)data.Length);
@@ -219,7 +219,7 @@ public static class Codec
}
}
public static (uint, object) ParseAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static (uint, object) ParseAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
if (tdu.Class == TDUClass.Invalid)
throw new NullReferenceException("DataType can't be parsed.");
@@ -293,21 +293,21 @@ public static class Codec
/// Check if a resource is local to a given connection.
/// </summary>
/// <param name="resource">Resource to check.</param>
/// <param name="connection">DistributedConnection to check if the resource is local to it.</param>
/// <param name="connection">EpConnection to check if the resource is local to it.</param>
/// <returns>True, if the resource owner is the given connection, otherwise False.</returns>
public static bool IsLocalResource(IResource resource, DistributedConnection connection)
public static bool IsLocalResource(IResource resource, EpConnection connection)
{
if (resource == null)
throw new NullReferenceException("Resource is null.");
if (resource is DistributedResource)
if (((DistributedResource)(resource)).DistributedResourceConnection == connection)
if (resource is EpResource)
if (((EpResource)(resource)).DistributedResourceConnection == connection)
return true;
return false;
}
public delegate TDU Composer(object value, Warehouse warehouse, DistributedConnection connection);
public delegate TDU Composer(object value, Warehouse warehouse, EpConnection connection);
public static Dictionary<Type, Composer> Composers = new Dictionary<Type, Composer>()
{
@@ -382,7 +382,7 @@ public static class Codec
internal static TDU
ComposeInternal(object valueOrSource, Warehouse warehouse, DistributedConnection connection)
ComposeInternal(object valueOrSource, Warehouse warehouse, EpConnection connection)
{
if (valueOrSource == null)
return new TDU(TDUIdentifier.Null, null, 0);
@@ -400,9 +400,9 @@ public static class Codec
else if (genericType == typeof(Func<>))
{
var args = genericType.GetGenericArguments();
if (args.Length == 2 && args[0] == typeof(DistributedConnection))
if (args.Length == 2 && args[0] == typeof(EpConnection))
{
//Func<DistributedConnection, DistributedConnection> a;
//Func<EpConnection, EpConnection> a;
//a.Invoke()
}
}
@@ -497,10 +497,10 @@ public static class Codec
/// Compose a variable
/// </summary>
/// <param name="value">Value to compose.</param>
/// <param name="connection">DistributedConnection is required to check locality.</param>
/// <param name="connection">EpConnection is required to check locality.</param>
/// <param name="prependType">If True, prepend the DataType at the beginning of the output.</param>
/// <returns>Array of bytes in the network byte order.</returns>
public static byte[] Compose(object valueOrSource, Warehouse warehouse, DistributedConnection connection)//, bool prependType = true)
public static byte[] Compose(object valueOrSource, Warehouse warehouse, EpConnection connection)//, bool prependType = true)
{
var tdu = ComposeInternal(valueOrSource, warehouse, connection);
return tdu.Composed;

View File

@@ -26,8 +26,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Esiur.Net.IIP;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Net;

View File

@@ -1,5 +1,5 @@
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Net.EP;
using Esiur.Resource;
using System;
using System.Collections.Generic;
@@ -14,115 +14,115 @@ namespace Esiur.Data;
public static class DataDeserializer
{
public static AsyncReply NullParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply NullParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply(null);
}
public static AsyncReply BooleanTrueParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply BooleanTrueParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<bool>(true);
}
public static AsyncReply BooleanFalseParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply BooleanFalseParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<bool>(false);
}
public static AsyncReply NotModifiedParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply NotModifiedParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<NotModified>(new NotModified());
}
public static AsyncReply ByteParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply ByteParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<byte>(data[offset]);
}
public static AsyncReply SByteParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply SByteParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<sbyte>((sbyte)data[offset]);
}
public static unsafe AsyncReply Char16Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Char16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<char>(*(char*)ptr);
}
public static AsyncReply Char8Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply Char8Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<char>((char)data[offset]);
}
public static unsafe AsyncReply Int16Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Int16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<short>(*(short*)ptr);
}
public static unsafe AsyncReply UInt16Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply UInt16Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<ushort>(*(ushort*)ptr);
}
public static unsafe AsyncReply Int32Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Int32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<int>(*(int*)ptr);
}
public static unsafe AsyncReply UInt32Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply UInt32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<uint>(*(uint*)ptr);
}
public static unsafe AsyncReply Float32Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Float32Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<float>(*(float*)ptr);
}
public static unsafe AsyncReply Float64Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Float64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<double>(*(double*)ptr);
}
public static unsafe AsyncReply Float128Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Float128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<decimal>(*(decimal*)ptr);
}
public static unsafe AsyncReply Int128Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Int128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<decimal>(*(decimal*)ptr);
}
public static unsafe AsyncReply UInt128Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply UInt128Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<decimal>(*(decimal*)ptr);
}
public static unsafe AsyncReply Int64Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply Int64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<long>(*(long*)ptr);
}
public static unsafe AsyncReply UInt64Parser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply UInt64Parser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<ulong>(*(ulong*)ptr);
}
public static unsafe AsyncReply DateTimeParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply DateTimeParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return new AsyncReply<DateTime>(new DateTime(*(long*)ptr, DateTimeKind.Utc));
@@ -130,30 +130,30 @@ public static class DataDeserializer
}
public static unsafe AsyncReply ResourceParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply ResourceParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return connection.Fetch(*(uint*)ptr, requestSequence);
}
public static unsafe AsyncReply LocalResourceParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply LocalResourceParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &data[offset])
return Warehouse.GetById(*(uint*)ptr);
}
public static unsafe AsyncReply RawDataParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply RawDataParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<byte[]>(data.Clip(offset, length));
}
public static unsafe AsyncReply StringParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply StringParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
return new AsyncReply<string>(data.GetString(offset, length));
}
public static unsafe AsyncReply RecordParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply RecordParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var reply = new AsyncReply<IRecord>();
@@ -229,12 +229,12 @@ public static class DataDeserializer
return reply;
}
public static unsafe AsyncReply ConstantParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply ConstantParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
throw new NotImplementedException();
}
public static unsafe AsyncReply EnumParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply EnumParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var classId = data.GetUUID(offset);
@@ -262,7 +262,7 @@ public static class DataDeserializer
public static AsyncReply RecordListParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply RecordListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<IRecord>();
@@ -286,7 +286,7 @@ public static class DataDeserializer
return rt;
}
public static AsyncReply ResourceListParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply ResourceListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<IResource>();
@@ -311,7 +311,7 @@ public static class DataDeserializer
}
public static AsyncBag<object> ListParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncBag<object> ListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<object>();
@@ -335,7 +335,7 @@ public static class DataDeserializer
return rt;
}
public static AsyncReply TypedMapParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TypedMapParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
// get key type
var (keyCs, keyRepType) = RepresentationType.Parse(data, offset);
@@ -384,7 +384,7 @@ public static class DataDeserializer
}
public static AsyncReply TupleParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TupleParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var results = new AsyncBag<object>();
var rt = new AsyncReply();
@@ -443,7 +443,7 @@ public static class DataDeserializer
return rt;
}
public static AsyncReply TypedListParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TypedListParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<object>();
@@ -478,7 +478,7 @@ public static class DataDeserializer
}
public static AsyncBag<PropertyValue> PropertyValueArrayParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
public static AsyncBag<PropertyValue> PropertyValueArrayParser(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
{
var rt = new AsyncBag<PropertyValue>();
@@ -499,7 +499,7 @@ public static class DataDeserializer
}
public static (uint, AsyncReply<PropertyValue>) PropertyValueParser(byte[] data, uint offset, DistributedConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
public static (uint, AsyncReply<PropertyValue>) PropertyValueParser(byte[] data, uint offset, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
{
var reply = new AsyncReply<PropertyValue>();
@@ -520,7 +520,7 @@ public static class DataDeserializer
return (16 + valueSize, reply);
}
public static AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> HistoryParser(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> HistoryParser(byte[] data, uint offset, uint length, IResource resource, EpConnection connection, uint[] requestSequence)
{
//var count = (int)toAge - (int)fromAge;

View File

@@ -1,9 +1,9 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Data.GVWIE;
using Esiur.Data.Schema;
using Esiur.Data.Types;
using Esiur.Misc;
using Esiur.Net.IIP;
using Esiur.Protocol;
using Esiur.Resource;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
@@ -17,7 +17,7 @@ namespace Esiur.Data;
public static class DataDeserializer
{
public static object NullParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object NullParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return null;
}
@@ -27,7 +27,7 @@ public static class DataDeserializer
return null;
}
public static object BooleanTrueParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object BooleanTrueParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return true;
}
@@ -37,7 +37,7 @@ public static class DataDeserializer
return true;
}
public static object BooleanFalseParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object BooleanFalseParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return false;
}
@@ -47,7 +47,7 @@ public static class DataDeserializer
return false;
}
public static object NotModifiedParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object NotModifiedParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return NotModified.Default;
}
@@ -57,7 +57,7 @@ public static class DataDeserializer
return NotModified.Default;
}
public static object UInt8ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object UInt8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return tdu.Data[tdu.Offset];
}
@@ -66,7 +66,7 @@ public static class DataDeserializer
return tdu.Data[tdu.Offset];
}
public static object Int8ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object Int8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return (sbyte)tdu.Data[tdu.Offset];
}
@@ -75,7 +75,7 @@ public static class DataDeserializer
return (sbyte)tdu.Data[tdu.Offset];
}
public static unsafe object Char16ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Char16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(char*)ptr;
@@ -87,7 +87,7 @@ public static class DataDeserializer
return *(char*)ptr;
}
public static object Char8ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object Char8ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return (char)tdu.Data[tdu.Offset];
}
@@ -98,7 +98,7 @@ public static class DataDeserializer
}
public static unsafe object Int16ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Int16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(short*)ptr;
@@ -110,7 +110,7 @@ public static class DataDeserializer
return *(short*)ptr;
}
public static unsafe object UInt16ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object UInt16ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(ushort*)ptr;
@@ -122,7 +122,7 @@ public static class DataDeserializer
return *(ushort*)ptr;
}
public static unsafe object Int32ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Int32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(int*)ptr;
@@ -134,7 +134,7 @@ public static class DataDeserializer
return *(int*)ptr;
}
public static unsafe object UInt32ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object UInt32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(uint*)ptr;
@@ -147,7 +147,7 @@ public static class DataDeserializer
}
public static unsafe object Float32ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Float32ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(float*)ptr;
@@ -159,7 +159,7 @@ public static class DataDeserializer
return *(float*)ptr;
}
public static unsafe object Float64ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Float64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(double*)ptr;
@@ -172,7 +172,7 @@ public static class DataDeserializer
}
public static unsafe object Decimal128ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Decimal128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(decimal*)ptr;
@@ -184,7 +184,7 @@ public static class DataDeserializer
return *(decimal*)ptr;
}
public static unsafe object UUIDParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object UUIDParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return new UUID(tdu.Data, tdu.Offset);
}
@@ -196,7 +196,7 @@ public static class DataDeserializer
public static unsafe object Int128ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Int128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
@@ -210,7 +210,7 @@ public static class DataDeserializer
return new Int128(*(ulong*)ptr1, *(ulong*)ptr2);
}
public static unsafe object UInt128ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object UInt128ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr1 = &tdu.Data[tdu.Offset])
fixed (byte* ptr2 = &tdu.Data[tdu.Offset + 8])
@@ -224,7 +224,7 @@ public static class DataDeserializer
return new UInt128(*(ulong*)ptr1, *(ulong*)ptr2);
}
public static unsafe object Int64ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object Int64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(long*)ptr;
@@ -237,7 +237,7 @@ public static class DataDeserializer
}
public static unsafe object UInt64ParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object UInt64ParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return *(ulong*)ptr;
@@ -250,7 +250,7 @@ public static class DataDeserializer
}
public static unsafe object DateTimeParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object DateTimeParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
return new DateTime(*(long*)ptr, DateTimeKind.Utc);
@@ -264,7 +264,7 @@ public static class DataDeserializer
}
public static object ResourceLinkParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static object ResourceLinkParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var link = tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
if (connection == null)
@@ -283,7 +283,7 @@ public static class DataDeserializer
return new ResourceLink(link);
}
public static unsafe object ResourceParser8Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object ResourceParser8Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
if (connection == null)
return new ResourceId(false, tdu.Data[tdu.Offset]);
@@ -296,7 +296,7 @@ public static class DataDeserializer
return new ResourceId(false, tdu.Data[tdu.Offset]);
}
public static unsafe object LocalResourceParser8Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object LocalResourceParser8Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
if (connection == null)
return new ResourceId(true, tdu.Data[tdu.Offset]);
@@ -309,7 +309,7 @@ public static class DataDeserializer
return new ResourceId(true, tdu.Data[tdu.Offset]);
}
public static unsafe object ResourceParser16Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object ResourceParser16Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
if (connection == null)
@@ -325,7 +325,7 @@ public static class DataDeserializer
}
public static unsafe object LocalResourceParser16Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object LocalResourceParser16Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
if (connection == null)
@@ -340,7 +340,7 @@ public static class DataDeserializer
return new ResourceId(true, *(ushort*)ptr);
}
public static unsafe object ResourceParser32Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object ResourceParser32Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
if (connection == null)
@@ -356,7 +356,7 @@ public static class DataDeserializer
}
public static unsafe object LocalResourceParser32Async(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object LocalResourceParser32Async(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
fixed (byte* ptr = &tdu.Data[tdu.Offset])
if (connection == null)
@@ -372,7 +372,7 @@ public static class DataDeserializer
}
public static unsafe object RawDataParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object RawDataParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return tdu.Data.Clip(tdu.Offset, (uint)tdu.ContentLength);
}
@@ -383,7 +383,7 @@ public static class DataDeserializer
}
public static unsafe object StringParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object StringParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
return tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
}
@@ -393,10 +393,10 @@ public static class DataDeserializer
return tdu.Data.GetString(tdu.Offset, (uint)tdu.ContentLength);
}
public static unsafe object RecordParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object RecordParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var classId = tdu.Metadata.GetUUID(0);
var template = connection.Instance.Warehouse.GetTemplateByClassId(classId,
var typeId = tdu.Metadata.GetUUID(0);
var typeDef = connection.Instance.Warehouse.GetTypeDefById(typeId,
TypeDefKind.Record);
var rt = new AsyncReply<IRecord>();
@@ -410,9 +410,9 @@ public static class DataDeserializer
var length = tdu.ContentLength;
var ends = offset + (uint)length;
var initRecord = (TypeDef template) =>
var initRecord = (TypeDef typeDef) =>
{
for (var i = 0; i < template.Properties.Length; i++)
for (var i = 0; i < typeDef.Properties.Length; i++)
{
current = ParsedTDU.Parse(tdu.Data, offset, ends);
@@ -428,7 +428,7 @@ public static class DataDeserializer
}
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
{
var (idf, mt) = template.Properties[i].ValueType.GetMetadata();
var (idf, mt) = typeDef.Properties[i].ValueType.GetMetadata();
current.Class = TDUClass.Typed;
current.Identifier = idf;
current.Metadata = mt;
@@ -454,16 +454,16 @@ public static class DataDeserializer
list.Then(results =>
{
if (template.DefinedType != null)
if (typeDef.DefinedType != null)
{
var record = Activator.CreateInstance(template.DefinedType) as IRecord;
for (var i = 0; i < template.Properties.Length; i++)
var record = Activator.CreateInstance(typeDef.DefinedType) as IRecord;
for (var i = 0; i < typeDef.Properties.Length; i++)
{
try
{
var v = RuntimeCaster.Cast(results[i], template.Properties[i].PropertyInfo.PropertyType);
template.Properties[i].PropertyInfo.SetValue(record, v);
var v = RuntimeCaster.Cast(results[i], typeDef.Properties[i].PropertyInfo.PropertyType);
typeDef.Properties[i].PropertyInfo.SetValue(record, v);
}
catch (Exception ex)
{
@@ -477,8 +477,8 @@ public static class DataDeserializer
{
var record = new Record();
for (var i = 0; i < template.Properties.Length; i++)
record.Add(template.Properties[i].Name, results[i]);
for (var i = 0; i < typeDef.Properties.Length; i++)
record.Add(typeDef.Properties[i].Name, results[i]);
rt.Trigger(record);
}
@@ -492,14 +492,14 @@ public static class DataDeserializer
};
if (template != null)
if (typeDef != null)
{
initRecord(template);
initRecord(typeDef);
}
else if (connection != null)
{
// try to get the template from the other end
connection.GetTemplate(classId).Then(tmp =>
// try to get the TypeDef from the other end
connection.GetTypeDefById(typeId).Then(tmp =>
{
initRecord(tmp);
}).Error(x => rt.TriggerError(x));
@@ -511,87 +511,20 @@ public static class DataDeserializer
return rt;
//var classId = tdu.Metadata.GetUUID(0);
//var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Record);
//var initRecord = (TypeSchema template) =>
//{
// ListParserAsync(tdu, connection, requestSequence).Then(r =>
// {
// var ar = (object[])r;
// if (template == null)
// {
// // @TODO: add parse if no template settings
// reply.TriggerError(new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TemplateNotFound,
// "Template not found for record."));
// }
// else if (template.DefinedType != null)
// {
// var record = Activator.CreateInstance(template.DefinedType) as IRecord;
// for (var i = 0; i < template.Properties.Length; i++)
// {
// try
// {
// //var v = Convert.ChangeType(ar[i], template.Properties[i].PropertyInfo.PropertyType);
// var v = RuntimeCaster.Cast(ar[i], template.Properties[i].PropertyInfo.PropertyType);
// template.Properties[i].PropertyInfo.SetValue(record, v);
// }
// catch (Exception ex)
// {
// Global.Log(ex);
// }
// }
// reply.Trigger(record);
// }
// else
// {
// var record = new Record();
// for (var i = 0; i < template.Properties.Length; i++)
// record.Add(template.Properties[i].Name, ar[i]);
// reply.Trigger(record);
// }
// });
//};
//if (template != null)
//{
// initRecord(template);
//}
//else if (connection != null)
//{
// // try to get the template from the other end
// connection.GetTemplate(classId).Then(tmp =>
// {
// initRecord(tmp);
// }).Error(x => reply.TriggerError(x));
//}
//else
//{
// initRecord(null);
//}
//return reply;
}
public static unsafe object RecordParser(ParsedTDU tdu, Warehouse warehouse)
{
var classId = tdu.Metadata.GetUUID(0);
var template = warehouse.GetTypeDefByClassId(classId, TypeDefKind.Record);
var typeDef = warehouse.GetTypeDefById(classId, TypeDefKind.Record);
if (template == null)
if (typeDef == null)
{
// @TODO: add parse if no template settings
throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.SchemaNotFound,
"Template not found for record.");
// @TODO: add parse if no TypeDef settings
throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TypeDefNotFound,
"TypeDef not found for record.");
}
var list = new List<object>();
@@ -604,7 +537,7 @@ public static class DataDeserializer
var ends = offset + (uint)length;
for (var i = 0; i < template.Properties.Length; i++)
for (var i = 0; i < typeDef.Properties.Length; i++)
{
current = ParsedTDU.Parse(tdu.Data, offset, ends);
@@ -620,7 +553,7 @@ public static class DataDeserializer
}
else if (current.Identifier == TDUIdentifier.TypeOfTarget)
{
var (idf, mt) = template.Properties[i].ValueType.GetMetadata();
var (idf, mt) = typeDef.Properties[i].ValueType.GetMetadata();
current.Class = TDUClass.Typed;
current.Identifier = idf;
current.Metadata = mt;
@@ -642,16 +575,16 @@ public static class DataDeserializer
}
if (template.DefinedType != null)
if (typeDef.DefinedType != null)
{
var record = Activator.CreateInstance(template.DefinedType) as IRecord;
for (var i = 0; i < template.Properties.Length; i++)
var record = Activator.CreateInstance(typeDef.DefinedType) as IRecord;
for (var i = 0; i < typeDef.Properties.Length; i++)
{
try
{
var v = RuntimeCaster.Cast(list[i], template.Properties[i].PropertyInfo.PropertyType);
template.Properties[i].PropertyInfo.SetValue(record, v);
var v = RuntimeCaster.Cast(list[i], typeDef.Properties[i].PropertyInfo.PropertyType);
typeDef.Properties[i].PropertyInfo.SetValue(record, v);
}
catch (Exception ex)
{
@@ -665,14 +598,14 @@ public static class DataDeserializer
{
var record = new Record();
for (var i = 0; i < template.Properties.Length; i++)
record.Add(template.Properties[i].Name, list[i]);
for (var i = 0; i < typeDef.Properties.Length; i++)
record.Add(typeDef.Properties[i].Name, list[i]);
return record;
}
}
public static unsafe object ConstantParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe object ConstantParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
throw new NotImplementedException();
}
@@ -682,26 +615,26 @@ public static class DataDeserializer
throw new NotImplementedException();
}
public static unsafe AsyncReply EnumParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static unsafe AsyncReply EnumParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var classId = tdu.Metadata.GetUUID(0);
var typeId = tdu.Metadata.GetUUID(0);
var index = tdu.Data[tdu.Offset];
var template = connection.Instance.Warehouse.GetTemplateByClassId(classId,
var typeDef = connection.Instance.Warehouse.GetTypeDefById(typeId,
TypeDefKind.Enum);
if (template != null)
if (typeDef != null)
{
return new AsyncReply(template.Constants[index].Value);
return new AsyncReply(typeDef.Constants[index].Value);
}
else
{
var reply = new AsyncReply();
connection.GetTemplate(classId).Then(tmp =>
connection.GetTypeDefById(typeId).Then(tmp =>
{
reply.Trigger(tmp.Constants[index].Value);
}).Error(x => reply.TriggerError(x));
@@ -713,25 +646,25 @@ public static class DataDeserializer
public static unsafe object EnumParser(ParsedTDU tdu, Warehouse warehouse)
{
var classId = tdu.Metadata.GetUUID(0);
var typeId = tdu.Metadata.GetUUID(0);
var index = tdu.Data[tdu.Offset];
var template = warehouse.GetTemplateByClassId(classId, TypeDefKind.Enum);
var typeDef = warehouse.GetTypeDefById(typeId, TypeDefKind.Enum);
if (template != null)
if (typeDef != null)
{
return template.Constants[index].Value;
return typeDef.Constants[index].Value;
}
else
{
throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.SchemaNotFound,
"Template not found for enum.");
throw new AsyncException(ErrorType.Management, (ushort)ExceptionCode.TypeDefNotFound,
"TypeDef not found for enum.");
}
}
public static AsyncReply RecordListParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply RecordListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<IRecord>();
@@ -784,7 +717,7 @@ public static class DataDeserializer
return rt.ToArray();
}
public static AsyncReply ResourceListParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply ResourceListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncBag<IResource>();
@@ -838,7 +771,7 @@ public static class DataDeserializer
return rt.ToArray();
}
public static AsyncBag<object> ListParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncBag<object> ListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
//var rt = new AsyncBag<object>();
@@ -990,7 +923,7 @@ public static class DataDeserializer
}
public static AsyncReply TypedMapParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TypedMapParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncReply();
@@ -1105,12 +1038,12 @@ public static class DataDeserializer
var enumType = tru.GetRuntimeType(warehouse);
var enums = Array.CreateInstance(enumType, (int)tdu.ContentLength);
var enumTemplate = warehouse.GetTemplateByType(enumType);
var enumTypeDef = warehouse.GetTypeDefByType(enumType);
for (var i = 0; i < (int)tdu.ContentLength; i++)
{
var index = tdu.Data[tdu.Offset + i];
enums.SetValue(enumTemplate.Constants[index].Value, i);
enums.SetValue(enumTypeDef.Constants[index].Value, i);
}
return enums;
@@ -1202,7 +1135,7 @@ public static class DataDeserializer
}
public static AsyncReply TupleParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TupleParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
var rt = new AsyncReply();
@@ -1392,7 +1325,7 @@ public static class DataDeserializer
}
public static AsyncReply TypedArrayParserAsync(ParsedTDU tdu, TRU tru, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TypedArrayParserAsync(ParsedTDU tdu, TRU tru, EpConnection connection, uint[] requestSequence)
{
switch (tru.Identifier)
{
@@ -1419,13 +1352,13 @@ public static class DataDeserializer
var enumType = tru.GetRuntimeType(connection.Instance.Warehouse);
var rt = Array.CreateInstance(enumType, (int)tdu.ContentLength);
var enumTemplate = connection.Instance.Warehouse.GetTemplateByType(enumType);
var enumTypeDef = connection.Instance.Warehouse.GetTypeDefByType(enumType);
for (var i = 0; i < (int)tdu.ContentLength; i++)
{
var index = tdu.Data[tdu.Offset + i];
rt.SetValue(Enum.ToObject(enumType, enumTemplate.Constants[index].Value), i);
rt.SetValue(Enum.ToObject(enumType, enumTypeDef.Constants[index].Value), i);
}
return new AsyncReply(rt);
@@ -1488,7 +1421,7 @@ public static class DataDeserializer
}
public static AsyncReply TypedListParserAsync(ParsedTDU tdu, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply TypedListParserAsync(ParsedTDU tdu, EpConnection connection, uint[] requestSequence)
{
// get the type
var (hdrCs, tru) = TRU.Parse(tdu.Metadata, 0);
@@ -1573,7 +1506,7 @@ public static class DataDeserializer
return TypedArrayParser(tdu, tru, warehouse);
}
public static AsyncBag<PropertyValue> PropertyValueArrayParserAsync(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
public static AsyncBag<PropertyValue> PropertyValueArrayParserAsync(byte[] data, uint offset, uint length, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
{
var rt = new AsyncBag<PropertyValue>();
@@ -1597,7 +1530,7 @@ public static class DataDeserializer
}
public static (uint, AsyncReply<PropertyValue>) PropertyValueParserAsync(byte[] data, uint offset, DistributedConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
public static (uint, AsyncReply<PropertyValue>) PropertyValueParserAsync(byte[] data, uint offset, EpConnection connection, uint[] requestSequence)//, bool ageIncluded = true)
{
var reply = new AsyncReply<PropertyValue>();
@@ -1625,13 +1558,13 @@ public static class DataDeserializer
return (16 + valueSize, reply);
}
public static AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, DistributedConnection connection, uint[] requestSequence)
public static AsyncReply<KeyList<PropertyDef, PropertyValue[]>> HistoryParserAsync(byte[] data, uint offset, uint length, IResource resource, EpConnection connection, uint[] requestSequence)
{
//var count = (int)toAge - (int)fromAge;
var list = new KeyList<PropertyDefinition, PropertyValue[]>();
var list = new KeyList<PropertyDef, PropertyValue[]>();
var reply = new AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>>();
var reply = new AsyncReply<KeyList<PropertyDef, PropertyValue[]>>();
var bagOfBags = new AsyncBag<PropertyValue[]>();
@@ -1639,7 +1572,7 @@ public static class DataDeserializer
while (offset < ends)
{
var index = data[offset++];
var pt = resource.Instance.Schema.GetPropertyDefByIndex(index);
var pt = resource.Instance.Definition.GetPropertyDefByIndex(index);
list.Add(pt, null);
var cs = data.GetUInt32(offset, Endian.Little);
offset += 4;

View File

@@ -1,7 +1,7 @@
using Esiur.Core;
using Esiur.Data.GVWIE;
using Esiur.Data.Schema;
using Esiur.Net.IIP;
using Esiur.Data.Types;
using Esiur.Protocol;
using Esiur.Resource;
using Microsoft.CodeAnalysis;
using System;
@@ -17,7 +17,7 @@ public static class DataSerializer
{
public delegate byte[] Serializer(object value);
public static unsafe TDU Int32Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Int32Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (int)value;
@@ -44,7 +44,7 @@ public static class DataSerializer
}
}
public static unsafe TDU UInt32Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU UInt32Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (uint)value;
@@ -73,7 +73,7 @@ public static class DataSerializer
}
}
public static unsafe TDU Int16Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Int16Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (short)value;
@@ -93,7 +93,7 @@ public static class DataSerializer
}
}
public static unsafe TDU UInt16Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU UInt16Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (ushort)value;
@@ -114,7 +114,7 @@ public static class DataSerializer
}
public static unsafe TDU Float32Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Float32Composer(object value, Warehouse warehouse, EpConnection connection)
{
float v = (float)value;
@@ -152,7 +152,7 @@ public static class DataSerializer
}
public unsafe static TDU Float64Composer(object value, Warehouse warehouse, DistributedConnection connection)
public unsafe static TDU Float64Composer(object value, Warehouse warehouse, EpConnection connection)
{
double v = (double)value;
@@ -211,7 +211,7 @@ public static class DataSerializer
return new TDU(TDUIdentifier.Float64, rt, 8);
}
}
public static unsafe TDU Int64Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Int64Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (long)value;
@@ -249,7 +249,7 @@ public static class DataSerializer
}
}
public static unsafe TDU UInt64Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU UInt64Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (ulong)value;
@@ -288,7 +288,7 @@ public static class DataSerializer
}
public static unsafe TDU DateTimeComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU DateTimeComposer(object value, Warehouse warehouse, EpConnection connection)
{
var v = ((DateTime)value).ToUniversalTime().Ticks;
var rt = new byte[8];
@@ -298,7 +298,7 @@ public static class DataSerializer
return new TDU(TDUIdentifier.DateTime, rt, 8);
}
//public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, DistributedConnection connection)
//public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, EpConnection connection)
//{
// var v = (decimal)value;
// var rt = new byte[16];
@@ -308,7 +308,7 @@ public static class DataSerializer
// return new TDU(TDUIdentifier.Decimal128, rt, 16);
//}
public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Decimal128Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (decimal)value;
@@ -381,14 +381,14 @@ public static class DataSerializer
}
}
public static TDU StringComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU StringComposer(object value, Warehouse warehouse, EpConnection connection)
{
var b = Encoding.UTF8.GetBytes((string)value);
return new TDU(TDUIdentifier.String, b, (uint)b.Length);
}
public static TDU ResourceLinkComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU ResourceLinkComposer(object value, Warehouse warehouse, EpConnection connection)
{
var b = Encoding.UTF8.GetBytes((ResourceLink)value);
@@ -396,7 +396,7 @@ public static class DataSerializer
}
public static TDU EnumComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU EnumComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, null, 0);
@@ -406,11 +406,11 @@ public static class DataSerializer
//if (warehouse == null)
// throw new Exception("Warehouse not set.");
var template = warehouse.GetTemplateByType(value.GetType());
var typeDef = warehouse.GetTypeDefByType(value.GetType());
var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode());
var ct = template.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
var ct = typeDef.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
if (ct == null)
return new TDU(TDUIdentifier.Null, null, 0);
@@ -418,28 +418,28 @@ public static class DataSerializer
//return Codec.ComposeInternal(intVal, warehouse, connection);
return new TDU(TDUIdentifier.TypedEnum,
new byte[] { ct.Index }, 1, template.ClassId.Data);
new byte[] { ct.Index }, 1, typeDef.Id.Data);
}
public static TDU UInt8Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU UInt8Composer(object value, Warehouse warehouse, EpConnection connection)
{
return new TDU(TDUIdentifier.UInt8,
new byte[] { (byte)value }, 1);
}
public static TDU Int8Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU Int8Composer(object value, Warehouse warehouse, EpConnection connection)
{
return new TDU(TDUIdentifier.Int8,
new byte[] { (byte)(sbyte)value }, 1);
}
public static TDU Char8Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU Char8Composer(object value, Warehouse warehouse, EpConnection connection)
{
return new TDU(TDUIdentifier.Int8,
new byte[] { (byte)(char)value }, 1);
}
public static unsafe TDU Char16Composer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU Char16Composer(object value, Warehouse warehouse, EpConnection connection)
{
var v = (char)value;
var rt = new byte[2];
@@ -450,7 +450,7 @@ public static class DataSerializer
}
public static TDU BoolComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU BoolComposer(object value, Warehouse warehouse, EpConnection connection)
{
if ((bool)value)
{
@@ -463,24 +463,24 @@ public static class DataSerializer
}
public static TDU NotModifiedComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU NotModifiedComposer(object value, Warehouse warehouse, EpConnection connection)
{
return new TDU(TDUIdentifier.NotModified, null, 0);
}
public static TDU RawDataComposerFromArray(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU RawDataComposerFromArray(object value, Warehouse warehouse, EpConnection connection)
{
var b = (byte[])value;
return new TDU(TDUIdentifier.RawData, b, (uint)b.Length);
}
public static TDU RawDataComposerFromList(dynamic value, Warehouse warehouse, DistributedConnection connection)
public static TDU RawDataComposerFromList(dynamic value, Warehouse warehouse, EpConnection connection)
{
var b = value as List<byte>;
return new TDU(TDUIdentifier.RawData, b.ToArray(), (uint)b.Count);
}
//public static (TDUIdentifier, byte[]) ListComposerFromArray(dynamic value, DistributedConnection connection)
//public static (TDUIdentifier, byte[]) ListComposerFromArray(dynamic value, EpConnection connection)
//{
// var rt = new List<byte>();
// var array = (object[])value;
@@ -491,7 +491,7 @@ public static class DataSerializer
// return (TDUIdentifier.List, rt.ToArray());
//}
public static TDU ListComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU ListComposer(object value, Warehouse warehouse, EpConnection connection)
{
var composed = DynamicArrayComposer((IEnumerable)value, warehouse, connection);
@@ -534,7 +534,7 @@ public static class DataSerializer
//return new TDU(TDUIdentifier.List, rt.ToArray(), (uint)rt.Count);
}
public static byte[] TypedArrayComposer(IEnumerable value, TRU tru, Warehouse warehouse, DistributedConnection connection)
public static byte[] TypedArrayComposer(IEnumerable value, TRU tru, Warehouse warehouse, EpConnection connection)
{
byte[] composed;
@@ -570,12 +570,12 @@ public static class DataSerializer
{
var rt = new List<byte>();
var template = warehouse.GetTemplateByType(tru.GetRuntimeType(warehouse));
var typeDef = warehouse.GetTypeDefByType(tru.GetRuntimeType(warehouse));
foreach (var v in value)
{
var intVal = Convert.ChangeType(v, (v as Enum).GetTypeCode());
var ct = template.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
var ct = typeDef.Constants.FirstOrDefault(x => x.Value.Equals(intVal));
if (ct == null)
throw new Exception("Unknown Enum.");
rt.Add(ct.Index);
@@ -630,7 +630,7 @@ public static class DataSerializer
}
public static TDU TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, DistributedConnection connection)
public static TDU TypedListComposer(IEnumerable value, Type type, Warehouse warehouse, EpConnection connection)
{
var tru = TRU.FromType(type);
@@ -644,7 +644,7 @@ public static class DataSerializer
return new TDU(TDUIdentifier.TypedList, composed, (uint)composed.Length, metadata);
}
//public static byte[] PropertyValueComposer(PropertyValue propertyValue, DistributedConnection connection)//, bool includeAge = true)
//public static byte[] PropertyValueComposer(PropertyValue propertyValue, EpConnection connection)//, bool includeAge = true)
//{
// var rt = new BinaryList();
@@ -655,7 +655,7 @@ public static class DataSerializer
// .ToArray();
//}
public static TDU PropertyValueArrayComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU PropertyValueArrayComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 0);
@@ -674,7 +674,7 @@ public static class DataSerializer
(uint)rt.Count);
}
public static TDU TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
public static TDU TypedMapComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 0);
@@ -712,7 +712,7 @@ public static class DataSerializer
//return new TDU(TDUIdentifier.TypedMap, rt.ToArray(), (uint)rt.Count,
// );
}
public static TDU TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, DistributedConnection connection)
public static TDU TypedDictionaryComposer(object value, Type keyType, Type valueType, Warehouse warehouse, EpConnection connection)
{
if (value == null)
@@ -775,7 +775,7 @@ public static class DataSerializer
// DC.Combine(kt, 0, (uint)kt.Length, vt, 0, (uint)vt.Length));
}
public static byte[] DynamicArrayComposer(IEnumerable value, Warehouse warehouse, DistributedConnection connection)
public static byte[] DynamicArrayComposer(IEnumerable value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return null;
@@ -806,7 +806,7 @@ public static class DataSerializer
return rt.ToArray();
}
public static TDU ResourceListComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU ResourceListComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 0);
@@ -817,7 +817,7 @@ public static class DataSerializer
(uint)composed.Length);
}
public static TDU RecordListComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU RecordListComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 0);
@@ -829,7 +829,7 @@ public static class DataSerializer
}
public static unsafe TDU ResourceComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU ResourceComposer(object value, Warehouse warehouse, EpConnection connection)
{
var resource = (IResource)value;
@@ -840,7 +840,7 @@ public static class DataSerializer
if (Codec.IsLocalResource(resource, connection))
{
var rid = (resource as DistributedResource).DistributedResourceInstanceId;
var rid = (resource as EpResource).DistributedResourceInstanceId;
if (rid <= 0xFF)
return new TDU(TDUIdentifier.LocalResource8, new byte[] { (byte)rid }, 1);
@@ -863,7 +863,6 @@ public static class DataSerializer
else
{
//rt.Append((value as IResource).Instance.Template.ClassId, (value as IResource).Instance.Id);
connection.cache.Add(value as IResource, DateTime.UtcNow);
var rid = resource.Instance.Id;
@@ -888,7 +887,7 @@ public static class DataSerializer
}
}
public static unsafe TDU MapComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU MapComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 1);
@@ -902,21 +901,21 @@ public static class DataSerializer
return new TDU(TDUIdentifier.Map, rt.ToArray(), (uint)rt.Count);
}
public static unsafe TDU UUIDComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU UUIDComposer(object value, Warehouse warehouse, EpConnection connection)
{
return new TDU(TDUIdentifier.UUID, ((UUID)value).Data, 16);
}
public static unsafe TDU RecordComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static unsafe TDU RecordComposer(object value, Warehouse warehouse, EpConnection connection)
{
var rt = new List<byte>();
var record = (IRecord)value;
var template = warehouse.GetTemplateByType(record.GetType());
var typeDef = warehouse.GetTypeDefByType(record.GetType());
foreach (var pt in template.Properties)
foreach (var pt in typeDef.Properties)
{
var propValue = pt.PropertyInfo.GetValue(record, null);
@@ -940,11 +939,11 @@ public static class DataSerializer
return new TDU(TDUIdentifier.Record, rt.ToArray(),
(uint)rt.Count,
template.ClassId.Data);
typeDef.Id.Data);
}
public static byte[] HistoryComposer(KeyList<PropertyDefinition, PropertyValue[]> history, Warehouse warehouse,
DistributedConnection connection, bool prependLength = false)
public static byte[] HistoryComposer(KeyList<PropertyDef, PropertyValue[]> history, Warehouse warehouse,
EpConnection connection, bool prependLength = false)
{
//@TODO:Test
var rt = new BinaryList();
@@ -959,7 +958,7 @@ public static class DataSerializer
return rt.ToArray();
}
public static TDU TupleComposer(object value, Warehouse warehouse, DistributedConnection connection)
public static TDU TupleComposer(object value, Warehouse warehouse, EpConnection connection)
{
if (value == null)
return new TDU(TDUIdentifier.Null, new byte[0], 0);

View File

@@ -25,7 +25,6 @@ SOFTWARE.
using Esiur.Core;
using Esiur.Data;
using Esiur.Misc;
using Esiur.Net.IIP;
using System;
using System.Collections;
using System.Collections.Generic;

View File

@@ -23,7 +23,6 @@ SOFTWARE.
*/
using Esiur.Net.IIP;
using Esiur.Resource;
using System;
using System.Collections.Generic;
@@ -52,7 +51,7 @@ class ResourceJsonConverter : JsonConverter<IResource>
writer.WriteStartObject();
foreach (var pt in resource.Instance.Schema.Properties)
foreach (var pt in resource.Instance.Definition.Properties)
{
var rt = pt.PropertyInfo.GetValue(resource, null);
if (rt != null && rt.GetType().IsGenericType)

View File

@@ -458,7 +458,7 @@ public static class RuntimeCaster
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsListType(Type t)
{
return t.IsGenericType && t.GetGenericTypeDef() == typeof(List<>);
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(List<>);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View File

@@ -1,5 +1,4 @@
using Esiur.Net.IIP;
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Linq;

View File

@@ -1,6 +1,5 @@
using Esiur.Core;
using Esiur.Data.Types;
using Esiur.Net.IIP;
using Esiur.Resource;
using Microsoft.CodeAnalysis;
using System;

View File

@@ -107,7 +107,7 @@ public class ConstantDef : MemberDef
var value = ci.GetValue(null);
if (typeDef?.Type == TypeDefKind.Enum)
if (typeDef?.Kind == TypeDefKind.Enum)
value = Convert.ChangeType(value, ci.FieldType.GetEnumUnderlyingType());
Map<string, string> annotations = null;

View File

@@ -1,6 +1,6 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Net.IIP;
using Esiur.Protocol;
using Esiur.Resource;
using System;
using System.Collections.Generic;
@@ -217,7 +217,7 @@ public class FunctionDef : MemberDef
if (args.Length > 0)
{
if (args.Last().ParameterType == typeof(DistributedConnection)
if (args.Last().ParameterType == typeof(EpConnection)
|| args.Last().ParameterType == typeof(InvocationContext))
args = args.Take(args.Count() - 1).ToArray();
}
@@ -286,7 +286,7 @@ public class FunctionDef : MemberDef
{
annotations = new Map<string, string>();
annotations.Add("", "(" + String.Join(",",
mi.GetParameters().Where(x => x.ParameterType != typeof(DistributedConnection))
mi.GetParameters().Where(x => x.ParameterType != typeof(EpConnection))
.Select(x => "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name);
}
@@ -307,7 +307,7 @@ public class FunctionDef : MemberDef
public override string ToString()
{
//return = "(" + String.Join(",", mi.GetParameters().Where(x => x.ParameterType != typeof(DistributedConnection)).Select(x => "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name;
//return = "(" + String.Join(",", mi.GetParameters().Where(x => x.ParameterType != typeof(EpConnection)).Select(x => "[" + x.ParameterType.Name + "] " + x.Name)) + ") -> " + mi.ReturnType.Name;
return $"{ReturnType} {Name}({string.Join(", ", Arguments.Select(a => a.ToString()))})";
}

View File

@@ -22,7 +22,7 @@ public class MemberDef
// Inherited = inherited;
//}
public string Fullname => Definition.ClassName + "." + Name;
public string Fullname => Definition.Name + "." + Name;
//public virtual byte[] Compose()
//{

View File

@@ -1,5 +1,5 @@
using Esiur.Data;
using Esiur.Net.IIP;
using Esiur.Protocol;
using Esiur.Resource;
using System;
using System.Collections.Generic;
@@ -34,7 +34,7 @@ public class PropertyDef : MemberDef
}
*/
//bool ReadOnly;
//IIPTypes::DataType ReturnType;
//EPTypes::DataType ReturnType;
public PropertyPermission Permission
{
get;
@@ -43,7 +43,7 @@ public class PropertyDef : MemberDef
//public bool IsNullable { get; set; }
public bool Recordable
public bool HasHistory
{
get;
set;
@@ -87,7 +87,7 @@ public class PropertyDef : MemberDef
var hasAnnotation = ((data[offset] & 0x8) == 0x8);
var recordable = ((data[offset] & 1) == 1);
var hasHistory = ((data[offset] & 1) == 1);
var permission = (PropertyPermission)((data[offset++] >> 1) & 0x3);
var name = data.GetString(offset + 1, data[offset]);
@@ -116,7 +116,7 @@ public class PropertyDef : MemberDef
Name = name,
Inherited = inherited,
Permission = permission,
Recordable = recordable,
HasHistory = hasHistory,
ValueType = valueType,
Annotations = annotations
});
@@ -127,7 +127,7 @@ public class PropertyDef : MemberDef
{
var name = DC.ToBytes(Name);
var pv = ((byte)(Permission) << 1) | (Recordable ? 1 : 0);
var pv = ((byte)(Permission) << 1) | (HasHistory ? 1 : 0);
if (Inherited)
pv |= 0x80;
@@ -193,17 +193,7 @@ public class PropertyDef : MemberDef
}
}
//public PropertyTemplate(TypeSchema template, byte index, string name, bool inherited,
// TRU valueType, string readAnnotation = null, string writeAnnotation = null, bool recordable = false)
// : base(template, index, name, inherited)
//{
// this.Recordable = recordable;
// //this.Storage = storage;
// if (readAnnotation != null)
// this.ReadAnnotation = readAnnotation;
// this.WriteAnnotation = writeAnnotation;
// this.ValueType = valueType;
//}
public static PropertyDef MakePropertyDef(Type type, PropertyInfo pi, string name, byte index, PropertyPermission permission, TypeDef schema)
{
@@ -273,24 +263,12 @@ public class PropertyDef : MemberDef
Inherited = pi.DeclaringType != type,
ValueType = propType,
PropertyInfo = pi,
Recordable = storageAttr == null ? false : storageAttr.Mode == StorageMode.Recordable,
HasHistory = storageAttr == null ? false : storageAttr.Mode == StorageMode.History,
Permission = permission,
Annotations = annotations,
};
//var pt = new PropertyTemplate(TypeSchema, index, customName ?? pi.Name, pi.DeclaringType != type, propType);
//if (storageAttr != null)
// pt.Recordable = storageAttr.Mode == StorageMode.Recordable;
//if (annotationAttr != null)
// pt.ReadAnnotation = annotationAttr.Annotation;
//else
// pt.ReadAnnotation = GetTypeAnnotationName(pi.PropertyType);
//pt.PropertyInfo = pi;
//return pt;
}

View File

@@ -8,9 +8,9 @@ using Esiur.Data;
using Esiur.Core;
using System.Security.Cryptography;
using Esiur.Proxy;
using Esiur.Net.IIP;
using System.Runtime.CompilerServices;
using Esiur.Resource;
using Esiur.Protocol;
namespace Esiur.Data.Types;
@@ -245,7 +245,7 @@ public class TypeDef
// Get parents
while (parentType != null)
{
var parentTemplate = warehouse.GetTemplateByType(parentType);
var parentTemplate = warehouse.GetTypeDefByType(parentType);
if (parentTemplate != null)
{
list.Add(parentTemplate);
@@ -262,7 +262,7 @@ public class TypeDef
foreach (var functionReturnType in functionReturnTypes)
{
var functionReturnTemplate = warehouse.GetTemplateByType(functionReturnType);
var functionReturnTemplate = warehouse.GetTypeDefByType(functionReturnType);
if (functionReturnTemplate != null)
{
if (!bag.Contains(functionReturnTemplate))
@@ -281,7 +281,7 @@ public class TypeDef
foreach (var fpType in fpTypes)
{
var fpt = warehouse.GetTemplateByType(fpType);
var fpt = warehouse.GetTypeDefByType(fpType);
if (fpt != null)
{
if (!bag.Contains(fpt))
@@ -293,18 +293,18 @@ public class TypeDef
}
}
// skip DistributedConnection argument
// skip EpConnection argument
if (args.Length > 0)
{
var last = args.Last();
if (last.ParameterType != typeof(DistributedConnection))
if (last.ParameterType != typeof(EpConnection))
{
var fpTypes = GetDistributedTypes(last.ParameterType);
foreach (var fpType in fpTypes)
{
var fpt = warehouse.GetTemplateByType(fpType);
var fpt = warehouse.GetTypeDefByType(fpType);
if (fpt != null)
{
if (!bag.Contains(fpt))
@@ -326,7 +326,7 @@ public class TypeDef
foreach (var propertyType in propertyTypes)
{
var propertyTemplate = warehouse.GetTemplateByType(propertyType);
var propertyTemplate = warehouse.GetTypeDefByType(propertyType);
if (propertyTemplate != null)
{
if (!bag.Contains(propertyTemplate))
@@ -345,7 +345,7 @@ public class TypeDef
foreach (var eventType in eventTypes)
{
var eventTemplate = warehouse.GetTemplateByType(eventType);
var eventTemplate = warehouse.GetTypeDefByType(eventType);
if (eventTemplate != null)
{
@@ -398,7 +398,7 @@ public class TypeDef
else
throw new Exception("Type must implement IResource, IRecord or inherit from DistributedResource.");
IsWrapper = Codec.InheritsClass(type, typeof(DistributedResource));
IsWrapper = Codec.InheritsClass(type, typeof(EpResource));
type = ResourceProxy.GetBaseType(type);
@@ -410,7 +410,7 @@ public class TypeDef
typeId = GetTypeUUID(type);
if (warehouse != null)
warehouse.RegisterSchema(this);
warehouse.RegisterTypeDef(this);
var hierarchy = GetHierarchy(type);
@@ -729,6 +729,7 @@ public class TypeDef
byte functionIndex = 0;
byte propertyIndex = 0;
byte eventIndex = 0;
byte constantIndex = 0;
for (int i = 0; i < methodsCount; i++)
{
@@ -750,14 +751,14 @@ public class TypeDef
}
else if (type == 2) // Event
{
var (len, et) = EventDef.Parse(data, offset, propertyIndex++, inherited);
var (len, et) = EventDef.Parse(data, offset, eventIndex++, inherited);
offset += len;
od.events.Add(et);
}
// constant
else if (type == 3)
{
var (len, ct) = ConstantDef.Parse(data, offset, propertyIndex++, inherited);
var (len, ct) = ConstantDef.Parse(data, offset, constantIndex++, inherited);
offset += len;
od.constants.Add(ct);
}

View File

@@ -1,25 +1,25 @@
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Net.Packets;
using Esiur.Protocol;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.HTTP;
public class IIPoHTTP : HTTPFilter
public class EPoHTTP : HTTPFilter
{
[Attribute]
EntryPoint EntryPoint { get; set; }
public override AsyncReply<bool> Execute(HTTPConnection sender)
{
if (sender.Request.URL != "iip")
if (sender.Request.URL != "EP")
return new AsyncReply<bool>(false);
IIPPacketRequest action = (IIPPacketRequest)Convert.ToByte(sender.Request.Query["a"]);
EpPacketRequest action = (EpPacketRequest)Convert.ToByte(sender.Request.Query["a"]);
if (action == IIPPacketRequest.Query)
if (action == EpPacketRequest.Query)
{
EntryPoint.Query(sender.Request.Query["l"], null).Then(x =>
{

View File

@@ -28,15 +28,15 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Esiur.Resource;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Esiur.Core;
using Esiur.Protocol;
namespace Esiur.Net.HTTP;
public class IIPoWS : HTTPFilter
public class EPoWS : HTTPFilter
{
[Attribute]
public DistributedServer Server
public EpServer Server
{
get;
set;
@@ -59,10 +59,10 @@ public class IIPoWS : HTTPFilter
var wsSocket = new WSocket(tcpSocket);
httpServer.Remove(sender);
var iipConnection = new DistributedConnection();
var EPConnection = new EpConnection();
Server.Add(iipConnection);
iipConnection.Assign(wsSocket);
Server.Add(EPConnection);
EPConnection.Assign(wsSocket);
wsSocket.Begin();
return new AsyncReply<bool>(true);

View File

@@ -1,36 +0,0 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Net.Packets;
using Esiur.Security.Membership;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
{
public class DistributedConnectionConfig
{
public ExceptionLevel ExceptionLevel { get; set; }
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
public bool AutoReconnect { get; set; } = false;
public uint ReconnectInterval { get; set; } = 5;
public string Username { get; set; }
public bool UseWebSocket { get; set; }
public bool SecureWebSocket { get; set; }
public string Password { get; set; }
public string Token { get; set; }
public ulong TokenIndex { get; set; }
public string Domain { get; set; }
}
}

View File

@@ -1,20 +0,0 @@
using Esiur.Core;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
{
internal class DistributedResourceAttachRequestInfo
{
public AsyncReply<DistributedResource> Reply { get; set; }
public uint[] RequestSequence { get; set; }
public DistributedResourceAttachRequestInfo(AsyncReply<DistributedResource> reply, uint[] requestSequence)
{
Reply = reply;
RequestSequence = requestSequence;
}
}
}

View File

@@ -1,36 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP;
public interface IPropertyContext
{
object GetValue(DistributedConnection connection);
}
public class PropertyContext<T> : IPropertyContext
{
public T Value { get; private set; }
public DistributedConnection Connection { get; private set; }
public Func<DistributedConnection, T> Method { get; private set; }
public PropertyContext(DistributedConnection connection, T value)
{
this.Value = value;
this.Connection = connection;
}
public PropertyContext(Func<DistributedConnection, T> method)
{
this.Method = method;
}
public static implicit operator PropertyContext<T>(Func<DistributedConnection, T> method)
=> new PropertyContext<T>(method);
public object GetValue(DistributedConnection connection)
{
return Method.Invoke(connection);
}
}

View File

@@ -4,19 +4,19 @@ using System.Text;
namespace Esiur.Net.Packets
{
public static class IIPAuthExtensions
public static class EpAuthExtensions
{
public static IIPAuthPacketIAuthFormat GetIAuthFormat(this object value)
public static EpAuthPacketIAuthFormat GetIAuthFormat(this object value)
{
if (value is string)
return IIPAuthPacketIAuthFormat.Text;
return EpAuthPacketIAuthFormat.Text;
else if (value is int || value is uint
|| value is byte || value is sbyte
|| value is short || value is ushort
|| value is long || value is ulong)
return IIPAuthPacketIAuthFormat.Number;
return EpAuthPacketIAuthFormat.Number;
else if (value.GetType().IsArray)
return IIPAuthPacketIAuthFormat.Choice;
return EpAuthPacketIAuthFormat.Choice;
throw new Exception("Unknown IAuth format");
}

View File

@@ -35,33 +35,33 @@ using System.Timers;
namespace Esiur.Net.Packets;
public class IIPAuthPacket : Packet
public class EpAuthPacket : Packet
{
public IIPAuthPacketCommand Command
public EpAuthPacketCommand Command
{
get;
set;
}
public IIPAuthPacketInitialize Initialization
public EpAuthPacketInitialize Initialization
{
get;
set;
}
public IIPAuthPacketAcknowledge Acknowledgement
public EpAuthPacketAcknowledge Acknowledgement
{
get;
set;
}
public IIPAuthPacketAction Action
public EpAuthPacketAction Action
{
get;
set;
}
public IIPAuthPacketEvent Event
public EpAuthPacketEvent Event
{
get;
set;
@@ -92,13 +92,13 @@ public class IIPAuthPacket : Packet
}
public IIPAuthPacketPublicKeyAlgorithm PublicKeyAlgorithm
public EpAuthPacketPublicKeyAlgorithm PublicKeyAlgorithm
{
get;
set;
}
public IIPAuthPacketHashAlgorithm HashAlgorithm
public EpAuthPacketHashAlgorithm HashAlgorithm
{
get;
set;
@@ -176,14 +176,14 @@ public class IIPAuthPacket : Packet
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
Command = (IIPAuthPacketCommand)(data[offset] >> 6);
Command = (EpAuthPacketCommand)(data[offset] >> 6);
if (Command == IIPAuthPacketCommand.Initialize)
if (Command == EpAuthPacketCommand.Initialize)
{
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
Initialization = (IIPAuthPacketInitialize)(data[offset++] & 0xFC); // remove last two reserved LSBs
Initialization = (EpAuthPacketInitialize)(data[offset++] & 0xFC); // remove last two reserved LSBs
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -197,13 +197,13 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Command == IIPAuthPacketCommand.Acknowledge)
else if (Command == EpAuthPacketCommand.Acknowledge)
{
LocalMethod = (AuthenticationMethod)(data[offset] >> 4 & 0x3);
RemoteMethod = (AuthenticationMethod)(data[offset] >> 2 & 0x3);
Acknowledgement = (IIPAuthPacketAcknowledge)(data[offset++] & 0xFC); // remove last two reserved LSBs
Acknowledgement = (EpAuthPacketAcknowledge)(data[offset++] & 0xFC); // remove last two reserved LSBs
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -216,19 +216,19 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Command == IIPAuthPacketCommand.Action)
else if (Command == EpAuthPacketCommand.Action)
{
Action = (IIPAuthPacketAction)data[offset++]; // (IIPAuthPacketAction)(data[offset++] & 0x3f);
Action = (EpAuthPacketAction)data[offset++]; // (EPAuthPacketAction)(data[offset++] & 0x3f);
if (Action == IIPAuthPacketAction.AuthenticateHash
|| Action == IIPAuthPacketAction.AuthenticatePublicHash
|| Action == IIPAuthPacketAction.AuthenticatePrivateHash
|| Action == IIPAuthPacketAction.AuthenticatePublicPrivateHash)
if (Action == EpAuthPacketAction.AuthenticateHash
|| Action == EpAuthPacketAction.AuthenticatePublicHash
|| Action == EpAuthPacketAction.AuthenticatePrivateHash
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHash)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var hashLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -241,13 +241,13 @@ public class IIPAuthPacket : Packet
offset += hashLength;
}
else if (Action == IIPAuthPacketAction.AuthenticatePrivateHashCert
|| Action == IIPAuthPacketAction.AuthenticatePublicPrivateHashCert)
else if (Action == EpAuthPacketAction.AuthenticatePrivateHashCert
|| Action == EpAuthPacketAction.AuthenticatePublicPrivateHashCert)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var hashLength = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -272,7 +272,7 @@ public class IIPAuthPacket : Packet
offset += certLength;
}
else if (Action == IIPAuthPacketAction.IAuthPlain)
else if (Action == EpAuthPacketAction.IAuthPlain)
{
if (NotEnough(offset, ends, 5))
return -dataLengthNeeded;
@@ -288,7 +288,7 @@ public class IIPAuthPacket : Packet
offset += (uint)DataType.Value.TotalLength;
}
else if (Action == IIPAuthPacketAction.IAuthHashed)
else if (Action == EpAuthPacketAction.IAuthHashed)
{
if (NotEnough(offset, ends, 7))
return -dataLengthNeeded;
@@ -296,7 +296,7 @@ public class IIPAuthPacket : Packet
Reference = data.GetUInt32(offset, Endian.Little);
offset += 4;
HashAlgorithm = (IIPAuthPacketHashAlgorithm)data[offset++];
HashAlgorithm = (EpAuthPacketHashAlgorithm)data[offset++];
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -309,7 +309,7 @@ public class IIPAuthPacket : Packet
offset += cl;
}
else if (Action == IIPAuthPacketAction.IAuthEncrypted)
else if (Action == EpAuthPacketAction.IAuthEncrypted)
{
if (NotEnough(offset, ends, 7))
return -dataLengthNeeded;
@@ -317,7 +317,7 @@ public class IIPAuthPacket : Packet
Reference = data.GetUInt32(offset, Endian.Little);
offset += 4;
PublicKeyAlgorithm = (IIPAuthPacketPublicKeyAlgorithm)data[offset++];
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
var cl = data.GetUInt16(offset, Endian.Little);
offset += 2;
@@ -330,11 +330,11 @@ public class IIPAuthPacket : Packet
offset += cl;
}
else if (Action == IIPAuthPacketAction.EstablishNewSession)
else if (Action == EpAuthPacketAction.EstablishNewSession)
{
// Nothing here
}
else if (Action == IIPAuthPacketAction.EstablishResumeSession)
else if (Action == EpAuthPacketAction.EstablishResumeSession)
{
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;
@@ -349,7 +349,7 @@ public class IIPAuthPacket : Packet
offset += sessionLength;
}
else if (Action == IIPAuthPacketAction.EncryptKeyExchange)
else if (Action == EpAuthPacketAction.EncryptKeyExchange)
{
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
@@ -366,13 +366,13 @@ public class IIPAuthPacket : Packet
offset += keyLength;
}
else if (Action == IIPAuthPacketAction.RegisterEndToEndKey
|| Action == IIPAuthPacketAction.RegisterHomomorphic)
else if (Action == EpAuthPacketAction.RegisterEndToEndKey
|| Action == EpAuthPacketAction.RegisterHomomorphic)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
PublicKeyAlgorithm = (IIPAuthPacketPublicKeyAlgorithm)data[offset++];
PublicKeyAlgorithm = (EpAuthPacketPublicKeyAlgorithm)data[offset++];
var keyLength = data.GetUInt16(offset, Endian.Little);
@@ -387,14 +387,14 @@ public class IIPAuthPacket : Packet
}
}
else if (Command == IIPAuthPacketCommand.Event)
else if (Command == EpAuthPacketCommand.Event)
{
Event = (IIPAuthPacketEvent)data[offset++];
Event = (EpAuthPacketEvent)data[offset++];
if (Event == IIPAuthPacketEvent.ErrorTerminate
|| Event == IIPAuthPacketEvent.ErrorMustEncrypt
|| Event == IIPAuthPacketEvent.ErrorRetry)
if (Event == EpAuthPacketEvent.ErrorTerminate
|| Event == EpAuthPacketEvent.ErrorMustEncrypt
|| Event == EpAuthPacketEvent.ErrorRetry)
{
if (NotEnough(offset, ends, 3))
return -dataLengthNeeded;
@@ -411,7 +411,7 @@ public class IIPAuthPacket : Packet
offset += msgLength;
}
else if (Event == IIPAuthPacketEvent.IndicationEstablished)
else if (Event == EpAuthPacketEvent.IndicationEstablished)
{
if (NotEnough(offset, ends, 2))
return -dataLengthNeeded;
@@ -438,9 +438,9 @@ public class IIPAuthPacket : Packet
offset += accountLength;
}
else if (Event == IIPAuthPacketEvent.IAuthPlain
|| Event == IIPAuthPacketEvent.IAuthHashed
|| Event == IIPAuthPacketEvent.IAuthEncrypted)
else if (Event == EpAuthPacketEvent.IAuthPlain
|| Event == EpAuthPacketEvent.IAuthHashed
|| Event == EpAuthPacketEvent.IAuthEncrypted)
{
if (NotEnough(offset, ends, 1))
return -dataLengthNeeded;

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketAcknowledge : byte
public enum EpAuthPacketAcknowledge : byte
{
NoAuthNoAuth = 0x40, // 0b01000000,
NoAuthCredentials = 0x44, // 0b01000100,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketAction : byte
public enum EpAuthPacketAction : byte
{
AuthenticateHash = 0x80,
AuthenticatePublicHash = 0x81,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketCommand : byte
public enum EpAuthPacketCommand : byte
{
Initialize = 0x0,
Acknowledge = 0x1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketEvent : byte
public enum EpAuthPacketEvent : byte
{
ErrorTerminate = 0xC0,
ErrorMustEncrypt = 0xC1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketHashAlgorithm
public enum EpAuthPacketHashAlgorithm
{
SHA256,
SHA3,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketHeader
public enum EpAuthPacketHeader
{
Version = 0,
Domain = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthDestination
public enum EpAuthPacketIAuthDestination
{
Self = 0,
Device = 1, // logged in device

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthFormat
public enum EpAuthPacketIAuthFormat
{
None = 0,
Number = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketIAuthHeader : byte
public enum EpAuthPacketIAuthHeader : byte
{
Reference = 0,
Destination = 1,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketInitialize
public enum EpAuthPacketInitialize
{
NoAuthNoAuth = 0x0, //0b00000000,
NoAuthCredentials = 0x4, //0b00000100,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPAuthPacketPublicKeyAlgorithm
public enum EpAuthPacketPublicKeyAlgorithm
{
RSA = 0,
CKKS = 1,

View File

@@ -32,15 +32,15 @@ using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.Packets;
class IIPPacket : Packet
class EpPacket : Packet
{
public uint CallbackId { get; set; }
public IIPPacketMethod Method { get; set; }
public IIPPacketRequest Request { get; set; }
public IIPPacketReply Reply { get; set; }
public EpPacketMethod Method { get; set; }
public EpPacketRequest Request { get; set; }
public EpPacketReply Reply { get; set; }
public IIPPacketNotification Notification { get; set; }
public EpPacketNotification Notification { get; set; }
public byte Extension { get; set; }
@@ -59,10 +59,10 @@ class IIPPacket : Packet
{
return Method switch
{
IIPPacketMethod.Notification => $"{Method} {Notification}",
IIPPacketMethod.Request => $"{Method} {Request}",
IIPPacketMethod.Reply => $"{Method} {Reply}",
IIPPacketMethod.Extension => $"{Method} {Extension}",
EpPacketMethod.Notification => $"{Method} {Notification}",
EpPacketMethod.Request => $"{Method} {Request}",
EpPacketMethod.Reply => $"{Method} {Reply}",
EpPacketMethod.Extension => $"{Method} {Extension}",
_ => $"{Method}"
};
}
@@ -88,15 +88,15 @@ class IIPPacket : Packet
var hasDTU = (data[offset] & 0x20) == 0x20;
Method = (IIPPacketMethod)(data[offset] >> 6);
Method = (EpPacketMethod)(data[offset] >> 6);
if (Method == IIPPacketMethod.Notification)
if (Method == EpPacketMethod.Notification)
{
Notification = (IIPPacketNotification)(data[offset++] & 0x1f);
Notification = (EpPacketNotification)(data[offset++] & 0x1f);
}
else if (Method == IIPPacketMethod.Request)
else if (Method == EpPacketMethod.Request)
{
Request = (IIPPacketRequest)(data[offset++] & 0x1f);
Request = (EpPacketRequest)(data[offset++] & 0x1f);
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
@@ -104,9 +104,9 @@ class IIPPacket : Packet
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Method == IIPPacketMethod.Reply)
else if (Method == EpPacketMethod.Reply)
{
Reply = (IIPPacketReply)(data[offset++] & 0x1f);
Reply = (EpPacketReply)(data[offset++] & 0x1f);
if (NotEnough(offset, ends, 4))
return -dataLengthNeeded;
@@ -114,7 +114,7 @@ class IIPPacket : Packet
CallbackId = data.GetUInt32(offset, Endian.Little);
offset += 4;
}
else if (Method == IIPPacketMethod.Extension)
else if (Method == EpPacketMethod.Extension)
{
Extension = (byte)(data[offset++] & 0x1f);
}

View File

@@ -5,14 +5,14 @@ using System.Text;
namespace Esiur.Net.Packets;
struct IIPPacketAttachInfo
struct EpPacketAttachInfo
{
public string Link;
public ulong Age;
public byte[] Content;
public UUID TypeId;
public IIPPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content)
public EpPacketAttachInfo(UUID typeId, ulong age, string link, byte[] content)
{
TypeId = typeId;
Age = age;

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketMethod : byte
public enum EpPacketMethod : byte
{
Notification = 0,
Request,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketNotification : byte
public enum EpPacketNotification : byte
{
// Notification Invoke
PropertyModified = 0x0,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketReply : byte
public enum EpPacketReply : byte
{
// Success
Completed = 0x0,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketReport : byte
public enum EpPacketReport : byte
{
ManagementError,
ExecutionError,

View File

@@ -4,7 +4,7 @@ using System.Text;
namespace Esiur.Net.Packets
{
public enum IIPPacketRequest : byte
public enum EpPacketRequest : byte
{
// Request Invoke
InvokeFunction = 0x0,
@@ -13,11 +13,11 @@ namespace Esiur.Net.Packets
Unsubscribe = 0x3,
// Request Inquire
SchemaFromClassName = 0x8,
SchemaFromClassId = 0x9,
SchemaFromResourceId = 0xA,
TypeDefByName = 0x8,
TypeDefById = 0x9,
TypeDefByResourceId = 0xA,
Query = 0xB,
LinkSchemas = 0xC,
LinkTypeDefs = 0xC,
Token = 0xD,
GetResourceIdByLink = 0xE,

View File

@@ -35,7 +35,7 @@ using Esiur.Core;
namespace Esiur.Net.UDP;
/* public class IIPConnection
/* public class EPConnection
{
public EndPoint SenderPoint;
public

View File

@@ -27,13 +27,12 @@ using System.Text;
using Esiur.Core;
using Esiur.Data;
using Esiur.Resource;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Protocol;
namespace Esiur.Net.IIP;
public abstract class EntryPoint : Esiur.Resource.Resource
public abstract class EntryPoint : Resource.Resource
{
public abstract AsyncReply<IResource> Query(string path, DistributedConnection sender);
public abstract AsyncReply<IResource> Query(string path, EpConnection sender);
protected abstract override bool Create();
}

View File

@@ -0,0 +1,35 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Net.Packets;
using Esiur.Security.Membership;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Protocol;
public class EpConnectionConfig
{
public ExceptionLevel ExceptionLevel { get; set; }
= ExceptionLevel.Code | ExceptionLevel.Message | ExceptionLevel.Source | ExceptionLevel.Trace;
public Func<AuthorizationRequest, AsyncReply<object>> Authenticator { get; set; }
public bool AutoReconnect { get; set; } = false;
public uint ReconnectInterval { get; set; } = 5;
public string Username { get; set; }
public bool UseWebSocket { get; set; }
public bool SecureWebSocket { get; set; }
public string Password { get; set; }
public string Token { get; set; }
public ulong TokenIndex { get; set; }
public string Domain { get; set; }
}

View File

@@ -2,9 +2,9 @@
using System.Collections.Generic;
using System.Text;
namespace Esiur.Net.IIP
namespace Esiur.Protocol
{
public enum ConnectionStatus
public enum EpConnectionStatus
{
Closed,
Connecting,

View File

@@ -43,10 +43,10 @@ using Esiur.Resource;
using Esiur.Net.Packets;
using Esiur.Data.Types;
namespace Esiur.Net.IIP;
namespace Esiur.Protocol;
//[System.Runtime.InteropServices.ComVisible(true)]
public class DistributedResource : DynamicObject, IResource, INotifyPropertyChanged, IDynamicResource
public class EpResource : DynamicObject, IResource, INotifyPropertyChanged, IDynamicResource
{
/// <summary>
@@ -58,7 +58,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
uint instanceId;
TypeDef typeDef;
DistributedConnection connection;
EpConnection connection;
bool attached = false;
@@ -71,17 +71,17 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
ulong age;
protected object[] properties;
internal List<DistributedResource> parents = new List<DistributedResource>();
internal List<DistributedResource> children = new List<DistributedResource>();
internal List<EpResource> parents = new List<EpResource>();
internal List<EpResource> children = new List<EpResource>();
DistributedResourceEvent[] events;
EpResourceEvent[] events;
/// <summary>
/// Connection responsible for the distributed resource.
/// </summary>
public DistributedConnection DistributedResourceConnection
public EpConnection DistributedResourceConnection
{
get { return connection; }
}
@@ -145,7 +145,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
/// <param name="template">Resource template.</param>
/// <param name="instanceId">Instance Id given by the other end.</param>
/// <param name="age">Resource age.</param>
public DistributedResource(DistributedConnection connection, uint instanceId, ulong age, string link)
public EpResource(EpConnection connection, uint instanceId, ulong age, string link)
{
this.link = link;
this.connection = connection;
@@ -163,7 +163,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
this.properties = new object[properties.Length];
this.events = new DistributedResourceEvent[Instance.Definition.Events.Length];
this.events = new EpResourceEvent[Instance.Definition.Events.Length];
for (byte i = 0; i < properties.Length; i++)
{
@@ -209,7 +209,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
throw new Exception("Function template not found.");
if (ft.IsStatic)
return connection.StaticCall(Instance.Definition.ClassId, index, args);
return connection.StaticCall(Instance.Definition.Id, index, args);
else
return connection.SendInvoke(instanceId, index, args);
}
@@ -416,7 +416,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
if (et == null)
return false;
events[et.Index] = (DistributedResourceEvent)value;
events[et.Index] = (EpResourceEvent)value;
return true;
}
@@ -448,7 +448,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
/// <summary>
/// Create a new instance of distributed resource.
/// </summary>
public DistributedResource()
public EpResource()
{
//stack = new DistributedResourceStack(this);
//this.Instance.ResourceModified += this.OnModified;
@@ -553,7 +553,7 @@ public class DistributedResource : DynamicObject, IResource, INotifyPropertyChan
return;
}
~DistributedResource()
~EpResource()
{
Destroy();
}

View File

@@ -0,0 +1,19 @@
using Esiur.Core;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Protocol;
internal class EpResourceAttachRequestInfo
{
public AsyncReply<EpResource> Reply { get; set; }
public uint[] RequestSequence { get; set; }
public EpResourceAttachRequestInfo(AsyncReply<EpResource> reply, uint[] requestSequence)
{
Reply = reply;
RequestSequence = requestSequence;
}
}

View File

@@ -28,6 +28,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.IIP;
namespace Esiur.Protocol;
public delegate void DistributedResourceEvent(DistributedResource sender, object argument);
public delegate void EpResourceEvent(EpResource sender, object argument);

View File

@@ -28,8 +28,8 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Esiur.Net.IIP;
public class DistributedResourceQueueItem
namespace Esiur.Protocol;
public class EpResourceQueueItem
{
public enum DistributedResourceQueueItemType
{
@@ -40,9 +40,9 @@ public class DistributedResourceQueueItem
DistributedResourceQueueItemType type;
byte index;
object value;
DistributedResource resource;
EpResource resource;
public DistributedResourceQueueItem(DistributedResource resource, DistributedResourceQueueItemType type, object value, byte index)
public EpResourceQueueItem(EpResource resource, DistributedResourceQueueItemType type, object value, byte index)
{
this.resource = resource;
this.index = index;
@@ -50,7 +50,7 @@ public class DistributedResourceQueueItem
this.value = value;
}
public DistributedResource Resource
public EpResource Resource
{
get { return resource; }
}

View File

@@ -35,10 +35,12 @@ using System.Net;
using Esiur.Resource;
using Esiur.Security.Membership;
using System.Threading.Tasks;
using Esiur.Data.Schema;
using Esiur.Data.Types;
using Esiur.Net;
namespace Esiur.Protocol;
namespace Esiur.Net.IIP;
public class DistributedServer : NetworkServer<DistributedConnection>, IResource
public class EpServer : NetworkServer<EpConnection>, IResource
{
@@ -133,7 +135,7 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
protected override void ClientConnected(DistributedConnection connection)
protected override void ClientConnected(EpConnection connection)
{
//Task.Delay(10000).ContinueWith((x) =>
//{
@@ -145,20 +147,20 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
}
public override void Add(DistributedConnection connection)
public override void Add(EpConnection connection)
{
connection.Server = this;
connection.ExceptionLevel = ExceptionLevel;
base.Add(connection);
}
public override void Remove(DistributedConnection connection)
public override void Remove(EpConnection connection)
{
connection.Server = null;
base.Remove(connection);
}
protected override void ClientDisconnected(DistributedConnection connection)
protected override void ClientDisconnected(EpConnection connection)
{
//connection.OnReady -= ConnectionReadyEventReceiver;
//Warehouse.Remove(connection);
@@ -168,13 +170,13 @@ public class DistributedServer : NetworkServer<DistributedConnection>, IResource
public struct CallInfo
{
public FunctionDefinition Template;
public FunctionDef Template;
public Delegate Delegate;
}
public DistributedServer MapCall(string call, Delegate handler)
public EpServer MapCall(string call, Delegate handler)
{
var ft = FunctionDefinition.MakeFunctionDef(null, handler.Method, 0, call, null);
var ft = FunctionDef.MakeFunctionDef(null, handler.Method, 0, call, null);
Calls.Add(call, new CallInfo() { Delegate = handler, Template = ft });
return this;
}

View File

@@ -25,11 +25,12 @@ SOFTWARE.
using System;
using System.Collections.Generic;
using System.Text;
using Esiur.Net;
using Esiur.Net.Sockets;
using Esiur.Security.Authority;
namespace Esiur.Net.IIP;
public class DistributedSession : NetworkSession
namespace Esiur.Protocol;
public class EpSession : NetworkSession
{
public Source Source { get; set; }
public Authentication Authentication { get; set; }

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Protocol;
public interface IPropertyContext
{
object GetValue(EpConnection connection);
}
public class PropertyContext<T> : IPropertyContext
{
public T Value { get; private set; }
public EpConnection Connection { get; private set; }
public Func<EpConnection, T> Method { get; private set; }
public PropertyContext(EpConnection connection, T value)
{
this.Value = value;
this.Connection = connection;
}
public PropertyContext(Func<EpConnection, T> method)
{
this.Method = method;
}
public static implicit operator PropertyContext<T>(Func<EpConnection, T> method)
=> new PropertyContext<T>(method);
public object GetValue(EpConnection connection)
{
return Method.Invoke(connection);
}
}

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
namespace Esiur.Net.IIP
namespace Esiur.Protocol
{
public class ResourcePropertyChangedEventArgs : PropertyChangedEventArgs
{

View File

@@ -5,7 +5,7 @@
using Esiur.Core;
using Esiur.Data;
using Esiur.Data.Types;
using Esiur.Net.IIP;
using Esiur.Protocol;
using Esiur.Resource;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
@@ -52,11 +52,11 @@ namespace Esiur.Proxy
{
try
{
if (!TemplateGenerator.urlRegex.IsMatch(path))
if (!TypeDefGenerator.urlRegex.IsMatch(path))
continue;
var parts = TemplateGenerator.urlRegex.Split(path);
var con = Warehouse.Default.Get<DistributedConnection>($"{parts[1]}://{parts[2]}").Wait(20000);
var parts = TypeDefGenerator.urlRegex.Split(path);
var con = Warehouse.Default.Get<EpConnection>($"{parts[1]}://{parts[2]}").Wait(20000);
var templates = con.GetLinkDefinitions(parts[3]).Wait(60000);
EmitTemplates(spc, templates);
@@ -228,20 +228,20 @@ $@" public partial class {ci.Name} : IResource {{
{
if (tmp.Kind == TypeDefKind.Resource)
{
var source = TemplateGenerator.GenerateClass(tmp, templates, false);
var source = TypeDefGenerator.GenerateClass(tmp, templates, false);
spc.AddSource(tmp.Name + ".g.cs", source);
}
else if (tmp.Kind == TypeDefKind.Record)
{
var source = TemplateGenerator.GenerateRecord(tmp, templates);
var source = TypeDefGenerator.GenerateRecord(tmp, templates);
spc.AddSource(tmp.Name + ".g.cs", source);
}
}
var typesFile = "using System; \r\n namespace Esiur { public static class Generated { public static Type[] Resources {get;} = new Type[] { " +
string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Resource).Select(x => $"typeof({x.ClassName})"))
string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Resource).Select(x => $"typeof({x.Name})"))
+ " }; \r\n public static Type[] Records { get; } = new Type[] { " +
string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Record).Select(x => $"typeof({x.ClassName})"))
string.Join(",", templates.Where(x => x.Kind == TypeDefKind.Record).Select(x => $"typeof({x.Name})"))
+ " }; " +
"\r\n } \r\n}";

View File

@@ -6,13 +6,13 @@ using System.Text;
using System.Linq;
using System.Text.RegularExpressions;
using Esiur.Resource;
using Esiur.Net.IIP;
using System.Diagnostics;
using Esiur.Data.Types;
using Esiur.Protocol;
namespace Esiur.Proxy;
public static class TemplateGenerator
public static class TypeDefGenerator
{
internal static Regex urlRegex = new Regex(@"^(?:([\S]*)://([^/]*)/?)");
@@ -71,7 +71,7 @@ public static class TemplateGenerator
var rt = new StringBuilder();
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Net.IIP;");
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Protocol;");
rt.AppendLine($"namespace {nameSpace} {{");
if (typeDef.Annotations != null)
@@ -118,7 +118,7 @@ public static class TemplateGenerator
var rt = new StringBuilder();
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Net.IIP;");
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Protocol;");
rt.AppendLine($"namespace {nameSpace} {{");
if (template.Annotations != null)
@@ -202,10 +202,10 @@ public static class TemplateGenerator
{
if (!urlRegex.IsMatch(url))
throw new Exception("Invalid IIP URL");
throw new Exception("Invalid EP URL");
var path = urlRegex.Split(url);
var con = Warehouse.Default.Get<DistributedConnection>(path[1] + "://" + path[2],
var con = Warehouse.Default.Get<EpConnection>(path[1] + "://" + path[2],
!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) ? new { Username = username, Password = password } : null
).Wait(20000);
@@ -288,7 +288,7 @@ public static class TemplateGenerator
var rt = new StringBuilder();
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Net.IIP;");
rt.AppendLine("using System;\r\nusing Esiur.Resource;\r\nusing Esiur.Core;\r\nusing Esiur.Data;\r\nusing Esiur.Protocol;");
rt.AppendLine("#nullable enable");
rt.AppendLine($"namespace {nameSpace} {{");
@@ -306,12 +306,12 @@ public static class TemplateGenerator
// extends
if (template.ParentId == null)
rt.AppendLine($"public class {className} : DistributedResource {{");
rt.AppendLine($"public class {className} : EpResource {{");
else
rt.AppendLine($"public class {className} : {templates.First(x => x.Id == template.ParentId && x.Kind == TypeDefKind.Resource).Name} {{");
rt.AppendLine($"public {className}(DistributedConnection connection, uint instanceId, ulong age, string link) : base(connection, instanceId, age, link) {{}}");
rt.AppendLine($"public {className}(EpConnection connection, uint instanceId, ulong age, string link) : base(connection, instanceId, age, link) {{}}");
rt.AppendLine($"public {className}() {{}}");
foreach (var f in template.Functions)
@@ -335,7 +335,7 @@ public static class TemplateGenerator
if (f.IsStatic)
{
rt.Append($"[Export] public static AsyncReply<{rtTypeName}> {f.Name}(DistributedConnection connection");
rt.Append($"[Export] public static AsyncReply<{rtTypeName}> {f.Name}(EpConnection connection");
if (positionalArgs.Length > 0)
rt.Append(", " +

View File

@@ -83,7 +83,7 @@ Now we can add our resource to the memory store using ***Warehouse.Put***
await Warehouse.Put("sys/hello", new HelloResource());
```
To distribute our resource using Esiur IIP Protocol we need to add a DistributedServer
To distribute our resource using Esiur EP Protocol we need to add a DistributedServer
```C#
@@ -111,7 +111,7 @@ To sum up
To access our resource remotely, we need to use it's full path including the protocol, host and instance link.
```C#
dynamic res = await Warehouse.Get<IResource>("iip://localhost/sys/hello");
dynamic res = await Warehouse.Get<IResource>("EP://localhost/sys/hello");
```
Now we can invoke the exported functions and read/write properties;
@@ -128,7 +128,7 @@ Summing up
>```C#
> using Esiur.Resource;
>
> dynamic res = await Warehouse.Get<IResource>("iip://localhost/sys/hello");
> dynamic res = await Warehouse.Get<IResource>("EP://localhost/sys/hello");
>
> var reply = await res.SayHi("Hi, I'm calling you from dotnet");
>
@@ -146,14 +146,14 @@ Esiur has a self describing feature which comes with every language it supports,
After installing the Esiur nuget package a new command is added to Visual Studio Package Console Manager that is called ***Get-Template***, which generates client side classes for robust static typing.
```ps
Get-Template iip://localhost/sys/hello
Get-Template EP://localhost/sys/hello
```
This will generate and add wrappers for all types needed by our resource.
Allowing us to use
```C#
var res = await Warehouse.Get<MyResource>("iip://localhost/sys/hello");
var res = await Warehouse.Get<MyResource>("EP://localhost/sys/hello");
var reply = await res.SayHi("Static typing is better");
Console.WriteLine(reply);
```

View File

@@ -31,7 +31,7 @@ using System.Text;
using System.Threading.Tasks;
using Esiur.Security.Permissions;
using Esiur.Security.Authority;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Resource;
public interface IStore : IResource
@@ -39,8 +39,8 @@ public interface IStore : IResource
AsyncReply<IResource> Get(string path);
AsyncReply<bool> Put(IResource resource, string path);
string Link(IResource resource);
bool Record(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime);
bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime);
//bool Record(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime);
bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime);
AsyncReply<bool> Remove(IResource resource);
AsyncReply<bool> Remove(string path);
@@ -73,5 +73,5 @@ public interface IStore : IResource
//AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecord(IResource resource, ulong fromAge, ulong toAge);
// AsyncReply<KeyList<PropertyTemplate, PropertyValue[]>> GetRecordByDate(IResource resource, DateTime fromDate, DateTime toDate);
AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
//AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
}

File diff suppressed because it is too large Load Diff

View File

@@ -23,7 +23,6 @@ SOFTWARE.
*/
using Esiur.Data;
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Security.Authority;
using System;
using System.Collections.Generic;
@@ -37,10 +36,10 @@ namespace Esiur.Resource;
public delegate void ResourceEventHandler<in T>(T argument);//where T : class;
// public delegate void CustomUsersEventHanlder(string[] usernames, params object[] args);
//public delegate void CustomReceiversEventHanlder(DistributedConnection[] connections, params object[] args);
//public delegate void CustomReceiversEventHanlder(EpConnection[] connections, params object[] args);
//public delegate void CustomInquirerEventHanlder(object inquirer, params object[] args);
public delegate void CustomResourceEventHandler<in T>(object issuer, Func<Session, bool> receivers, T argument);// object issuer, Session[] receivers, params object[] args);
// public delegate void CustomReceiversEventHanlder(string[] usernames, DistributedConnection[] connections, params object[] args);
// public delegate void CustomReceiversEventHanlder(string[] usernames, EpConnection[] connections, params object[] args);

View File

@@ -7,5 +7,5 @@ public enum StorageMode : byte
{
NonVolatile,
Volatile,
Recordable
History
}

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Esiur.Core;
using Esiur.Data;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Resource;
public abstract class Store<T> : IStore where T : IResource
@@ -23,12 +23,12 @@ public abstract class Store<T> : IStore where T : IResource
public abstract AsyncReply<IResource> Get(string path);
public abstract AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
public abstract AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate);
public abstract string Link(IResource resource);
public abstract bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime);
public abstract bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime);
public abstract AsyncReply<bool> Put(IResource resource, string path);

View File

@@ -26,8 +26,8 @@ using Esiur.Core;
using Esiur.Data;
using Esiur.Data.Types;
using Esiur.Misc;
using Esiur.Net.IIP;
using Esiur.Net.Packets;
using Esiur.Protocol;
using Esiur.Proxy;
using Esiur.Security.Permissions;
using System;
@@ -59,13 +59,11 @@ public class Warehouse
uint resourceCounter = 0;
KeyList<TypeDefKind, KeyList<UUID, TypeDef>> schemas
KeyList<TypeDefKind, KeyList<UUID, TypeDef>> typeDefs
= new KeyList<TypeDefKind, KeyList<UUID, TypeDef>>()
{
//[TemplateType.Unspecified] = new KeyList<Guid, TypeSchema>(),
[TypeDefKind.Resource] = new KeyList<UUID, TypeDef>(),
[TypeDefKind.Record] = new KeyList<UUID, TypeDef>(),
//[TemplateType.Wrapper] = new KeyList<Guid, TypeSchema>(),
[TypeDefKind.Enum] = new KeyList<UUID, TypeDef>(),
};
@@ -84,14 +82,14 @@ public class Warehouse
public Warehouse()
{
Protocols.Add("iip",
Protocols.Add("EP",
async (name, attributes)
=> await New<DistributedConnection>(name, null, attributes));
=> await New<EpConnection>(name, null, attributes));
new TypeDef(typeof(IIPAuthPacketIAuthHeader), this);
new TypeDef(typeof(EpAuthPacketIAuthHeader), this);
new TypeDef(typeof(IIPAuthPacketIAuthDestination), this);
new TypeDef(typeof(IIPAuthPacketIAuthFormat), this);
new TypeDef(typeof(EpAuthPacketIAuthDestination), this);
new TypeDef(typeof(EpAuthPacketIAuthFormat), this);
}
@@ -139,19 +137,19 @@ public class Warehouse
var resourceTypes = (Type[])generatedType.GetProperty("Resources").GetValue(null);
foreach (var t in resourceTypes)
{
RegisterSchema(new TypeDef(t));
RegisterTypeDef(new TypeDef(t));
}
var recordTypes = (Type[])generatedType.GetProperty("Records").GetValue(null);
foreach (var t in recordTypes)
{
RegisterSchema(new TypeDef(t));
RegisterTypeDef(new TypeDef(t));
}
var enumsTypes = (Type[])generatedType.GetProperty("Enums").GetValue(null);
foreach (var t in enumsTypes)
{
RegisterSchema(new TypeDef(t));
RegisterTypeDef(new TypeDef(t));
}
}
}
@@ -339,86 +337,6 @@ public class Warehouse
}
/// <summary>
/// Put a resource in the warehouse.
/// </summary>
/// <param name="name">Resource name.</param>
/// <param name="resource">Resource instance.</param>
/// <param name="store">IStore that manages the resource. Can be null if the resource is a store.</param>
/// <param name="parent">Parent resource. if not presented the store becomes the parent for the resource.</param>
//public async AsyncReply<T> Put<T>(string instanceName, T resource, IStore store, TypeSchema customTemplate = null, ulong age = 0, IPermissionsManager manager = null, object attributes = null) where T : IResource
//{
// if (resource.Instance != null)
// throw new Exception("Resource has a store.");
// var resourceReference = new WeakReference<IResource>(resource);
// if (resource is IStore && store == null)
// store = (IStore)resource;
// if (store == null)
// throw new Exception("Resource store is not set.");
// resource.Instance = new Instance(this, resourceCounter++, instanceName, resource, store, customTemplate, age);
// if (attributes != null)
// if (attributes is Map<string, object> attrs)
// resource.Instance.SetAttributes(attrs);
// else
// resource.Instance.SetAttributes(Map<string, object>.FromObject(attributes));
// if (manager != null)
// resource.Instance.Managers.Add(manager);
// //if (store == parent)
// // parent = null;
// try
// {
// if (resource is IStore)
// stores.TryAdd(resource as IStore, new List<WeakReference<IResource>>());
// if (!await store.Put(resource))
// throw new Exception("Store failed to put the resource");
// //return default(T);
// //if (parent != null)
// //{
// // await parent.Instance.Store.AddChild(parent, resource);
// // await store.AddParent(resource, parent);
// //}
// var t = resource.GetType();
// Global.Counters["T-" + t.Namespace + "." + t.Name]++;
// resources.TryAdd(resource.Instance.Id, resourceReference);
// if (warehouseIsOpen)
// {
// await resource.Trigger(ResourceTrigger.Initialize);
// if (resource is IStore)
// await resource.Trigger(ResourceTrigger.Open);
// }
// if (resource is IStore)
// StoreConnected?.Invoke(resource as IStore);
// }
// catch (Exception ex)
// {
// Remove(resource);
// throw ex;
// }
// return resource;
//}
/// <summary>
/// Put a resource in the warehouse.
/// </summary>
@@ -525,9 +443,9 @@ public class Warehouse
{
if (properties is Map<byte, object> map)
{
var template = GetTemplateByType(type);
var typeDef = GetTypeDefByType(type);
foreach (var kvp in map)
template.GetPropertyDefByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value);
typeDef.GetPropertyDefByIndex(kvp.Key).PropertyInfo.SetValue(res, kvp.Value);
}
else
{
@@ -587,22 +505,22 @@ public class Warehouse
/// <summary>
/// Put a resource schema in the schemas warehouse.
/// </summary>
/// <param name="schema">Resource schema.</param>
public void RegisterSchema(TypeDef typeDef)
/// <param name="typeDef">Resource type definition.</param>
public void RegisterTypeDef(TypeDef typeDef)
{
if (schemas[typeDef.Kind].ContainsKey(typeDef.Id))
throw new Exception($"Template with same class Id already exists. {schemas[typeDef.Kind][typeDef.Id].Name} -> {typeDef.Name}");
if (typeDefs[typeDef.Kind].ContainsKey(typeDef.Id))
throw new Exception($"TypeDef with same class Id already exists. {typeDefs[typeDef.Kind][typeDef.Id].Name} -> {typeDef.Name}");
schemas[typeDef.Kind][typeDef.Id] = typeDef;
typeDefs[typeDef.Kind][typeDef.Id] = typeDef;
}
/// <summary>
/// Get a template by type from the templates warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse.
/// </summary>
/// <param name="type">.Net type.</param>
/// <returns>Resource template.</returns>
public TypeDef GetTemplateByType(Type type)
/// <summary>
/// Get a TypeDef by type from the typeDefs warehouse. If not in the warehouse, a new ResourceTemplate is created and added to the warehouse.
/// </summary>
/// <param name="type">.Net type.</param>
/// <returns>Resource template.</returns>
public TypeDef GetTypeDefByType(Type type)
{
if (!(type.IsClass || type.IsEnum))
return null;
@@ -623,7 +541,7 @@ public class Warehouse
else
return null;
var schema = schemas[schemaKind].Values.FirstOrDefault(x => x.DefinedType == baseType);
var schema = typeDefs[schemaKind].Values.FirstOrDefault(x => x.DefinedType == baseType);
if (schema != null)
return schema;
@@ -644,27 +562,22 @@ public class Warehouse
if (templateType == null)
{
// look into resources
var template = schemas[TypeDefKind.Resource][typeId];
var template = typeDefs[TypeDefKind.Resource][typeId];
if (template != null)
return template;
// look into records
template = schemas[TypeDefKind.Record][typeId];
template = typeDefs[TypeDefKind.Record][typeId];
if (template != null)
return template;
// look into enums
template = schemas[TypeDefKind.Enum][typeId];
template = typeDefs[TypeDefKind.Enum][typeId];
return template;
//if (template != null)
//// look in wrappers
//template = templates[TemplateType.Wrapper][classId];
//return template;
}
else
return schemas[templateType.Value][typeId];
return typeDefs[templateType.Value][typeId];
}
@@ -673,32 +586,28 @@ public class Warehouse
/// </summary>
/// <param name="className">Class name.</param>
/// <returns>Resource template.</returns>
public TypeDef GetTypeDfByName(string typeName, TypeDefKind? templateType = null)
public TypeDef GetTypeDefByName(string typeName, TypeDefKind? typeDefKind = null)
{
if (templateType == null)
if (typeDefKind == null)
{
// look into resources
var template = schemas[TypeDefKind.Resource].Values.FirstOrDefault(x => x.Name == typeName);
if (template != null)
return template;
var typeDef = typeDefs[TypeDefKind.Resource].Values.FirstOrDefault(x => x.Name == typeName);
if (typeDef != null)
return typeDef;
// look into records
template = schemas[TypeDefKind.Record].Values.FirstOrDefault(x => x.Name == typeName);
if (template != null)
return template;
typeDef = typeDefs[TypeDefKind.Record].Values.FirstOrDefault(x => x.Name == typeName);
if (typeDef != null)
return typeDef;
// look into enums
template = schemas[TypeDefKind.Enum].Values.FirstOrDefault(x => x.Name == typeName);
//if (template != null)
return template;
//// look in wrappers
//template = templates[TemplateType.Wrapper].Values.FirstOrDefault(x => x.ClassName == className);
//return template;
typeDef = typeDefs[TypeDefKind.Enum].Values.FirstOrDefault(x => x.Name == typeName);
return typeDef;
}
else
{
return schemas[templateType.Value].Values.FirstOrDefault(x => x.Name == typeName);
return typeDefs[typeDefKind.Value].Values.FirstOrDefault(x => x.Name == typeName);
}
}

View File

@@ -27,7 +27,6 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Esiur.Net.Packets.IIPAuthPacket;
namespace Esiur.Security.Authority;

View File

@@ -48,8 +48,8 @@ public class Session
public ISymetricCipher SymetricCipher { get; set; } = null;
public Map<IIPAuthPacketHeader, object> LocalHeaders { get; set; } = new Map<IIPAuthPacketHeader, object>();
public Map<IIPAuthPacketHeader, object> RemoteHeaders { get; set; } = new Map<IIPAuthPacketHeader, object>();
public Map<EpAuthPacketHeader, object> LocalHeaders { get; set; } = new Map<EpAuthPacketHeader, object>();
public Map<EpAuthPacketHeader, object> RemoteHeaders { get; set; } = new Map<EpAuthPacketHeader, object>();
public AuthenticationMethod LocalMethod { get; set; }
public AuthenticationMethod RemoteMethod { get; set; }

View File

@@ -11,10 +11,10 @@ namespace Esiur.Security.Membership
public class AuthorizationRequest
{
public uint Reference { get; set; }
public IIPAuthPacketIAuthDestination Destination { get; set; }
public EpAuthPacketIAuthDestination Destination { get; set; }
public string Clue { get; set; }
public IIPAuthPacketIAuthFormat? RequiredFormat { get; set; }
public IIPAuthPacketIAuthFormat? ContentFormat { get; set; }
public EpAuthPacketIAuthFormat? RequiredFormat { get; set; }
public EpAuthPacketIAuthFormat? ContentFormat { get; set; }
public object? Content { get; set; }
public byte? Trials { get; set; }
@@ -24,29 +24,29 @@ namespace Esiur.Security.Membership
public int Timeout => Expire.HasValue && Issue.HasValue ? (int)(Expire.Value - Issue.Value).TotalSeconds : 0;
public AuthorizationRequest(Map<IIPAuthPacketIAuthHeader, object> headers)
public AuthorizationRequest(Map<EpAuthPacketIAuthHeader, object> headers)
{
Reference = (uint)headers[IIPAuthPacketIAuthHeader.Reference];
Destination =(IIPAuthPacketIAuthDestination)headers[IIPAuthPacketIAuthHeader.Destination];
Clue = (string)headers[IIPAuthPacketIAuthHeader.Clue];
Reference = (uint)headers[EpAuthPacketIAuthHeader.Reference];
Destination =(EpAuthPacketIAuthDestination)headers[EpAuthPacketIAuthHeader.Destination];
Clue = (string)headers[EpAuthPacketIAuthHeader.Clue];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.RequiredFormat))
RequiredFormat = (IIPAuthPacketIAuthFormat)headers[IIPAuthPacketIAuthHeader.RequiredFormat];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.RequiredFormat))
RequiredFormat = (EpAuthPacketIAuthFormat)headers[EpAuthPacketIAuthHeader.RequiredFormat];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.ContentFormat))
ContentFormat = (IIPAuthPacketIAuthFormat)headers[IIPAuthPacketIAuthHeader.ContentFormat];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.ContentFormat))
ContentFormat = (EpAuthPacketIAuthFormat)headers[EpAuthPacketIAuthHeader.ContentFormat];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.Content))
Content = headers[IIPAuthPacketIAuthHeader.Content];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.Content))
Content = headers[EpAuthPacketIAuthHeader.Content];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.Trials))
Trials = (byte)headers[IIPAuthPacketIAuthHeader.Trials];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.Trials))
Trials = (byte)headers[EpAuthPacketIAuthHeader.Trials];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.Issue))
Issue = (DateTime)headers[IIPAuthPacketIAuthHeader.Issue];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.Issue))
Issue = (DateTime)headers[EpAuthPacketIAuthHeader.Issue];
if (headers.ContainsKey(IIPAuthPacketIAuthHeader.Expire))
Expire = (DateTime)headers[IIPAuthPacketIAuthHeader.Expire];
if (headers.ContainsKey(EpAuthPacketIAuthHeader.Expire))
Expire = (DateTime)headers[EpAuthPacketIAuthHeader.Expire];
}
}
}

View File

@@ -13,10 +13,10 @@ namespace Esiur.Security.Membership
public uint Reference { get; set; }
public IIPAuthPacketIAuthDestination Destination { get; set; }
public EpAuthPacketIAuthDestination Destination { get; set; }
public string? Clue { get; set; }
public IIPAuthPacketIAuthFormat? RequiredFormat { get; set; }
public IIPAuthPacketIAuthFormat? ContentFormat { get; set; }
public EpAuthPacketIAuthFormat? RequiredFormat { get; set; }
public EpAuthPacketIAuthFormat? ContentFormat { get; set; }
public object? Content { get; set; }
public byte? Trials { get; set; }

View File

@@ -28,7 +28,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Esiur.Data;
using Esiur.Net.IIP;
using Esiur.Core;
using Esiur.Security.Authority;
using Esiur.Resource;
@@ -47,8 +46,8 @@ public interface IMembership
AsyncReply<byte[]> GetToken(ulong tokenIndex, string domain);
AsyncReply<AuthorizationResults> Authorize(Session session);
AsyncReply<AuthorizationResults> AuthorizePlain(Session session, uint reference, object value);
AsyncReply<AuthorizationResults> AuthorizeHashed(Session session, uint reference, IIPAuthPacketHashAlgorithm algorithm, byte[] value);
AsyncReply<AuthorizationResults> AuthorizeEncrypted(Session session, uint reference, IIPAuthPacketPublicKeyAlgorithm algorithm, byte[] value);
AsyncReply<AuthorizationResults> AuthorizeHashed(Session session, uint reference, EpAuthPacketHashAlgorithm algorithm, byte[] value);
AsyncReply<AuthorizationResults> AuthorizeEncrypted(Session session, uint reference, EpAuthPacketPublicKeyAlgorithm algorithm, byte[] value);
AsyncReply<bool> Login(Session session);
AsyncReply<bool> Logout(Session session);

View File

@@ -79,7 +79,7 @@ namespace Esiur.Security.Membership
var ar = new AuthorizationResults()
{
Clue = q.Question,
Destination = IIPAuthPacketIAuthDestination.Self,
Destination = EpAuthPacketIAuthDestination.Self,
Reference = (uint)r.Next(),
RequiredFormat = format,
Expire = DateTime.Now.AddSeconds(60),
@@ -96,14 +96,14 @@ namespace Esiur.Security.Membership
}
}
public AsyncReply<AuthorizationResults> AuthorizeEncrypted(Session session, uint reference, IIPAuthPacketPublicKeyAlgorithm algorithm, byte[] value)
public AsyncReply<AuthorizationResults> AuthorizeEncrypted(Session session, uint reference, EpAuthPacketPublicKeyAlgorithm algorithm, byte[] value)
{
throw new NotImplementedException();
}
public AsyncReply<AuthorizationResults> AuthorizeHashed(Session session, uint reference, IIPAuthPacketHashAlgorithm algorithm, byte[] value)
public AsyncReply<AuthorizationResults> AuthorizeHashed(Session session, uint reference, EpAuthPacketHashAlgorithm algorithm, byte[] value)
{
if (algorithm != IIPAuthPacketHashAlgorithm.SHA256)
if (algorithm != EpAuthPacketHashAlgorithm.SHA256)
throw new NotImplementedException();
var ar = users[session.AuthorizedAccount].Results.First(x => x.Reference == reference);
@@ -112,8 +112,8 @@ namespace Esiur.Security.Membership
// compute hash
var remoteNonce = (byte[])session.RemoteHeaders[IIPAuthPacketHeader.Nonce];
var localNonce = (byte[])session.LocalHeaders[IIPAuthPacketHeader.Nonce];
var remoteNonce = (byte[])session.RemoteHeaders[EpAuthPacketHeader.Nonce];
var localNonce = (byte[])session.LocalHeaders[EpAuthPacketHeader.Nonce];
var hashFunc = SHA256.Create();
// local nonce + password or token + remote nonce

View File

@@ -29,7 +29,7 @@ using Esiur.Data;
using Esiur.Core;
using Esiur.Resource;
using Esiur.Security.Authority;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Security.Permissions;
@@ -39,7 +39,7 @@ public class StorePermissionsManager : IPermissionsManager
public Map<string,object> Settings => settings;
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDefinition member, object inquirer = null)
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDef member, object inquirer = null)
{
return resource.Instance.Store.Instance.Applicable(session, action, member, inquirer);
}

View File

@@ -29,7 +29,7 @@ using Esiur.Data;
using Esiur.Core;
using Esiur.Resource;
using Esiur.Security.Authority;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Security.Permissions;
@@ -40,7 +40,7 @@ public class UserPermissionsManager : IPermissionsManager
public Map<string,object> Settings => settings;
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDefinition member, object inquirer)
public Ruling Applicable(IResource resource, Session session, ActionType action, MemberDef member, object inquirer)
{
Map<string,object> userPermissions = null;

View File

@@ -6,8 +6,8 @@ using System.Text;
using System.Threading.Tasks;
using Esiur.Core;
using Esiur.Data;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Stores;
public class MemoryStore : IStore
@@ -78,13 +78,13 @@ public class MemoryStore : IStore
throw new NotImplementedException();
}
public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
public AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{
throw new NotImplementedException();
}
public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
public bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime)
{
return true;
}

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading.Tasks;
using Esiur.Core;
using Esiur.Data;
using Esiur.Data.Schema;
using Esiur.Data.Types;
namespace Esiur.Stores;
public class TemporaryStore : IStore
@@ -69,13 +69,13 @@ public class TemporaryStore : IStore
throw new NotImplementedException();
}
public AsyncReply<KeyList<PropertyDefinition, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
public AsyncReply<KeyList<PropertyDef, PropertyValue[]>> GetRecord(IResource resource, DateTime fromDate, DateTime toDate)
{
throw new NotImplementedException();
}
public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime)
public bool Modify(IResource resource, PropertyDef propertyDef, object value, ulong? age, DateTime? dateTime)
{
return true;
}

View File

@@ -10,7 +10,7 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Test
{
[Resource]
[Annotation("A", "B", "C", "D")]
[Annotation("A", "B")]
public partial class MyResource
{
[Export][Annotation("Comment")] string description;

View File

@@ -1,11 +1,11 @@
using Esiur.Data;
using Esiur.Core;
using Esiur.Net.IIP;
using Esiur.Resource;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Esiur.Protocol;
#nullable enable
@@ -183,12 +183,12 @@ public partial class MyService
}
[Export]
public void Connection(object a1, int a2, DistributedConnection a3) =>
public void Connection(object a1, int a2, EpConnection a3) =>
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
[Export]
public void ConnectionOptional(object a1, int a2, string a3 = "sss", DistributedConnection? a4 = null) =>
public void ConnectionOptional(object a1, int a2, string a3 = "sss", EpConnection? a4 = null) =>
Console.WriteLine($"VoidArgs {a1} {a2} {a3}");
[Export]

View File

@@ -25,7 +25,6 @@ SOFTWARE.
using Esiur.Data;
using Esiur.Core;
using Esiur.Net.HTTP;
using Esiur.Net.IIP;
using Esiur.Net.Sockets;
using Esiur.Resource;
using Esiur.Security.Permissions;
@@ -49,6 +48,7 @@ using Esiur.Security.Cryptography;
using Esiur.Security.Membership;
using Esiur.Net.Packets;
using System.Numerics;
using Esiur.Protocol;
namespace Test
{
@@ -56,7 +56,7 @@ namespace Test
class Program
{
static void TestSerialization(object x, DistributedConnection connection = null)
static void TestSerialization(object x, EpConnection connection = null)
{
var d = Codec.Compose(x, Warehouse.Default, connection);
@@ -145,7 +145,7 @@ namespace Test
// Create stores to keep objects.
var system = await wh.Put("sys", new MemoryStore());
var server = await wh.Put("sys/server", new DistributedServer() { Membership = membership });
var server = await wh.Put("sys/server", new EpServer() { Membership = membership });
var web = await wh.Put("sys/web", new HTTPServer() { Port = 8088 });
@@ -158,7 +158,7 @@ namespace Test
//TestSerialization(res1);
server.MapCall("Hello", (string msg, DateTime time, DistributedConnection sender) =>
server.MapCall("Hello", (string msg, DateTime time, EpConnection sender) =>
{
Console.WriteLine(msg);
return "Hi " + DateTime.UtcNow;
@@ -200,9 +200,9 @@ namespace Test
var format = x.RequiredFormat;
if (format == IIPAuthPacketIAuthFormat.Number)
if (format == EpAuthPacketIAuthFormat.Number)
return new AsyncReply<object>(Convert.ToInt32(10));
else if (format == IIPAuthPacketIAuthFormat.Text)
else if (format == EpAuthPacketIAuthFormat.Text)
return new AsyncReply<object>(Console.ReadLine().Trim());
throw new NotImplementedException("Not supported format.");
@@ -211,7 +211,7 @@ namespace Test
private static async void TestClient(IResource local)
{
var con = await new Warehouse().Get<DistributedConnection>("iip://localhost", new DistributedConnectionConfig
var con = await new Warehouse().Get<EpConnection>("EP://localhost", new EpConnectionConfig
{
AutoReconnect = true,
Username = "admin",
@@ -258,11 +258,11 @@ namespace Test
var t4 = await remote.GetTuple4(1, "A", 1.3, true);
Console.WriteLine(t4);
remote.StringEvent += new DistributedResourceEvent((sender, args) =>
remote.StringEvent += new EpResourceEvent((sender, args) =>
Console.WriteLine($"StringEvent {args}")
);
remote.ArrayEvent += new DistributedResourceEvent((sender, args) =>
remote.ArrayEvent += new EpResourceEvent((sender, args) =>
Console.WriteLine($"ArrayEvent {args}")
);
@@ -270,7 +270,7 @@ namespace Test
//var path = TemplateGenerator.GetTemplate("iip://localhost/sys/service", "Generated");
//var path = TemplateGenerator.GetTemplate("EP://localhost/sys/service", "Generated");
//Console.WriteLine(path);
@@ -295,7 +295,7 @@ namespace Test
static Timer perodicTimer;
static void TestObjectProps(IResource local, DistributedResource remote)
static void TestObjectProps(IResource local, EpResource remote)
{
foreach (var pt in local.Instance.Definition.Properties)
@@ -333,6 +333,10 @@ namespace Test
return rt;
}
else if (value is Record)
{
return value.ToString();
}
else if (value is IRecord)
{
return "{" + String.Join(", ", t.GetProperties().Select(x => x.Name + ": " + x.GetValue(value))) + "}";