private CreateClassData CreateUseCase(MakeUseCaseParameter param) { var className = $"{param.CompleteName}Interactor"; var classNameSpace = $"Domain.Application.{param.ControllerName}"; var meta = new ClassMeta(classNameSpace, className); meta.SetupUsing() .AddUsing("System") .AddUsing("UseCase." + param.ControllerName + "." + param.ActionName); meta.SetupImplements() .AddImplements("I" + param.CompleteName + "UseCase"); meta.SetupMethods() .AddMethod("Handle", method => method .SetReturnType(param.CompleteName + "Response") .AddArgument("request", param.CompleteName + "Request") .SetAccessLevel(AccessLevel.Public) ); var content = classFileGenerateDriver.Create(meta, Language.CSharp); return(new CreateClassData( Path.Combine("Application", param.ActionName), className + ".cs", content )); }
public List <CreateClassData> Make(MakeUseCaseParameter param) { return(new List <CreateClassData> { CreateUseCase(param) }); }
public void Run(CreateUseCaseTaskParameter taskParam) { var projectDirectoryFullPath = taskParam.ProjectDirectoryFullPath; var usecaseParam = new MakeUseCaseParameter(taskParam.ControllerName, taskParam.ActionName); CreateUsecaseTo("UseCase", projectDirectoryFullPath, usecaseParam, new UseCaseMaker()); CreateUsecaseTo("MockUseCase", projectDirectoryFullPath, usecaseParam, new MockUseCaseMaker()); CreateUsecaseTo("Domain", projectDirectoryFullPath, usecaseParam, new DomainUseCaseMaker()); var registerParameter = new UseCaseRegisterParameter(taskParam.WebProjectFullPath, taskParam.ControllerName, taskParam.ActionName); RegisterUseCase(registerParameter); CreateJsonResponseFile(taskParam); }
private CreateClassData CreateInteractor(MakeUseCaseParameter param) { var className = $"Mock{param.CompleteName}Interactor"; var classNamespace = $"MockUseCase.{param.ControllerName}"; var meta = new ClassMeta(classNamespace, className); meta.SetupUsing() .AddUsing("NrsLib.SequentiallyJsonDataLoader") .AddUsing("UseCase." + param.ControllerName + "." + param.ActionName); meta.SetupImplements() .AddImplements("I" + param.CompleteName + "UseCase"); meta.SetupFields() .AddField("jsonsLoader", field => field.SetReadOnly(true).SetType("JsonsLoader")); meta.SetupConstructor() .AddConstructor(constructor => constructor .SetAccessLevel(AccessLevel.Public) .AddArgument("jsonsLoader", "JsonsLoader") .AddBody("this.jsonsLoader = jsonsLoader;")); var responseClassName = param.CompleteName + "Response"; meta.SetupMethods() .AddMethod("Handle", method => method .SetReturnType(responseClassName) .AddArgument("request", param.CompleteName + "Request") .SetAccessLevel(AccessLevel.Public) .AddBody($"return jsonsLoader.Generate<{responseClassName}>();") ); var content = classFileGenerateDriver.Create(meta, Language.CSharp); return(new CreateClassData( param.ControllerName, className + ".cs", content )); }
private void CreateUsecaseTo(string projectName, string projectDirectoryFullPath, MakeUseCaseParameter param, params IMaker[] makers) { var classes = makers.SelectMany(x => x.Make(param)).ToArray(); var usecaseFullPath = Path.Combine(projectDirectoryFullPath, projectName); prepareTemplates(projectDirectoryFullPath, projectName); prepareDirectory(usecaseFullPath, classes); createClassFile(usecaseFullPath, classes); }