Практически доделанный кодген, но не работает демка
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using Example.Shared;
|
||||
|
||||
namespace Example.Backend
|
||||
|
||||
@@ -8,27 +8,31 @@ namespace Example.Backend
|
||||
{
|
||||
public class PagesList : RemoteObjectBase, IPagesList
|
||||
{
|
||||
public PagesList(int id, IRepresentationModule representationModule) : base(id, representationModule)
|
||||
{
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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<IPage>? 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<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.");
|
||||
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<IPage>? OnPrint;
|
||||
public event Action<IPage, RequestContext>? OnPrint;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Console.WriteLine(
|
||||
"Dispose printer with name {0}, Dispose works, Dispose works, Dispose works, Dispose works,", Name);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<ISerializationToolkit>()! },
|
||||
typeof(RepresentationModule)));
|
||||
builder.Modules.Add(new CancellationRepository());
|
||||
|
||||
|
||||
builder.Build();
|
||||
new RemoteTypeBinder();
|
||||
|
||||
@@ -49,6 +48,5 @@ class Program
|
||||
var gateway = builder.GetModule<IGatewayModule>();
|
||||
|
||||
gateway.Run();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<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}");
|
||||
await Task.Yield();
|
||||
return new ClientBasedPage();
|
||||
}
|
||||
|
||||
public event Action<IPage>? OnPrint;
|
||||
public event Action<IPage, RequestContext>? OnPrint;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using mROA.Implementation;
|
||||
using mROA.Implementation.Attributes;
|
||||
|
||||
namespace Example.Shared
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@ using mROA.Implementation.Attributes;
|
||||
namespace Example.Shared
|
||||
{
|
||||
[SharedObjectInterface]
|
||||
public interface IPagesList : IDataList<IPage>
|
||||
public partial interface IPagesList : IDataList<IPage>
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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<IPage> Print(string text, bool someParameter, CancellationToken cancellationToken);
|
||||
event Action<IPage> OnPrint;
|
||||
Task<IPage> Print(string text, bool someParameter, RequestContext context, CancellationToken cancellationToken);
|
||||
event Action<IPage, RequestContext> OnPrint;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,6 @@ using Microsoft.CodeAnalysis;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.CodeAnalysis.Text;
|
||||
|
||||
|
||||
namespace mROA.Codegen
|
||||
{
|
||||
/// <summary>
|
||||
@@ -19,6 +18,45 @@ namespace mROA.Codegen
|
||||
[Generator]
|
||||
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,
|
||||
ImmutableArray<InterfaceDeclarationSyntax> classes)
|
||||
{
|
||||
@@ -31,6 +69,7 @@ namespace mROA.Codegen
|
||||
var frontendContextRepo = new List<string>();
|
||||
List<IMethodSymbol> totalMethods = new List<IMethodSymbol>();
|
||||
|
||||
|
||||
List<string> invokers = new List<string>();
|
||||
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 = $@"// <auto-generated/>
|
||||
|
||||
using mROA;
|
||||
@@ -138,7 +180,7 @@ namespace {namespaceName}
|
||||
if (totalMethods.Count != 0)
|
||||
{
|
||||
var methodsStringed = invokers;
|
||||
|
||||
|
||||
var coCodegenRepoCode = @$"// <auto-generated/>
|
||||
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<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)
|
||||
return inner +
|
||||
@@ -212,10 +308,10 @@ namespace mROA.Codegen
|
||||
return $"({type.ToDisplayString()})" + inner;
|
||||
}
|
||||
|
||||
private void GenerateDeclaredMethod(IMethodSymbol method, List<string> declaredMethods,
|
||||
List<IMethodSymbol> methods, List<string> invokers)
|
||||
private void GenerateDeclaredMethod(IMethodSymbol method, List<string> declaredMethods, List<string> 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<IParameterSymbol> ParameterFilter =
|
||||
i => i.Type.Name is "CancellationToken" or "RequestContext";
|
||||
|
||||
public void GeneratePropertyMethod(IMethodSymbol method, List<IMethodSymbol> methods,
|
||||
List<(string, IMethodSymbol)> propsCollection, List<string> invokers)
|
||||
private void GenerateEventCode(IEventSymbol eventSymbol, List<string> 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<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 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<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,
|
||||
InterfaceDeclarationSyntax interfaceDeclarationSyntax)
|
||||
{
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace mROA.Abstract
|
||||
namespace mROA.Abstract
|
||||
{
|
||||
public interface IMethodRepository : IInjectableModule
|
||||
{
|
||||
|
||||
@@ -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>(T dependency)
|
||||
@@ -244,8 +241,7 @@ namespace mROA.Implementation.Backend
|
||||
multiClientOwnershipRepository?.FreeOwnership();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
// result.ContinueWith(t =>
|
||||
// {
|
||||
// var finalResult = t.GetType().GetProperty("Result")?.GetValue(t);
|
||||
|
||||
@@ -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} }}";
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Text.Json.Serialization;
|
||||
using mROA.Abstract;
|
||||
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||
|
||||
@@ -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>(T dependency)
|
||||
|
||||
@@ -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<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;
|
||||
|
||||
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<T> value) => value.Value;
|
||||
|
||||
public static implicit operator SharedObjectShellShell<T>(T value) =>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user