Практически доделанный кодген, но не работает демка

This commit is contained in:
2025-03-10 00:00:24 +03:00
parent e0088ea22c
commit 0dbc065d9e
18 changed files with 248 additions and 149 deletions
-1
View File
@@ -1,4 +1,3 @@
using System;
using Example.Shared; using Example.Shared;
namespace Example.Backend namespace Example.Backend
+14 -6
View File
@@ -8,27 +8,31 @@ namespace Example.Backend
{ {
public class PagesList : RemoteObjectBase, IPagesList public class PagesList : RemoteObjectBase, IPagesList
{ {
public PagesList(int id, IRepresentationModule representationModule) : base(id, representationModule)
{
}
public IReadOnlyList<IPage> Collection { get; } public IReadOnlyList<IPage> Collection { get; }
public Example.Shared.IPage this[int index] public IPage this[int index]
{ {
get => GetResultAsync<Example.Shared.IPage>(3, new object[] { index }).GetAwaiter().GetResult(); get => GetResultAsync<IPage>(3, new object[] { index }).GetAwaiter().GetResult();
set => CallAsync(5, new object[] { index, value }).Wait(); set => CallAsync(5, new object[] { index, value }).Wait();
} }
public IPage Get(int index) public IPage Get(int index)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public void Add(IPage item) public void Add(IPage item)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public void Remove(int index, IPage item) public void Remove(int index, IPage item)
{ {
throw new System.NotImplementedException(); throw new NotImplementedException();
} }
public event Action<IPage>? OnAdd; public event Action<IPage>? OnAdd;
@@ -39,7 +43,11 @@ namespace Example.Backend
// TODO release managed resources here // TODO release managed resources here
} }
public PagesList(int id, IRepresentationModule representationModule) : base(id, representationModule) public void OnAddExternal(IPage p0)
{
}
public void OnRemoveExternal(IPage p0)
{ {
} }
} }
+9 -4
View File
@@ -10,6 +10,10 @@ namespace Example.Backend
{ {
public string Name; public string Name;
public void OnPrintExternal(IPage p0, RequestContext p1)
{
}
public double Resource { get; set; } = 100d; public double Resource { get; set; } = 100d;
public string GetName() public string GetName()
@@ -17,22 +21,23 @@ namespace Example.Backend
return Name; return Name;
} }
public async Task<IPage> Print(string text, bool some, CancellationToken cancellationToken = default) public async Task<IPage> Print(string text, bool some, RequestContext context,
CancellationToken cancellationToken = default)
{ {
// throw new Exception("The method or operation is not implemented."); // throw new Exception("The method or operation is not implemented.");
var page = new Page { Text = text }; var page = new Page { Text = text };
OnPrint?.Invoke(page); Console.WriteLine($"Request id : :{context.RequestId}");
OnPrint?.Invoke(page, context);
Resource /= 1.5; Resource /= 1.5;
return page; return page;
} }
public event Action<IPage>? OnPrint; public event Action<IPage, RequestContext>? OnPrint;
public void Dispose() public void Dispose()
{ {
Console.WriteLine( Console.WriteLine(
"Dispose printer with name {0}, Dispose works, Dispose works, Dispose works, Dispose works,", Name); "Dispose printer with name {0}, Dispose works, Dispose works, Dispose works, Dispose works,", Name);
} }
} }
} }
-1
View File
@@ -2,7 +2,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Example.Shared; using Example.Shared;
using mROA.Implementation;
using mROA.Implementation.Attributes; using mROA.Implementation.Attributes;
namespace Example.Backend namespace Example.Backend
-2
View File
@@ -1,6 +1,5 @@
using System.Net; using System.Net;
using Example.Backend; using Example.Backend;
using Example.Shared;
using mROA.Abstract; using mROA.Abstract;
using mROA.Cbor; using mROA.Cbor;
using mROA.Codegen; using mROA.Codegen;
@@ -49,6 +48,5 @@ class Program
var gateway = builder.GetModule<IGatewayModule>(); var gateway = builder.GetModule<IGatewayModule>();
gateway.Run(); gateway.Run();
} }
} }
+7 -3
View File
@@ -8,6 +8,10 @@ namespace Example.Frontend
{ {
public class ClientBasedPrinter : IPrinter public class ClientBasedPrinter : IPrinter
{ {
public void OnPrintExternal(IPage p0, RequestContext p1)
{
}
public double Resource { get; set; } public double Resource { get; set; }
public string GetName() public string GetName()
@@ -17,18 +21,18 @@ namespace Example.Frontend
return "ClientBasedPrinter from mroa"; return "ClientBasedPrinter from mroa";
} }
public async Task<IPage> Print(string text, bool some, CancellationToken cancellationToken) public async Task<IPage> Print(string text, bool some, RequestContext context,
CancellationToken cancellationToken)
{ {
Console.WriteLine($"Printed: {text}"); Console.WriteLine($"Printed: {text}");
await Task.Yield(); await Task.Yield();
return new ClientBasedPage(); return new ClientBasedPage();
} }
public event Action<IPage>? OnPrint; public event Action<IPage, RequestContext>? OnPrint;
public void Dispose() public void Dispose()
{ {
} }
} }
+2 -3
View File
@@ -72,7 +72,8 @@ class Program
Console.WriteLine(string.Join(", ", names)); 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 printed");
Console.WriteLine(page.ToString()); Console.WriteLine(page.ToString());
@@ -112,7 +113,5 @@ class Program
// Console.WriteLine("X is {0}", x); // Console.WriteLine("X is {0}", x);
// Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds); // Console.WriteLine("Time : {0}", timer.Elapsed.TotalMilliseconds);
// Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms"); // Console.WriteLine($"Time per call: {timer.Elapsed.TotalMilliseconds / iterations} ms");
} }
} }
-1
View File
@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using mROA.Implementation; using mROA.Implementation;
using mROA.Implementation.Attributes;
namespace Example.Shared namespace Example.Shared
{ {
+1 -1
View File
@@ -3,7 +3,7 @@ using mROA.Implementation.Attributes;
namespace Example.Shared namespace Example.Shared
{ {
[SharedObjectInterface] [SharedObjectInterface]
public interface IPagesList : IDataList<IPage> public partial interface IPagesList : IDataList<IPage>
{ {
} }
} }
+3 -3
View File
@@ -7,11 +7,11 @@ using mROA.Implementation.Attributes;
namespace Example.Shared namespace Example.Shared
{ {
[SharedObjectInterface] [SharedObjectInterface]
public interface IPrinter : IDisposable, IShared public partial interface IPrinter : IDisposable, IShared
{ {
double Resource { get; set; } double Resource { get; set; }
string GetName(); string GetName();
Task<IPage> Print(string text, bool someParameter, CancellationToken cancellationToken); Task<IPage> Print(string text, bool someParameter, RequestContext context, CancellationToken cancellationToken);
event Action<IPage> OnPrint; event Action<IPage, RequestContext> OnPrint;
} }
} }
+158 -61
View File
@@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.Text;
namespace mROA.Codegen namespace mROA.Codegen
{ {
/// <summary> /// <summary>
@@ -19,6 +18,45 @@ namespace mROA.Codegen
[Generator] [Generator]
public class mROASourceGenerator : ISourceGenerator public class mROASourceGenerator : ISourceGenerator
{ {
private static Predicate<IParameterSymbol> ParameterFilter =
i => i.Type.Name is "CancellationToken" or "RequestContext";
private static Predicate<ITypeSymbol> 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<InterfaceDeclarationSyntax>();
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, private void GenerateCode(GeneratorExecutionContext context, Compilation compilation,
ImmutableArray<InterfaceDeclarationSyntax> classes) ImmutableArray<InterfaceDeclarationSyntax> classes)
{ {
@@ -31,6 +69,7 @@ namespace mROA.Codegen
var frontendContextRepo = new List<string>(); var frontendContextRepo = new List<string>();
List<IMethodSymbol> totalMethods = new List<IMethodSymbol>(); List<IMethodSymbol> totalMethods = new List<IMethodSymbol>();
List<string> invokers = new List<string>(); List<string> invokers = new List<string>();
var declarations = classes.ToList().OrderBy(i => i.Identifier.Text).ToList(); var declarations = classes.ToList().OrderBy(i => i.Identifier.Text).ToList();
foreach (var classDeclarationSyntax in declarations) foreach (var classDeclarationSyntax in declarations)
@@ -66,10 +105,11 @@ namespace mROA.Codegen
switch (method.MethodKind) switch (method.MethodKind)
{ {
case MethodKind.PropertyGet or MethodKind.PropertySet: case MethodKind.PropertyGet or MethodKind.PropertySet:
GeneratePropertyMethod(method, totalMethods, propertiesAccessMethods, invokers); GeneratePropertyMethod(method, propertiesAccessMethods, invokers,
classSymbol);
continue; continue;
default: default:
GenerateDeclaredMethod(method, declaredMethods, totalMethods, invokers); GenerateDeclaredMethod(method, declaredMethods, invokers, classSymbol);
break; break;
} }
} }
@@ -105,6 +145,8 @@ namespace mROA.Codegen
} }
} }
GenerateEventImplementation(classSymbol, invokers, declaredMethods, context);
var code = $@"// <auto-generated/> var code = $@"// <auto-generated/>
using mROA; using mROA;
@@ -203,7 +245,61 @@ namespace mROA.Codegen
} }
} }
public static string Caster(ITypeSymbol type, string inner) private void GenerateEventImplementation(INamedTypeSymbol classSymbol, List<string> invokers,
List<string> declaredMethods, GeneratorExecutionContext context)
{
var events = classSymbol.AllInterfaces.Add(classSymbol).SelectMany(i => i.GetMembers())
.OfType<IEventSymbol>().ToList();
if (events.Count == 0)
return;
var additionalSignatures = new List<string>(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) if (!type.IsValueType)
return inner + return inner +
@@ -212,10 +308,10 @@ namespace mROA.Codegen
return $"({type.ToDisplayString()})" + inner; return $"({type.ToDisplayString()})" + inner;
} }
private void GenerateDeclaredMethod(IMethodSymbol method, List<string> declaredMethods, private void GenerateDeclaredMethod(IMethodSymbol method, List<string> declaredMethods, List<string> invokers,
List<IMethodSymbol> methods, List<string> invokers) INamedTypeSymbol baseInterace)
{ {
var index = methods.IndexOf(method); var index = invokers.Count;
var sb = new StringBuilder(); var sb = new StringBuilder();
bool isParametrized; bool isParametrized;
@@ -327,7 +423,7 @@ namespace mROA.Codegen
{level} IsVoid = {isVoid.ToString().ToLower()}, {level} IsVoid = {isVoid.ToString().ToLower()},
{(isVoid ? String.Empty : (level + "\t" + "ReturnType = typeof(" + ExtractTaskType(method.ReturnType)) + "),")} {(isVoid ? String.Empty : (level + "\t" + "ReturnType = typeof(" + ExtractTaskType(method.ReturnType)) + "),")}
{level} ParameterTypes = new Type[] {{ {parameterTypes} }}, {level} ParameterTypes = new Type[] {{ {parameterTypes} }},
{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), {level} SuitableType = typeof({baseInterace.ToDisplayString()}),
{level} Invoking = (i, parameters, special, post) => {funcInvoking}, {level} Invoking = (i, parameters, special, post) => {funcInvoking},
{level}}}"; {level}}}";
else else
@@ -336,21 +432,62 @@ namespace mROA.Codegen
{level} IsVoid = {isVoid.ToString().ToLower()}, {level} IsVoid = {isVoid.ToString().ToLower()},
{level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}),
{level} ParameterTypes = new Type[] {{ {parameterTypes} }}, {level} ParameterTypes = new Type[] {{ {parameterTypes} }},
{level} SuitableType = typeof({method.ContainingType.ToDisplayString()}), {level} SuitableType = typeof({baseInterace.ToDisplayString()}),
{level} Invoking = (i, parameters, special) => {funcInvoking} {level} Invoking = (i, parameters, special) => {funcInvoking}
{level}}}"; {level}}}";
invokers.Add(backend); invokers.Add(backend);
} }
private static Predicate<IParameterSymbol> ParameterFilter = private void GenerateEventCode(IEventSymbol eventSymbol, List<string> invokers, ITypeSymbol baseInterface)
i => i.Type.Name is "CancellationToken" or "RequestContext";
public void GeneratePropertyMethod(IMethodSymbol method, List<IMethodSymbol> methods,
List<(string, IMethodSymbol)> propsCollection, List<string> invokers)
{ {
var level = "\t\t\t"; 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<string>();
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<string> invokers, INamedTypeSymbol baseInterace)
{
var level = "\t\t\t";
var index = invokers.Count;
string frontend; string frontend;
string backend = string.Empty; string backend = string.Empty;
if (method.MethodKind == MethodKind.PropertyGet) if (method.MethodKind == MethodKind.PropertyGet)
@@ -363,21 +500,14 @@ namespace mROA.Codegen
var parameterTypes = string.Join(", ", var parameterTypes = string.Join(", ",
$"{string.Join(", ", method.Parameters.Select(p => "typeof(" + p.Type.ToDisplayString() + ")"))}"); $"{string.Join(", ", method.Parameters.Select(p => "typeof(" + p.Type.ToDisplayString() + ")"))}");
var parameterInserts = string.Join(", ", var parameterInserts = string.Join(", ",
method.Parameters.Select(p => method.Parameters.Select(
{ p => Caster(p.Type, "parameters[" + method.Parameters.IndexOf(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)}]";
}
));
backend = $@"new mROA.Implementation.MethodInvoker backend = $@"new mROA.Implementation.MethodInvoker
{level}{{ {level}{{
{level} IsVoid = false, {level} IsVoid = false,
{level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}),
{level} ParameterTypes = new Type[] {{ {parameterTypes} }}, {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} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()})[{parameterInserts}],
{level}}}"; {level}}}";
} }
@@ -387,7 +517,7 @@ namespace mROA.Codegen
{level}{{ {level}{{
{level} IsVoid = false, {level} IsVoid = false,
{level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {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} Invoking = (i, _, _) => (i as {method.ContainingType.ToDisplayString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name},
{level}}}"; {level}}}";
} }
@@ -426,7 +556,7 @@ namespace mROA.Codegen
{level} IsVoid = true, {level} IsVoid = true,
{level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}),
{level} ParameterTypes = new Type[] {{ {parameterTypes} }}, {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} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()})[{parameterInserts}] = {valueInsert},
{level}}}"; {level}}}";
} }
@@ -437,7 +567,7 @@ namespace mROA.Codegen
{level} IsVoid = true, {level} IsVoid = true,
{level} ReturnType = typeof({method.ReturnType.ToDisplayString()}), {level} ReturnType = typeof({method.ReturnType.ToDisplayString()}),
{level} ParameterTypes = new Type[] {{ typeof({method.Parameters.First().Type.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} Invoking = (i, parameters, _) => (i as {method.ContainingType.ToDisplayString()}).{(method.AssociatedSymbol as IPropertySymbol)!.Name} = {Caster((method.AssociatedSymbol as IPropertySymbol)!.Type, "parameters[0]")},
{level}}}"; {level}}}";
} }
@@ -464,39 +594,6 @@ namespace mROA.Codegen
return (taskType as INamedTypeSymbol).TypeArguments[0].ToDisplayString(); 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<InterfaceDeclarationSyntax>();
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<AttributeListSyntax> attributes, GeneratorExecutionContext context, private bool ContainsSOIAttribute(SyntaxList<AttributeListSyntax> attributes, GeneratorExecutionContext context,
InterfaceDeclarationSyntax interfaceDeclarationSyntax) InterfaceDeclarationSyntax interfaceDeclarationSyntax)
{ {
+1 -3
View File
@@ -1,6 +1,4 @@
using System.Reflection; namespace mROA.Abstract
namespace mROA.Abstract
{ {
public interface IMethodRepository : IInjectableModule public interface IMethodRepository : IInjectableModule
{ {
@@ -1,8 +1,5 @@
using System; using System;
using System.Linq;
using System.Reflection;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
using mROA.Implementation.CommandExecution; using mROA.Implementation.CommandExecution;
@@ -10,8 +7,8 @@ namespace mROA.Implementation.Backend
{ {
public class BasicExecutionModule : IExecuteModule public class BasicExecutionModule : IExecuteModule
{ {
private IMethodRepository? _methodRepo;
private ICancellationRepository? _cancellationRepo; private ICancellationRepository? _cancellationRepo;
private IMethodRepository? _methodRepo;
private ISerializationToolkit? _serialization; private ISerializationToolkit? _serialization;
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
@@ -245,7 +242,6 @@ namespace mROA.Implementation.Backend
}); });
// result.ContinueWith(t => // result.ContinueWith(t =>
// { // {
// var finalResult = t.GetType().GetProperty("Result")?.GetValue(t); // var finalResult = t.GetType().GetProperty("Result")?.GetValue(t);
+2 -1
View File
@@ -1,5 +1,4 @@
using System; using System;
using mROA.Implementation.Attributes;
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
@@ -21,6 +20,7 @@ namespace mROA.Implementation
public int ObjectId { get; set; } = -1; public int ObjectId { get; set; } = -1;
public object?[]? Parameters { get; set; } public object?[]? Parameters { get; set; }
public override string ToString() public override string ToString()
{ {
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}"; return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
@@ -33,6 +33,7 @@ namespace mROA.Implementation
public int CommandId { get; set; } = -2; public int CommandId { get; set; } = -2;
public int ObjectId { get; set; } = -2; public int ObjectId { get; set; } = -2;
public object?[]? Parameters { get; set; } = null; public object?[]? Parameters { get; set; } = null;
public override string ToString() public override string ToString()
{ {
return $"Cancel request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}"; return $"Cancel request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
@@ -1,5 +1,4 @@
using System; using System;
using System.Text.Json.Serialization;
using mROA.Abstract; using mROA.Abstract;
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
@@ -1,5 +1,4 @@
using System; using System;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
@@ -12,10 +11,10 @@ namespace mROA.Implementation.Frontend
{ {
public class RequestExtractor : IRequestExtractor public class RequestExtractor : IRequestExtractor
{ {
private IRepresentationModule? _representationModule;
private IContextRepository? _contextRepository; private IContextRepository? _contextRepository;
private IMethodRepository? _methodRepository;
private IExecuteModule? _executeModule; private IExecuteModule? _executeModule;
private IMethodRepository? _methodRepository;
private IRepresentationModule? _representationModule;
private ISerializationToolkit? _serializationToolkit; private ISerializationToolkit? _serializationToolkit;
public void Inject<T>(T dependency) public void Inject<T>(T dependency)
+43 -44
View File
@@ -1,6 +1,5 @@
using System; using System;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using System.Threading.Tasks;
using mROA.Abstract; using mROA.Abstract;
using mROA.Implementation.Attributes; using mROA.Implementation.Attributes;
@@ -18,47 +17,22 @@ namespace mROA.Implementation
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull public class SharedObjectShellShell<T> : 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; 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; 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] [JsonIgnore]
[SerializationIgnore] [SerializationIgnore]
public T Value public T Value
@@ -80,18 +54,43 @@ namespace mROA.Implementation
} }
} }
// ReSharper disable once MemberCanBePrivate.Global [SerializationIgnore]
// ReSharper disable once UnusedMember.Global [JsonIgnore]
public SharedObjectShellShell() 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 object UniversalValue
public SharedObjectShellShell(T value)
{ {
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<T> value) => value.Value; public static implicit operator T(SharedObjectShellShell<T> value) => value.Value;
public static implicit operator SharedObjectShellShell<T>(T value) => public static implicit operator SharedObjectShellShell<T>(T value) =>
@@ -1,5 +1,4 @@
using System; using System;
using mROA.Abstract;
namespace mROA.Implementation namespace mROA.Implementation
{ {