билдится на старом дотнете
This commit is contained in:
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
using Example.Shared;
|
using System;
|
||||||
|
using Example.Shared;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Backend;
|
namespace Example.Backend
|
||||||
|
{
|
||||||
[SharedObjectSingleton]
|
[SharedObjectSingleton]
|
||||||
public class LoadTestImp : ILoadTest
|
public class LoadTestImp : ILoadTest
|
||||||
{
|
{
|
||||||
@@ -26,3 +27,4 @@ public class LoadTestImp : ILoadTest
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
|
|
||||||
namespace Example.Backend;
|
namespace Example.Backend
|
||||||
|
{
|
||||||
public class Page : IPage
|
public class Page : IPage
|
||||||
{
|
{
|
||||||
public string Text;
|
public string Text;
|
||||||
@@ -11,3 +11,4 @@ public class Page : IPage
|
|||||||
return Encoding.UTF8.GetBytes(Text);
|
return Encoding.UTF8.GetBytes(Text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace Example.Backend;
|
namespace Example.Backend
|
||||||
|
{
|
||||||
|
|
||||||
public class Printer : IPrinter
|
public class Printer : IPrinter
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
@@ -18,3 +19,4 @@ public class Printer : IPrinter
|
|||||||
return new Page {Text = text};
|
return new Page {Text = text};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Backend;
|
namespace Example.Backend
|
||||||
|
{
|
||||||
[SharedObjectSingleton]
|
[SharedObjectSingleton]
|
||||||
public class PrinterFactory : IPrinterFactory
|
public class PrinterFactory : IPrinterFactory
|
||||||
{
|
{
|
||||||
private List<IPrinter> _printers = new();
|
private List<IPrinter> _printers = new List<IPrinter>();
|
||||||
|
|
||||||
public SharedObject<IPrinter> Create(string printerName)
|
public SharedObject<IPrinter> Create(string printerName)
|
||||||
{
|
{
|
||||||
@@ -38,3 +41,4 @@ public class PrinterFactory : IPrinterFactory
|
|||||||
return _printers.Select(i => i.GetName()).ToArray();
|
return _printers.Select(i => i.GetName()).ToArray();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,10 @@ using mROA.Implementation.Backend;
|
|||||||
using mROA.Implementation.Bootstrap;
|
using mROA.Implementation.Bootstrap;
|
||||||
using mROA.Implementation.Frontend;
|
using mROA.Implementation.Frontend;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
var builder = new FullMixBuilder();
|
var builder = new FullMixBuilder();
|
||||||
builder.UseJsonSerialisation();
|
builder.UseJsonSerialisation();
|
||||||
builder.Modules.Add(new BackendIdentityGenerator());
|
builder.Modules.Add(new BackendIdentityGenerator());
|
||||||
@@ -28,7 +31,8 @@ builder.Modules.Add(new MultiClientContextRepository(i =>
|
|||||||
return repo;
|
return repo;
|
||||||
}));
|
}));
|
||||||
builder.SetupMethodsRepository(new CoCodegenMethodRepository());
|
builder.SetupMethodsRepository(new CoCodegenMethodRepository());
|
||||||
builder.Modules.Add(new CreativeRepresentationModuleProducer([builder.GetModule<JsonSerializationToolkit>()!],
|
builder.Modules.Add(new CreativeRepresentationModuleProducer(
|
||||||
|
new IInjectableModule[] { builder.GetModule<JsonSerializationToolkit>()! },
|
||||||
typeof(RepresentationModule)));
|
typeof(RepresentationModule)));
|
||||||
|
|
||||||
builder.Build();
|
builder.Build();
|
||||||
@@ -41,3 +45,5 @@ TransmissionConfig.OwnershipRepository = new MultiClientOwnershipRepository();
|
|||||||
var gateway = builder.GetModule<IGatewayModule>();
|
var gateway = builder.GetModule<IGatewayModule>();
|
||||||
|
|
||||||
gateway.Run();
|
gateway.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
using Example.Shared;
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Example.Shared;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace Example.Frontend;
|
namespace Example.Frontend
|
||||||
|
{
|
||||||
public class ClientBasedPrinter : IPrinter
|
public class ClientBasedPrinter : IPrinter
|
||||||
{
|
{
|
||||||
public string GetName()
|
public string GetName()
|
||||||
@@ -23,6 +26,7 @@ public class ClientBasedPage : IPage
|
|||||||
{
|
{
|
||||||
public byte[] GetData()
|
public byte[] GetData()
|
||||||
{
|
{
|
||||||
return [1, 2, 3];
|
return new byte[] { 1, 2, 3 };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,9 +2,11 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
using System.Diagnostics;
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using Example.Frontend;
|
using Example.Frontend;
|
||||||
using Example.Shared;
|
using Example.Shared;
|
||||||
using mROA.Codegen;
|
using mROA.Codegen;
|
||||||
@@ -9,6 +11,10 @@ using mROA.Implementation.Backend;
|
|||||||
using mROA.Implementation.Bootstrap;
|
using mROA.Implementation.Bootstrap;
|
||||||
using mROA.Implementation.Frontend;
|
using mROA.Implementation.Frontend;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
var builder = new FullMixBuilder();
|
var builder = new FullMixBuilder();
|
||||||
new RemoteTypeBinder();
|
new RemoteTypeBinder();
|
||||||
builder.Modules.Add(new JsonSerializationToolkit());
|
builder.Modules.Add(new JsonSerializationToolkit());
|
||||||
@@ -77,3 +83,5 @@ timer.Stop();
|
|||||||
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,9 +1,11 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
|
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Shared;
|
namespace Example.Shared
|
||||||
|
{
|
||||||
[SharedObjectInterface]
|
[SharedObjectInterface]
|
||||||
public interface ILoadTest
|
public interface ILoadTest
|
||||||
{
|
{
|
||||||
@@ -10,4 +10,5 @@ public interface ILoadTest
|
|||||||
void C();
|
void C();
|
||||||
void A();
|
void A();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Shared;
|
namespace Example.Shared
|
||||||
|
{
|
||||||
[SharedObjectInterface]
|
[SharedObjectInterface]
|
||||||
public interface IPage
|
public interface IPage
|
||||||
{
|
{
|
||||||
byte[] GetData();
|
byte[] GetData();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Shared;
|
namespace Example.Shared
|
||||||
|
{
|
||||||
[SharedObjectInterface]
|
[SharedObjectInterface]
|
||||||
public interface IPrinter
|
public interface IPrinter
|
||||||
{
|
{
|
||||||
@@ -10,3 +12,4 @@ public interface IPrinter
|
|||||||
Task<SharedObject<IPage>> Print(string text, CancellationToken cancellationToken);
|
Task<SharedObject<IPage>> Print(string text, CancellationToken cancellationToken);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace Example.Shared;
|
namespace Example.Shared
|
||||||
|
{
|
||||||
[SharedObjectInterface]
|
[SharedObjectInterface]
|
||||||
public interface IPrinterFactory
|
public interface IPrinterFactory
|
||||||
{
|
{
|
||||||
@@ -13,3 +13,4 @@ public interface IPrinterFactory
|
|||||||
string[] CollectAllNames();
|
string[] CollectAllNames();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
using BenchmarkDotNet.Attributes;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using BenchmarkDotNet.Attributes;
|
||||||
using BenchmarkDotNet.Running;
|
using BenchmarkDotNet.Running;
|
||||||
|
|
||||||
namespace mROA.Benchmark;
|
namespace mROA.Benchmark
|
||||||
|
{
|
||||||
class Program
|
class Program
|
||||||
{
|
{
|
||||||
static void Main(string[] args)
|
static void Main(string[] args)
|
||||||
@@ -48,3 +51,4 @@ public class CollectionsSpeed
|
|||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,8 @@
|
|||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -25,8 +25,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.3.0" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.3.0" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -7,14 +7,14 @@ using Microsoft.CodeAnalysis.CSharp.Syntax;
|
|||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
|
|
||||||
|
|
||||||
namespace mROA.Codegen;
|
namespace mROA.Codegen
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A sample source generator that creates a custom report based on class properties. The target class should be annotated with the 'Generators.ReportAttribute' attribute.
|
/// A sample source generator that creates a custom report based on class properties. The target class should be annotated with the 'Generators.ReportAttribute' attribute.
|
||||||
/// When using the source code as a baseline, an incremental source generator is preferable because it reduces the performance overhead.
|
/// When using the source code as a baseline, an incremental source generator is preferable because it reduces the performance overhead.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Generator]
|
[Generator]
|
||||||
public class mROASourceGenerator : IIncrementalGenerator
|
public class mROASourceGenerator : ISourceGenerator
|
||||||
{
|
{
|
||||||
private const string Namespace = "mROA.Implementation";
|
private const string Namespace = "mROA.Implementation";
|
||||||
private const string AttributeName = "SharedObjectInterafceAttribute";
|
private const string AttributeName = "SharedObjectInterafceAttribute";
|
||||||
@@ -29,47 +29,47 @@ namespace {Namespace}
|
|||||||
}}
|
}}
|
||||||
}}";
|
}}";
|
||||||
|
|
||||||
public void Initialize(IncrementalGeneratorInitializationContext context)
|
// public void Initialize(IncrementalGeneratorInitializationContext context)
|
||||||
{
|
// {
|
||||||
// Filter classes annotated with the [Report] attribute. Only filtered Syntax Nodes can trigger code generation.
|
// // Filter classes annotated with the [Report] attribute. Only filtered Syntax Nodes can trigger code generation.
|
||||||
var provider = context.SyntaxProvider
|
// var provider = context.SyntaxProvider
|
||||||
.CreateSyntaxProvider(
|
// .CreateSyntaxProvider(
|
||||||
(s, _) => s is InterfaceDeclarationSyntax,
|
// (s, _) => s is InterfaceDeclarationSyntax,
|
||||||
(ctx, _) => GetClassDeclarationForSourceGen(ctx))
|
// (ctx, _) => GetClassDeclarationForSourceGen(ctx))
|
||||||
.Where(t => t.reportAttributeFound)
|
// .Where(t => t.reportAttributeFound)
|
||||||
.Select((t, _) => t.Item1);
|
// .Select((t, _) => t.Item1);
|
||||||
|
//
|
||||||
// Generate the source code.
|
// // Generate the source code.
|
||||||
context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()),
|
// context.RegisterSourceOutput(context.CompilationProvider.Combine(provider.Collect()),
|
||||||
((ctx, t) => GenerateCode(ctx, t.Left, t.Right)));
|
// ((ctx, t) => GenerateCode(ctx, t.Left, t.Right)));
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks whether the Node is annotated with the [Report] attribute and maps syntax context to the specific node type (ClassDeclarationSyntax).
|
/// Checks whether the Node is annotated with the [Report] attribute and maps syntax context to the specific node type (ClassDeclarationSyntax).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="context">Syntax context, based on CreateSyntaxProvider predicate</param>
|
/// <param name="context">Syntax context, based on CreateSyntaxProvider predicate</param>
|
||||||
/// <returns>The specific cast and whether the attribute was found.</returns>
|
/// <returns>The specific cast and whether the attribute was found.</returns>
|
||||||
private static (InterfaceDeclarationSyntax, bool reportAttributeFound) GetClassDeclarationForSourceGen(
|
// private static (InterfaceDeclarationSyntax, bool reportAttributeFound) GetClassDeclarationForSourceGen(
|
||||||
GeneratorSyntaxContext context)
|
// GeneratorSyntaxContext context)
|
||||||
{
|
// {
|
||||||
var classDeclarationSyntax = (InterfaceDeclarationSyntax)context.Node;
|
// var classDeclarationSyntax = (InterfaceDeclarationSyntax)context.Node;
|
||||||
|
//
|
||||||
// Go through all attributes of the class.
|
// // Go through all attributes of the class.
|
||||||
foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists)
|
// foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists)
|
||||||
foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes)
|
// foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes)
|
||||||
{
|
// {
|
||||||
if (context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol)
|
// if (context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol)
|
||||||
continue; // if we can't get the symbol, ignore it
|
// continue; // if we can't get the symbol, ignore it
|
||||||
|
//
|
||||||
string attributeName = attributeSymbol.ContainingType.ToDisplayString();
|
// string attributeName = attributeSymbol.ContainingType.ToDisplayString();
|
||||||
|
//
|
||||||
// Check the full name of the [Report] attribute.
|
// // Check the full name of the [Report] attribute.
|
||||||
if (attributeName == "mROA.Implementation.Attributes.SharedObjectInterfaceAttribute")
|
// if (attributeName == "mROA.Implementation.Attributes.SharedObjectInterfaceAttribute")
|
||||||
return (classDeclarationSyntax, true);
|
// return (classDeclarationSyntax, true);
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
return (classDeclarationSyntax, false);
|
// return (classDeclarationSyntax, false);
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Generate code action.
|
/// Generate code action.
|
||||||
@@ -78,7 +78,7 @@ namespace {Namespace}
|
|||||||
/// <param name="context">Source generation context used to add source files.</param>
|
/// <param name="context">Source generation context used to add source files.</param>
|
||||||
/// <param name="compilation">Compilation used to provide access to the Semantic Model.</param>
|
/// <param name="compilation">Compilation used to provide access to the Semantic Model.</param>
|
||||||
/// <param name="classes">Nodes annotated with the [Report] attribute that trigger the generate action.</param>
|
/// <param name="classes">Nodes annotated with the [Report] attribute that trigger the generate action.</param>
|
||||||
private void GenerateCode(SourceProductionContext context, Compilation compilation,
|
private void GenerateCode(GeneratorExecutionContext context, Compilation compilation,
|
||||||
ImmutableArray<InterfaceDeclarationSyntax> classes)
|
ImmutableArray<InterfaceDeclarationSyntax> classes)
|
||||||
{
|
{
|
||||||
var methods = new List<(string, IMethodSymbol)>();
|
var methods = new List<(string, IMethodSymbol)>();
|
||||||
@@ -166,9 +166,9 @@ namespace {Namespace}
|
|||||||
//
|
//
|
||||||
// sb.AppendLine("\t}");
|
// sb.AppendLine("\t}");
|
||||||
|
|
||||||
sb.AppendLine("\t\t" + prefix + caller + postfix+ ";");
|
sb.AppendLine("\t\t\t" + prefix + caller + postfix + ";");
|
||||||
|
|
||||||
sb.AppendLine("\t}");
|
sb.AppendLine("\t\t}");
|
||||||
|
|
||||||
methodsText.Add(sb.ToString());
|
methodsText.Add(sb.ToString());
|
||||||
}
|
}
|
||||||
@@ -181,8 +181,8 @@ using mROA.Implementation;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace {namespaceName};
|
namespace {namespaceName}
|
||||||
|
{{
|
||||||
partial class {className} : RemoteObjectBase, {originalName}
|
partial class {className} : RemoteObjectBase, {originalName}
|
||||||
{{
|
{{
|
||||||
public {className}(int id, IRepresentationModule representationModule) : base(id, representationModule)
|
public {className}(int id, IRepresentationModule representationModule) : base(id, representationModule)
|
||||||
@@ -191,9 +191,11 @@ partial class {className} : RemoteObjectBase, {originalName}
|
|||||||
|
|
||||||
{string.Join("\r\n\t", methodsText)}
|
{string.Join("\r\n\t", methodsText)}
|
||||||
}}
|
}}
|
||||||
|
}}
|
||||||
";
|
";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Add the source code to the compilation.
|
// Add the source code to the compilation.
|
||||||
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8));
|
||||||
|
|
||||||
@@ -204,21 +206,23 @@ partial class {className} : RemoteObjectBase, {originalName}
|
|||||||
if (methods.Count != 0)
|
if (methods.Count != 0)
|
||||||
{
|
{
|
||||||
var methodsStringed = methods.Select(i =>
|
var methodsStringed = methods.Select(i =>
|
||||||
$"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", [{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}])")
|
$"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", new Type[] {{{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}}})")
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
var coCodegenRepoCode = @$"// <auto-generated/>
|
var coCodegenRepoCode = @$"// <auto-generated/>
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
using System;
|
||||||
|
|
||||||
namespace mROA.Codegen;
|
namespace mROA.Codegen
|
||||||
|
{{
|
||||||
public class CoCodegenMethodRepository : IMethodRepository
|
public class CoCodegenMethodRepository : IMethodRepository
|
||||||
{{
|
{{
|
||||||
private readonly List<MethodInfo> _methods = [
|
private readonly List<MethodInfo> _methods = new () {{
|
||||||
{string.Join(", // test comment\r\n\t\t", methodsStringed)}
|
{string.Join(",\r\n\t\t\t", methodsStringed)}
|
||||||
];
|
}};
|
||||||
|
|
||||||
public MethodInfo GetMethod(int id)
|
public MethodInfo GetMethod(int id)
|
||||||
{{
|
{{
|
||||||
if (_methods.Count <= id)
|
if (_methods.Count <= id)
|
||||||
@@ -242,6 +246,7 @@ public class CoCodegenMethodRepository : IMethodRepository
|
|||||||
{{
|
{{
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
|
}}
|
||||||
";
|
";
|
||||||
context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
|
context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8));
|
||||||
}
|
}
|
||||||
@@ -249,17 +254,20 @@ public class CoCodegenMethodRepository : IMethodRepository
|
|||||||
if (frontendContextRepo.Count != 0)
|
if (frontendContextRepo.Count != 0)
|
||||||
{
|
{
|
||||||
var fronendRepoCode = @$"// <auto-generated/>
|
var fronendRepoCode = @$"// <auto-generated/>
|
||||||
using System.Collections.Frozen;
|
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace mROA.Codegen;
|
namespace mROA.Codegen
|
||||||
|
{{
|
||||||
public sealed class RemoteTypeBinder
|
public sealed class RemoteTypeBinder
|
||||||
{{
|
{{
|
||||||
static RemoteTypeBinder(){{
|
static RemoteTypeBinder(){{
|
||||||
RemoteContextRepository.RemoteTypes = new Dictionary<Type, Type> {{
|
RemoteContextRepository.RemoteTypes = new Dictionary<Type, Type> {{
|
||||||
{string.Join(", \r\n\t\t", frontendContextRepo)}}}.ToFrozenDictionary();
|
{string.Join(", \r\n\t\t\t", frontendContextRepo)}}};
|
||||||
|
}}
|
||||||
}}
|
}}
|
||||||
}}
|
}}
|
||||||
";
|
";
|
||||||
@@ -283,4 +291,58 @@ public sealed class RemoteTypeBinder
|
|||||||
type = type.Substring(type.IndexOf('<') + 1);
|
type = type.Substring(type.IndexOf('<') + 1);
|
||||||
return type.Substring(0, type.Length - 1);
|
return type.Substring(0, type.Length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
foreach (AttributeListSyntax attributeListSyntax in attributes)
|
||||||
|
foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes)
|
||||||
|
{
|
||||||
|
if (context.Compilation.GetSemanticModel(interfaceDeclarationSyntax.SyntaxTree)
|
||||||
|
.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol)
|
||||||
|
continue; // if we can't get the symbol, ignore it
|
||||||
|
|
||||||
|
string attributeName = attributeSymbol.ContainingType.ToDisplayString();
|
||||||
|
|
||||||
|
// Check the full name of the [Report] attribute.
|
||||||
|
if (attributeName == "mROA.Implementation.Attributes.SharedObjectInterfaceAttribute")
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,16 +1,19 @@
|
|||||||
using System.Net;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace mROA.Test;
|
namespace mROA.Test
|
||||||
|
{
|
||||||
public class NextGenTest
|
public class NextGenTest
|
||||||
{
|
{
|
||||||
private TcpListener _listener;
|
private TcpListener _listener;
|
||||||
private NextGenerationInteractionModule _interactionModuleA;
|
private NextGenerationInteractionModule _interactionModuleA;
|
||||||
private NextGenerationInteractionModule _interactionModuleB;
|
private NextGenerationInteractionModule _interactionModuleB;
|
||||||
private Guid[] guids = [Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid()];
|
private Guid[] guids = new[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
@@ -70,3 +73,4 @@ public class NextGenTest
|
|||||||
_listener.Dispose();
|
_listener.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
namespace mROA.Abstract;
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface ICommandExecution
|
public interface ICommandExecution
|
||||||
{
|
{
|
||||||
Guid Id { get; init; }
|
Guid Id { get; set; }
|
||||||
int ClientId { get; set; }
|
int ClientId { get; set; }
|
||||||
int CommandId { get; }
|
int CommandId { get; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public delegate void ConnectionHandler(IRepresentationModule representationModule);
|
public delegate void ConnectionHandler(IRepresentationModule representationModule);
|
||||||
public delegate void DisconnectionHandler(IRepresentationModule representationModule);
|
public delegate void DisconnectionHandler(IRepresentationModule representationModule);
|
||||||
|
|
||||||
@@ -10,3 +10,4 @@ public interface IConnectionHub : IInjectableModule
|
|||||||
event ConnectionHandler? OnConnected;
|
event ConnectionHandler? OnConnected;
|
||||||
event DisconnectionHandler? OnDisconnected;
|
event DisconnectionHandler? OnDisconnected;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IContextRepository : IInjectableModule
|
public interface IContextRepository : IInjectableModule
|
||||||
{
|
{
|
||||||
int ResisterObject(object o);
|
int ResisterObject(object o);
|
||||||
@@ -9,3 +11,4 @@ public interface IContextRepository : IInjectableModule
|
|||||||
object GetSingleObject(Type type);
|
object GetSingleObject(Type type);
|
||||||
int GetObjectIndex(object o);
|
int GetObjectIndex(object o);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IContextRepositoryHub
|
public interface IContextRepositoryHub
|
||||||
{
|
{
|
||||||
IContextRepository GetRepository(int clientId);
|
IContextRepository GetRepository(int clientId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IExecuteModule : IInjectableModule
|
public interface IExecuteModule : IInjectableModule
|
||||||
{
|
{
|
||||||
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository);
|
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
|
public interface IFrontendBridge : IInjectableModule
|
||||||
|
{
|
||||||
|
|
||||||
public interface IFrontendBridge : IInjectableModule;
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
namespace mROA.Abstract;
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IGatewayModule : IDisposable, IInjectableModule
|
public interface IGatewayModule : IDisposable, IInjectableModule
|
||||||
{
|
{
|
||||||
void Run();
|
void Run();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IIdentityGenerator : IInjectableModule
|
public interface IIdentityGenerator : IInjectableModule
|
||||||
{
|
{
|
||||||
int GetNextIdentity();
|
int GetNextIdentity();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IInjectableModule
|
public interface IInjectableModule
|
||||||
{
|
{
|
||||||
void Inject<T>(T dependency);
|
void Inject<T>(T dependency);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
|
|
||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface INextGenerationInteractionModule : IInjectableModule
|
public interface INextGenerationInteractionModule : IInjectableModule
|
||||||
{
|
{
|
||||||
int ConnectionId { get; }
|
int ConnectionId { get; }
|
||||||
@@ -12,3 +15,4 @@ public interface INextGenerationInteractionModule : IInjectableModule
|
|||||||
NetworkMessage[] UnhandledMessages { get; }
|
NetworkMessage[] UnhandledMessages { get; }
|
||||||
NetworkMessage? FirstByFilter(Predicate<NetworkMessage> predicate);
|
NetworkMessage? FirstByFilter(Predicate<NetworkMessage> predicate);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
using System.Reflection;
|
using System.Collections.Generic;
|
||||||
|
using System.Reflection;
|
||||||
namespace mROA.Abstract;
|
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IMethodRepository : IInjectableModule
|
public interface IMethodRepository : IInjectableModule
|
||||||
{
|
{
|
||||||
MethodInfo GetMethod(int id);
|
MethodInfo GetMethod(int id);
|
||||||
@@ -9,3 +10,4 @@ public interface IMethodRepository : IInjectableModule
|
|||||||
|
|
||||||
IEnumerable<MethodInfo> GetMethods();
|
IEnumerable<MethodInfo> GetMethods();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IOwnershipRepository
|
public interface IOwnershipRepository
|
||||||
{
|
{
|
||||||
int GetOwnershipId();
|
int GetOwnershipId();
|
||||||
int GetHostOwnershipId();
|
int GetHostOwnershipId();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IRepresentationModuleProducer : IInjectableModule
|
public interface IRepresentationModuleProducer : IInjectableModule
|
||||||
{
|
{
|
||||||
IRepresentationModule Produce(int id);
|
IRepresentationModule Produce(int id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
namespace mROA.Abstract;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface IRequestExtractor : IInjectableModule
|
public interface IRequestExtractor : IInjectableModule
|
||||||
{
|
{
|
||||||
Task StartExtraction();
|
Task StartExtraction();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,10 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Implementation;
|
using mROA.Implementation;
|
||||||
using mROA.Implementation.CommandExecution;
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
namespace mROA.Abstract;
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface ISerialisationModule : IInjectableModule
|
public interface ISerialisationModule : IInjectableModule
|
||||||
{
|
{
|
||||||
void HandleIncomingRequest(int clientId, byte[] message);
|
void HandleIncomingRequest(int clientId, byte[] message);
|
||||||
@@ -29,3 +31,4 @@ public interface IRepresentationModule : IInjectableModule
|
|||||||
void PostCallMessage<T>(Guid id, MessageType messageType, T payload) where T : notnull;
|
void PostCallMessage<T>(Guid id, MessageType messageType, T payload) where T : notnull;
|
||||||
void PostCallMessage(Guid id, MessageType messageType, object payload, Type payloadType);
|
void PostCallMessage(Guid id, MessageType messageType, object payload, Type payloadType);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
namespace mROA.Abstract;
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
public interface ISerializationToolkit : IInjectableModule
|
public interface ISerializationToolkit : IInjectableModule
|
||||||
{
|
{
|
||||||
byte[] Serialize<T>(T objectToSerialize);
|
byte[] Serialize<T>(T objectToSerialize);
|
||||||
@@ -12,3 +14,4 @@ public interface ISerializationToolkit : IInjectableModule
|
|||||||
object Cast(object nonCasted, Type type);
|
object Cast(object nonCasted, Type type);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
namespace mROA.Implementation.Attributes;
|
using System;
|
||||||
|
|
||||||
public class SharedObjectInterfaceAttribute : Attribute;
|
namespace mROA.Implementation.Attributes
|
||||||
|
{
|
||||||
|
public class SharedObjectInterfaceAttribute : Attribute { }
|
||||||
|
}
|
||||||
@@ -1,3 +1,6 @@
|
|||||||
namespace mROA.Implementation.Attributes;
|
using System;
|
||||||
|
|
||||||
public class SharedObjectSingletonAttribute : Attribute;
|
namespace mROA.Implementation.Attributes
|
||||||
|
{
|
||||||
|
public class SharedObjectSingletonAttribute : Attribute { }
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class BackendIdentityGenerator : IIdentityGenerator
|
public class BackendIdentityGenerator : IIdentityGenerator
|
||||||
{
|
{
|
||||||
private int _currentId;
|
private int _currentId;
|
||||||
@@ -15,3 +15,4 @@ public class BackendIdentityGenerator : IIdentityGenerator
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Bootstrap;
|
using mROA.Implementation.Bootstrap;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public static class BasicConfigurationExtensions
|
public static class BasicConfigurationExtensions
|
||||||
{
|
{
|
||||||
public static void UseJsonSerialisation(this FullMixBuilder builder)
|
public static void UseJsonSerialisation(this FullMixBuilder builder)
|
||||||
@@ -35,3 +36,4 @@ public static class BasicConfigurationExtensions
|
|||||||
builder.Modules.Add(methodRepository);
|
builder.Modules.Add(methodRepository);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
using System.Reflection;
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.CommandExecution;
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class BasicExecutionModule : IExecuteModule
|
public class BasicExecutionModule : IExecuteModule
|
||||||
{
|
{
|
||||||
private IMethodRepository? _methodRepo;
|
private IMethodRepository? _methodRepo;
|
||||||
@@ -45,7 +48,8 @@ public class BasicExecutionModule : IExecuteModule
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var finalResult = currentCommand.Invoke(context, parameter is null ? [] : [parameter]);
|
var finalResult = currentCommand.Invoke(context, parameter is null ? new object[0] : new[]
|
||||||
|
{ parameter });
|
||||||
return new TypedFinalCommandExecution
|
return new TypedFinalCommandExecution
|
||||||
{
|
{
|
||||||
CommandId = command.CommandId, Result = finalResult,
|
CommandId = command.CommandId, Result = finalResult,
|
||||||
@@ -70,7 +74,8 @@ public class BasicExecutionModule : IExecuteModule
|
|||||||
var token = tokenSource.Token;
|
var token = tokenSource.Token;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result = (Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!;
|
var result = (Task)currentCommand.Invoke(context, parameter is null ? new object[] { token } : new[]
|
||||||
|
{ parameter, token })!;
|
||||||
|
|
||||||
|
|
||||||
result.Wait(token);
|
result.Wait(token);
|
||||||
@@ -96,7 +101,8 @@ public class BasicExecutionModule : IExecuteModule
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var result =
|
var result =
|
||||||
(Task)currentCommand.Invoke(context, parameter is null ? [token] : [parameter, token])!;
|
(Task)currentCommand.Invoke(context, parameter is null ? new object[] { token } : new[]
|
||||||
|
{ parameter, token })!;
|
||||||
|
|
||||||
result.Wait(token);
|
result.Wait(token);
|
||||||
|
|
||||||
@@ -119,3 +125,4 @@ public class BasicExecutionModule : IExecuteModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
namespace mROA.Implementation.Backend;
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class ConnectionHub : IConnectionHub
|
public class ConnectionHub : IConnectionHub
|
||||||
{
|
{
|
||||||
private readonly Dictionary<int, INextGenerationInteractionModule> _connections = new();
|
private readonly Dictionary<int, INextGenerationInteractionModule> _connections = new();
|
||||||
@@ -33,3 +35,4 @@ public class ConnectionHub : IConnectionHub
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
using System.Collections.Frozen;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class ContextRepository : IContextRepository
|
public class ContextRepository : IContextRepository
|
||||||
{
|
{
|
||||||
private FrozenDictionary<int, object?>? _singletons;
|
private Dictionary<int, object?>? _singletons;
|
||||||
private object?[] _storage = new object[StartupSize];
|
private object?[] _storage = new object[StartupSize];
|
||||||
|
|
||||||
private Task<int> _lastIndexFinder = Task.FromResult(0);
|
private Task<int> _lastIndexFinder = Task.FromResult(0);
|
||||||
@@ -22,7 +25,7 @@ public class ContextRepository : IContextRepository
|
|||||||
type is { IsClass: true, IsAbstract: false, IsGenericType: false } &&
|
type is { IsClass: true, IsAbstract: false, IsGenericType: false } &&
|
||||||
type.GetCustomAttributes(typeof(SharedObjectSingletonAttribute), true).Length > 0);
|
type.GetCustomAttributes(typeof(SharedObjectSingletonAttribute), true).Length > 0);
|
||||||
_singletons =
|
_singletons =
|
||||||
types.ToFrozenDictionary(
|
types.ToDictionary(
|
||||||
t => t.GetInterfaces().FirstOrDefault(i =>
|
t => t.GetInterfaces().FirstOrDefault(i =>
|
||||||
i.GetCustomAttributes(typeof(SharedObjectInterfaceAttribute), true).Length > 0)!.GetHashCode(),
|
i.GetCustomAttributes(typeof(SharedObjectInterfaceAttribute), true).Length > 0)!.GetHashCode(),
|
||||||
Activator.CreateInstance);
|
Activator.CreateInstance);
|
||||||
@@ -86,3 +89,4 @@ public class ContextRepository : IContextRepository
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
|
using System;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class HubRequestExtractor(Type extractoType) : IInjectableModule
|
public class HubRequestExtractor : IInjectableModule
|
||||||
{
|
{
|
||||||
private IConnectionHub? _hub;
|
private IConnectionHub? _hub;
|
||||||
|
|
||||||
@@ -10,6 +11,12 @@ public class HubRequestExtractor(Type extractoType) : IInjectableModule
|
|||||||
private IMethodRepository? _methodRepository;
|
private IMethodRepository? _methodRepository;
|
||||||
private ISerializationToolkit? _serializationToolkit;
|
private ISerializationToolkit? _serializationToolkit;
|
||||||
private IExecuteModule? _executeModule;
|
private IExecuteModule? _executeModule;
|
||||||
|
private readonly Type _extractorType;
|
||||||
|
|
||||||
|
public HubRequestExtractor(Type extractorType)
|
||||||
|
{
|
||||||
|
_extractorType = extractorType;
|
||||||
|
}
|
||||||
|
|
||||||
public void Inject<T>(T dependency)
|
public void Inject<T>(T dependency)
|
||||||
{
|
{
|
||||||
@@ -36,7 +43,7 @@ public class HubRequestExtractor(Type extractoType) : IInjectableModule
|
|||||||
|
|
||||||
private void HubOnOnConnected(IRepresentationModule interaction)
|
private void HubOnOnConnected(IRepresentationModule interaction)
|
||||||
{
|
{
|
||||||
var extractor = (IRequestExtractor)Activator.CreateInstance(extractoType)!;
|
var extractor = (IRequestExtractor)Activator.CreateInstance(_extractorType)!;
|
||||||
extractor.Inject(interaction);
|
extractor.Inject(interaction);
|
||||||
if (_contextRepository is IContextRepositoryHub contextHub)
|
if (_contextRepository is IContextRepositoryHub contextHub)
|
||||||
extractor.Inject(contextHub.GetRepository(interaction.Id));
|
extractor.Inject(contextHub.GetRepository(interaction.Id));
|
||||||
@@ -48,3 +55,4 @@ public class HubRequestExtractor(Type extractoType) : IInjectableModule
|
|||||||
_ = extractor.StartExtraction();
|
_ = extractor.StartExtraction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class MultiClientContextRepository(Func<int, IContextRepository> produceRepository) : IContextRepository, IContextRepositoryHub
|
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub
|
||||||
{
|
{
|
||||||
private Dictionary<int, IContextRepository> _repositories = new();
|
private Dictionary<int, IContextRepository> _repositories = new();
|
||||||
|
private readonly Func<int, IContextRepository> _produceRepository;
|
||||||
|
|
||||||
|
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository)
|
||||||
|
{
|
||||||
|
_produceRepository = produceRepository;
|
||||||
|
}
|
||||||
|
|
||||||
private IContextRepository GetRepositoryByClientId(int clientId)
|
private IContextRepository GetRepositoryByClientId(int clientId)
|
||||||
{
|
{
|
||||||
if (_repositories.TryGetValue(clientId, out var repository))
|
if (_repositories.TryGetValue(clientId, out var repository))
|
||||||
return repository;
|
return repository;
|
||||||
|
|
||||||
var created = produceRepository(clientId);
|
var created = _produceRepository(clientId);
|
||||||
_repositories.Add(clientId, created);
|
_repositories.Add(clientId, created);
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
@@ -54,3 +62,4 @@ public class MultiClientContextRepository(Func<int, IContextRepository> produceR
|
|||||||
return GetRepositoryByClientId(clientId);
|
return GetRepositoryByClientId(clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
namespace mROA.Implementation.Backend;
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class MultiClientOwnershipRepository : IOwnershipRepository
|
public class MultiClientOwnershipRepository : IOwnershipRepository
|
||||||
{
|
{
|
||||||
private Dictionary<int, int> _ownerships = new();
|
private Dictionary<int, int> _ownerships = new();
|
||||||
@@ -26,3 +28,4 @@ public class MultiClientOwnershipRepository : IOwnershipRepository
|
|||||||
_ownerships.Remove(Environment.CurrentManagedThreadId);
|
_ownerships.Remove(Environment.CurrentManagedThreadId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
using System.Net;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Backend;
|
namespace mROA.Implementation.Backend
|
||||||
|
{
|
||||||
public class NetworkGatewayModule : IGatewayModule
|
public class NetworkGatewayModule : IGatewayModule
|
||||||
{
|
{
|
||||||
private readonly Type? _interactionModuleType;
|
private readonly Type? _interactionModuleType;
|
||||||
@@ -40,7 +42,6 @@ public class NetworkGatewayModule : IGatewayModule
|
|||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_tcpListener.Stop();
|
_tcpListener.Stop();
|
||||||
_tcpListener.Dispose();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleIncomingConnections()
|
private void HandleIncomingConnections()
|
||||||
@@ -87,3 +88,4 @@ public class NetworkGatewayModule : IGatewayModule
|
|||||||
_serialization = serializationToolkit;
|
_serialization = serializationToolkit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Bootstrap;
|
namespace mROA.Implementation.Bootstrap
|
||||||
|
{
|
||||||
public class FullMixBuilder
|
public class FullMixBuilder
|
||||||
{
|
{
|
||||||
public List<IInjectableModule> Modules { get; } = [];
|
public List<IInjectableModule> Modules { get; } = new() { };
|
||||||
|
|
||||||
public void Build()
|
public void Build()
|
||||||
{
|
{
|
||||||
@@ -18,3 +20,4 @@ public class FullMixBuilder
|
|||||||
return Modules.OfType<T>().FirstOrDefault();
|
return Modules.OfType<T>().FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||||
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public interface ICallRequest
|
public interface ICallRequest
|
||||||
{
|
{
|
||||||
Guid Id { get; }
|
Guid Id { get; }
|
||||||
@@ -15,10 +16,11 @@ public interface ICallRequest
|
|||||||
public class DefaultCallRequest : ICallRequest
|
public class DefaultCallRequest : ICallRequest
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; } = Guid.NewGuid();
|
public Guid Id { get; set; } = Guid.NewGuid();
|
||||||
public int CommandId { get; init; }
|
public int CommandId { get; set; }
|
||||||
public int ObjectId { get; init; } = -1;
|
public int ObjectId { get; set; } = -1;
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Type? ParameterType { get; init; }
|
public Type? ParameterType { get; set; }
|
||||||
public object? Parameter { get; set; }
|
public object? Parameter { get; set; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +1,19 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Frontend;
|
using mROA.Implementation.Frontend;
|
||||||
|
|
||||||
namespace mROA.Implementation.CommandExecution;
|
namespace mROA.Implementation.CommandExecution
|
||||||
|
{
|
||||||
public class ExceptionCommandExecution : ICommandExecution
|
public class ExceptionCommandExecution : ICommandExecution
|
||||||
{
|
{
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; set; }
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
public int CommandId { get; init; }
|
public int CommandId { get; set; }
|
||||||
public required string Exception { get; set; }
|
public string Exception { get; set; }
|
||||||
|
|
||||||
public RemoteException GetException()
|
public RemoteException GetException()
|
||||||
{
|
{
|
||||||
return new RemoteException(Exception) { CallRequestId = Id };
|
return new RemoteException(Exception) { CallRequestId = Id };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +1,22 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||||
|
|
||||||
namespace mROA.Implementation.CommandExecution;
|
namespace mROA.Implementation.CommandExecution
|
||||||
|
{
|
||||||
public class FinalCommandExecution : ICommandExecution
|
public class FinalCommandExecution : ICommandExecution
|
||||||
{
|
{
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int CommandId { get; init; }
|
public int CommandId { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FinalCommandExecution<T> : FinalCommandExecution
|
public class FinalCommandExecution<T> : FinalCommandExecution
|
||||||
{
|
{
|
||||||
public T? Result { get; init; }
|
public T? Result { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,12 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
namespace mROA.Implementation.CommandExecution;
|
|
||||||
|
|
||||||
|
namespace mROA.Implementation.CommandExecution
|
||||||
|
{
|
||||||
public class TypedFinalCommandExecution : FinalCommandExecution<object>
|
public class TypedFinalCommandExecution : FinalCommandExecution<object>
|
||||||
{
|
{
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
// ReSharper disable once UnusedAutoPropertyAccessor.Global
|
||||||
public Type? Type { get; set; }
|
public Type? Type { get; set; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using mROA.Abstract;
|
||||||
namespace mROA.Implementation;
|
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class CreativeRepresentationModuleProducer : IRepresentationModuleProducer
|
public class CreativeRepresentationModuleProducer : IRepresentationModuleProducer
|
||||||
{
|
{
|
||||||
private Type _reprModuleType;
|
private Type _reprModuleType;
|
||||||
@@ -38,3 +39,4 @@ public class CreativeRepresentationModuleProducer : IRepresentationModuleProduce
|
|||||||
return produced;
|
return produced;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
namespace mROA.Implementation.Frontend;
|
using System;
|
||||||
|
|
||||||
|
namespace mROA.Implementation.Frontend
|
||||||
|
{
|
||||||
// public class JsonFrontendSerialisationModule
|
// public class JsonFrontendSerialisationModule
|
||||||
// : ISerialisationModule.IFrontendSerialisationModule
|
// : ISerialisationModule.IFrontendSerialisationModule
|
||||||
// {
|
// {
|
||||||
@@ -77,8 +79,16 @@ namespace mROA.Implementation.Frontend;
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
public class RemoteException(string error) : Exception
|
public class RemoteException : Exception
|
||||||
{
|
{
|
||||||
public Guid CallRequestId;
|
public Guid CallRequestId;
|
||||||
public override string Message => $"Error in request {CallRequestId} : {error}";
|
private readonly string _error;
|
||||||
|
|
||||||
|
public RemoteException(string error)
|
||||||
|
{
|
||||||
|
_error = error;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string Message => $"Error in request {CallRequestId} : {_error}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
|
using System;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Frontend;
|
namespace mROA.Implementation.Frontend
|
||||||
|
{
|
||||||
public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge
|
public class NetworkFrontendBridge : IFrontendBridge
|
||||||
{
|
{
|
||||||
private readonly TcpClient _tcpClient = new();
|
private readonly TcpClient _tcpClient = new();
|
||||||
private NextGenerationInteractionModule? _interactionModule;
|
private NextGenerationInteractionModule? _interactionModule;
|
||||||
private ISerializationToolkit? _serialization;
|
private ISerializationToolkit? _serialization;
|
||||||
|
private readonly IPEndPoint _ipEndPoint;
|
||||||
|
|
||||||
|
public NetworkFrontendBridge(IPEndPoint ipEndPoint)
|
||||||
|
{
|
||||||
|
_ipEndPoint = ipEndPoint;
|
||||||
|
}
|
||||||
|
|
||||||
public void Inject<T>(T dependency)
|
public void Inject<T>(T dependency)
|
||||||
{
|
{
|
||||||
@@ -30,7 +37,7 @@ public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge
|
|||||||
if (_serialization == null)
|
if (_serialization == null)
|
||||||
throw new NullReferenceException("Serialization toolkit is not initialized");
|
throw new NullReferenceException("Serialization toolkit is not initialized");
|
||||||
|
|
||||||
_tcpClient.Connect(ipEndPoint);
|
_tcpClient.Connect(_ipEndPoint);
|
||||||
_interactionModule.BaseStream = _tcpClient.GetStream();
|
_interactionModule.BaseStream = _tcpClient.GetStream();
|
||||||
var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult();
|
var welcomeMessage = _interactionModule.GetNextMessageReceiving().GetAwaiter().GetResult();
|
||||||
if (welcomeMessage.SchemaId != MessageType.IdAssigning)
|
if (welcomeMessage.SchemaId != MessageType.IdAssigning)
|
||||||
@@ -41,3 +48,4 @@ public class NetworkFrontendBridge(IPEndPoint ipEndPoint) : IFrontendBridge
|
|||||||
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_serialization.Deserialize<IdAssingnment>(welcomeMessage.Data)!.Id);
|
TransmissionConfig.OwnershipRepository = new StaticOwnershipRepository(_serialization.Deserialize<IdAssingnment>(welcomeMessage.Data)!.Id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Backend;
|
using mROA.Implementation.Backend;
|
||||||
using mROA.Implementation.CommandExecution;
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
// ReSharper disable MethodHasAsyncOverload
|
// ReSharper disable MethodHasAsyncOverload
|
||||||
|
|
||||||
namespace mROA.Implementation.Frontend;
|
namespace mROA.Implementation.Frontend
|
||||||
|
{
|
||||||
public class RequestExtractor : IRequestExtractor
|
public class RequestExtractor : IRequestExtractor
|
||||||
{
|
{
|
||||||
private IRepresentationModule? _representationModule;
|
private IRepresentationModule? _representationModule;
|
||||||
@@ -86,3 +89,4 @@ public class RequestExtractor : IRequestExtractor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,24 @@
|
|||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation.Frontend;
|
namespace mROA.Implementation.Frontend
|
||||||
|
|
||||||
public class StaticOwnershipRepository(int id) : IOwnershipRepository
|
|
||||||
{
|
{
|
||||||
|
public class StaticOwnershipRepository : IOwnershipRepository
|
||||||
|
{
|
||||||
|
private readonly int _id;
|
||||||
|
|
||||||
|
public StaticOwnershipRepository(int id)
|
||||||
|
{
|
||||||
|
_id = id;
|
||||||
|
}
|
||||||
|
|
||||||
public int GetOwnershipId()
|
public int GetOwnershipId()
|
||||||
{
|
{
|
||||||
return id;
|
return _id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int GetHostOwnershipId()
|
public int GetHostOwnershipId()
|
||||||
{
|
{
|
||||||
return id;
|
return _id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class IdAssingnment
|
public class IdAssingnment
|
||||||
{
|
{
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
using System.Text.Json;
|
using System;
|
||||||
|
using System.Text.Json;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class JsonSerializationToolkit : ISerializationToolkit
|
public class JsonSerializationToolkit : ISerializationToolkit
|
||||||
{
|
{
|
||||||
public byte[] Serialize<T>(T objectToSerialize)
|
public byte[] Serialize<T>(T objectToSerialize)
|
||||||
@@ -57,3 +58,4 @@ public class JsonSerializationToolkit : ISerializationToolkit
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,15 @@
|
|||||||
using System.Reflection;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.Attributes;
|
using mROA.Implementation.Attributes;
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class MethodRepository : IMethodRepository
|
public class MethodRepository : IMethodRepository
|
||||||
{
|
{
|
||||||
private readonly List<MethodInfo> _methods = [];
|
private readonly List<MethodInfo> _methods = new() { };
|
||||||
|
|
||||||
public MethodInfo GetMethod(int id)
|
public MethodInfo GetMethod(int id)
|
||||||
{
|
{
|
||||||
@@ -41,3 +44,4 @@ public class MethodRepository : IMethodRepository
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class NetworkMessage
|
public class NetworkMessage
|
||||||
{
|
{
|
||||||
public Guid Id { get; init; }
|
public Guid Id { get; set; }
|
||||||
[JsonConverter(typeof(JsonStringEnumConverter))]
|
[JsonConverter(typeof(JsonStringEnumConverter))]
|
||||||
public MessageType SchemaId { get; init; }
|
public MessageType SchemaId { get; set; }
|
||||||
|
|
||||||
public required byte[] Data { get; init; }
|
public byte[] Data { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MessageType
|
public enum MessageType
|
||||||
{
|
{
|
||||||
Unknown, FinishedCommandExecution, ExceptionCommandExecution, AsyncCancelCommandExecution, CallRequest, IdAssigning
|
Unknown, FinishedCommandExecution, ExceptionCommandExecution, AsyncCancelCommandExecution, CallRequest, IdAssigning
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,12 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
namespace mROA.Implementation;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
||||||
{
|
{
|
||||||
private ISerializationToolkit? _serialization;
|
private ISerializationToolkit? _serialization;
|
||||||
@@ -26,7 +31,6 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Task<NetworkMessage> GetNextMessageReceiving()
|
public Task<NetworkMessage> GetNextMessageReceiving()
|
||||||
{
|
{
|
||||||
if (_currentReceiving != null) return _currentReceiving;
|
if (_currentReceiving != null) return _currentReceiving;
|
||||||
@@ -62,7 +66,7 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
|||||||
return _messageBuffer.FirstOrDefault(m => predicate(m));
|
return _messageBuffer.FirstOrDefault(m => predicate(m));
|
||||||
}
|
}
|
||||||
|
|
||||||
private NetworkMessage GetNextMessage()
|
private async Task<NetworkMessage> GetNextMessage()
|
||||||
{
|
{
|
||||||
if (BaseStream == null)
|
if (BaseStream == null)
|
||||||
throw new NullReferenceException("BaseStream is null");
|
throw new NullReferenceException("BaseStream is null");
|
||||||
@@ -72,16 +76,20 @@ public class NextGenerationInteractionModule : INextGenerationInteractionModule
|
|||||||
|
|
||||||
|
|
||||||
// Console.WriteLine("Receiving message");
|
// Console.WriteLine("Receiving message");
|
||||||
var len = BitConverter.ToUInt16([(byte)BaseStream.ReadByte(), (byte)BaseStream.ReadByte()]);
|
var firstBit = (byte)BaseStream.ReadByte();
|
||||||
var localSpan = _buffer.Span.Slice(0, len);
|
var secondBit = (byte)BaseStream.ReadByte();
|
||||||
BaseStream.ReadExactly(localSpan);
|
|
||||||
|
var len = BitConverter.ToUInt16(new[] { firstBit, secondBit});
|
||||||
|
var localSpan = _buffer.Slice(0, len);
|
||||||
|
await BaseStream.ReadExactlyAsync(localSpan);
|
||||||
|
|
||||||
// Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len]));
|
// Console.WriteLine("Receiving {0}", Encoding.Default.GetString(_buffer[..len]));
|
||||||
|
|
||||||
var message = _serialization.Deserialize<NetworkMessage>(localSpan);
|
var message = _serialization.Deserialize<NetworkMessage>(localSpan.Span);
|
||||||
_messageBuffer.Add(message!);
|
_messageBuffer.Add(message!);
|
||||||
_currentReceiving = Task.Run(GetNextMessage);
|
_currentReceiving = GetNextMessage();
|
||||||
|
|
||||||
return message!;
|
return message!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
using System.Collections.Frozen;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class RemoteContextRepository : IContextRepository
|
public class RemoteContextRepository : IContextRepository
|
||||||
{
|
{
|
||||||
private IRepresentationModuleProducer? _representationProducer;
|
private IRepresentationModuleProducer? _representationProducer;
|
||||||
public static FrozenDictionary<Type, Type> RemoteTypes = FrozenDictionary<Type, Type>.Empty;
|
public static Dictionary<Type, Type> RemoteTypes = new();
|
||||||
public int ResisterObject(object o)
|
public int ResisterObject(object o)
|
||||||
{
|
{
|
||||||
throw new NotSupportedException();
|
throw new NotSupportedException();
|
||||||
@@ -55,3 +56,4 @@ public class RemoteContextRepository : IContextRepository
|
|||||||
_representationProducer = serialisationModule;
|
_representationProducer = serialisationModule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,26 +1,36 @@
|
|||||||
using mROA.Abstract;
|
using System.Threading.Tasks;
|
||||||
|
using mROA.Abstract;
|
||||||
using mROA.Implementation.CommandExecution;
|
using mROA.Implementation.CommandExecution;
|
||||||
|
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
|
||||||
public abstract class RemoteObjectBase(int id, IRepresentationModule representationModule)
|
|
||||||
{
|
{
|
||||||
public int Id => id;
|
public abstract class RemoteObjectBase
|
||||||
public int OwnerId => representationModule.Id;
|
{
|
||||||
|
private readonly int _id;
|
||||||
|
private readonly IRepresentationModule _representationModule;
|
||||||
|
|
||||||
|
protected RemoteObjectBase(int id, IRepresentationModule representationModule)
|
||||||
|
{
|
||||||
|
_id = id;
|
||||||
|
_representationModule = representationModule;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int Id => _id;
|
||||||
|
public int OwnerId => _representationModule.Id;
|
||||||
|
|
||||||
protected async Task<T> GetResultAsync<T>(int methodId, object? parameter = default)
|
protected async Task<T> GetResultAsync<T>(int methodId, object? parameter = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||||
|
|
||||||
var successResponse =
|
var successResponse =
|
||||||
representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
_representationModule.GetMessageAsync<FinalCommandExecution<T>>(
|
||||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||||
var errorResponse =
|
var errorResponse =
|
||||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||||
Task.WaitAny(successResponse, errorResponse);
|
Task.WaitAny(successResponse, errorResponse);
|
||||||
|
|
||||||
@@ -33,14 +43,14 @@ public abstract class RemoteObjectBase(int id, IRepresentationModule representat
|
|||||||
protected async Task CallAsync(int methodId, object? parameter = default)
|
protected async Task CallAsync(int methodId, object? parameter = default)
|
||||||
{
|
{
|
||||||
var request = new DefaultCallRequest
|
var request = new DefaultCallRequest
|
||||||
{ CommandId = methodId, ObjectId = id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
{ CommandId = methodId, ObjectId = _id, Parameter = parameter, ParameterType = parameter?.GetType() };
|
||||||
await representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
await _representationModule.PostCallMessageAsync(request.Id, MessageType.CallRequest, request);
|
||||||
|
|
||||||
var successResponse =
|
var successResponse =
|
||||||
representationModule.GetMessageAsync<FinalCommandExecution>(
|
_representationModule.GetMessageAsync<FinalCommandExecution>(
|
||||||
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
messageType: MessageType.FinishedCommandExecution, requestId: request.Id);
|
||||||
var errorResponse =
|
var errorResponse =
|
||||||
representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
_representationModule.GetMessageAsync<ExceptionCommandExecution>(
|
||||||
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
messageType: MessageType.ExceptionCommandExecution, requestId: request.Id);
|
||||||
|
|
||||||
Task.WaitAny(successResponse, errorResponse);
|
Task.WaitAny(successResponse, errorResponse);
|
||||||
@@ -51,3 +61,4 @@ public abstract class RemoteObjectBase(int id, IRepresentationModule representat
|
|||||||
throw errorResponse.Result.GetException();
|
throw errorResponse.Result.GetException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using System.Threading.Tasks;
|
||||||
namespace mROA.Implementation;
|
using mROA.Abstract;
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class RepresentationModule : IRepresentationModule
|
public class RepresentationModule : IRepresentationModule
|
||||||
{
|
{
|
||||||
private ISerializationToolkit? _serialization;
|
private ISerializationToolkit? _serialization;
|
||||||
@@ -91,3 +93,4 @@ public class RepresentationModule : IRepresentationModule
|
|||||||
PostCallMessageAsync(id, messageType, payload, payloadType).GetAwaiter().GetResult();
|
PostCallMessageAsync(id, messageType, payload, payloadType).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,10 +1,11 @@
|
|||||||
using System.Text.Json.Serialization;
|
using System;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
using mROA.Abstract;
|
using mROA.Abstract;
|
||||||
// ReSharper disable UnusedMember.Global
|
// ReSharper disable UnusedMember.Global
|
||||||
#pragma warning disable CS8618, CS9264
|
#pragma warning disable CS8618, CS9264
|
||||||
|
|
||||||
namespace mROA.Implementation;
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public static class TransmissionConfig
|
public static class TransmissionConfig
|
||||||
{
|
{
|
||||||
private static IContextRepository? _realContextRepository;
|
private static IContextRepository? _realContextRepository;
|
||||||
@@ -50,7 +51,7 @@ public class SharedObject<T> where T : notnull
|
|||||||
_ownerId = _ownerId == -1 ? TransmissionConfig.OwnershipRepository.GetOwnershipId() : _ownerId;
|
_ownerId = _ownerId == -1 ? TransmissionConfig.OwnershipRepository.GetOwnershipId() : _ownerId;
|
||||||
return _ownerId;
|
return _ownerId;
|
||||||
}
|
}
|
||||||
init => _ownerId = value;
|
set => _ownerId = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
@@ -65,14 +66,14 @@ public class SharedObject<T> where T : notnull
|
|||||||
_contextId = TransmissionConfig.RealContextRepository.GetObjectIndex(Value);
|
_contextId = TransmissionConfig.RealContextRepository.GetObjectIndex(Value);
|
||||||
return _contextId;
|
return _contextId;
|
||||||
}
|
}
|
||||||
init
|
set
|
||||||
{
|
{
|
||||||
_contextId = value;
|
_contextId = value;
|
||||||
Value = GetDefaultContextRepository().GetObject<T>(_contextId)!;
|
Value = GetDefaultContextRepository().GetObject<T>(_contextId)!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[JsonIgnore] public T Value { get; private init; }
|
[JsonIgnore] public T Value { get; private set; }
|
||||||
|
|
||||||
// ReSharper disable once MemberCanBePrivate.Global
|
// ReSharper disable once MemberCanBePrivate.Global
|
||||||
// ReSharper disable once UnusedMember.Global
|
// ReSharper disable once UnusedMember.Global
|
||||||
@@ -99,3 +100,4 @@ public class SharedObject<T> where T : notnull
|
|||||||
public static implicit operator SharedObject<T>(T value) =>
|
public static implicit operator SharedObject<T>(T value) =>
|
||||||
new(value);
|
new(value);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
using mROA.Abstract;
|
using System;
|
||||||
|
using mROA.Abstract;
|
||||||
namespace mROA.Implementation;
|
|
||||||
|
|
||||||
|
namespace mROA.Implementation
|
||||||
|
{
|
||||||
public class StaticRepresentationModuleProducer : IRepresentationModuleProducer
|
public class StaticRepresentationModuleProducer : IRepresentationModuleProducer
|
||||||
{
|
{
|
||||||
private IRepresentationModule? _representationModule;
|
private IRepresentationModule? _representationModule;
|
||||||
@@ -19,3 +20,4 @@ public class StaticRepresentationModuleProducer : IRepresentationModuleProducer
|
|||||||
_representationModule = serialisationModule;
|
_representationModule = serialisationModule;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
|
using global::System;
|
||||||
|
using global::System.IO;
|
||||||
|
using global::System.Threading;
|
||||||
|
using global::System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace mROA
|
||||||
|
{
|
||||||
|
public static class LegacyExtentions
|
||||||
|
{
|
||||||
|
public static async ValueTask<int> ReadExactlyAsync(this Stream stream, byte[] buffer, int offset, int count)
|
||||||
|
{
|
||||||
|
return await stream.ReadAtLeastAsyncCore(buffer.AsMemory(offset, count), count, true, default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ValueTask<int> ReadExactlyAsync(this Stream stream, Memory<byte> buffer,
|
||||||
|
CancellationToken cancellationToken = default(CancellationToken))
|
||||||
|
{
|
||||||
|
return stream.ReadAtLeastAsyncCore(buffer, buffer.Length, true, cancellationToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async ValueTask<int> ReadAtLeastAsyncCore(this Stream stream,
|
||||||
|
Memory<byte> buffer,
|
||||||
|
int minimumBytes,
|
||||||
|
bool throwOnEndOfStream,
|
||||||
|
CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
int totalRead;
|
||||||
|
int num;
|
||||||
|
for (totalRead = 0; totalRead < minimumBytes; totalRead += num)
|
||||||
|
{
|
||||||
|
num = await stream.ReadAsync(buffer.Slice(totalRead), cancellationToken).ConfigureAwait(false);
|
||||||
|
if (num == 0)
|
||||||
|
{
|
||||||
|
if (throwOnEndOfStream)
|
||||||
|
throw new EndOfStreamException();
|
||||||
|
return totalRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return totalRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-2
@@ -1,8 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net9.0</TargetFramework>
|
<TargetFramework>netstandard2.1</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<Title>mROA</Title>
|
<Title>mROA</Title>
|
||||||
<Version>2.0.0</Version>
|
<Version>2.0.0</Version>
|
||||||
@@ -12,6 +11,11 @@
|
|||||||
<PackageProjectUrl>https://github.com/YaslePoy/mROA</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/YaslePoy/mROA</PackageProjectUrl>
|
||||||
<RepositoryType>git</RepositoryType>
|
<RepositoryType>git</RepositoryType>
|
||||||
<PackageTags>RPC</PackageTags>
|
<PackageTags>RPC</PackageTags>
|
||||||
|
<LangVersion>9</LangVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="System.Text.Json" Version="9.0.2" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
Reference in New Issue
Block a user