public static void Build(string concern, string operation, GroupByType groupBy)
        {
            var responseNameSpace = groupBy switch
            {
                GroupByType.Concern => $"{concern}.Responses",
                GroupByType.Operation => $"Responses.{concern}"
            };

            ClassAssembler
            .Configure(concern, operation, PatternDirectoryType.Commands, groupBy)
            .ImportNamespaces(new List <NamespaceModel>
            {
                new NamespaceModel("MediatR"),
                new NamespaceModel(responseNameSpace, true)
            })
            .CreateNamespace()
            .CreateClass()
            .WithInheritance(new List <string>
            {
                $"IRequest<{concern}{operation}{PatternFileType.Response}>"
            })
            .Generate()
            ;
        }
    }
        public static void Build(string path)
        {
            Console.WriteLine(ExecuteCommandUtility.Run($"echo ADD LOGIC SERVICE COLLECTION EXTENSION"));

            const string className  = "LogicServiceCollectionExtensions";
            const string methodName = "AddLogic";
            const string nameSpace  = "Logic.Configuration";

            Directory.CreateDirectory(path);

            ExecuteCommandUtility.Run("cd Logic/Configuration");

            var importNameSpaces = new List <NamespaceModel>
            {
                new NamespaceModel("MediatR"),
                new NamespaceModel("Microsoft.Extensions.Configuration"),
                new NamespaceModel("Microsoft.Extensions.DependencyInjection")
            };

            var modifiers = new[]
            {
                SyntaxFactory.Token(SyntaxKind.PublicKeyword)
                , SyntaxFactory.Token(SyntaxKind.StaticKeyword)
            };

            var statements = new List <StatementSyntax>
            {
                SyntaxFactory.ParseStatement("services")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
                SyntaxFactory.ParseStatement(".AddMediatR(typeof(LogicServiceCollectionExtensions).Assembly)")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
                SyntaxFactory.ParseStatement(";")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
                SyntaxFactory.ParseStatement("return services;")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
            };

            var paramArray = new[]
            {
                SyntaxFactory.Parameter(SyntaxFactory.Identifier("services"))
                .WithType(SyntaxFactory.ParseTypeName("this IServiceCollection")),
                SyntaxFactory.Parameter(SyntaxFactory.Identifier("config"))
                .WithType(SyntaxFactory.ParseTypeName("IConfiguration"))
            };

            ClassAssembler
            .Configure()
            .ImportNamespaces(importNameSpaces)
            .CreateNamespace(nameSpace)
            .CreateClass(modifiers, className)
            .AddMethod(
                modifiers
                , SyntaxFactory.ParseTypeName($"IServiceCollection")
                , methodName
                , paramArray
                , statements)
            .Generate(path, className);

            ExecuteCommandUtility.Run("cd ../../");
        }
        public static void Build(string path)
        {
            Console.WriteLine(ExecuteCommandUtility.Run($"echo ADD HEALTH CHECK EXTENSION"));
            const string className = "HealthCheckExtensions";

            Directory.CreateDirectory(path);
            ExecuteCommandUtility.Run("cd Extensions");

            var importNameSpaces = new List <NamespaceModel>
            {
                new NamespaceModel("Microsoft.AspNetCore.Builder"),
                new NamespaceModel("Microsoft.Extensions.DependencyInjection"),
            };

            var statementsOne = new List <StatementSyntax>
            {
                SyntaxFactory.ParseStatement("return services;")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
            };
            var statementsTwo = new List <StatementSyntax>
            {
                SyntaxFactory.ParseStatement("return app;")
                .WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
            };

            var modifiers = new[]
            {
                SyntaxFactory.Token(SyntaxKind.PublicKeyword)
                , SyntaxFactory.Token(SyntaxKind.StaticKeyword)
            };

            var paramArrayOne = new[] { SyntaxFactory.Parameter(SyntaxFactory.Identifier("services"))
                                        .WithType(SyntaxFactory.ParseTypeName("this IServiceCollection")) };

            var paramArrayTwo = new[] { SyntaxFactory.Parameter(SyntaxFactory.Identifier("app"))
                                        .WithType(SyntaxFactory.ParseTypeName("this IApplicationBuilder")) };

            ClassAssembler
            .Configure()
            .ImportNamespaces(importNameSpaces)
            .CreateNamespace("Api.Extensions")
            .CreateClass(modifiers, className)
            .AddMethod(
                modifiers
                , SyntaxFactory.ParseTypeName($"IServiceCollection")
                , "AddMicroserviceHealthChecks"
                , paramArrayOne
                , statementsOne)
            .AddMethod(
                modifiers
                , SyntaxFactory.ParseTypeName($"IApplicationBuilder")
                , "UseMicroserviceHealthChecks"
                , paramArrayTwo
                , statementsTwo
                )
            .Generate(path, className);
        }
 public static void Build(string concern, string operation, GroupByType groupBy)
 {
     ClassAssembler
     .ConfigureHandler(concern, operation, PatternDirectoryType.Responses, groupBy)
     .ImportNamespaces()
     .CreateNamespace()
     .CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) })
     .GenerateHandler()
     ;
 }
 public static void Build(string concern, string operation, GroupByType groupBy)
 {
     ClassAssembler
     .Configure(concern, operation, PatternDirectoryType.Responses, groupBy)
     .ImportNamespaces()
     .CreateNamespace()
     .CreateClass()
     .Generate()
     ;
 }
