diff --git a/Esiur.ASPNet/Controllers/MainController.cs b/Esiur.ASPNet/Controllers/MainController.cs index f52caf0..ea1045f 100644 --- a/Esiur.ASPNet/Controllers/MainController.cs +++ b/Esiur.ASPNet/Controllers/MainController.cs @@ -19,7 +19,7 @@ namespace Esiur.AspNetCore.Example [HttpGet(Name = "Get")] public async AsyncReply Get() { - return await Warehouse.Get("/sys/demo"); + return await Warehouse.Default.Get("/sys/demo"); } } } diff --git a/Esiur.ASPNet/Program.cs b/Esiur.ASPNet/Program.cs index 23de2b4..4d90cf6 100644 --- a/Esiur.ASPNet/Program.cs +++ b/Esiur.ASPNet/Program.cs @@ -56,12 +56,12 @@ var webSocketOptions = new WebSocketOptions() app.UseWebSockets(webSocketOptions); + +await Warehouse.Default.Put("sys", new MemoryStore()); +await Warehouse.Default.Put("sys/service", new MyResource()); +var server = await Warehouse.Default.Put("sys/server", new DistributedServer()); -await Warehouse.Put("sys", new MemoryStore()); -await Warehouse.Put("sys/service", new MyResource()); -var server = await Warehouse.Put("sys/server", new DistributedServer()); - -await Warehouse.Open(); +await Warehouse.Default.Open(); app.UseEsiur(new EsiurOptions() { Server = server }); diff --git a/Esiur.Examples.StandaloneWebServerDemo/Program.cs b/Esiur.Examples.StandaloneWebServerDemo/Program.cs index cc6c763..8c0cfbb 100644 --- a/Esiur.Examples.StandaloneWebServerDemo/Program.cs +++ b/Esiur.Examples.StandaloneWebServerDemo/Program.cs @@ -13,14 +13,16 @@ internal class Program private static async Task Main(string[] args) { - // Create a store to keep objects. - var system = await Warehouse.Put("sys", new MemoryStore()); - // Create a distibuted server - var esiurServer = await Warehouse.Put("sys/server", new DistributedServer()); - // Add your object to the store - var service = await Warehouse.Put("sys/demo", new Demo()); + var wh = new Warehouse(); - var http = await Warehouse.Put("sys/http", new HTTPServer() { Port = 8888 }); + // 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()); + // Add your object to the store + var service = await wh.Put("sys/demo", new Demo()); + + var http = await wh.Put("sys/http", new HTTPServer() { Port = 8888 }); http.MapGet("{url}", (string url, HTTPConnection sender) => @@ -49,7 +51,7 @@ internal class Program // Start your server - await Warehouse.Open(); + await wh.Open(); Console.WriteLine("Running on http://localhost:8888"); diff --git a/Esiur.Stores.EntityCore/EntityStore.cs b/Esiur.Stores.EntityCore/EntityStore.cs index 7e56ebb..580bb39 100644 --- a/Esiur.Stores.EntityCore/EntityStore.cs +++ b/Esiur.Stores.EntityCore/EntityStore.cs @@ -185,25 +185,7 @@ public class EntityStore : IStore //throw new NotImplementedException(); } - public bool Remove(IResource resource) - { - var type = ResourceProxy.GetBaseType(resource); - - var eid = TypesByType[type].PrimaryKey.GetValue(resource); - - lock (DBLock) - { - if (DB[type].ContainsKey(eid)) - { - DB[type].Remove(eid); - return true; - } - } - - return false; - //throw new NotImplementedException(); - } - + public AsyncReply AddChild(IResource parent, IResource child) { throw new NotImplementedException(); @@ -290,4 +272,32 @@ public class EntityStore : IStore { OnDestroy?.Invoke(this); } + + public AsyncReply Remove(IResource resource) + { + var type = ResourceProxy.GetBaseType(resource); + + var eid = TypesByType[type].PrimaryKey.GetValue(resource); + + lock (DBLock) + { + if (DB[type].ContainsKey(eid)) + { + DB[type].Remove(eid); + return new AsyncReply(true); + } + } + + return new AsyncReply(false); + } + + public AsyncReply Remove(string path) + { + throw new NotImplementedException(); + } + + public AsyncReply Move(IResource resource, string newPath) + { + throw new NotImplementedException(); + } } diff --git a/Esiur.Stores.MongoDB/MongoDBStore.cs b/Esiur.Stores.MongoDB/MongoDBStore.cs index 1cec67f..fd16229 100644 --- a/Esiur.Stores.MongoDB/MongoDBStore.cs +++ b/Esiur.Stores.MongoDB/MongoDBStore.cs @@ -225,7 +225,7 @@ public class MongoDBStore : IStore var doc = value.AsBsonDocument; if (doc["type"] == 0) { - return Warehouse.Get(doc["link"].AsString); + return Instance.Warehouse.Get(doc["link"].AsString); } // structure else if (doc["type"] == 1) { @@ -845,7 +845,7 @@ public class MongoDBStore : IStore foreach (var child in children) { - var r = Warehouse.Get(child); + var r = Instance.Warehouse.Get(child); if (r is AsyncReply) rt.Add(r);// (AsyncReply)r); } @@ -855,41 +855,7 @@ public class MongoDBStore : IStore } } - public AsyncBag Parents(IResource resource, string name) where T : IResource - { - - if (resource == this) - { - return new AsyncBag(null); - } - else - { - var parents = (string[])resource.Instance.Variables["parents"]; - - if (parents == null) - { - return new AsyncBag(null); - } - - var rt = new AsyncBag(); - - - - foreach (var parent in parents) - { - var r = Warehouse.Get(parent); - if (r is AsyncReply) - rt.Add(r);// (AsyncReply)r); - } - - - rt.Seal(); - - - return rt; - } - } - + public AsyncReply AddChild(IResource resource, IResource child) { @@ -920,4 +886,24 @@ public class MongoDBStore : IStore { throw new NotImplementedException(); } + + AsyncReply IStore.Remove(IResource resource) + { + throw new NotImplementedException(); + } + + public AsyncReply Remove(string path) + { + throw new NotImplementedException(); + } + + public AsyncReply Move(IResource resource, string newPath) + { + throw new NotImplementedException(); + } + + public AsyncReply Parent(IResource resource, string name) where T : IResource + { + throw new NotImplementedException(); + } } diff --git a/Esiur/Core/InvocationContext.cs b/Esiur/Core/InvocationContext.cs index 0118f8f..c97a20b 100644 --- a/Esiur/Core/InvocationContext.cs +++ b/Esiur/Core/InvocationContext.cs @@ -19,7 +19,7 @@ namespace Esiur.Core Connection.SendChunk(CallbackId, value); } - public void Progress(int value, int max) { + public void Progress(uint value, uint max) { if (Ended) throw new Exception("Execution has ended."); @@ -27,6 +27,15 @@ namespace Esiur.Core Connection.SendProgress(CallbackId, value, max); } + public void Warning(byte level, string message) + { + + if (Ended) + throw new Exception("Execution has ended."); + + Connection.SendWarning(CallbackId, level, message); + } + public DistributedConnection Connection { get; internal set; } diff --git a/Esiur/Data/Codec.cs b/Esiur/Data/Codec.cs index e658fb0..7ccf231 100644 --- a/Esiur/Data/Codec.cs +++ b/Esiur/Data/Codec.cs @@ -42,7 +42,7 @@ public static class Codec //delegate AsyncReply AsyncParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence); delegate object AsyncParser(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence); - delegate object SyncParser(byte[] data, uint offset, uint length); + delegate object SyncParser(byte[] data, uint offset, uint length, Warehouse warehouse); static AsyncParser[][] FixedAsyncParsers = new AsyncParser[][] { @@ -211,7 +211,7 @@ public static class Codec } } - public static (uint, object) ParseSync(byte[] data, uint offset, TransmissionType? dataType = null) + public static (uint, object) ParseSync(byte[] data, uint offset, Warehouse warehouse, TransmissionType? dataType = null) { uint len = 0; @@ -232,15 +232,15 @@ public static class Codec if (tt.Class == TransmissionTypeClass.Fixed) { - return (len, FixedParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength)); + return (len, FixedParsers[tt.Exponent][tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse)); } else if (tt.Class == TransmissionTypeClass.Dynamic) { - return (len, DynamicParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength)); + return (len, DynamicParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse)); } else //if (tt.Class == TransmissionTypeClass.Typed) { - return (len, TypedParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength)); + return (len, TypedParsers[tt.Index](data, dataType.Value.Offset, (uint)tt.ContentLength, warehouse)); } } /// diff --git a/Esiur/Data/DataDeserializer.cs b/Esiur/Data/DataDeserializer.cs index e7ef840..74271d7 100644 --- a/Esiur/Data/DataDeserializer.cs +++ b/Esiur/Data/DataDeserializer.cs @@ -19,7 +19,7 @@ public static class DataDeserializer return null; } - public static object NullParser(byte[] data, uint offset, uint length) + public static object NullParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return null; } @@ -29,7 +29,7 @@ public static class DataDeserializer return true; } - public static object BooleanTrueParser(byte[] data, uint offset, uint length) + public static object BooleanTrueParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return true; } @@ -39,7 +39,7 @@ public static class DataDeserializer return false; } - public static object BooleanFalseParser(byte[] data, uint offset, uint length) + public static object BooleanFalseParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return false; } @@ -49,7 +49,7 @@ public static class DataDeserializer return NotModified.Default; } - public static object NotModifiedParser(byte[] data, uint offset, uint length) + public static object NotModifiedParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return NotModified.Default; } @@ -58,7 +58,7 @@ public static class DataDeserializer { return data[offset]; } - public static object UInt8Parser(byte[] data, uint offset, uint length) + public static object UInt8Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { return data[offset]; } @@ -67,7 +67,7 @@ public static class DataDeserializer { return (sbyte)data[offset]; } - public static object Int8Parser(byte[] data, uint offset, uint length) + public static object Int8Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { return (sbyte)data[offset]; } @@ -78,7 +78,7 @@ public static class DataDeserializer return *(char*)ptr; } - public static unsafe object Char16Parser(byte[] data, uint offset, uint length) + public static unsafe object Char16Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(char*)ptr; @@ -89,7 +89,7 @@ public static class DataDeserializer return (char)data[offset]; } - public static object Char8Parser(byte[] data, uint offset, uint length) + public static object Char8Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { return (char)data[offset]; } @@ -101,7 +101,7 @@ public static class DataDeserializer return *(short*)ptr; } - public static unsafe object Int16Parser(byte[] data, uint offset, uint length) + public static unsafe object Int16Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(short*)ptr; @@ -113,7 +113,7 @@ public static class DataDeserializer return *(ushort*)ptr; } - public static unsafe object UInt16Parser(byte[] data, uint offset, uint length) + public static unsafe object UInt16Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(ushort*)ptr; @@ -125,7 +125,7 @@ public static class DataDeserializer return *(int*)ptr; } - public static unsafe object Int32Parser(byte[] data, uint offset, uint length) + public static unsafe object Int32Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(int*)ptr; @@ -137,7 +137,7 @@ public static class DataDeserializer return *(uint*)ptr; } - public static unsafe object UInt32Parser(byte[] data, uint offset, uint length) + public static unsafe object UInt32Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(uint*)ptr; @@ -150,7 +150,7 @@ public static class DataDeserializer return *(float*)ptr; } - public static unsafe object Float32Parser(byte[] data, uint offset, uint length) + public static unsafe object Float32Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(float*)ptr; @@ -162,7 +162,7 @@ public static class DataDeserializer return *(double*)ptr; } - public static unsafe object Float64Parser(byte[] data, uint offset, uint length) + public static unsafe object Float64Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(double*)ptr; @@ -175,7 +175,7 @@ public static class DataDeserializer return *(decimal*)ptr; } - public static unsafe object Float128Parser(byte[] data, uint offset, uint length) + public static unsafe object Float128Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(decimal*)ptr; @@ -189,7 +189,7 @@ public static class DataDeserializer return new Int128(*(ulong*)ptr1, *(ulong*)ptr2); } - public static unsafe object Int128Parser(byte[] data, uint offset, uint length) + public static unsafe object Int128Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr1 = &data[offset]) fixed (byte* ptr2 = &data[offset + 8]) @@ -203,7 +203,7 @@ public static class DataDeserializer return new UInt128(*(ulong*)ptr1, *(ulong*)ptr2); } - public static unsafe object UInt128Parser(byte[] data, uint offset, uint length) + public static unsafe object UInt128Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr1 = &data[offset]) fixed (byte* ptr2 = &data[offset + 8]) @@ -216,7 +216,7 @@ public static class DataDeserializer return *(long*)ptr; } - public static unsafe object Int64Parser(byte[] data, uint offset, uint length) + public static unsafe object Int64Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(long*)ptr; @@ -229,7 +229,7 @@ public static class DataDeserializer return *(ulong*)ptr; } - public static unsafe object UInt64Parser(byte[] data, uint offset, uint length) + public static unsafe object UInt64Parser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return *(ulong*)ptr; @@ -242,7 +242,7 @@ public static class DataDeserializer } - public static unsafe object DateTimeParser(byte[] data, uint offset, uint length) + public static unsafe object DateTimeParser(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return new DateTime(*(long*)ptr, DateTimeKind.Utc); @@ -257,7 +257,7 @@ public static class DataDeserializer return connection.Fetch(data[offset], requestSequence); } - public static unsafe object ResourceParser8(byte[] data, uint offset, uint length) + public static unsafe object ResourceParser8(byte[] data, uint offset, uint length, Warehouse warehouse) { return new ResourceId(false, data[offset]); } @@ -267,10 +267,10 @@ public static class DataDeserializer if (connection == null) return new ResourceId(true, data[offset]); else - return Warehouse.GetById(data[offset]); + return connection.Instance.Warehouse.GetById(data[offset]); } - public static unsafe object LocalResourceParser8(byte[] data, uint offset, uint length) + public static unsafe object LocalResourceParser8(byte[] data, uint offset, uint length, Warehouse warehouse) { return new ResourceId(true, data[offset]); } @@ -284,7 +284,7 @@ public static class DataDeserializer return connection.Fetch(*(ushort*)ptr, requestSequence); } - public static unsafe object ResourceParser16(byte[] data, uint offset, uint length) + public static unsafe object ResourceParser16(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return new ResourceId(false, *(ushort*)ptr); @@ -297,13 +297,13 @@ public static class DataDeserializer if (connection == null) return new ResourceId(true, *(ushort*)ptr); else - return Warehouse.GetById(*(ushort*)ptr); + return connection.Instance.Warehouse.GetById(*(ushort*)ptr); } - public static unsafe object LocalResourceParser16(byte[] data, uint offset, uint length) + public static unsafe object LocalResourceParser16(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) - return Warehouse.GetById(*(ushort*)ptr); + return new ResourceId(true, *(ushort*)ptr); } public static unsafe object ResourceParser32Async(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence) @@ -315,7 +315,7 @@ public static class DataDeserializer return connection.Fetch(*(uint*)ptr, requestSequence); } - public static unsafe object ResourceParser32(byte[] data, uint offset, uint length) + public static unsafe object ResourceParser32(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return new ResourceId(false, *(uint*)ptr); @@ -328,10 +328,10 @@ public static class DataDeserializer if (connection == null) return new ResourceId(true, *(uint*)ptr); else - return Warehouse.GetById(*(uint*)ptr); + return connection.Instance.Warehouse.GetById(*(uint*)ptr); } - public static unsafe object LocalResourceParser32(byte[] data, uint offset, uint length) + public static unsafe object LocalResourceParser32(byte[] data, uint offset, uint length, Warehouse warehouse) { fixed (byte* ptr = &data[offset]) return new ResourceId(true, *(uint*)ptr); @@ -343,7 +343,7 @@ public static class DataDeserializer return data.Clip(offset, length); } - public static unsafe object RawDataParser(byte[] data, uint offset, uint length) + public static unsafe object RawDataParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return data.Clip(offset, length); } @@ -354,7 +354,7 @@ public static class DataDeserializer return data.GetString(offset, length); } - public static unsafe object StringParser(byte[] data, uint offset, uint length) + public static unsafe object StringParser(byte[] data, uint offset, uint length, Warehouse warehouse) { return data.GetString(offset, length); } @@ -369,7 +369,7 @@ public static class DataDeserializer length -= 16; - var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record); + var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Record); var initRecord = (TypeTemplate template) => { @@ -436,16 +436,16 @@ public static class DataDeserializer } - public static unsafe object RecordParser(byte[] data, uint offset, uint length) + public static unsafe object RecordParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var classId = data.GetUUID(offset); offset += 16; length -= 16; - var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Record); + var template = warehouse.GetTemplateByClassId(classId, TemplateType.Record); - var r = ListParser(data, offset, length); + var r = ListParser(data, offset, length, warehouse); var ar = (object[])r; @@ -490,7 +490,7 @@ public static class DataDeserializer throw new NotImplementedException(); } - public static unsafe object ConstantParser(byte[] data, uint offset, uint length) + public static unsafe object ConstantParser(byte[] data, uint offset, uint length, Warehouse warehouse) { throw new NotImplementedException(); } @@ -502,7 +502,7 @@ public static class DataDeserializer offset += 16; var index = data[offset++]; - var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Enum); + var template = connection.Instance.Warehouse.GetTemplateByClassId(classId, TemplateType.Enum); if (template != null) { @@ -521,14 +521,14 @@ public static class DataDeserializer } } - public static unsafe object EnumParser(byte[] data, uint offset, uint length) + public static unsafe object EnumParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var classId = data.GetUUID(offset); offset += 16; var index = data[offset++]; - var template = Warehouse.GetTemplateByClassId(classId, TemplateType.Enum); + var template = warehouse.GetTemplateByClassId(classId, TemplateType.Enum); if (template != null) { @@ -566,13 +566,13 @@ public static class DataDeserializer return rt; } - public static object RecordListParser(byte[] data, uint offset, uint length) + public static object RecordListParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var rt = new List(); while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); rt.Add(reply as IRecord); @@ -614,13 +614,13 @@ public static class DataDeserializer } - public static object ResourceListParser(byte[] data, uint offset, uint length) + public static object ResourceListParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var rt = new List(); while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); rt.Add(reply as IResource); @@ -661,13 +661,13 @@ public static class DataDeserializer return rt; } - public static object ListParser(byte[] data, uint offset, uint length) + public static object ListParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var rt = new List(); while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); rt.Add(reply); @@ -685,13 +685,13 @@ public static class DataDeserializer } - public static (uint, ulong, object[]) LimitedCountListParser(byte[] data, uint offset, ulong length, uint countLimit = uint.MaxValue) + public static (uint, ulong, object[]) LimitedCountListParser(byte[] data, uint offset, ulong length, Warehouse warehouse, uint countLimit = uint.MaxValue) { var rt = new List(); while (length > 0 && rt.Count < countLimit) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); rt.Add(reply); @@ -720,7 +720,9 @@ public static class DataDeserializer offset += valueCs; length -= valueCs; - var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keyRepType.GetRuntimeType(), valueRepType.GetRuntimeType())); + var wh = connection.Instance.Warehouse; + + var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keyRepType.GetRuntimeType(wh), valueRepType.GetRuntimeType(wh))); var rt = new AsyncReply(); @@ -758,7 +760,7 @@ public static class DataDeserializer } - public static object TypedMapParser(byte[] data, uint offset, uint length) + public static object TypedMapParser(byte[] data, uint offset, uint length, Warehouse warehouse) { // get key type var (keyCs, keyRepType) = RepresentationType.Parse(data, offset); @@ -769,14 +771,14 @@ public static class DataDeserializer offset += valueCs; length -= valueCs; - var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keyRepType.GetRuntimeType(), valueRepType.GetRuntimeType())); + var map = (IMap)Activator.CreateInstance(typeof(Map<,>).MakeGenericType(keyRepType.GetRuntimeType(warehouse), valueRepType.GetRuntimeType(warehouse))); var results = new List(); while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); results.Add(reply); @@ -799,6 +801,7 @@ public static class DataDeserializer public static AsyncReply TupleParserAsync(byte[] data, uint offset, uint length, DistributedConnection connection, uint[] requestSequence) { + var results = new AsyncBag(); var rt = new AsyncReply(); @@ -810,7 +813,7 @@ public static class DataDeserializer for (var i = 0; i < tupleSize; i++) { var (cs, rep) = RepresentationType.Parse(data, offset); - types.Add(rep.GetRuntimeType()); + types.Add(rep.GetRuntimeType(connection.Instance.Warehouse)); offset += cs; length -= cs; } @@ -871,7 +874,7 @@ public static class DataDeserializer return rt; } - public static object TupleParser(byte[] data, uint offset, uint length) + public static object TupleParser(byte[] data, uint offset, uint length, Warehouse warehouse) { var results = new List(); @@ -884,14 +887,14 @@ public static class DataDeserializer for (var i = 0; i < tupleSize; i++) { var (cs, rep) = RepresentationType.Parse(data, offset); - types.Add(rep.GetRuntimeType()); + types.Add(rep.GetRuntimeType(warehouse)); offset += cs; length -= cs; } while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); results.Add(reply); @@ -951,7 +954,7 @@ public static class DataDeserializer offset += hdrCs; length -= hdrCs; - var runtimeType = rep.GetRuntimeType(); + var runtimeType = rep.GetRuntimeType(connection.Instance.Warehouse); rt.ArrayType = runtimeType; @@ -975,7 +978,7 @@ public static class DataDeserializer return rt; } - public static object TypedListParser(byte[] data, uint offset, uint length) + public static object TypedListParser(byte[] data, uint offset, uint length, Warehouse warehouse) { // get the type @@ -984,13 +987,13 @@ public static class DataDeserializer offset += hdrCs; length -= hdrCs; - var runtimeType = rep.GetRuntimeType(); + var runtimeType = rep.GetRuntimeType(warehouse); var list = new List(); while (length > 0) { - var (cs, reply) = Codec.ParseSync(data, offset); + var (cs, reply) = Codec.ParseSync(data, offset, warehouse); list.Add(reply); diff --git a/Esiur/Data/DataSerializer.cs b/Esiur/Data/DataSerializer.cs index 636edc3..6f1c067 100644 --- a/Esiur/Data/DataSerializer.cs +++ b/Esiur/Data/DataSerializer.cs @@ -117,7 +117,7 @@ public static class DataSerializer if (value == null) return (TransmissionTypeIdentifier.Null, new byte[0]); - var template = Warehouse.GetTemplateByType(value.GetType()); + var template = connection.Instance.Warehouse.GetTemplateByType(value.GetType()); var intVal = Convert.ChangeType(value, (value as Enum).GetTypeCode()); @@ -390,7 +390,7 @@ public static class DataSerializer var rt = new List();// BinaryList(); var record = (IRecord)value; - var template = Warehouse.GetTemplateByType(record.GetType()); + var template = connection.Instance.Warehouse.GetTemplateByType(record.GetType()); rt.AddRange(template.ClassId.Data); diff --git a/Esiur/Data/RepresentationType.cs b/Esiur/Data/RepresentationType.cs index e8e0446..faae1d4 100644 --- a/Esiur/Data/RepresentationType.cs +++ b/Esiur/Data/RepresentationType.cs @@ -136,12 +136,12 @@ namespace Esiur.Data st.SetNotNull(flag); } - public Type? GetRuntimeType() + public Type? GetRuntimeType(Warehouse warehouse) { if (Identifier == RepresentationTypeIdentifier.TypedList) { - var sub = SubTypes?[0].GetRuntimeType(); + var sub = SubTypes?[0].GetRuntimeType(warehouse); if (sub == null) return null; @@ -151,11 +151,11 @@ namespace Esiur.Data } else if (Identifier == RepresentationTypeIdentifier.TypedMap) { - var subs = SubTypes.Select(x => x.GetRuntimeType()).ToArray(); + var subs = SubTypes.Select(x => x.GetRuntimeType(warehouse)).ToArray(); var rt = typeof(Map<,>).MakeGenericType(subs); return rt; } - + return Identifier switch { (RepresentationTypeIdentifier.Void) => typeof(void), @@ -177,9 +177,9 @@ namespace Esiur.Data (RepresentationTypeIdentifier.DateTime) => Nullable ? typeof(DateTime?) : typeof(DateTime), (RepresentationTypeIdentifier.Resource) => typeof(IResource), (RepresentationTypeIdentifier.Record) => typeof(IRecord), - (RepresentationTypeIdentifier.TypedRecord) => Warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Record)?.DefinedType, - (RepresentationTypeIdentifier.TypedResource) => Warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Resource)?.DefinedType, - (RepresentationTypeIdentifier.Enum) => Warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Enum)?.DefinedType, + (RepresentationTypeIdentifier.TypedRecord) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Record)?.DefinedType, + (RepresentationTypeIdentifier.TypedResource) => warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Resource)?.DefinedType, + (RepresentationTypeIdentifier.Enum) =>warehouse.GetTemplateByClassId((UUID)UUID!, TemplateType.Enum)?.DefinedType, _ => null }; @@ -194,7 +194,6 @@ namespace Esiur.Data public RepresentationType[]? SubTypes = null; - public RepresentationType ToNullable() { return new RepresentationType(Identifier, true, UUID, SubTypes); diff --git a/Esiur/Net/HTTP/IIPoHTTP.cs b/Esiur/Net/HTTP/IIPoHTTP.cs index 26484ec..00d64f1 100644 --- a/Esiur/Net/HTTP/IIPoHTTP.cs +++ b/Esiur/Net/HTTP/IIPoHTTP.cs @@ -19,7 +19,7 @@ public class IIPoHTTP : HTTPFilter IIPPacketRequest action = (IIPPacketRequest)Convert.ToByte(sender.Request.Query["a"]); - if (action == IIPPacketRequest.QueryLink) + if (action == IIPPacketRequest.Query) { EntryPoint.Query(sender.Request.Query["l"], null).Then(x => { diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index 5c73723..506408e 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -666,7 +666,7 @@ public partial class DistributedConnection : NetworkConnection, IStore var dataType = authPacket.DataType.Value; - var (_, parsed) = Codec.ParseSync(data, dataType.Offset, dataType); + var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var rt = (Map)parsed; @@ -793,7 +793,7 @@ public partial class DistributedConnection : NetworkConnection, IStore else if (authPacket.Event == IIPAuthPacketEvent.IAuthPlain) { var dataType = authPacket.DataType.Value; - var (_, parsed) = Codec.ParseSync(data, dataType.Offset, dataType); + var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var rt = (Map)parsed; var headers = rt.Select(x => new KeyValuePair((IIPAuthPacketIAuthHeader)x.Key, x.Value)); @@ -833,7 +833,7 @@ public partial class DistributedConnection : NetworkConnection, IStore else if (authPacket.Event == IIPAuthPacketEvent.IAuthHashed) { var dataType = authPacket.DataType.Value; - var (_, parsed) = Codec.ParseSync(data, dataType.Offset, dataType); + var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var rt = (Map)parsed; @@ -896,7 +896,7 @@ public partial class DistributedConnection : NetworkConnection, IStore var dataType = authPacket.DataType.Value; - var (_, parsed) = Codec.ParseSync(data, dataType.Offset, dataType); + var (_, parsed) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var rt = (Map)parsed; @@ -1154,7 +1154,7 @@ public partial class DistributedConnection : NetworkConnection, IStore var reference = authPacket.Reference; var dataType = authPacket.DataType.Value; - var (_, value) = Codec.ParseSync(data, dataType.Offset, dataType); + var (_, value) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); Server.Membership.AuthorizePlain(session, reference, value) .Then(x => ProcessAuthorization(x)); @@ -1698,7 +1698,7 @@ public partial class DistributedConnection : NetworkConnection, IStore } - public AsyncBag Parent(IResource resource, string name) where T : IResource + public AsyncBag Parents(IResource resource, string name) where T : IResource { throw new NotImplementedException(); } @@ -1723,8 +1723,5 @@ public partial class DistributedConnection : NetworkConnection, IStore throw new NotImplementedException(); } - AsyncReply IStore.Parent(IResource resource, string name) - { - throw new NotImplementedException(); - } + } diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs index 0c42b02..e3cfaf1 100644 --- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs @@ -252,6 +252,11 @@ partial class DistributedConnection SendReply(IIPPacketReply.Progress, callbackId, value, max); } + internal void SendWarning(uint callbackId, byte level, string message) + { + SendReply(IIPPacketReply.Warning, callbackId, level, message); + } + internal void SendChunk(uint callbackId, object chunk) { SendReply(IIPPacketReply.Chunk, callbackId, chunk); @@ -320,7 +325,7 @@ partial class DistributedConnection return; } - var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength) + var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength, Instance.Warehouse) as object[]; var errorCode = (ushort)args[0]; @@ -339,7 +344,7 @@ partial class DistributedConnection return; } - var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength) + var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength, Instance.Warehouse) as object[]; var current = (uint)args[0]; @@ -358,7 +363,7 @@ partial class DistributedConnection return; } - var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength) + var args = DataDeserializer.ListParser(data, dataType.Offset, (uint)dataType.ContentLength, Instance.Warehouse) as object[]; var level = (byte)args[0]; @@ -395,7 +400,7 @@ partial class DistributedConnection void IIPNotificationResourceDestroyed(TransmissionType dataType, byte[] data) { - var (size, rt) = Codec.ParseSync(data, dataType.Offset, dataType); + var (size, rt) = Codec.ParseSync(data, dataType.Offset, Instance.Warehouse, dataType); var resourceId = (uint)rt; @@ -428,7 +433,7 @@ partial class DistributedConnection { // resourceId, index, value var (valueOffset, valueSize, args) = - DataDeserializer.LimitedCountListParser(data, dataType.Offset, dataType.ContentLength, 2); + DataDeserializer.LimitedCountListParser(data, dataType.Offset, dataType.ContentLength, Instance.Warehouse, 2); var rid = (uint)args[0]; var index = (byte)args[1]; @@ -468,7 +473,7 @@ partial class DistributedConnection // resourceId, index, value var (valueOffset, valueSize, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 2); + dataType.ContentLength, Instance.Warehouse, 2); var resourceId = (uint)args[0]; var index = (byte)args[1]; @@ -515,7 +520,7 @@ partial class DistributedConnection void IIPRequestAttachResource(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceId = (uint)value; @@ -572,7 +577,7 @@ partial class DistributedConnection // resourceId, index, value var (valueOffset, valueSize, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 2); + dataType.ContentLength, Instance.Warehouse, 2); var resourceId = (uint)args[0]; var age = (ulong)args[1]; @@ -628,7 +633,7 @@ partial class DistributedConnection void IIPRequestDetachResource(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceId = (uint)value; @@ -720,7 +725,7 @@ partial class DistributedConnection void IIPRequestDeleteResource(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceId = (uint)value; @@ -750,7 +755,7 @@ partial class DistributedConnection { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength); + dataType.ContentLength, Instance.Warehouse); var resourceId = (uint)args[0]; var name = (string)args[1]; @@ -792,7 +797,7 @@ partial class DistributedConnection void IIPRequestLinkTemplates(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceLink = (string)value; @@ -813,7 +818,7 @@ partial class DistributedConnection var templates = TypeTemplate.GetDependencies(r.Instance.Template, Instance.Warehouse); // Send - SendReply(IIPPacketReply.Completed, callback, templates.Select(x=>x.Content).ToArray()); + SendReply(IIPPacketReply.Completed, callback, templates.Select(x => x.Content).ToArray()); }; @@ -825,7 +830,7 @@ partial class DistributedConnection void IIPRequestTemplateFromClassName(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var className = (string)value; @@ -845,7 +850,7 @@ partial class DistributedConnection void IIPRequestTemplateFromClassId(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var classId = new UUID((byte[])value); @@ -867,7 +872,7 @@ partial class DistributedConnection void IIPRequestTemplateFromResourceId(uint callback, TransmissionType dataType, byte[] data) { - var (_, value) = Codec.ParseSync(data, 0, dataType); + var (_, value) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceId = (uint)value; @@ -889,7 +894,7 @@ partial class DistributedConnection void IIPRequestGetResourceIdByLink(uint callback, TransmissionType dataType, byte[] data) { - var (_, parsed) = Codec.ParseSync(data, 0, dataType); + var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceLink = (string)parsed; Action queryCallback = (r) => @@ -917,7 +922,7 @@ partial class DistributedConnection void IIPRequestQueryResources(uint callback, TransmissionType dataType, byte[] data) { - var (_, parsed) = Codec.ParseSync(data, 0, dataType); + var (_, parsed) = Codec.ParseSync(data, 0, Instance.Warehouse, dataType); var resourceLink = (string)parsed; @@ -976,7 +981,7 @@ partial class DistributedConnection void IIPRequestProcedureCall(uint callback, TransmissionType dataType, byte[] data) { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 1); + dataType.ContentLength, Instance.Warehouse, 1); var procedureCall = (string)args[0]; @@ -1036,7 +1041,7 @@ partial class DistributedConnection void IIPRequestStaticCall(uint callback, TransmissionType dataType, byte[] data) { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 2); + dataType.ContentLength, Instance.Warehouse, 2); var classId = new UUID((byte[])args[0]); var index = (byte)args[1]; @@ -1113,7 +1118,7 @@ partial class DistributedConnection void IIPRequestInvokeFunction(uint callback, TransmissionType dataType, byte[] data) { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 2); + dataType.ContentLength, Instance.Warehouse, 2); var resourceId = (uint)args[0]; var index = (byte)args[1]; @@ -1370,7 +1375,7 @@ partial class DistributedConnection { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength); + dataType.ContentLength, Instance.Warehouse); var resourceId = (uint)args[0]; var index = (byte)args[1]; @@ -1429,7 +1434,7 @@ partial class DistributedConnection { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength); + dataType.ContentLength, Instance.Warehouse); var resourceId = (uint)args[0]; var index = (byte)args[1]; @@ -1490,7 +1495,7 @@ partial class DistributedConnection { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength, 2); + dataType.ContentLength, Instance.Warehouse, 2); var rid = (uint)args[0]; var index = (byte)args[1]; @@ -1795,7 +1800,7 @@ partial class DistributedConnection var age = (ulong)args[1]; var link = (string)args[2]; var hops = (byte)args[3]; - var pv = (PropertyValue[])args[4]; + var pvData = (byte[])args[4]; DistributedResource dr; TypeTemplate template = null; @@ -1817,30 +1822,12 @@ partial class DistributedConnection var initResource = (DistributedResource ok) => { - var (_, parsed) = Codec.ParseAsync(content, 0, this, newSequence, transmissionType); + var parsedReply = DataDeserializer.PropertyValueArrayParserAsync(pvData, 0, (uint)pvData.Length, this, newSequence);// Codec.proper (content, 0, this, newSequence, transmissionType); - if (parsed is AsyncReply parsedReply) + + parsedReply.Then(results => { - parsedReply.Then(results => - { - var ar = results as object[]; - - var pvs = new List(); - - for (var i = 0; i < ar.Length; i += 3) - pvs.Add(new PropertyValue(ar[i + 2], Convert.ToUInt64(ar[i]), (DateTime)ar[i + 1])); - - dr._Attach(pvs.ToArray()); - resourceRequests.Remove(id); - // move from needed to attached. - neededResources.Remove(id); - attachedResources[id] = new WeakReference(dr); - reply.Trigger(dr); - }).Error(ex => reply.TriggerError(ex)); - } - else - { - var ar = parsed as object[]; + var ar = results as object[]; var pvs = new List(); @@ -1853,7 +1840,8 @@ partial class DistributedConnection neededResources.Remove(id); attachedResources[id] = new WeakReference(dr); reply.Trigger(dr); - } + }).Error(ex => reply.TriggerError(ex)); + }; @@ -2063,7 +2051,7 @@ partial class DistributedConnection { var (offset, length, args) = DataDeserializer.LimitedCountListParser(data, dataType.Offset, - dataType.ContentLength); + dataType.ContentLength, Instance.Warehouse); var peerTime = (DateTime)args[0]; var interval = (uint)args[0]; diff --git a/Esiur/Proxy/ResourceGenerator.cs b/Esiur/Proxy/ResourceGenerator.cs index 94bedb5..f95ffa8 100644 --- a/Esiur/Proxy/ResourceGenerator.cs +++ b/Esiur/Proxy/ResourceGenerator.cs @@ -153,7 +153,7 @@ public class ResourceGenerator : ISourceGenerator try { - var con = Warehouse.Get(url[1] + "://" + url[2]).Wait(20000); + var con = Warehouse.Default.Get(url[1] + "://" + url[2]).Wait(20000); var templates = con.GetLinkTemplates(url[3]).Wait(60000); cache[path] = templates; diff --git a/Esiur/Proxy/TemplateGenerator.cs b/Esiur/Proxy/TemplateGenerator.cs index a366f09..b36f549 100644 --- a/Esiur/Proxy/TemplateGenerator.cs +++ b/Esiur/Proxy/TemplateGenerator.cs @@ -186,7 +186,7 @@ public static class TemplateGenerator throw new Exception("Invalid IIP URL"); var path = urlRegex.Split(url); - var con = Warehouse.Get(path[1] + "://" + path[2], + var con = Warehouse.Default.Get(path[1] + "://" + path[2], !string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password) ? new { Username = username, Password = password } : null ).Wait(20000); @@ -198,7 +198,7 @@ public static class TemplateGenerator var templates = con.GetLinkTemplates(path[3]).Wait(60000); // no longer needed - Warehouse.Remove(con); + Warehouse.Default.Remove(con); var dstDir = new DirectoryInfo(tempDir ? Path.GetTempPath() + Path.DirectorySeparatorChar + Misc.Global.GenerateCode(20) + Path.DirectorySeparatorChar + dir : dir); diff --git a/Esiur/Resource/IStore.cs b/Esiur/Resource/IStore.cs index caa7c9d..6d6344a 100644 --- a/Esiur/Resource/IStore.cs +++ b/Esiur/Resource/IStore.cs @@ -63,7 +63,7 @@ public interface IStore : IResource AsyncBag Children(IResource resource, string name) where T : IResource; - AsyncReply Parent(IResource resource, string name) where T : IResource; + AsyncBag Parents(IResource resource, string name) where T : IResource; diff --git a/Esiur/Resource/StoreGeneric.cs b/Esiur/Resource/StoreGeneric.cs index cc804b2..811277a 100644 --- a/Esiur/Resource/StoreGeneric.cs +++ b/Esiur/Resource/StoreGeneric.cs @@ -13,10 +13,7 @@ public abstract class Store : IStore where T : IResource public event DestroyedEvent OnDestroy; - public abstract AsyncReply AddChild(IResource parent, IResource child); - - public abstract AsyncReply AddParent(IResource child, IResource parent); - + public abstract AsyncBag Children(IResource resource, string name) where T1 : IResource; public virtual void Destroy() @@ -33,25 +30,29 @@ public abstract class Store : IStore where T : IResource public abstract bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime); - public abstract AsyncBag Parents(IResource resource, string name) where T1 : IResource; - + public abstract AsyncReply Put(IResource resource); public abstract bool Record(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime); - public abstract bool Remove(IResource resource); - - public abstract AsyncReply RemoveChild(IResource parent, IResource child); - - public abstract AsyncReply RemoveParent(IResource child, IResource parent); - + + + public abstract AsyncReply Trigger(ResourceTrigger trigger); - public async AsyncReply New(string name = null, object attributes = null, object properties = null) - { - var resource = await Warehouse.New(name, this, null, null, attributes, properties); - resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray()); - return resource; - } + //public async AsyncReply New(string name = null, object attributes = null, object properties = null) + //{ + // var resource = await Warehouse.New(name, this, null, null, attributes, properties); + // resource.Instance.Managers.AddRange(this.Instance.Managers.ToArray()); + // return resource; + //} + + public abstract AsyncReply Remove(IResource resource); + + public abstract AsyncReply Remove(string path); + + public abstract AsyncReply Move(IResource resource, string newPath); + + public abstract AsyncBag Parents(IResource resource, string name) where T1 : IResource; } diff --git a/Esiur/Resource/Template/TypeTemplate.cs b/Esiur/Resource/Template/TypeTemplate.cs index cc2213e..39a0945 100644 --- a/Esiur/Resource/Template/TypeTemplate.cs +++ b/Esiur/Resource/Template/TypeTemplate.cs @@ -887,7 +887,7 @@ public class TypeTemplate offset += dts; - (dts, var value) = Codec.ParseSync(data, offset); + (dts, var value) = Codec.ParseSync(data, offset, Warehouse.Default); offset += dts; diff --git a/Esiur/Stores/MemoryStore.cs b/Esiur/Stores/MemoryStore.cs index 58e1635..2b47478 100644 --- a/Esiur/Stores/MemoryStore.cs +++ b/Esiur/Stores/MemoryStore.cs @@ -65,18 +65,18 @@ public class MemoryStore : IStore return new AsyncReply(true); } - public AsyncReply Retrieve(uint iid) - { - if (resources.ContainsKey(iid)) - { - if (resources.ContainsKey(iid))// .TryGetTarget(out r)) - return new AsyncReply(resources[iid]); - else - return new AsyncReply(null); - } - else - return new AsyncReply(null); - } + //public AsyncReply Retrieve(uint iid) + //{ + // if (resources.ContainsKey(iid)) + // { + // if (resources.ContainsKey(iid))// .TryGetTarget(out r)) + // return new AsyncReply(resources[iid]); + // else + // return new AsyncReply(null); + // } + // else + // return new AsyncReply(null); + //} public AsyncReply Trigger(ResourceTrigger trigger) { @@ -104,33 +104,29 @@ public class MemoryStore : IStore return true; } - public AsyncReply AddChild(IResource parent, IResource child) - { - if (parent.Instance.Store == this) - { - (parent.Instance.Variables["children"] as AutoList).Add(child); - return new AsyncReply(true); - } - else - return new AsyncReply(false); - } + //public AsyncReply AddChild(IResource parent, IResource child) + //{ + // if (parent.Instance.Store == this) + // { + // (parent.Instance.Variables["children"] as AutoList).Add(child); + // return new AsyncReply(true); + // } + // else + // return new AsyncReply(false); + //} + - public AsyncReply RemoveChild(IResource parent, IResource child) - { - throw new NotImplementedException(); - } + //public AsyncReply AddParent(IResource resource, IResource parent) + //{ - public AsyncReply AddParent(IResource resource, IResource parent) - { - - if (resource.Instance.Store == this) - { - (resource.Instance.Variables["parents"] as AutoList).Add(parent); - return new AsyncReply(true); - } - else - return new AsyncReply(false); - } + // if (resource.Instance.Store == this) + // { + // (resource.Instance.Variables["parents"] as AutoList).Add(parent); + // return new AsyncReply(true); + // } + // else + // return new AsyncReply(false); + //} public AsyncReply RemoveParent(IResource child, IResource parent) { @@ -157,4 +153,20 @@ public class MemoryStore : IStore else return new AsyncBag(parents.Where(x => x is T && x.Instance.Name == name).Select(x => (T)x).ToArray()); } + + AsyncReply IStore.Remove(IResource resource) + { + throw new NotImplementedException(); + } + + public AsyncReply Remove(string path) + { + throw new NotImplementedException(); + } + + public AsyncReply Move(IResource resource, string newPath) + { + throw new NotImplementedException(); + } + } diff --git a/Esiur/Stores/TemporaryStore.cs b/Esiur/Stores/TemporaryStore.cs index 424f3bb..2c4f5a1 100644 --- a/Esiur/Stores/TemporaryStore.cs +++ b/Esiur/Stores/TemporaryStore.cs @@ -42,7 +42,7 @@ public class TemporaryStore : IStore public AsyncReply Put(IResource resource) { - resources.Add(resource.Instance.Id, new WeakReference(resource));// new WeakReference(resource)); + resources.Add(resource.Instance.Id, new WeakReference(resource)); return new AsyncReply(true); } @@ -74,41 +74,34 @@ public class TemporaryStore : IStore throw new NotImplementedException(); } - public bool Remove(IResource resource) - { - resources.Remove(resource.Instance.Id); - return true; - } - + public bool Modify(IResource resource, string propertyName, object value, ulong? age, DateTime? dateTime) { return true; } - public AsyncReply AddChild(IResource parent, IResource child) - { - throw new NotImplementedException(); - } - - public AsyncReply RemoveChild(IResource parent, IResource child) - { - throw new NotImplementedException(); - } - - public AsyncReply AddParent(IResource child, IResource parent) - { - throw new NotImplementedException(); - } - - public AsyncReply RemoveParent(IResource child, IResource parent) - { - throw new NotImplementedException(); - } - + public AsyncBag Children(IResource resource, string name) where T : IResource { throw new NotImplementedException(); } + + + AsyncReply IStore.Remove(IResource resource) + { + resources.Remove(resource.Instance.Id); + return new AsyncReply(true); + } + + public AsyncReply Remove(string path) + { + throw new NotImplementedException(); + } + + public AsyncReply Move(IResource resource, string newPath) + { + throw new NotImplementedException(); + } public AsyncBag Parents(IResource resource, string name) where T : IResource { diff --git a/Test/Program.cs b/Test/Program.cs index dd24691..567cea0 100644 --- a/Test/Program.cs +++ b/Test/Program.cs @@ -107,8 +107,7 @@ namespace Test //Console.WriteLine(g); - var hhhh = Warehouse.GetTemplateByType(typeof(IMyRecord)); - + var a = new ECDH(); var b = new ECDH(); @@ -135,18 +134,20 @@ namespace Test } }); + var wh = new Warehouse(); + // Create stores to keep objects. - var system = await Warehouse.Put("sys", new MemoryStore()); - var server = await Warehouse.Put("sys/server", new DistributedServer() { Membership = membership }); + var system = await wh.Put("sys", new MemoryStore()); + var server = await wh.Put("sys/server", new DistributedServer() { Membership = membership }); - var web = await Warehouse.Put("sys/web", new HTTPServer() { Port = 8088 }); + var web = await wh.Put("sys/web", new HTTPServer() { Port = 8088 }); - var service = await Warehouse.Put("sys/service", new MyService()); - var res1 = await Warehouse.Put("sys/service/r1", new MyResource() { Description = "Testing 1", CategoryId = 10 }); - var res2 = await Warehouse.Put("sys/service/r2", new MyResource() { Description = "Testing 2", CategoryId = 11 }); - var res3 = await Warehouse.Put("sys/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 }); - var res4 = await Warehouse.Put("sys/service/c2", new MyChildResource() { ChildName = "Child 2 Destroy", Description = "Testing Destroy Handler", CategoryId = 12 }); + var service = await wh.Put("sys/service", new MyService()); + var res1 = await wh.Put("sys/service/r1", new MyResource() { Description = "Testing 1", CategoryId = 10 }); + var res2 = await wh.Put("sys/service/r2", new MyResource() { Description = "Testing 2", CategoryId = 11 }); + var res3 = await wh.Put("sys/service/c1", new MyChildResource() { ChildName = "Child 1", Description = "Child Testing 3", CategoryId = 12 }); + var res4 = await wh.Put("sys/service/c2", new MyChildResource() { ChildName = "Child 2 Destroy", Description = "Testing Destroy Handler", CategoryId = 12 }); //TestSerialization(res1); @@ -174,7 +175,7 @@ namespace Test sender.Send("Hello"); }); - await Warehouse.Open(); + await wh.Open(); // Start testing TestClient(service); @@ -200,7 +201,7 @@ namespace Test { - var con = await Warehouse.Get("iip://localhost", new DistributedConnectionConfig + var con = await Warehouse.Default.Get("iip://localhost", new DistributedConnectionConfig { AutoReconnect = true, Username = "admin",