Ejemplo n.º 1
0
        public CodeNamespace Build(AsyncDomainHook hook)
        {
            var targetClass   = _classBuilderUtil.Build(_nameBuilderUtil.AsyncEventHookHandlerName(hook));
            var codeNamespace = _nameSpaceBuilderUtil.WithName($"{_nameSpace}.{hook.ClassType}s.AsyncHooks").WithApplication().WithTask().WithList().WithDomainEntityNameSpace(hook.ClassType).Build();

            codeNamespace.Types.Add(targetClass);

            var handler = new AsyncHookCreateEventHandler(hook);

            _propertyBuilderUtil.Build(targetClass, handler.Properties);
            var constructor = _constructorBuilderUtil.BuildPublic(handler.Properties);

            targetClass.Members.Add(constructor);

            var method = new CodeMemberMethod();

            method.Name       = "Run";
            method.ReturnType = new CodeTypeReference("async Task");
            method.Attributes = MemberAttributes.Public | MemberAttributes.Final;

            method.Statements.Add(new CodeSnippetExpression($"var events = await {handler.Properties[1].Name}.GetEvents(\"{hook.Name}\")"));
            method.Statements.Add(new CodeSnippetExpression($"var handledEvents = new List<{new EventAndJobClass().Name}>()"));

            method.Statements.Add(new CodeSnippetExpression("var enumerator = events.GetEnumerator()"));

            var codeIterationStatement = CreateLoopOverEvents(hook);

            method.Statements.Add(codeIterationStatement);

            method.Statements.Add(
                new CodeSnippetExpression($"await {handler.Properties[1].Name}.RemoveEventsFromQueue(handledEvents)"));
            targetClass.Members.Add(method);
            return(codeNamespace);
        }
Ejemplo n.º 2
0
        public CodeNamespace Build(List <AsyncDomainHook> domainHooks)
        {
            var nameSpace      = _nameSpaceBuilderUtil.WithName($"{_nameSpace}").WithList().Build();
            var generatedClass = _classBuilderUtil.Build("EventJobRegistration");
            var constructor    = new CodeConstructor();

            constructor.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            constructor.Statements.Add(new CodeSnippetExpression($"EventJobs = new List<{new EventTupleClass().Name}>()"));
            foreach (var domainHook in domainHooks)
            {
                nameSpace.Imports.Add(new CodeNamespaceImport($"Domain.{domainHook.ClassType}s"));
                constructor.Statements.Add(new CodeSnippetExpression(
                                               $"EventJobs.Add(new EventTuple(typeof({_nameBuilderUtil.HooKEventName(domainHook)}).ToString(), \"{domainHook.Name}\"))"));
            }

            _propertyBuilderUtil.Build(generatedClass, new List <Property> {
                new Property {
                    Name = "EventJobs", Type = $"List<{new EventTupleClass().Name}>"
                }
            });

            generatedClass.Members.Add(constructor);
            nameSpace.Types.Add(generatedClass);

            return(nameSpace);
        }
Ejemplo n.º 3
0
        public CodeNamespace Build(QueueRepositoryClass hangfireQueue)
        {
            var targetClass   = _classBuilderUtil.Build(hangfireQueue.Name);
            var codeNamespace = _nameSpaceBuilderUtil.WithName($"{_nameSpace}").WithApplication().WithTask()
                                .WithDomain().WithList().WithLinq().WithEfCore().Build();

            codeNamespace.Types.Add(targetClass);

            targetClass.BaseTypes.Add(new CodeTypeReference($"I{hangfireQueue.Name}"));

            _propertyBuilderUtil.Build(targetClass, hangfireQueue.Properties);
            var constructor = _constructorBuilderUtil.BuildPublic(hangfireQueue.Properties);

            targetClass.Members.Add(constructor);

            var addEventsMethod = CreateAddEventsMethod();

            targetClass.Members.Add(addEventsMethod);

            var getEventsMethod = CreateGetEventsMethod();

            targetClass.Members.Add(getEventsMethod);

            var removeEventsMethod = CreateRemoveEventsMethod();

            targetClass.Members.Add(removeEventsMethod);

            return(codeNamespace);
        }
