From 44796d8e7219d0c4bbccd1b02819fe5fd5ec0f43 Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Fri, 8 Nov 2024 11:07:22 +0300 Subject: [PATCH] Cleanup --- Esiur.CLI/Program.cs | 1 - Esiur/Core/AsyncBagAwaiterGeneric.cs | 51 ----- Esiur/Core/AsyncBagGeneric.cs | 83 -------- Esiur/Core/AsyncReplyNon.cs | 184 ------------------ Esiur/Core/IAsyncReply.cs | 20 -- Esiur/Data/DataType.cs | 117 ----------- Esiur/Esiur.csproj | 53 +---- Esiur/Net/IIP/DistributedConnection.cs | 6 - .../Net/IIP/DistributedConnectionProtocol.cs | 1 - Esiur/Net/Packets/IIPAuthExtensions.cs | 3 +- Esiur/Net/Packets/IIPAuthPacket.cs | 1 - Esiur/Resource/ResourceEvent.cs | 51 ----- Esiur/Resource/ResourceFunction.cs | 51 ----- Esiur/Resource/ResourceProperty.cs | 54 ----- 14 files changed, 3 insertions(+), 673 deletions(-) delete mode 100644 Esiur/Core/AsyncBagAwaiterGeneric.cs delete mode 100644 Esiur/Core/AsyncBagGeneric.cs delete mode 100644 Esiur/Core/AsyncReplyNon.cs delete mode 100644 Esiur/Core/IAsyncReply.cs delete mode 100644 Esiur/Data/DataType.cs delete mode 100644 Esiur/Resource/ResourceEvent.cs delete mode 100644 Esiur/Resource/ResourceFunction.cs delete mode 100644 Esiur/Resource/ResourceProperty.cs diff --git a/Esiur.CLI/Program.cs b/Esiur.CLI/Program.cs index b4eeab6..99d597e 100644 --- a/Esiur.CLI/Program.cs +++ b/Esiur.CLI/Program.cs @@ -28,7 +28,6 @@ SOFTWARE. using CommandLine; using Esiur.CLI; using Esiur.Data; -using Microsoft.CodeAnalysis; using System; using System.Diagnostics; using System.IO; diff --git a/Esiur/Core/AsyncBagAwaiterGeneric.cs b/Esiur/Core/AsyncBagAwaiterGeneric.cs deleted file mode 100644 index c60d947..0000000 --- a/Esiur/Core/AsyncBagAwaiterGeneric.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Core; - -public class AsyncBagAwaiter : INotifyCompletion -{ - Action callback = null; - - AsyncException exception = null; - - T[] result; - - public AsyncBagAwaiter(AsyncBag reply) - { - reply.Then(x => - { - this.IsCompleted = true; - this.result = x; - this.callback?.Invoke(); - }).Error(x => - { - exception = x; - this.IsCompleted = true; - this.callback?.Invoke(); - }); - } - - public T[] GetResult() - { - if (exception != null) - throw exception; - return result; - } - - public bool IsCompleted { get; private set; } - - public void OnCompleted(Action continuation) - { - if (IsCompleted) - continuation?.Invoke(); - else - // Continue.... - callback = continuation; - } - - -} diff --git a/Esiur/Core/AsyncBagGeneric.cs b/Esiur/Core/AsyncBagGeneric.cs deleted file mode 100644 index f6feddb..0000000 --- a/Esiur/Core/AsyncBagGeneric.cs +++ /dev/null @@ -1,83 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Core; - -public class AsyncBag : AsyncBag -{ - public AsyncBag Then(Action callback) - { - //base.Then(new Action((o) => callback(((object[])o).Select(x => (T)x).ToArray()))); - base.Then(x => callback((T[])x)); - - return this; - } - - public override Type ArrayType => typeof(T); - - public void Add(AsyncReply reply) - { - base.Add(reply); - } - - public void AddBag(AsyncBag bag) - { - foreach (var r in bag.replies) - Add(r); - } - - - public new AsyncBagAwaiter GetAwaiter() - { - return new AsyncBagAwaiter(this); - } - - public new T[] Wait() - { - return (T[])base.Wait();// base.Wait().Select(x => (T)x).ToArray(); - } - - public new T[] Wait(int timeout) - { - return (T[])base.Wait(timeout); - } - - - public AsyncBag() - { - - } - - public AsyncBag(T[] results) - : base(results.Select(x => (object)x).ToArray()) - { - - } -} \ No newline at end of file diff --git a/Esiur/Core/AsyncReplyNon.cs b/Esiur/Core/AsyncReplyNon.cs deleted file mode 100644 index 3efd09b..0000000 --- a/Esiur/Core/AsyncReplyNon.cs +++ /dev/null @@ -1,184 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Core; - -public class AsyncReply -{ - - - - - protected List> callbacks = new List>(); - protected object result; - - protected List> errorCallbacks = new List>(); - - protected List> progressCallbacks = new List>(); - - protected List> chunkCallbacks = new List>(); - - object callbacksLock = new object(); - - protected bool resultReady = false; - AsyncException exception; - - TaskCompletionSource tcs = new TaskCompletionSource(); - - - public bool Ready - { - get { return resultReady; } - } - - public object Result - { - get { return result; } - } - - public AsyncReply Then(Action callback) - { - callbacks.Add(callback); - - if (resultReady) - callback(result); - - return this; - } - - public AsyncReply Error(Action callback) - { - errorCallbacks.Add(callback); - - if (exception != null) - { - callback(exception); - tcs.SetException(exception); - } - - return this; - } - - public AsyncReply Progress(Action callback) - { - progressCallbacks.Add(callback); - return this; - } - - public AsyncReply Chunk(Action callback) - { - chunkCallbacks.Add(callback); - return this; - } - - public void Trigger(object result) - { - - lock (callbacksLock) - { - if (resultReady) - return; - - this.result = result; - resultReady = true; - - foreach (var cb in callbacks) - cb(result); - - tcs.TrySetResult(result); - - } - - } - - public void TriggerError(AsyncException exception) - { - if (resultReady) - return; - - this.exception = exception; - - - lock (callbacksLock) - { - foreach (var cb in errorCallbacks) - cb(exception); - } - - tcs.TrySetException(exception); - } - - public void TriggerProgress(ProgressType type, int value, int max) - { - if (resultReady) - return; - - lock (callbacksLock) - { - foreach (var cb in progressCallbacks) - cb(type, value, max); - - } - } - - public void TriggerChunk(object value) - { - if (resultReady) - return; - - lock (callbacksLock) - { - foreach (var cb in chunkCallbacks) - cb(value); - - } - } - - - public Task Task - { - get - { - return tcs.Task; - } - } - - public AsyncReply() - { - - } - - public AsyncReply(object result) - { - resultReady = true; - tcs.SetResult(result); - this.result = result; - } -} diff --git a/Esiur/Core/IAsyncReply.cs b/Esiur/Core/IAsyncReply.cs deleted file mode 100644 index 5e0705d..0000000 --- a/Esiur/Core/IAsyncReply.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; -using System.Text; - -namespace Esiur.Core; - -public interface IAsyncReply//IAsyncEnumerator -{ - IAsyncReply Then(Action callback); - IAsyncReply Error(Action callback); - IAsyncReply Progress(Action callback); - IAsyncReply Chunk(Action callback); - void Trigger(object result); - void TriggerError(Exception exception); - void TriggerProgress(ProgressType type, int value, int max); - void TriggerChunk(object value); - - T Wait(); -} diff --git a/Esiur/Data/DataType.cs b/Esiur/Data/DataType.cs deleted file mode 100644 index 912b21c..0000000 --- a/Esiur/Data/DataType.cs +++ /dev/null @@ -1,117 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Data; -public enum DataType : byte -{ - Void = 0x0, - //Variant, - Bool, - Int8, - UInt8, - Char, - Int16, - UInt16, - Int32, - UInt32, - Int64, - UInt64, - Float32, - Float64, - Decimal, - DateTime, - Resource, - DistributedResource, - ResourceLink, - String, - Structure, - Record, - //Stream, - //Array = 0x80, - VarArray = 0x80, - BoolArray, - Int8Array, - UInt8Array, - CharArray, - Int16Array, - UInt16Array, - Int32Array, - UInt32Array, - Int64Array, - UInt64Array, - Float32Array, - Float64Array, - DecimalArray, - DateTimeArray, - ResourceArray, - DistributedResourceArray, - ResourceLinkArray, - StringArray, - StructureArray, - RecordArray, - NotModified = 0x7f, - Unspecified = 0xff, -} - -public static class DataTypeExpansions -{ - public static int Size(this DataType t) - { - switch (t) - { - case DataType.Void: - case DataType.NotModified: - return 0; - case DataType.Bool: - case DataType.UInt8: - case DataType.Int8: - return 1; - case DataType.Char: - case DataType.UInt16: - case DataType.Int16: - return 2; - case DataType.Int32: - case DataType.UInt32: - case DataType.Float32: - case DataType.Resource: - return 4; - case DataType.Int64: - case DataType.UInt64: - case DataType.Float64: - case DataType.DateTime: - return 8; - case DataType.DistributedResource: - return 4; - - default: - return -1; - } - } -} diff --git a/Esiur/Esiur.csproj b/Esiur/Esiur.csproj index 8903ed9..e53b33f 100644 --- a/Esiur/Esiur.csproj +++ b/Esiur/Esiur.csproj @@ -36,77 +36,28 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + - - - - - - - - - - - diff --git a/Esiur/Net/IIP/DistributedConnection.cs b/Esiur/Net/IIP/DistributedConnection.cs index a51f1ac..f5b4537 100644 --- a/Esiur/Net/IIP/DistributedConnection.cs +++ b/Esiur/Net/IIP/DistributedConnection.cs @@ -36,19 +36,13 @@ using Esiur.Resource; using Esiur.Security.Authority; using Esiur.Resource.Template; using System.Linq; -using System.Diagnostics; -using static Esiur.Net.Packets.IIPPacket; using Esiur.Net.HTTP; using System.Timers; using System.Threading.Tasks; using System.Runtime.InteropServices; using Esiur.Net.Packets.HTTP; -using System.ComponentModel.DataAnnotations; -using static System.Collections.Specialized.BitVector32; using Esiur.Security.Membership; using Esiur.Net.Packets; -using System.Reflection.PortableExecutable; -using System.Net.Http.Headers; namespace Esiur.Net.IIP; public partial class DistributedConnection : NetworkConnection, IStore diff --git a/Esiur/Net/IIP/DistributedConnectionProtocol.cs b/Esiur/Net/IIP/DistributedConnectionProtocol.cs index 41b0cc1..08baee4 100644 --- a/Esiur/Net/IIP/DistributedConnectionProtocol.cs +++ b/Esiur/Net/IIP/DistributedConnectionProtocol.cs @@ -38,7 +38,6 @@ using System.Threading.Tasks; using System.Security.Cryptography.X509Certificates; using Esiur.Misc; using Esiur.Net.Packets; -using System.Reflection.Metadata; namespace Esiur.Net.IIP; diff --git a/Esiur/Net/Packets/IIPAuthExtensions.cs b/Esiur/Net/Packets/IIPAuthExtensions.cs index 8705ba9..9bd4c23 100644 --- a/Esiur/Net/Packets/IIPAuthExtensions.cs +++ b/Esiur/Net/Packets/IIPAuthExtensions.cs @@ -1,5 +1,4 @@ -using Microsoft.CodeAnalysis.CSharp.Syntax; -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/Esiur/Net/Packets/IIPAuthPacket.cs b/Esiur/Net/Packets/IIPAuthPacket.cs index d805e4d..ecf6304 100644 --- a/Esiur/Net/Packets/IIPAuthPacket.cs +++ b/Esiur/Net/Packets/IIPAuthPacket.cs @@ -26,7 +26,6 @@ using Esiur.Data; using Esiur.Security.Authority; using System; using System.Collections.Generic; -using System.ComponentModel.DataAnnotations; using System.Data.Common; using System.Linq; using System.Security.Cryptography; diff --git a/Esiur/Resource/ResourceEvent.cs b/Esiur/Resource/ResourceEvent.cs deleted file mode 100644 index 50b51e0..0000000 --- a/Esiur/Resource/ResourceEvent.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Resource; - -[AttributeUsage(AttributeTargets.Event)] -public class ResourceEvent : System.Attribute -{ - - string annotation; - - public readonly string Annotation - { - get - { - return annotation; - } - } - - - public ResourceEvent(string annotation = null) - { - this.annotation = annotation; - } -} diff --git a/Esiur/Resource/ResourceFunction.cs b/Esiur/Resource/ResourceFunction.cs deleted file mode 100644 index 211f5d5..0000000 --- a/Esiur/Resource/ResourceFunction.cs +++ /dev/null @@ -1,51 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Resource; - -[AttributeUsage(AttributeTargets.Method)] -public class ResourceFunction : System.Attribute -{ - private string annotation = null; - - public string Annotation - { - get - { - return annotation; - } - } - - - public ResourceFunction(string annotation = null) - { - this.annotation = annotation; - } -} diff --git a/Esiur/Resource/ResourceProperty.cs b/Esiur/Resource/ResourceProperty.cs deleted file mode 100644 index c21eead..0000000 --- a/Esiur/Resource/ResourceProperty.cs +++ /dev/null @@ -1,54 +0,0 @@ -/* - -Copyright (c) 2017 Ahmed Kh. Zamil - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -*/ - -using Esiur.Resource.Template; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Esiur.Resource; - -[AttributeUsage(AttributeTargets.Property)] -public class ResourceProperty : System.Attribute -{ - - - public readonly bool Nullable; - public readonly StorageMode Storage; - public readonly bool Serialize; - public readonly string ReadAnnotation; - public readonly string WriteAnnotation; - - - public ResourceProperty(StorageMode storage = StorageMode.NonVolatile, bool serialize = true, - string readAnnotation = null, string writeAnnotation = null) - { - this.ReadAnnotation = readAnnotation; - this.WriteAnnotation = writeAnnotation; - this.Storage = storage; - this.Serialize = serialize; - } -}