Ejemplo n.º 6
0
        public static void Build(string path)
        {
            Console.WriteLine(ExecuteCommandUtility.Run($"echo ADD STARTUP"));
            ExecuteCommandUtility.Run("rm Startup.cs");

            ClassAssembler
            .Configure()
            .ImportNamespaces(_namespaceModels)
            .CreateNamespace("Api")
            .CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) }, "Startup")
            .AddGetProperty("IConfiguration", "Configuration", SyntaxKind.PrivateKeyword)
            .AddStartupConstructor()
            .AddStartupConfigureServices()
            .AddStartupConfigure()
            .Generate(path, "Startup")
            ;
        }
 public static void Build(string concern, string operation, GroupByType groupBy)
 {
     ClassAssembler
     .Configure(concern, operation, PatternDirectoryType.Queries, groupBy)
     .ImportNamespaces(new List <NamespaceModel>
     {
         new NamespaceModel("MediatR"),
         new NamespaceModel($"{NamespaceResolver.Resolve(concern,"Responses",groupBy)}", true),
     })
     .CreateNamespace()
     .CreateClass()
     .WithInheritance(new List <string>
     {
         $"IRequest<{concern}{operation}{PatternFileType.Response}>"
     })
     .Generate()
     ;
 }
Ejemplo n.º 8
0
        public static void Build(string concern, string operation, OperationType ot, GroupByType groupBy)
        {
            var tInObjectName = ot switch
            {
                OperationType.COMMAND => $"{concern}{operation}Command",
                OperationType.QUERY => $"{concern}{operation}Query"
            };

            var operationTypeNamespace = ot switch
            {
                OperationType.COMMAND => NamespaceResolver.Resolve(concern, "Commands", groupBy),
                OperationType.QUERY => NamespaceResolver.Resolve(concern, "Queries", groupBy)
            };

            ClassAssembler
            .ConfigureHandler(concern, operation, PatternDirectoryType.Handlers, groupBy)
            .ImportNamespaces(new List <NamespaceModel>
            {
                new NamespaceModel("MediatR"),
                new NamespaceModel(operationTypeNamespace, true),
                new NamespaceModel($"{NamespaceResolver.Resolve(concern,"Responses",groupBy)}", true),
                new NamespaceModel("System.Collections.Generic"),
                new NamespaceModel("System.Threading"),
                new NamespaceModel("System.Threading.Tasks")
            })
            .CreateNamespace()
            .CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) })
            .WithInheritance(new List <string>
            {
                $"IRequestHandler<{tInObjectName},{concern}{operation}Response>"
            })
            .ImplementMediatorHandlerInheritance($"{concern}{operation}Response", tInObjectName)
            .GenerateHandler()
            ;
        }
    }
}