Ejemplo n.º 4
0
        public CodeNamespace Build(EventStoreRepositoryInterface hookClass)
        {
            var targetClass = _interfaceBuilderUtil.Build(hookClass);
            var nameSpace   = _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().WithList().Build();

            nameSpace.Types.Add(targetClass);
            return(nameSpace);
        }
Ejemplo n.º 5
0
        public CodeNamespace Build(HangfireQueueInterface eventStore)
        {
            var codeNamespace       = _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().WithList().Build();
            var codeTypeDeclaration = _interfaceBuilderUtil.Build(eventStore);

            codeNamespace.Types.Add(codeTypeDeclaration);
            return(codeNamespace);
        }
Ejemplo n.º 6
0
        public CodeNamespace Build(QueueRepositoryInterface repo)
        {
            var codeNamespace       = _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().WithList().Build();
            var codeTypeDeclaration = _interfaceBuilderUtil.Build(repo);

            codeNamespace.Types.Add(codeTypeDeclaration);
            return(codeNamespace);
        }
Ejemplo n.º 7
0
 public void AddNameSpace()
 {
     _nameSpace = _nameSpaceBuilderUtil.WithName($"Application.{_hook.ClassType}s.AsyncHooks")
                  .WithList()
                  .WithTask()
                  .WithDomainEntityNameSpace(_hook.ClassType)
                  .Build();
 }
Ejemplo n.º 8
0
        public CodeNamespace Build(SynchronousDomainHook domainClass)
        {
            var codeNamespace = _nameSpaceBuilderUtil.WithName($"{_applicationNameSpace}.{domainClass.ClassType}s.Hooks")
                                .WithTask()
                                .WithDomainEntityNameSpace(domainClass.ClassType)
                                .WithDomain()
                                .Build();
            var codeTypeDeclaration = _classBuilderUtil.BuildPartial($"{domainClass.Name}Hook");

            codeTypeDeclaration.BaseTypes.Add(new CodeTypeReference(new DomainHookBaseClass().Name));

            var field = new CodeMemberField
            {
                Name       = $"EventType {{ get; private set; }} = typeof({domainClass.ClassType}{domainClass.MethodName}Event);NewHackGuid302315ed-3a05-4992-9f76-4cf075cde515",
                Attributes = MemberAttributes.Public | MemberAttributes.Final,
                Type       = new CodeTypeReference("Type")
            };

            codeTypeDeclaration.Members.Add(field);

            codeNamespace.Types.Add(codeTypeDeclaration);

            var codeMemberMethod = new CodeMemberMethod();

            codeMemberMethod.Parameters.Add(
                new CodeParameterDeclarationExpression(new CodeTypeReference(new DomainEventBaseClass().Name),
                                                       "domainEvent"));
            codeMemberMethod.ReturnType = new CodeTypeReference($"async {new DomainHookBaseClass().Methods[0].ReturnType}");
            codeMemberMethod.Attributes = MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethod.Name       = new DomainHookBaseClass().Methods[0].Name;
            codeMemberMethod.Statements.Add(new CodeConditionStatement(
                                                new CodeSnippetExpression(
                                                    $"domainEvent is {domainClass.ClassType}{domainClass.MethodName}Event parsedEvent"),
                                                new CodeStatement[]
            {
                new CodeExpressionStatement(new  CodeSnippetExpression("return await Execute(parsedEvent)"))
            }
                                                ));

            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression("throw new Exception(\"Event is not in the correct list\")"));

            codeTypeDeclaration.Members.Add(codeMemberMethod);
            return(codeNamespace);
        }
