diff --git a/Example.Backend/Printer.cs b/Example.Backend/Printer.cs index 88be74e..7ef462e 100644 --- a/Example.Backend/Printer.cs +++ b/Example.Backend/Printer.cs @@ -12,7 +12,7 @@ public class Printer : IPrinter return Name; } - public async Task> Print(string text) + public async Task> Print(string text, CancellationToken cancellationToken = default) { return new Page {Text = text}; } diff --git a/Example.Backend/PrinterFactory.cs b/Example.Backend/PrinterFactory.cs index 85390f3..126166a 100644 --- a/Example.Backend/PrinterFactory.cs +++ b/Example.Backend/PrinterFactory.cs @@ -9,6 +9,6 @@ public class PrinterFactory : IPrinterFactory { public TransmittedSharedObject Create(string printerName) { - return new Printer(){Name = printerName}; + return new Printer {Name = printerName}; } } \ No newline at end of file diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index e0da284..fb9aa23 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -23,6 +23,6 @@ var factory = context.GetSingleObject(typeof(Example.Shared.IPrinterFactory)) as var printer = factory.Create("Test"); var name = printer.Value.GetName(); Console.WriteLine("Printer name : {0}", name); -var page = printer.Value.Print("Test Page"); +var page = await printer.Value.Print("Test Page", new CancellationToken()); var data = page.Value.GetData(); Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data)); \ No newline at end of file diff --git a/Example.Shared/IPrinter.cs b/Example.Shared/IPrinter.cs index bded350..ee92dc8 100644 --- a/Example.Shared/IPrinter.cs +++ b/Example.Shared/IPrinter.cs @@ -6,6 +6,5 @@ namespace Example.Shared; public interface IPrinter { string GetName(); - Task> Print(string text); - + Task> Print(string text, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/mROA.Codegen/SampleIncrementalSourceGenerator.cs b/mROA.Codegen/SampleIncrementalSourceGenerator.cs index 696acc4..484daef 100644 --- a/mROA.Codegen/SampleIncrementalSourceGenerator.cs +++ b/mROA.Codegen/SampleIncrementalSourceGenerator.cs @@ -58,17 +58,17 @@ namespace {Namespace} // Go through all attributes of the class. foreach (AttributeListSyntax attributeListSyntax in classDeclarationSyntax.AttributeLists) - foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) - { - if (context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol) - continue; // if we can't get the symbol, ignore it + foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes) + { + if (context.SemanticModel.GetSymbolInfo(attributeSyntax).Symbol is not IMethodSymbol attributeSymbol) + 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. - if (attributeName == "mROA.Implementation.SharedObjectInterfaceAttribute") - return (classDeclarationSyntax, true); - } + // Check the full name of the [Report] attribute. + if (attributeName == "mROA.Implementation.SharedObjectInterfaceAttribute") + return (classDeclarationSyntax, true); + } return (classDeclarationSyntax, false); } @@ -96,7 +96,7 @@ namespace {Namespace} if (semanticModel.GetDeclaredSymbol(classDeclarationSyntax) is not INamedTypeSymbol classSymbol) continue; - + var namespaceName = classSymbol.ContainingNamespace.ToDisplayString(); // 'Identifier' means the token of the node. Get class name from the syntax node. @@ -135,22 +135,22 @@ namespace {Namespace} method.Parameters.Length == 2 && isAsync) { sb.AppendLine( - $"\t\tvar request = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id, Parameter = {method.Parameters.First().Name} }};"); + $"\t\tvar defaultCallRequestCodegen = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id, Parameter = {method.Parameters.First().Name} }};"); } else { sb.AppendLine( - $"\t\tvar request = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id }};"); + $"\t\tvar defaultCallRequestCodegen = new DefaultCallRequest {{ CommandId = {index}, ObjectId = id }};"); } //Post created request - sb.AppendLine("\t\tserialisationModule.PostCallRequest(request);"); + sb.AppendLine("\t\tserialisationModule.PostCallRequest(defaultCallRequestCodegen);"); if (method.ReturnType.ToString() == "System.Threading.Tasks.Task") { sb.AppendLine( - "\t\tawait serialisationModule.GetNextCommandExecution(request.CallRequestId);"); + "\t\tawait serialisationModule.GetNextCommandExecution(defaultCallRequestCodegen.CallRequestId);"); } else if (method.ReturnType.OriginalDefinition.ToString() == "System.Threading.Tasks.Task") { @@ -159,14 +159,14 @@ namespace {Namespace} type = type.Substring(type.IndexOf('<') + 1); type = type.Substring(0, type.Length - 1); sb.AppendLine( - $"\t\tvar response = await serialisationModule.GetFinalCommandExecution<{type}>(request.CallRequestId);"); + $"\t\tvar response = await serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId);"); sb.AppendLine($"\t\treturn ({type})response.Result;"); } else if (!isAsync && method.ReturnType.ToDisplayString() != "void") { var type = method.ReturnType.ToDisplayString(); sb.AppendLine( - $"\t\tvar response = serialisationModule.GetFinalCommandExecution<{type}>(request.CallRequestId).GetAwaiter().GetResult();"); + $"\t\tvar response = serialisationModule.GetFinalCommandExecution<{type}>(defaultCallRequestCodegen.CallRequestId).GetAwaiter().GetResult();"); sb.AppendLine($"\t\treturn ({type})response.Result;"); } @@ -195,16 +195,18 @@ partial class {className} (int id, ISerialisationModule.IFrontendSerialisationMo // Add the source code to the compilation. context.AddSource($"{className}.g.cs", SourceText.From(code, Encoding.UTF8)); - + frontendContextRepo.Add($"{{ typeof({classSymbol.ToDisplayString()}), typeof({namespaceName}.{className}) }}"); } + if (methods.Count != 0) + { - var methodsStringed = methods.Select(i => - $"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", [{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}])") - .ToList(); + var methodsStringed = methods.Select(i => + $"typeof({i.Item1}).GetMethod(\"{i.Item2.Name}\", [{string.Join(", ", i.Item2.Parameters.Select(p => $"typeof({p.Type.ToDisplayString()})"))}])") + .ToList(); - var coCodegenRepoCode = @$"// + var coCodegenRepoCode = @$"// using System.Collections.Generic; using System.Reflection; @@ -243,9 +245,13 @@ public class CoCodegenMethodRepository :IMethodRepository }} }} "; - context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8)); + context.AddSource($"CoCodegenMethodRepository.g.cs", SourceText.From(coCodegenRepoCode, Encoding.UTF8)); + } - var fronendRepoCode = @$"// + if (frontendContextRepo.Count != 0) + { + + var fronendRepoCode = @$"// using System.Collections.Frozen; using mROA.Implementation; @@ -310,6 +316,8 @@ public class FrontendContextRepository : IContextRepository }} }} "; - context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8)); + context.AddSource("FrontendContextRepository.g.cs", SourceText.From(fronendRepoCode, Encoding.UTF8)); + } + } } \ No newline at end of file diff --git a/mROA.Codegen/mROA.Codegen.csproj b/mROA.Codegen/mROA.Codegen.csproj index 3b0c37d..87d0354 100644 --- a/mROA.Codegen/mROA.Codegen.csproj +++ b/mROA.Codegen/mROA.Codegen.csproj @@ -17,7 +17,7 @@ https://github.com/YaslePoy/mROA git True - 1.0.1 + 1.0.4 diff --git a/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props b/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props index 6f36b67..8f44f76 100644 --- a/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props +++ b/mROA.Codegen/obj/mROA.Codegen.csproj.nuget.g.props @@ -5,18 +5,18 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference - 6.12.0 + 6.12.1 - + - C:\Users\Mimm\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4 + C:\Users\Mikhail\.nuget\packages\microsoft.codeanalysis.analyzers\3.3.4 \ No newline at end of file diff --git a/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs b/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs index 67f44a1..459141c 100644 --- a/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs +++ b/mROA.Test/obj/Debug/net9.0/mROA.Test.AssemblyInfo.cs @@ -13,7 +13,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5bcdb968f0f857381cbf8b7f5ee99b5e8a5f6b36")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+71e92f0301b2ba7aaaf7dca368a62bfba8554ca4")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs b/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs index 62758ce..6c712e6 100644 --- a/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs +++ b/mROA.Test/obj/Release/net9.0/mROA.Test.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Release")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d780d0ea0b8c501b99358c1e89abc9fa4c46f959")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+71e92f0301b2ba7aaaf7dca368a62bfba8554ca4")] [assembly: System.Reflection.AssemblyProductAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyTitleAttribute("mROA.Test")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/mROA.Test/obj/mROA.Test.csproj.nuget.g.props b/mROA.Test/obj/mROA.Test.csproj.nuget.g.props index f0b8464..92b7a7a 100644 --- a/mROA.Test/obj/mROA.Test.csproj.nuget.g.props +++ b/mROA.Test/obj/mROA.Test.csproj.nuget.g.props @@ -5,12 +5,12 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference - 6.12.0 + 6.12.1 - + @@ -21,6 +21,6 @@ - C:\Users\Mimm\.nuget\packages\nunit.analyzers\4.6.0 + C:\Users\Mikhail\.nuget\packages\nunit.analyzers\4.6.0 \ No newline at end of file diff --git a/mROA/obj/mROA.csproj.nuget.g.props b/mROA/obj/mROA.csproj.nuget.g.props index 7f9c9db..8ec82c1 100644 --- a/mROA/obj/mROA.csproj.nuget.g.props +++ b/mROA/obj/mROA.csproj.nuget.g.props @@ -5,12 +5,12 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Mimm\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Mikhail\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference - 6.12.0 + 6.12.1 - + \ No newline at end of file