diff --git a/mROA.Example/ITestController.cs b/mROA.Example/ITestController.cs new file mode 100644 index 0000000..adf052e --- /dev/null +++ b/mROA.Example/ITestController.cs @@ -0,0 +1,15 @@ +using mROA.Implementation; + +namespace mROA.Example; + +[SharedObjectInterafce] +public interface ITestController +{ + void A(); + Task AAsync(CancellationToken cancellationToken); + int B(); + Task BAsync(CancellationToken cancellationToken); + TransmittedSharedObject SharedObjectTransmitionTest(); + int Parametrized(TestParameter parameter); + TransmittedSharedObject GetTestParameter(); +} \ No newline at end of file diff --git a/mROA.Example/ITestParameter.cs b/mROA.Example/ITestParameter.cs new file mode 100644 index 0000000..7658ef7 --- /dev/null +++ b/mROA.Example/ITestParameter.cs @@ -0,0 +1,9 @@ +using mROA.Implementation; + +namespace mROA.Example; + +[SharedObjectInterafce] +public interface ITestParameter +{ + public int Test(); +} \ No newline at end of file diff --git a/mROA.Example/Main.cs b/mROA.Example/Main.cs new file mode 100644 index 0000000..f286f71 --- /dev/null +++ b/mROA.Example/Main.cs @@ -0,0 +1,9 @@ +namespace mROA.Example; + +public class MainX +{ + public static void Main(string[] args) + { + + } +} \ No newline at end of file diff --git a/mROA.Example/TestController.cs b/mROA.Example/TestController.cs new file mode 100644 index 0000000..a7c0456 --- /dev/null +++ b/mROA.Example/TestController.cs @@ -0,0 +1,45 @@ +using mROA.Implementation; + +namespace mROA.Example; + +[SharedObjectSingleton] +public class TestController : ITestController +{ + public ITestController? ReturnIfNotNull; + private int _bOut = 5; + + public void A() + { + Console.WriteLine("A called"); + } + + public Task AAsync(CancellationToken cancellationToken) + { + return Task.CompletedTask; + } + + public int B() + { + return _bOut++; + } + + public Task BAsync(CancellationToken cancellationToken) + { + return Task.FromResult(5); + } + + public TransmittedSharedObject SharedObjectTransmitionTest() + { + return new TransmissionTestController { ReturnIfNotNull = ReturnIfNotNull ?? new TestController() }; + } + + public int Parametrized(TestParameter parameter) + { + return parameter.A + parameter.LinkedObject.Value.Test(); + } + + public TransmittedSharedObject GetTestParameter() + { + return new TestParameterInstance(); + } +} \ No newline at end of file diff --git a/mROA.Test/ITestController.cs b/mROA.Example/TestControllerRemoteEndpoint.cs similarity index 52% rename from mROA.Test/ITestController.cs rename to mROA.Example/TestControllerRemoteEndpoint.cs index d22a0c7..dc33dc4 100644 --- a/mROA.Test/ITestController.cs +++ b/mROA.Example/TestControllerRemoteEndpoint.cs @@ -1,122 +1,7 @@ -using System.Text.Json; +using System.Text.Json; using mROA.Implementation; -namespace mROA.Test; - -[SharedObjectInterafce] -public interface ITestController -{ - void A(); - Task AAsync(CancellationToken cancellationToken); - int B(); - Task BAsync(CancellationToken cancellationToken); - TransmittedSharedObject SharedObjectTransmitionTest(); - int Parametrized(TestParameter parameter); - TransmittedSharedObject GetTestParameter(); -} - -[SharedObjectSingleton] -public class TestController : ITestController -{ - public ITestController? ReturnIfNotNull; - private int _bOut = 5; - - public void A() - { - Console.WriteLine("A called"); - } - - public Task AAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - - public int B() - { - return _bOut++; - } - - public Task BAsync(CancellationToken cancellationToken) - { - return Task.FromResult(5); - } - - public TransmittedSharedObject SharedObjectTransmitionTest() - { - return new TransmissionTestController { ReturnIfNotNull = ReturnIfNotNull ?? new TestController() }; - } - - public int Parametrized(TestParameter parameter) - { - return parameter.A + parameter.LinkedObject.Value.Test(); - } - - public TransmittedSharedObject GetTestParameter() - { - return new TestParameterInstance(); - } -} - -[SharedObjectInterafce] -public interface ITestParameter -{ - public int Test(); -} - -public class TestParameterInstance : ITestParameter -{ - public int Test() => 10; -} - -public class TransmissionTestController : ITestController -{ - public ITestController ReturnIfNotNull; - - public void A() - { - Console.WriteLine("A called alternative"); - } - - public Task AAsync(CancellationToken cancellationToken) - { - Thread.Sleep(500); - return Task.CompletedTask; - } - - public int B() - { - return 456789; - } - - public Task BAsync(CancellationToken cancellationToken) - { - return Task.FromResult(465789); - } - - public TransmittedSharedObject SharedObjectTransmitionTest() - { - TransmittedSharedObject x = new TestController(); - - - return new TestController { ReturnIfNotNull = this }; - } - - public int Parametrized(TestParameter parameter) - { - return parameter.A * parameter.LinkedObject.Value.Test(); - } - - public TransmittedSharedObject GetTestParameter() - { - return new TestParameterInstance(); - } -} - -public class TestParameter -{ - public int A { get; set; } - public TransmittedSharedObject LinkedObject { get; set; } -} +namespace mROA.Example; public class TestControllerRemoteEndpoint(int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : ITestController, IRemoteObject @@ -196,21 +81,5 @@ public class TestControllerRemoteEndpoint(int id, ISerialisationModule.IFrontend return convertation; } - public int Id => id; -} - -public class TestParameterRemoteEndpoint(int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : ITestParameter, IRemoteObject{ - public int Test() - { - var request = new JsonCallRequest { CommandId = 7, ObjectId = id }; - serialisationModule.PostCallRequest(request); - var response = serialisationModule.GetNextCommandExecution(request.CallRequestId) - .GetAwaiter().GetResult(); - TransmissionConfig.SetupFrontendRepository(); - var convertation = response.Result! is JsonElement e ? e.Deserialize() : (int)response.Result!; - TransmissionConfig.SetupBackendRepository(); - return convertation; - } - public int Id => id; } \ No newline at end of file diff --git a/mROA.Example/TestParameter.cs b/mROA.Example/TestParameter.cs new file mode 100644 index 0000000..abb742f --- /dev/null +++ b/mROA.Example/TestParameter.cs @@ -0,0 +1,9 @@ +using mROA.Implementation; + +namespace mROA.Example; + +public class TestParameter +{ + public int A { get; set; } + public TransmittedSharedObject LinkedObject { get; set; } +} \ No newline at end of file diff --git a/mROA.Example/TestParameterInstance.cs b/mROA.Example/TestParameterInstance.cs new file mode 100644 index 0000000..463239f --- /dev/null +++ b/mROA.Example/TestParameterInstance.cs @@ -0,0 +1,6 @@ +namespace mROA.Example; + +public class TestParameterInstance : ITestParameter +{ + public int Test() => 10; +} \ No newline at end of file diff --git a/mROA.Example/TestParameterRemoteEndpoint.cs b/mROA.Example/TestParameterRemoteEndpoint.cs new file mode 100644 index 0000000..777301b --- /dev/null +++ b/mROA.Example/TestParameterRemoteEndpoint.cs @@ -0,0 +1,20 @@ +using System.Text.Json; +using mROA.Implementation; + +namespace mROA.Example; + +public class TestParameterRemoteEndpoint(int id, ISerialisationModule.IFrontendSerialisationModule serialisationModule) : ITestParameter, IRemoteObject{ + public int Test() + { + var request = new JsonCallRequest { CommandId = 7, ObjectId = id }; + serialisationModule.PostCallRequest(request); + var response = serialisationModule.GetNextCommandExecution(request.CallRequestId) + .GetAwaiter().GetResult(); + TransmissionConfig.SetupFrontendRepository(); + var convertation = response.Result! is JsonElement e ? e.Deserialize() : (int)response.Result!; + TransmissionConfig.SetupBackendRepository(); + return convertation; + } + + public int Id => id; +} \ No newline at end of file diff --git a/mROA.Example/TransmissionTestController.cs b/mROA.Example/TransmissionTestController.cs new file mode 100644 index 0000000..e87693b --- /dev/null +++ b/mROA.Example/TransmissionTestController.cs @@ -0,0 +1,47 @@ +using mROA.Implementation; + +namespace mROA.Example; + +public class TransmissionTestController : ITestController +{ + public ITestController ReturnIfNotNull; + + public void A() + { + Console.WriteLine("A called alternative"); + } + + public Task AAsync(CancellationToken cancellationToken) + { + Thread.Sleep(500); + return Task.CompletedTask; + } + + public int B() + { + return 456789; + } + + public Task BAsync(CancellationToken cancellationToken) + { + return Task.FromResult(465789); + } + + public TransmittedSharedObject SharedObjectTransmitionTest() + { + TransmittedSharedObject x = new TestController(); + + + return new TestController { ReturnIfNotNull = this }; + } + + public int Parametrized(TestParameter parameter) + { + return parameter.A * parameter.LinkedObject.Value.Test(); + } + + public TransmittedSharedObject GetTestParameter() + { + return new TestParameterInstance(); + } +} \ No newline at end of file diff --git a/mROA.Test/FrontendFinalTest.cs b/mROA.Test/FrontendFinalTest.cs index 965dd3a..b17028f 100644 --- a/mROA.Test/FrontendFinalTest.cs +++ b/mROA.Test/FrontendFinalTest.cs @@ -1,6 +1,7 @@ using System.Net; using System.Net.Sockets; using System.Reflection; +using mROA.Example; using mROA.Implementation; namespace mROA.Test; diff --git a/mROA.Test/UnitTest1.cs b/mROA.Test/UnitTest1.cs index 4736608..8d254d7 100644 --- a/mROA.Test/UnitTest1.cs +++ b/mROA.Test/UnitTest1.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Text; using System.Text.Json; +using mROA.Example; using mROA.Implementation; using Newtonsoft.Json; using JsonSerializer = System.Text.Json.JsonSerializer; diff --git a/mROA.Test/mROA.Test.csproj b/mROA.Test/mROA.Test.csproj index 4262b31..8a3797b 100644 --- a/mROA.Test/mROA.Test.csproj +++ b/mROA.Test/mROA.Test.csproj @@ -27,6 +27,7 @@ + diff --git a/mROA.sln b/mROA.sln index b65ee37..b268ff7 100644 --- a/mROA.sln +++ b/mROA.sln @@ -4,6 +4,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA", "mROA\mROA.csproj", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Test", "mROA.Test\mROA.Test.csproj", "{D0E5760B-BB6E-453A-B396-A972CD94F133}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Codegen", "mROA.Codegen\mROA.Codegen.csproj", "{6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "mROA.Example", "mROA.Example\mROA.Example.csproj", "{5F4EEF2B-A82C-44DA-8995-AF1668A238EC}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -18,5 +22,13 @@ Global {D0E5760B-BB6E-453A-B396-A972CD94F133}.Debug|Any CPU.Build.0 = Debug|Any CPU {D0E5760B-BB6E-453A-B396-A972CD94F133}.Release|Any CPU.ActiveCfg = Release|Any CPU {D0E5760B-BB6E-453A-B396-A972CD94F133}.Release|Any CPU.Build.0 = Release|Any CPU + {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CE0ED21-88FD-44B3-B9C6-9B8FA4E07E89}.Release|Any CPU.Build.0 = Release|Any CPU + {5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5F4EEF2B-A82C-44DA-8995-AF1668A238EC}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/mROA/Abstract/ISerialisationModule.cs b/mROA/Abstract/ISerialisationModule.cs index b40ed61..7f5332a 100644 --- a/mROA/Abstract/ISerialisationModule.cs +++ b/mROA/Abstract/ISerialisationModule.cs @@ -10,6 +10,8 @@ public interface ISerialisationModule public interface IFrontendSerialisationModule { Task GetNextCommandExecution(Guid requestId) where T : ICommandExecution; + Task GetFinalCommandExecution(Guid requestId); + void PostCallRequest(ICallRequest callRequest); } } \ No newline at end of file diff --git a/mROA/Implementation/JsonFrontendSerialisationModule.cs b/mROA/Implementation/JsonFrontendSerialisationModule.cs index a5ffec9..1d02f2b 100644 --- a/mROA/Implementation/JsonFrontendSerialisationModule.cs +++ b/mROA/Implementation/JsonFrontendSerialisationModule.cs @@ -18,6 +18,19 @@ public class JsonFrontendSerialisationModule(IInteractionModule.IFrontendInterac return parsed; } + public async Task GetFinalCommandExecution(Guid requestId) + { + var receiveMessage = await interactionModule.ReceiveMessage(); + var parsed = JsonSerializer.Deserialize(receiveMessage); + while (parsed.CallRequestId != requestId) + { + receiveMessage = await interactionModule.ReceiveMessage(); + parsed = JsonSerializer.Deserialize(receiveMessage); + } + parsed.Result = parsed.Result! is JsonElement e ? e.Deserialize() : (T)parsed.Result!; + return parsed; + } + public void PostCallRequest(ICallRequest callRequest) { var post = JsonSerializer.Serialize(callRequest, callRequest.GetType());