Ejemplo n.º 9
0
        public CodeNamespace Build(List <DomainClass> domainClasses)
        {
            _nameSpaceBuilderUtil.WithName($"{_nameSpace}").WithDomain().WithEfCore();
            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil.WithDomainEntityNameSpace(domainClass.Name);
            }

            var nameSpace = _nameSpaceBuilderUtil.Build();

            var eventStore = _classBuilderUtil.Build("EventStoreContext");

            eventStore.BaseTypes.Add(new CodeTypeReference("DbContext"));

            var properties = new List <Property>();

            properties.Add(new Property {
                Name = "EventHistory", Type = $"DbSet<{new DomainEventBaseClass().Name}>"
            });
            foreach (var domainClass in domainClasses)
            {
                properties.Add(new Property {
                    Name = $"{domainClass.Name}s", Type = $"DbSet<{domainClass.Name}>"
                });
                foreach (var method in domainClass.Methods)
                {
                    properties.Add(new Property
                    {
                        Name = $"{_nameBuilderUtil.EventName(domainClass, method)}s",
                        Type = $"DbSet<{_nameBuilderUtil.EventName(domainClass, method)}>"
                    });
                }

                foreach (var method in domainClass.CreateMethods)
                {
                    properties.Add(new Property
                    {
                        Name = $"{_nameBuilderUtil.EventName(domainClass, method)}s",
                        Type = $"DbSet<{_nameBuilderUtil.EventName(domainClass, method)}>"
                    });
                }
            }

            _propertyBuilderUtil.Build(eventStore, properties);
            var codeConstructor = _constructorBuilderUtil.BuildPublicWithBaseCall(new List <Property>(),
                                                                                  new List <Property> {
                new Property {
                    Name = "options", Type = "DbContextOptions<EventStoreContext>"
                }
            });

            eventStore.Members.Add(codeConstructor);

            nameSpace.Types.Add(eventStore);

            return(nameSpace);
        }
Ejemplo n.º 10
0
        public CodeNamespace Build(DomainHookBaseClass hookClass)
        {
            var targetClass = _interfaceBuilderUtil.Build(hookClass);
            var nameSpace   = _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().Build();

            _propertyBuilderUtil.BuildForInterface(targetClass, hookClass.Properties);
            nameSpace.Types.Add(targetClass);
            return(nameSpace);
        }
Ejemplo n.º 11
0
        public CodeNamespace Build(IList <DomainClass> domainClasses, IList <SynchronousDomainHook> domainHooks)
        {
            var codeTypeDeclaration = _classBuilderUtil.Build("GeneratedDependencies");

            codeTypeDeclaration.Attributes = MemberAttributes.Final | MemberAttributes.Public;

            _nameSpaceBuilderUtil.WithName("Host")
            .WithApplication()
            .WithDependencyInjection()
            .WithSqlAdapter();

            var codeMemberMethod = new CodeMemberMethod();

            codeMemberMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethod.Name       = "ConfigureGeneratedServices";
            codeTypeDeclaration.Members.Add(codeMemberMethod);
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("IServiceCollection", "collection"));

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStore, EventStore>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStoreRepository, EventStoreRepository>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new QueueRepositoryInterface().Name}, {new QueueRepositoryClass().Name}>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<EventJobRegistration>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new HangfireQueueInterface().Name}, HangfireQueue>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddMvc().AddApplicationPart(typeof({domainClasses[0].Name}Controller).Assembly)"));

            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil
                .WithApplicationEntityNameSpace(domainClass.Name)
                .WithHttpAdapterEntityNameSpace(domainClass.Name)
                .WithSqlEntityNameSpace(domainClass.Name);

                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<I{domainClass.Name}Repository, {domainClass.Name}Repository>()"));
                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<{domainClass.Name}CommandHandler>()"));

                foreach (var hook in domainClass.ChildHookMethods)
                {
                    var onChildHookMethodName = _nameBuilderUtil.OnChildHookMethodName(hook);
                    codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new DomainHookBaseClass().Name}, {onChildHookMethodName}Hook>()"));
                }
            }

            foreach (var hook in domainHooks)
            {
                _nameSpaceBuilderUtil.WithHookEntityNameSpace(hook.ClassType);
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new DomainHookBaseClass().Name}, {hook.Name}Hook>()"));
            }

            var codeNamespace = _nameSpaceBuilderUtil.Build();

            codeNamespace.Types.Add(codeTypeDeclaration);

            return(codeNamespace);
        }
