Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #6

Open
wants to merge 5 commits into
base: feature/add-project-creation
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Builders/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CQRSAndMediator.Scaffolding.Enums;
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Models;
using Microsoft.CodeAnalysis.CSharp;

namespace CQRSAndMediator.Scaffolding.Builders
{
Expand All @@ -16,19 +17,19 @@ public static void Build(string concern, string operation, GroupByType groupBy)
};

ClassAssembler
.Configure(concern, operation, PatternDirectoryType.Commands, groupBy)
.ConfigureHandler(concern, operation, PatternDirectoryType.Commands, groupBy)
.ImportNamespaces(new List<NamespaceModel>
{
new NamespaceModel("MediatR"),
new NamespaceModel(responseNameSpace,true)
})
.CreateNamespace()
.CreateClass()
.CreateClass(new []{SyntaxFactory.Token(SyntaxKind.PublicKeyword)})
.WithInheritance(new List<string>
{
$"IRequest<{concern}{operation}{PatternFileType.Response}>"
})
.Generate()
.GenerateHandler()
;
}
}
Expand Down
59 changes: 59 additions & 0 deletions Builders/BuildCorsExtension.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Models;
using CQRSAndMediator.Scaffolding.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.IO;

namespace CQRSAndMediator.Scaffolding.Builders
{
public static class BuildCorsExtension
{
public static void Build(string path)
{
Console.WriteLine(ExecuteCommandUtility.Run($"echo ADD CORS EXTENSION"));
const string className = "CorsServiceCollectionExtensions";
const string methodName = "AddCorsRules";

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

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

var statements = new List<StatementSyntax>
{
SyntaxFactory.ParseStatement("return services;")
.WithTrailingTrivia(SyntaxFactory.CarriageReturnLineFeed),
};
var modifiers = new[]
{
SyntaxFactory.Token(SyntaxKind.PublicKeyword)
,SyntaxFactory.Token(SyntaxKind.StaticKeyword)
};
var paramArray = new[] { SyntaxFactory.Parameter(SyntaxFactory.Identifier("services"))
.WithType(SyntaxFactory.ParseTypeName("this IServiceCollection"))};

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


ExecuteCommandUtility.Run("cd ../");
}
}
}
68 changes: 68 additions & 0 deletions Builders/BuildDatabaseServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using CQRSAndMediator.Scaffolding.Models;
using CQRSAndMediator.Scaffolding.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System.Collections.Generic;
using System.IO;
using CQRSAndMediator.Scaffolding.Infrastructure;

namespace CQRSAndMediator.Scaffolding.Builders
{
public static class BuildDatabaseServiceCollectionExtensions
{
public static void Build(string path)
{
Console.WriteLine(ExecuteCommandUtility.Run($"echo ADD DATABASE SERVICE COLLECTION EXTENSION"));
const string className = "DatabaseServiceCollectionExtensions";
const string methodName = "AddDatabase";
const string nameSpace = "DB.Configuration";

Directory.CreateDirectory(path);

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

var importNameSpaces = new List<NamespaceModel>
{
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("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 ../../");
}
}
}
7 changes: 4 additions & 3 deletions Builders/BuildHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using CQRSAndMediator.Scaffolding.Models;
using System.Collections.Generic;
using CQRSAndMediator.Scaffolding.Resolver;
using Microsoft.CodeAnalysis.CSharp;

namespace CQRSAndMediator.Scaffolding.Builders
{
Expand All @@ -23,7 +24,7 @@ public static void Build(string concern, string operation, OperationType ot, Gr
};

ClassAssembler
.Configure(concern, operation, PatternDirectoryType.Handlers, groupBy)
.ConfigureHandler(concern, operation, PatternDirectoryType.Handlers, groupBy)
.ImportNamespaces(new List<NamespaceModel>
{
new NamespaceModel("MediatR"),
Expand All @@ -34,13 +35,13 @@ public static void Build(string concern, string operation, OperationType ot, Gr
new NamespaceModel("System.Threading.Tasks")
})
.CreateNamespace()
.CreateClass()
.CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) })
.WithInheritance(new List<string>
{
$"IRequestHandler<{tInObjectName},{concern}{operation}Response>"
})
.ImplementMediatorHandlerInheritance($"{concern}{operation}Response",tInObjectName)
.Generate()
.GenerateHandler()
;
}

Expand Down
74 changes: 74 additions & 0 deletions Builders/BuildHealthCheckExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Models;
using CQRSAndMediator.Scaffolding.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.IO;

namespace CQRSAndMediator.Scaffolding.Builders
{
public static class BuildHealthCheckExtensions
{
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);

}
}
}
76 changes: 76 additions & 0 deletions Builders/BuildLogicServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Models;
using CQRSAndMediator.Scaffolding.Utilities;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.IO;

namespace CQRSAndMediator.Scaffolding.Builders
{
public static class BuildLogicServiceCollectionExtensions
{
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 ../../");
}
}
}
7 changes: 4 additions & 3 deletions Builders/BuildQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CQRSAndMediator.Scaffolding.Infrastructure;
using CQRSAndMediator.Scaffolding.Models;
using CQRSAndMediator.Scaffolding.Resolver;
using Microsoft.CodeAnalysis.CSharp;
using System.Collections.Generic;

namespace CQRSAndMediator.Scaffolding.Builders
Expand All @@ -11,19 +12,19 @@ public static class BuildQuery
public static void Build(string concern, string operation, GroupByType groupBy)
{
ClassAssembler
.Configure(concern,operation, PatternDirectoryType.Queries, groupBy)
.ConfigureHandler(concern,operation, PatternDirectoryType.Queries, groupBy)
.ImportNamespaces(new List<NamespaceModel>
{
new NamespaceModel("MediatR"),
new NamespaceModel($"{NamespaceResolver.Resolve(concern,"Responses",groupBy)}",true),
})
.CreateNamespace()
.CreateClass()
.CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) })
.WithInheritance(new List<string>
{
$"IRequest<{concern}{operation}{PatternFileType.Response}>"
})
.Generate()
.GenerateHandler()
;
}
}
Expand Down
7 changes: 4 additions & 3 deletions Builders/BuildResponse.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CQRSAndMediator.Scaffolding.Enums;
using CQRSAndMediator.Scaffolding.Infrastructure;
using Microsoft.CodeAnalysis.CSharp;

namespace CQRSAndMediator.Scaffolding.Builders
{
Expand All @@ -8,11 +9,11 @@ public static class BuildResponse
public static void Build(string concern, string operation, GroupByType groupBy)
{
ClassAssembler
.Configure(concern, operation, PatternDirectoryType.Responses, groupBy)
.ConfigureHandler(concern, operation, PatternDirectoryType.Responses, groupBy)
.ImportNamespaces()
.CreateNamespace()
.CreateClass()
.Generate()
.CreateClass(new[] { SyntaxFactory.Token(SyntaxKind.PublicKeyword) })
.GenerateHandler()
;
}
}
Expand Down
Loading