diff --git a/Example.Backend/CsTest.cs b/Example.Backend/CsTest.cs index 8db1c75..ac30cb4 100644 --- a/Example.Backend/CsTest.cs +++ b/Example.Backend/CsTest.cs @@ -1,4 +1,3 @@ -using System; using Example.Shared; namespace Example.Backend diff --git a/Example.Backend/PagesList.cs b/Example.Backend/PagesList.cs index 1ce6be0..1b195c9 100644 --- a/Example.Backend/PagesList.cs +++ b/Example.Backend/PagesList.cs @@ -8,27 +8,31 @@ namespace Example.Backend { public class PagesList : RemoteObjectBase, IPagesList { + public PagesList(int id, IRepresentationModule representationModule) : base(id, representationModule) + { + } + public IReadOnlyList Collection { get; } - public Example.Shared.IPage this[int index] + public IPage this[int index] { - get => GetResultAsync(3, new object[] { index }).GetAwaiter().GetResult(); + get => GetResultAsync(3, new object[] { index }).GetAwaiter().GetResult(); set => CallAsync(5, new object[] { index, value }).Wait(); } public IPage Get(int index) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public void Add(IPage item) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public void Remove(int index, IPage item) { - throw new System.NotImplementedException(); + throw new NotImplementedException(); } public event Action? OnAdd; @@ -39,7 +43,11 @@ namespace Example.Backend // TODO release managed resources here } - public PagesList(int id, IRepresentationModule representationModule) : base(id, representationModule) + public void OnAddExternal(IPage p0) + { + } + + public void OnRemoveExternal(IPage p0) { } } diff --git a/Example.Backend/Printer.cs b/Example.Backend/Printer.cs index 85bd58a..c001071 100644 --- a/Example.Backend/Printer.cs +++ b/Example.Backend/Printer.cs @@ -10,6 +10,10 @@ namespace Example.Backend { public string Name; + public void OnPrintExternal(IPage p0, RequestContext p1) + { + } + public double Resource { get; set; } = 100d; public string GetName() @@ -17,22 +21,23 @@ namespace Example.Backend return Name; } - public async Task Print(string text, bool some, CancellationToken cancellationToken = default) + public async Task Print(string text, bool some, RequestContext context, + CancellationToken cancellationToken = default) { // throw new Exception("The method or operation is not implemented."); var page = new Page { Text = text }; - OnPrint?.Invoke(page); + Console.WriteLine($"Request id : :{context.RequestId}"); + OnPrint?.Invoke(page, context); Resource /= 1.5; return page; } - public event Action? OnPrint; + public event Action? OnPrint; public void Dispose() { Console.WriteLine( "Dispose printer with name {0}, Dispose works, Dispose works, Dispose works, Dispose works,", Name); } - } } \ No newline at end of file diff --git a/Example.Backend/PrinterFactory.cs b/Example.Backend/PrinterFactory.cs index 1fc2624..efc3975 100644 --- a/Example.Backend/PrinterFactory.cs +++ b/Example.Backend/PrinterFactory.cs @@ -2,7 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; using Example.Shared; -using mROA.Implementation; using mROA.Implementation.Attributes; namespace Example.Backend diff --git a/Example.Backend/Program.cs b/Example.Backend/Program.cs index a6b3ffc..73383be 100644 --- a/Example.Backend/Program.cs +++ b/Example.Backend/Program.cs @@ -1,6 +1,5 @@ using System.Net; using Example.Backend; -using Example.Shared; using mROA.Abstract; using mROA.Cbor; using mROA.Codegen; @@ -38,7 +37,7 @@ class Program new IInjectableModule[] { builder.GetModule()! }, typeof(RepresentationModule))); builder.Modules.Add(new CancellationRepository()); - + builder.Build(); new RemoteTypeBinder(); @@ -49,6 +48,5 @@ class Program var gateway = builder.GetModule(); gateway.Run(); - } } \ No newline at end of file diff --git a/Example.Frontend/ClientBasedPrinter.cs b/Example.Frontend/ClientBasedPrinter.cs index 4c9bea7..ed45914 100644 --- a/Example.Frontend/ClientBasedPrinter.cs +++ b/Example.Frontend/ClientBasedPrinter.cs @@ -8,27 +8,31 @@ namespace Example.Frontend { public class ClientBasedPrinter : IPrinter { + public void OnPrintExternal(IPage p0, RequestContext p1) + { + } + public double Resource { get; set; } public string GetName() { Console.WriteLine("ClientBasedPrinter called from server!!!!!!!!!!! Vova likes that:)"); - + return "ClientBasedPrinter from mroa"; } - public async Task Print(string text, bool some, CancellationToken cancellationToken) + public async Task Print(string text, bool some, RequestContext context, + CancellationToken cancellationToken) { Console.WriteLine($"Printed: {text}"); await Task.Yield(); return new ClientBasedPage(); } - public event Action? OnPrint; + public event Action? OnPrint; public void Dispose() { - } } diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index 07fa4ab..07bd283 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -72,7 +72,8 @@ class Program Console.WriteLine(string.Join(", ", names)); - var page = disposingPrinter.Print("Test Page", false, CancellationToken.None).GetAwaiter().GetResult(); + var page = disposingPrinter.Print("Test Page", false, default, CancellationToken.None).GetAwaiter() + .GetResult(); Console.WriteLine("Page printed"); Console.WriteLine(page.ToString()); @@ -112,7 +113,5 @@ class Program // Console.WriteLine("X is {0}", x); // Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds); // Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms"); - - } } \ No newline at end of file diff --git a/Example.Shared/IDataList.cs b/Example.Shared/IDataList.cs index f08bb75..bdaae63 100644 --- a/Example.Shared/IDataList.cs +++ b/Example.Shared/IDataList.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using mROA.Implementation; -using mROA.Implementation.Attributes; namespace Example.Shared { diff --git a/Example.Shared/IPagesList.cs b/Example.Shared/IPagesList.cs index 05bcc6a..0b4d5d5 100644 --- a/Example.Shared/IPagesList.cs +++ b/Example.Shared/IPagesList.cs @@ -3,7 +3,7 @@ using mROA.Implementation.Attributes; namespace Example.Shared { [SharedObjectInterface] - public interface IPagesList : IDataList + public partial interface IPagesList : IDataList { } } \ No newline at end of file diff --git a/Example.Shared/IPrinter.cs b/Example.Shared/IPrinter.cs index a94aae4..f5b25f0 100644 --- a/Example.Shared/IPrinter.cs +++ b/Example.Shared/IPrinter.cs @@ -7,11 +7,11 @@ using mROA.Implementation.Attributes; namespace Example.Shared { [SharedObjectInterface] - public interface IPrinter : IDisposable, IShared + public partial interface IPrinter : IDisposable, IShared { double Resource { get; set; } string GetName(); - Task Print(string text, bool someParameter, CancellationToken cancellationToken); - event Action OnPrint; + Task Print(string text, bool someParameter, RequestContext context, CancellationToken cancellationToken); + event Action OnPrint; } } \ No newline at end of file diff --git a/mROA.Codegen/mROASourceGenerator.cs b/mROA.Codegen/mROASourceGenerator.cs index b420758..33e2465 100644 --- a/mROA.Codegen/mROASourceGenerator.cs +++ b/mROA.Codegen/mROASourceGenerator.cs @@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; - namespace mROA.Codegen { /// @@ -19,6 +18,45 @@ namespace mROA.Codegen [Generator] public class mROASourceGenerator : ISourceGenerator { + private static Predicate ParameterFilter = + i => i.Type.Name is "CancellationToken" or "RequestContext"; + + private static Predicate ParameterFilterForType = + i => i.Name is "CancellationToken" or "RequestContext"; + + public void Initialize(GeneratorInitializationContext context) + { + } + + public void Execute(GeneratorExecutionContext context) + { + var trees = context.Compilation.SyntaxTrees; + + var interfaces = new List(); + foreach (var tree in trees) + { + var node = tree.GetRoot() as CompilationUnitSyntax; + + foreach (var member in node.Members) + { + if (member is InterfaceDeclarationSyntax ids) + { + interfaces.Add(ids); + } + else if (member is NamespaceDeclarationSyntax nds) + { + foreach (var inside in nds.Members) + + if (inside is InterfaceDeclarationSyntax ids2) + if (ContainsSOIAttribute(ids2.AttributeLists, context, ids2)) + interfaces.Add(ids2); + } + } + } + + GenerateCode(context, context.Compilation, interfaces.ToImmutableArray()); + } + private void GenerateCode(GeneratorExecutionContext context, Compilation compilation, ImmutableArray classes) { @@ -31,6 +69,7 @@ namespace mROA.Codegen var frontendContextRepo = new List(); List totalMethods = new List(); + List invokers = new List(); var declarations = classes.ToList().OrderBy(i => i.Identifier.Text).ToList(); foreach (var classDeclarationSyntax in declarations) @@ -52,7 +91,7 @@ namespace mROA.Codegen .ToList(); totalMethods.AddRange(innerMethods); - + var originalName = className; className = className.TrimStart('I') + "RemoteEndpoint"; @@ -66,10 +105,11 @@ namespace mROA.Codegen switch (method.MethodKind) { case MethodKind.PropertyGet or MethodKind.PropertySet: - GeneratePropertyMethod(method, totalMethods, propertiesAccessMethods, invokers); + GeneratePropertyMethod(method, propertiesAccessMethods, invokers, + classSymbol); continue; default: - GenerateDeclaredMethod(method, declaredMethods, totalMethods, invokers); + GenerateDeclaredMethod(method, declaredMethods, invokers, classSymbol); break; } } @@ -105,6 +145,8 @@ namespace mROA.Codegen } } + GenerateEventImplementation(classSymbol, invokers, declaredMethods, context); + var code = $@"// using mROA; @@ -138,7 +180,7 @@ namespace {namespaceName} if (totalMethods.Count != 0) { var methodsStringed = invokers; - + var coCodegenRepoCode = @$"// using System.Collections.Generic; using System.Reflection; @@ -203,7 +245,61 @@ namespace mROA.Codegen } } - public static string Caster(ITypeSymbol type, string inner) + private void GenerateEventImplementation(INamedTypeSymbol classSymbol, List invokers, + List declaredMethods, GeneratorExecutionContext context) + { + var events = classSymbol.AllInterfaces.Add(classSymbol).SelectMany(i => i.GetMembers()) + .OfType().ToList(); + if (events.Count == 0) + return; + + var additionalSignatures = new List(events.Count); + var namespaceName = classSymbol.ContainingNamespace.ToDisplayString(); + + for (int i = 0; i < events.Count; i++) + { + var currentEvent = events[i]; + + var additionalMethod = GenerateMethodExternalCaller(currentEvent, out var signature); + declaredMethods.Add(additionalMethod); + additionalSignatures.Add(signature); + GenerateEventCode(currentEvent, invokers, classSymbol); + } + + var partialInterface = $@" +namespace {classSymbol.ContainingNamespace.ToDisplayString()} +{{ + public partial interface {classSymbol.Name} + {{ +{string.Join("\r\n", additionalSignatures)} + }} +}} +"; +#if !DONT_ADD + context.AddSource($"{classSymbol.Name}.g.cs", SourceText.From(partialInterface, Encoding.UTF8)); +#endif + } + + private string GenerateMethodExternalCaller(IEventSymbol eventSymbol, out string interfaceSignature) + { + var level = "\t\t"; + var parameters = (eventSymbol.Type as INamedTypeSymbol).TypeArguments; + var parameterIndex = 0; + var parametersDeclaration = + string.Join(", ", parameters.Select(i => $"{i.ToDisplayString()} p{parameterIndex++}")); + var signature = $@"public void {EventExternalName(eventSymbol)}({parametersDeclaration})"; + interfaceSignature = level + signature + ";"; + var caller = $@"{signature} +{level}{{ +{level} {eventSymbol.Name}?.Invoke({string.Join(", ", Enumerable.Range(0, parameterIndex).Select(i => "p" + i))}); +{level}}} +"; + return caller; + } + + public static string EventExternalName(IEventSymbol eventSymbol) => $"{eventSymbol.Name}External"; + + private static string Caster(ITypeSymbol type, string inner) { if (!type.IsValueType) return inner + @@ -212,10 +308,10 @@ namespace mROA.Codegen return $"({type.ToDisplayString()})" + inner; } - private void GenerateDeclaredMethod(IMethodSymbol method, List declaredMethods, - List methods, List invokers) + private void GenerateDeclaredMethod(IMethodSymbol method, List declaredMethods, List invokers, + INamedTypeSymbol baseInterace) { - var index = methods.IndexOf(method); + var index = invokers.Count; var sb = new StringBuilder(); bool isParametrized; @@ -327,7 +423,7 @@ namespace mROA.Codegen {level} IsVoid = {isVoid.ToString().ToLower()}, {(isVoid ? String.Empty : (level + "\t" + "ReturnType = typeof(" + ExtractTaskType(method.ReturnType)) + "),")} {level} ParameterTypes = new Type[] {{ {parameterTypes} }}, -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, parameters, special, post) => {funcInvoking}, {level}}}"; else @@ -336,21 +432,62 @@ namespace mROA.Codegen {level} IsVoid = {isVoid.ToString().ToLower()}, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ParameterTypes = new Type[] {{ {parameterTypes} }}, -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, parameters, special) => {funcInvoking} {level}}}"; invokers.Add(backend); } - private static Predicate ParameterFilter = - i => i.Type.Name is "CancellationToken" or "RequestContext"; - - public void GeneratePropertyMethod(IMethodSymbol method, List methods, - List<(string, IMethodSymbol)> propsCollection, List invokers) + private void GenerateEventCode(IEventSymbol eventSymbol, List invokers, ITypeSymbol baseInterface) { var level = "\t\t\t"; - var index = methods.IndexOf(method); + + var parameters = (eventSymbol.Type as INamedTypeSymbol).TypeArguments; + var parsingParameters = parameters.RemoveAll(ParameterFilterForType).ToList(); + var parameterTypes = string.Join(", ", + $"{string.Join(", ", parsingParameters.Select(p => $"typeof({p.ToDisplayString()})"))}"); + + var parametersInsertList = new List(); + + for (var i = 0; i < parameters.Length; i++) + { + var parameter = parameters[i]; + switch (parameter.Name) + { + case "CancellationToken": + parametersInsertList.Add("(CancellationToken)special[1]"); + break; + case "RequestContext": + parametersInsertList.Add("special[1] as RequestContext"); + break; + default: + parametersInsertList.Add(Caster(parameter, + $"parameters[{parameters.IndexOf(parameter)}]")); + break; + } + } + + var parametersInsert = string.Join(", ", parametersInsertList); + var backend = $@"new mROA.Implementation.MethodInvoker +{level}{{ +{level} IsVoid = true, +{level} ReturnType = typeof(void), +{level} ParameterTypes = new Type[] {{ {parameterTypes} }}, +{level} SuitableType = typeof({baseInterface.ToDisplayString()}), +{level} Invoking = (i, parameters, special) => {{ +{level} (i as {baseInterface.ToDisplayString()}).{EventExternalName(eventSymbol)}({parametersInsert}); +{level} return null; +{level} }} +{level}}}"; + invokers.Add(backend); + } + + private void GeneratePropertyMethod(IMethodSymbol method, + List<(string, IMethodSymbol)> propsCollection, List invokers, INamedTypeSymbol baseInterace) + { + var level = "\t\t\t"; + var index = invokers.Count; string frontend; string backend = string.Empty; if (method.MethodKind == MethodKind.PropertyGet) @@ -363,21 +500,14 @@ namespace mROA.Codegen var parameterTypes = string.Join(", ", $"{string.Join(", ", method.Parameters.Select(p => "typeof(" + p.Type.ToDisplayString() + ")"))}"); var parameterInserts = string.Join(", ", - method.Parameters.Select(p => - { - return Caster(p.Type, "parameters[" + method.Parameters.IndexOf(p) + "]"); - // if (!p.Type.IsValueType) - // return "parameters[" + method.Parameters.IndexOf(p) + "] as " + - // p.Type.ToDisplayString(); - // return $"({p.Type.ToDisplayString()})parameters[{method.Parameters.IndexOf(p)}]"; - } - )); + method.Parameters.Select( + p => Caster(p.Type, "parameters[" + method.Parameters.IndexOf(p) + "]"))); backend = $@"new mROA.Implementation.MethodInvoker {level}{{ {level} IsVoid = false, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ParameterTypes = new Type[] {{ {parameterTypes} }}, -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()})[{parameterInserts}], {level}}}"; } @@ -387,7 +517,7 @@ namespace mROA.Codegen {level}{{ {level} IsVoid = false, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, _, _) => (i as {method.ContainingType.ToDisplayString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name}, {level}}}"; } @@ -426,7 +556,7 @@ namespace mROA.Codegen {level} IsVoid = true, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ParameterTypes = new Type[] {{ {parameterTypes} }}, -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()})[{parameterInserts}] = {valueInsert}, {level}}}"; } @@ -437,7 +567,7 @@ namespace mROA.Codegen {level} IsVoid = true, {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ParameterTypes = new Type[] {{ typeof({method.Parameters.First().Type.ToDisplayString()}) }}, -{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), +{level} SuitableType = typeof({baseInterace.ToDisplayString()}), {level} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name} = {Caster((method.AssociatedSymbol as IPropertySymbol)!.Type, "parameters[0]")}, {level}}}"; } @@ -464,39 +594,6 @@ namespace mROA.Codegen return (taskType as INamedTypeSymbol).TypeArguments[0].ToDisplayString(); } - public void Initialize(GeneratorInitializationContext context) - { - } - - public void Execute(GeneratorExecutionContext context) - { - var trees = context.Compilation.SyntaxTrees; - - var interfaces = new List(); - foreach (var tree in trees) - { - var node = tree.GetRoot() as CompilationUnitSyntax; - - foreach (var member in node.Members) - { - if (member is InterfaceDeclarationSyntax ids) - { - interfaces.Add(ids); - } - else if (member is NamespaceDeclarationSyntax nds) - { - foreach (var inside in nds.Members) - - if (inside is InterfaceDeclarationSyntax ids2) - if (ContainsSOIAttribute(ids2.AttributeLists, context, ids2)) - interfaces.Add(ids2); - } - } - } - - GenerateCode(context, context.Compilation, interfaces.ToImmutableArray()); - } - private bool ContainsSOIAttribute(SyntaxList attributes, GeneratorExecutionContext context, InterfaceDeclarationSyntax interfaceDeclarationSyntax) { diff --git a/mROA/Abstract/IMethodRepository.cs b/mROA/Abstract/IMethodRepository.cs index ec67928..4c468f1 100644 --- a/mROA/Abstract/IMethodRepository.cs +++ b/mROA/Abstract/IMethodRepository.cs @@ -1,6 +1,4 @@ -using System.Reflection; - -namespace mROA.Abstract +namespace mROA.Abstract { public interface IMethodRepository : IInjectableModule { diff --git a/mROA/Implementation/Backend/BasicExecutionModule.cs b/mROA/Implementation/Backend/BasicExecutionModule.cs index 7199b42..aa5b3ba 100644 --- a/mROA/Implementation/Backend/BasicExecutionModule.cs +++ b/mROA/Implementation/Backend/BasicExecutionModule.cs @@ -1,8 +1,5 @@ using System; -using System.Linq; -using System.Reflection; using System.Threading; -using System.Threading.Tasks; using mROA.Abstract; using mROA.Implementation.CommandExecution; @@ -10,8 +7,8 @@ namespace mROA.Implementation.Backend { public class BasicExecutionModule : IExecuteModule { - private IMethodRepository? _methodRepo; private ICancellationRepository? _cancellationRepo; + private IMethodRepository? _methodRepo; private ISerializationToolkit? _serialization; public void Inject(T dependency) @@ -244,8 +241,7 @@ namespace mROA.Implementation.Backend multiClientOwnershipRepository?.FreeOwnership(); }); - - + // result.ContinueWith(t => // { // var finalResult = t.GetType().GetProperty("Result")?.GetValue(t); diff --git a/mROA/Implementation/CallRequest.cs b/mROA/Implementation/CallRequest.cs index 9066319..0549069 100644 --- a/mROA/Implementation/CallRequest.cs +++ b/mROA/Implementation/CallRequest.cs @@ -1,5 +1,4 @@ using System; -using mROA.Implementation.Attributes; // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global @@ -21,6 +20,7 @@ namespace mROA.Implementation public int ObjectId { get; set; } = -1; public object?[]? Parameters { get; set; } + public override string ToString() { return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}"; @@ -33,6 +33,7 @@ namespace mROA.Implementation public int CommandId { get; set; } = -2; public int ObjectId { get; set; } = -2; public object?[]? Parameters { get; set; } = null; + public override string ToString() { return $"Cancel request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}"; diff --git a/mROA/Implementation/CommandExecution/FinalCommandExecution.cs b/mROA/Implementation/CommandExecution/FinalCommandExecution.cs index 2a99331..fba0dca 100644 --- a/mROA/Implementation/CommandExecution/FinalCommandExecution.cs +++ b/mROA/Implementation/CommandExecution/FinalCommandExecution.cs @@ -1,5 +1,4 @@ using System; -using System.Text.Json.Serialization; using mROA.Abstract; // ReSharper disable UnusedAutoPropertyAccessor.Global diff --git a/mROA/Implementation/Frontend/RequestExtractor.cs b/mROA/Implementation/Frontend/RequestExtractor.cs index 751e10d..d4b141c 100644 --- a/mROA/Implementation/Frontend/RequestExtractor.cs +++ b/mROA/Implementation/Frontend/RequestExtractor.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Threading; using System.Threading.Tasks; using mROA.Abstract; @@ -12,10 +11,10 @@ namespace mROA.Implementation.Frontend { public class RequestExtractor : IRequestExtractor { - private IRepresentationModule? _representationModule; private IContextRepository? _contextRepository; - private IMethodRepository? _methodRepository; private IExecuteModule? _executeModule; + private IMethodRepository? _methodRepository; + private IRepresentationModule? _representationModule; private ISerializationToolkit? _serializationToolkit; public void Inject(T dependency) diff --git a/mROA/Implementation/SharedObjectShell.cs b/mROA/Implementation/SharedObjectShell.cs index 3e55a78..27e1ab2 100644 --- a/mROA/Implementation/SharedObjectShell.cs +++ b/mROA/Implementation/SharedObjectShell.cs @@ -1,6 +1,5 @@ using System; using System.Text.Json.Serialization; -using System.Threading.Tasks; using mROA.Abstract; using mROA.Implementation.Attributes; @@ -18,47 +17,22 @@ namespace mROA.Implementation public class SharedObjectShellShell : ISharedObjectShell where T : notnull { - [SerializationIgnore] - [JsonIgnore] - public IEndPointContext EndPointContext { get; set; } = new EndPointContext - { - RealRepository = TransmissionConfig.RealContextRepository, - RemoteRepository = TransmissionConfig.RemoteEndpointContextRepository, - HostId = TransmissionConfig.OwnershipRepository.GetHostOwnershipId(), - OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId - }; - - private IContextRepository GetDefaultContextRepository() => - (_identifier.OwnerId == EndPointContext.HostId - ? EndPointContext.RealRepository - : EndPointContext.RemoteRepository) ?? - throw new NullReferenceException( - "DefaultContextRepository was not defined"); - private UniversalObjectIdentifier _identifier = UniversalObjectIdentifier.Null; - public UniversalObjectIdentifier Identifier - { - get - { - _identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId; - return _identifier; - } - set - { - _identifier = value; - Value = GetDefaultContextRepository().GetObjectBySharedObject(this); - } - } - - public object UniversalValue - { - get => _value; - set => _value = (T)value; - } - private T _value; + // ReSharper disable once MemberCanBePrivate.Global + // ReSharper disable once UnusedMember.Global + public SharedObjectShellShell() + { + } + + // ReSharper disable once UnusedMember.Global + public SharedObjectShellShell(T value) + { + Value = value; + } + [JsonIgnore] [SerializationIgnore] public T Value @@ -80,18 +54,43 @@ namespace mROA.Implementation } } - // ReSharper disable once MemberCanBePrivate.Global - // ReSharper disable once UnusedMember.Global - public SharedObjectShellShell() + [SerializationIgnore] + [JsonIgnore] + public IEndPointContext EndPointContext { get; set; } = new EndPointContext { + RealRepository = TransmissionConfig.RealContextRepository, + RemoteRepository = TransmissionConfig.RemoteEndpointContextRepository, + HostId = TransmissionConfig.OwnershipRepository.GetHostOwnershipId(), + OwnerFunc = TransmissionConfig.OwnershipRepository.GetOwnershipId + }; + + public UniversalObjectIdentifier Identifier + { + get + { + _identifier.OwnerId = _identifier.OwnerId == -1 ? EndPointContext.OwnerId : _identifier.OwnerId; + return _identifier; + } + set + { + _identifier = value; + Value = GetDefaultContextRepository().GetObjectBySharedObject(this); + } } - // ReSharper disable once UnusedMember.Global - public SharedObjectShellShell(T value) + public object UniversalValue { - Value = value; + get => _value; + set => _value = (T)value; } + private IContextRepository GetDefaultContextRepository() => + (_identifier.OwnerId == EndPointContext.HostId + ? EndPointContext.RealRepository + : EndPointContext.RemoteRepository) ?? + throw new NullReferenceException( + "DefaultContextRepository was not defined"); + public static implicit operator T(SharedObjectShellShell value) => value.Value; public static implicit operator SharedObjectShellShell(T value) => diff --git a/mROA/Implementation/UniversalObjectIdentifier.cs b/mROA/Implementation/UniversalObjectIdentifier.cs index 29491f2..781567e 100644 --- a/mROA/Implementation/UniversalObjectIdentifier.cs +++ b/mROA/Implementation/UniversalObjectIdentifier.cs @@ -1,5 +1,4 @@ using System; -using mROA.Abstract; namespace mROA.Implementation {