Ejemplo n.º 12
0
 public void AddNameSpace()
 {
     _nameSpace = _nameSpaceBuilderUtil
                  .WithName("SqlAdapter")
                  .WithDomain()
                  .WithTask()
                  .WithList()
                  .WithApplication()
                  .Build();
 }
Ejemplo n.º 13
0
        public CodeNamespace Build(DomainClass domainClass)
        {
            var nsUtil = _nameSpaceBuilderUtil
                         .WithName($"{_nameSpace}.{domainClass.Name}s")
                         .WithList()
                         .WithTask()
                         .WithDomain()
                         .WithDomainEntityNameSpace(domainClass.Name)
                         .WithMvcImport();

            foreach (var loadMethod in domainClass.LoadMethods)
            {
                foreach (var param in loadMethod.LoadParameters)
                {
                    nsUtil.WithRepository(param.Type);
                }
            }

            var codeNamespace = nsUtil.Build();

            var commandHandler  = _classBuilderUtil.BuildPartial(_nameBuilderUtil.BuildCommandHandlerName(domainClass));
            var codeConstructor = _constructorBuilderUtil.BuildPublic(_commandHandlerPropBuilderUtil.Build(domainClass));

            _propertyBuilderUtil.Build(commandHandler, _commandHandlerPropBuilderUtil.Build(domainClass));
            commandHandler.Members.Add(codeConstructor);

            var allMethod  = _commandHandlerMethodBuilderUtil.BuildGetAllMethod(domainClass);
            var byIdMethod = _commandHandlerMethodBuilderUtil.BuildGetByIdMethod(domainClass);

            commandHandler.Members.Add(allMethod);
            commandHandler.Members.Add(byIdMethod);
            foreach (var createMethod in domainClass.CreateMethods)
            {
                var method = _commandHandlerMethodBuilderUtil.BuildCreateMethod(createMethod, domainClass);
                commandHandler.Members.Add(method);
            }

            foreach (var method in domainClass.Methods.Except(domainClass.LoadMethods))
            {
                var methodParsed = _commandHandlerMethodBuilderUtil.BuildUpdateMethod(method, domainClass);
                commandHandler.Members.Add(methodParsed);
            }

            foreach (var method in domainClass.LoadMethods)
            {
                var methodParsed = _commandHandlerMethodBuilderUtil.BuildUpdateLoadMethod(method, domainClass);
                commandHandler.Members.Add(methodParsed);
            }

            codeNamespace.Types.Add(commandHandler);

            return(codeNamespace);
        }
Ejemplo n.º 14
0
        public void AddNameSpace()
        {
            _nameSpaceBuilderUtil.WithName($"Domain.{_domainClass.Name}s").WithList();

            foreach (var childHookMethod in _domainClass.ChildHookMethods)
            {
                var className = _nameBuilderUtil.GetClassName(childHookMethod, _domainClass.Properties, _domainClass.ListProperties);
                _nameSpaceBuilderUtil.WithDomainEntityNameSpace(className);
            }

            _nameSpaceRealClass = _nameSpaceBuilderUtil.Build();
        }
Ejemplo n.º 15
0
        public CodeNamespace Build(DomainClass domainClass)
        {
            var nameSpace = _nameSpaceBuilderUtil
                            .WithName($"{_nameSpace}.{domainClass.Name}s")
                            .WithList()
                            .WithLinq()
                            .WithTask()
                            .WithDomainEntityNameSpace(domainClass.Name)
                            .WithApplicationEntityNameSpace(domainClass.Name)
                            .WithEfCore()
                            .Build();

            var repository = _classBuilderUtil.Build($"{domainClass.Name}Repository");

            repository.BaseTypes.Add(new CodeTypeReference($"I{domainClass.Name}Repository"));

            var properties = new List <Property> {
                new Property {
                    Name = "EventStore", Type = "EventStoreContext"
                }
            };

            _propertyBuilderUtil.Build(repository,
                                       properties);
            var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);

            repository.Members.Add(codeConstructor);

            var createMethod = MakeCreateMethod(domainClass);

            repository.Members.Add(createMethod);

            var updateMethod = MakeUpdateMethod(domainClass);

            repository.Members.Add(updateMethod);

            var getByIdMethod = MakeGetByIdMethod(domainClass);

            repository.Members.Add(getByIdMethod);

            var getAllMethod = MakeGetAllMethod(domainClass);

            repository.Members.Add(getAllMethod);

            var getParentMethods = MakeGetParentMethods(domainClass);

            repository.Members.AddRange(getParentMethods);

            nameSpace.Types.Add(repository);

            return(nameSpace);
        }
Ejemplo n.º 16
0
        public CodeNamespace Build(EventStore eventStore)
        {
            var targetClass = _classBuilderUtil.Build(eventStore.Name);

            targetClass.BaseTypes.Add(new EventStoreInterface().Name);

            _nameSpaceBuilderUtil.WithName(_nameSpace).WithDomain().WithTask().WithList().WithLinq();

            _propertyBuilderUtil.BuildWithoutSet(targetClass, eventStore.Properties);
            var constructor = _constructorBuilderUtil.BuildPublic(eventStore.Properties);

            targetClass.Members.Add(constructor);

            var methodList = new List <CodeMemberMethod>();

            foreach (var eventStoreMethod in eventStore.Methods)
            {
                var method = new CodeMemberMethod();
                method.Name       = eventStoreMethod.Name;
                method.ReturnType = new CodeTypeReference(eventStoreMethod.ReturnType);
                method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
                foreach (var parameter in eventStoreMethod.Parameters)
                {
                    method.Parameters.Add(new CodeParameterDeclarationExpression(new CodeTypeReference(parameter.Type),
                                                                                 parameter.Name));
                }

                methodList.Add(method);
            }

            var codeMemberMethod = methodList[0];

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("var domainEventsFromHooks = new List<DomainEventBase>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("var enumerator = domainEvents.GetEnumerator()"));

            var codeWhile = CreateLoopOverDomainEvents();

            codeMemberMethod.Statements.Add(codeWhile);
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression("await EventStoreRepository.AddEvents(domainEvents)"));
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression("await EventStoreRepository.AddEvents(domainEventsFromHooks)"));
            codeMemberMethod.Statements.Add(
                new CodeSnippetExpression($"return {new HookResultBaseClass().Name}.OkResult()"));

            targetClass.Members.Add(methodList[0]);

            var nameSpace = _nameSpaceBuilderUtil.Build();

            nameSpace.Types.Add(targetClass);
            return(nameSpace);
        }
Ejemplo n.º 17
0
        public CodeNamespace Build(EventAndJobClass domainClasses)
        {
            var nameSpace      = _nameSpaceBuilderUtil.WithName($"{_nameSpace}").WithDomain().Build();
            var generatedClass = _classBuilderUtil.Build(domainClasses.Name);

            _propertyBuilderUtil.Build(generatedClass, domainClasses.Properties);
            var constructor      = _constructorBuilderUtil.BuildPublicWithIdCreateInBody(domainClasses.Properties.Skip(1).ToList(), domainClasses.Properties[0].Name);
            var constructorEmpty = _constructorBuilderUtil.BuildPrivate(new List <Property>());

            generatedClass.Members.Add(constructor);
            generatedClass.Members.Add(constructorEmpty);
            nameSpace.Types.Add(generatedClass);
            return(nameSpace);
        }
Ejemplo n.º 18
0
        public CodeNamespace Build(DomainMethod method, DomainClass domainClass)
        {
            var commandNameSpace = _nameSpaceBuilderUtil.WithName($"Application.{domainClass.Name}s").WithList().Build();
            var commandName      = _nameBuilderUtil.UpdateApiCommandName(domainClass, method);
            var properties       = method.Parameters.Select(param => new Property {
                Name = param.Name, Type = param.Type
            }).ToList();
            var loadProperties = method.LoadParameters.Select(param => new Property {
                Name = $"{param.Name}Id", Type = "Guid"
            }).ToList();

            properties.AddRange(loadProperties);
            var command         = _classBuilderUtil.Build(commandName);
            var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);

            _propertyBuilderUtil.Build(command, properties);
            command.Members.Add(codeConstructor);
            commandNameSpace.Types.Add(command);
            return(commandNameSpace);
        }
Ejemplo n.º 19
0
        public CodeNamespace Build(HookResultBaseClass userClass)
        {
            var targetClass = _classBuilder.Build(userClass.Name);

            var nameSpace = _nameSpaceBuilderUtil.WithName(_nameSpace).WithList().WithDomain().Build();

            var constructor = _constructorBuilderUtil.BuildPrivate(userClass.Properties);

            _propertyBuilderUtil.Build(targetClass, userClass.Properties);

            var buildOkResultConstructor         = BuildOkResultConstructor(userClass);
            var buildOkResultOverloadConstructor = BuildOkResultOverloadConstructor(userClass);
            var errorResultConstructor           = BuildErrorResultConstructor(userClass);

            targetClass.Members.Add(constructor);
            targetClass.Members.Add(buildOkResultConstructor);
            targetClass.Members.Add(buildOkResultOverloadConstructor);
            targetClass.Members.Add(errorResultConstructor);

            nameSpace.Types.Add(targetClass);

            return(nameSpace);
        }
Ejemplo n.º 20
0
        public List <CodeNamespace> Build(DomainClass domainClass)
        {
            var commandList = new List <CodeNamespace>();

            foreach (var method in domainClass.Methods.Except(domainClass.LoadMethods))
            {
                var commandNameSpace = _nameSpaceBuilderUtil.WithName($"Domain.{domainClass.Name}s").WithList().Build();
                var commandName      = _nameBuilderUtil.UpdateCommandName(domainClass, method);
                var properties       = method.Parameters.Select(param => new Property {
                    Name = param.Name, Type = param.Type
                }).ToList();
                var command         = _classBuilderUtil.Build(commandName);
                var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);
                _propertyBuilderUtil.Build(command, properties);
                command.Members.Add(codeConstructor);
                commandNameSpace.Types.Add(command);
                commandList.Add(commandNameSpace);
            }

            foreach (var loadMethod in domainClass.LoadMethods)
            {
                var nsBuilder = _nameSpaceBuilderUtil.WithName($"Domain.{domainClass.Name}s").WithList();
                foreach (var lodParam in loadMethod.LoadParameters)
                {
                    nsBuilder.WithDomainEntityNameSpace(lodParam.Type);
                }

                var commandNameSpace = nsBuilder.Build();
                var commandName      = _nameBuilderUtil.UpdateCommandName(domainClass, loadMethod);
                var properties       = loadMethod.Parameters.Select(param => new Property {
                    Name = param.Name, Type = param.Type
                }).ToList();
                var loadProperties = loadMethod.LoadParameters.Select(param => new Property {
                    Name = param.Name, Type = param.Type
                }).ToList();
                properties.AddRange(loadProperties);
                var command         = _classBuilderUtil.Build(commandName);
                var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);
                _propertyBuilderUtil.Build(command, properties);
                command.Members.Add(codeConstructor);
                commandNameSpace.Types.Add(command);
                commandList.Add(commandNameSpace);
            }

            foreach (var method in domainClass.CreateMethods)
            {
                var commandNameSpace = _nameSpaceBuilderUtil.WithName($"Domain.{domainClass.Name}s").WithList().Build();
                var commandName      = _nameBuilderUtil.CreateCommandName(domainClass, method);
                var properties       = method.Parameters.Select(param => new Property {
                    Name = param.Name, Type = param.Type
                }).ToList();
                var command         = _classBuilderUtil.Build(commandName);
                var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);
                _propertyBuilderUtil.Build(command, properties);
                command.Members.Add(codeConstructor);
                commandNameSpace.Types.Add(command);
                commandList.Add(commandNameSpace);
            }

            return(commandList);
        }
Ejemplo n.º 21
0
        public CodeNamespace Build(DomainClass domainClass)
        {
            var nameSpace = _nameSpaceBuilderUtil.WithName($"{_nameSpace}.{domainClass.Name}s")
                            .WithList()
                            .WithTask()
                            .WithDomainEntityNameSpace(domainClass.Name)
                            .WithMvcImport()
                            .WithApplicationEntityNameSpace(domainClass.Name)
                            .Build();

            var repository = _classBuilderUtil.Build($"{domainClass.Name}Controller");

            repository.BaseTypes.Add(new CodeTypeReference("Controller"));

            var properties = new List <Property>
            {
                new Property {
                    Name = "Handler", Type = $"{domainClass.Name}CommandHandler"
                }
            };

            _propertyBuilderUtil.Build(repository,
                                       properties);
            var codeConstructor = _constructorBuilderUtil.BuildPublic(properties);

            repository.Members.Add(codeConstructor);

            foreach (var createM in domainClass.CreateMethods)
            {
                var createMethod = MakeCreateMethod(domainClass, createM);
                createMethod.CustomAttributes.Add(new CodeAttributeDeclaration("HttpPost"));
                repository.Members.Add(createMethod);
            }

            foreach (var domainMethod in domainClass.Methods.Except(domainClass.LoadMethods))
            {
                var updateMethod = MakeUpdateMethod(domainClass, domainMethod);
                updateMethod.CustomAttributes.Add(new CodeAttributeDeclaration("HttpPut",
                                                                               new CodeAttributeArgument(new CodePrimitiveExpression($"{{id}}/{domainMethod.Name.ToLower()}"))));
                repository.Members.Add(updateMethod);
            }

            foreach (var domainMethod in domainClass.LoadMethods)
            {
                var updateMethod = MakeUpdateLoadMethod(domainClass, domainMethod);
                updateMethod.CustomAttributes.Add(new CodeAttributeDeclaration("HttpPut",
                                                                               new CodeAttributeArgument(new CodePrimitiveExpression($"{{id}}/{domainMethod.Name.ToLower()}"))));
                repository.Members.Add(updateMethod);
            }

            var getByIdMethod = MakeGetByIdMethod(domainClass);

            getByIdMethod.CustomAttributes.Add(new CodeAttributeDeclaration("HttpGet",
                                                                            new CodeAttributeArgument(new CodePrimitiveExpression("{id}"))));
            repository.Members.Add(getByIdMethod);

            var getAllMethod = MakeGetAllMethod(domainClass);

            getAllMethod.CustomAttributes.Add(new CodeAttributeDeclaration("HttpGet"));
            repository.Members.Add(getAllMethod);

            repository.CustomAttributes.Add(new CodeAttributeDeclaration("Route",
                                                                         new CodeAttributeArgument(new CodePrimitiveExpression($"api/{domainClass.Name.ToLower()}s"))));

            nameSpace.Types.Add(repository);

            return(nameSpace);
        }
Ejemplo n.º 22
0
        public CodeNamespace Write(IList <DomainClass> domainClasses, IList <AsyncDomainHook> domainHooks)
        {
            var codeTypeDeclaration = _classBuilderUtil.Build("GeneratedDependencies");

            codeTypeDeclaration.Attributes = MemberAttributes.Final | MemberAttributes.Public;

            _nameSpaceBuilderUtil.WithName("AsyncHost")
            .WithApplication()
            .WithDependencyInjection()
            .WithHangfire()
            .WithApplicatioBuilder()
            .WithSqlAdapter();

            var codeMemberMethod = new CodeMemberMethod();

            codeMemberMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethod.Name       = "ConfigureGeneratedServices";
            codeTypeDeclaration.Members.Add(codeMemberMethod);
            codeMemberMethod.Parameters.Add(new CodeParameterDeclarationExpression("IServiceCollection", "collection"));

            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStore, EventStore>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<IEventStoreRepository, EventStoreRepository>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new QueueRepositoryInterface().Name}, {new QueueRepositoryClass().Name}>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression("collection.AddTransient<EventJobRegistration>()"));
            codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{new HangfireQueueInterface().Name}, HangfireQueue>()"));

            foreach (var domainClass in domainClasses)
            {
                _nameSpaceBuilderUtil
                .WithApplicationEntityNameSpace(domainClass.Name)
                .WithSqlEntityNameSpace(domainClass.Name);

                codeMemberMethod.Statements.Add(new CodeSnippetExpression(
                                                    $"collection.AddTransient<I{domainClass.Name}Repository, {domainClass.Name}Repository>()"));
            }

            foreach (var hook in domainHooks)
            {
                _nameSpaceBuilderUtil.WithAsyncHookEntityNameSpace(hook.ClassType);
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{_nameBuilderUtil.AsyncEventHookHandlerName(hook)}>()"));
                codeMemberMethod.Statements.Add(new CodeSnippetExpression($"collection.AddTransient<{_nameBuilderUtil.AsyncEventHookName(hook)}>()"));
            }

            var codeNamespace = _nameSpaceBuilderUtil.Build();

            var codeMemberMethodApplicationConfig = new CodeMemberMethod();

            codeMemberMethodApplicationConfig.Attributes = MemberAttributes.Static | MemberAttributes.Public | MemberAttributes.Final;
            codeMemberMethodApplicationConfig.Name       = "ConfigureApplication";
            codeMemberMethodApplicationConfig.Parameters.Add(new CodeParameterDeclarationExpression("IApplicationBuilder", "app"));

            codeTypeDeclaration.Members.Add(codeMemberMethodApplicationConfig);

            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("var option = new BackgroundJobServerOptions {WorkerCount = 1}"));
            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("app.UseHangfireServer(option)"));
            codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression("app.UseHangfireDashboard()"));

            foreach (var hook in domainHooks)
            {
                codeMemberMethodApplicationConfig.Statements.Add(new CodeSnippetExpression($"RecurringJob.AddOrUpdate<{_nameBuilderUtil.AsyncEventHookHandlerName(hook)}>(handler => handler.Run(), Cron.Minutely())"));
            }

            codeNamespace.Types.Add(codeTypeDeclaration);

            return(codeNamespace);
        }
Ejemplo n.º 23
0
 public void AddNameSpace()
 {
     _nameSpace = _nameSpaceBuilderUtil.WithName("Domain").WithList().Build();
 }
Ejemplo n.º 24
0
 public void AddNameSpace()
 {
     _nameSpace = _nameSpaceBuilderUtil.WithName($"Domain.{_classModell.Name}s").Build();
 }
Ejemplo n.º 25
0
        public CodeNamespace Build(DomainClass domainClass)
        {
            var nameSpace = _nameSpaceBuilderUtil
                            .WithName($"{_nameSpace}.{domainClass.Name}s")
                            .WithList()
                            .WithTask()
                            .WithDomainEntityNameSpace(domainClass.Name)
                            .Build();

            var iface = new CodeTypeDeclaration($"I{domainClass.Name}Repository")
            {
                IsInterface = true
            };

            var createMethod = new CodeMemberMethod
            {
                Name       = $"Create{domainClass.Name}",
                ReturnType = new CodeTypeReference("Task")
            };

            createMethod.Parameters.Add(new CodeParameterDeclarationExpression {
                Type = new CodeTypeReference(domainClass.Name), Name = domainClass.Name.ToLower()
            });
            iface.Members.Add(createMethod);


            var updateMethod = new CodeMemberMethod
            {
                Name       = $"Update{domainClass.Name}",
                ReturnType = new CodeTypeReference("Task")
            };

            updateMethod.Parameters.Add(new CodeParameterDeclarationExpression {
                Type = new CodeTypeReference(domainClass.Name), Name = domainClass.Name.ToLower()
            });
            iface.Members.Add(updateMethod);

            var getByIdMethod = new CodeMemberMethod
            {
                Name       = $"Get{domainClass.Name}",
                ReturnType = new CodeTypeReference($"Task<{domainClass.Name}>")
            };

            getByIdMethod.Parameters.Add(new CodeParameterDeclarationExpression {
                Type = new CodeTypeReference("Guid"), Name = "id"
            });
            iface.Members.Add(getByIdMethod);

            var getAllMethod = new CodeMemberMethod
            {
                Name       = $"Get{domainClass.Name}s",
                ReturnType = new CodeTypeReference($"Task<List<{domainClass.Name}>>")
            };

            iface.Members.Add(getAllMethod);
            nameSpace.Types.Add(iface);

            iface.Members.AddRange(MakeGetParentMethods(domainClass));

            return(nameSpace);
        }