Exemple #1
0
        public async void HandleXX(CreateSchemaCommand command)
        {
            Guid gSchemaId     = new Guid("42E5B6A3-0B76-4FE7-B780-71935086B8ED");
            var  storedSchemaX = await _repository.Load <Schema>(gSchemaId, Int32.MaxValue);

            if (storedSchemaX == null)
            {
                Console.WriteLine("Item is not found. Create a new one.");
            }

            var schema = new Schema(gSchemaId); // = _repository.LoadNew<Schema>();

            schema.AddProperty("A");
            schema.AddProperty("BC");
            await _repository.Save(schema);


            // query event store for events
            var storedSchema = await _repository.Load <Schema>(gSchemaId, Int32.MaxValue);

            if (storedSchema == null)
            {
                Console.WriteLine("Item STILL not found.");
            }
            else
            {
                storedSchema.AddProperty("CD");
                await _repository.Save(storedSchema);
            }
        }
Exemple #2
0
        public override void Execute(ProjectState project, List <ActionParameter> parameters)
        {
            var schemaName       = GetStringParameterValue(parameters, NameParameter).ToWordPascalCase();
            var firstSchemaName  = GetStringParameterValue(parameters, FirstSchemaNameParameter);
            var secondSchemaName = GetStringParameterValue(parameters, SecondSchemaNameParameter);

            var firstSchema = project.GetSchema(firstSchemaName);

            if (firstSchema == null)
            {
                throw new Exception($"Can't find any schema named '{firstSchemaName}'");
            }

            var secondSchema = project.GetSchema(secondSchemaName);

            if (secondSchema == null)
            {
                throw new Exception($"Can't find any schema named '{secondSchemaName}'");
            }

            var firstAttributeName = firstSchema.Name == secondSchema.Name
                ? $"{firstSchema.Name}OneId"
                : $"{firstSchema.Name}Id";
            var secondAttributeName = firstSchema.Name == secondSchema.Name
                ? $"{secondSchema.Name}TwoId"
                : $"{secondSchema.Name}Id";

            var newSchema = new Schema(schemaName)
            {
                HasId = true, IsIntersection = true
            };

            newSchema.AddProperty(
                new SchemaProperty(firstAttributeName, SchemaProperty.PropertyTypes.ForeingKey, false));
            newSchema.AddProperty(
                new SchemaProperty(secondAttributeName, SchemaProperty.PropertyTypes.ForeingKey, false));

            //firstSchema.AddUseCase(new UseCase(UseCase.UseCaseTypes.RetrieveMultipleIntersection, newSchema));
            //secondSchema.AddUseCase(new UseCase(UseCase.UseCaseTypes.RetrieveMultipleIntersection, newSchema));
            OverrideOutputParameter(NameParameter.Name, schemaName);
        }
Exemple #3
0
        public async Task Handle(CreateSchemaCommand command)
        {
            // Define id for the new schema (assume the id doesn't exist yet)
            Guid gSchemaId = Guid.NewGuid();

            // create schema
            var schema = new Schema(gSchemaId);

            // set name
            schema.Rename(command.Name);

            // add properties
            foreach (var property in command.Properties)
            {
                schema.AddProperty(property);
            }

            // save
            await _repository.Save(schema);
        }
Exemple #4
0
        public override void Execute(ProjectState project, List <ActionParameter> parameters)
        {
            var name                = GetStringParameterValue(parameters, NameParameter).ToWordPascalCase();
            var hasState            = GetBoolParameterValue(parameters, HasStateParameter);
            var hasUserRelationship = GetBoolParameterValue(parameters, HasUserRelationshipParameter);
            var hasOwner            = GetBoolParameterValue(parameters, HasOwnerParameter);

            var domainName = GetStringParameterValue(parameters, DomainParameter);
            var domain     = project.Domains.FirstOrDefault(k => k.Name == domainName)
                             ?? throw new Exception($"Can't find domain named '{domainName}'");
            var schema = new Schema(name);

            schema.HasId = true;
            schema.AddProperty(new SchemaProperty(DefaultAttributesSchemaNames.Id, SchemaProperty.PropertyTypes.PrimaryKey, false)
            {
                IsPrimaryKey = true
            });

            if (hasState)
            {
                schema.HasState = true;
                schema.AddProperty(new SchemaProperty(DefaultAttributesSchemaNames.State, SchemaProperty.PropertyTypes.State, false));
                schema.AddProperty(new SchemaProperty(DefaultAttributesSchemaNames.Status, SchemaProperty.PropertyTypes.Status, false));
                schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.Active, false)
                                                                  .AddDefaultOutputViewParameter());
                schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.Inactive, false)
                                                                  .AddDefaultOutputViewParameter());
            }

            schema.HasDates = true;
            schema.AddProperty(new SchemaProperty(DefaultAttributesSchemaNames.CreatedOn, SchemaProperty.PropertyTypes.DateTime, false));
            schema.AddProperty(new SchemaProperty(DefaultAttributesSchemaNames.ModifiedOn, SchemaProperty.PropertyTypes.DateTime, false));

            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtYear, false)
                                                              .AddInputParameter(DomainInputType.Integer, "Year")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtMonth, false)
                                                              .AddInputParameter(DomainInputType.Integer, "Year")
                                                              .AddInputParameter(DomainInputType.Integer, "Month")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtDay, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtDayAndHour, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtDayAndHourAndMinute, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAtDayAndHourAndMinuteSecond, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnBetween, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTimeFrom")
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTimeTo")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnBefore, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedOnAfter, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtYear, false)
                                                              .AddInputParameter(DomainInputType.Integer, "Year")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtMonth, false)
                                                              .AddInputParameter(DomainInputType.Integer, "Year")
                                                              .AddInputParameter(DomainInputType.Integer, "Month")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtDay, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtDayAndHour, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtDayAndHourAndMinute, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAtDayAndHourAndMinuteSecond, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnBetween, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTimeFrom")
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTimeTo")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnBefore, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());
            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedOnAfter, false)
                                                              .AddInputParameter(DomainInputType.Datetime, "DateTime")
                                                              .AddDefaultOutputViewParameter());

            if (hasOwner)
            {
                var userSchema = project.GetSchema(Definitions.DefaultBasicDomainNames.User);
                if (userSchema == null)
                {
                    throw new Exception("Can't add user relationship because 'User' domain doesn't exists");
                }
                schema.HasOwner = true;
                schema.AddProperty(new SchemaProperty(Definitions.DefaultAttributesSchemaNames.Owner, SchemaProperty.PropertyTypes.ForeingKey, false)
                {
                    ForeingSchema = userSchema
                });

                schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.Owner, false)
                                                                  .AddInputParameter(DomainInputType.Guid, "Id")
                                                                  .AddDefaultOutputViewParameter());
            }

            if (hasUserRelationship)
            {
                var userSchema = project.GetSchema(Definitions.DefaultBasicDomainNames.User);
                if (userSchema == null)
                {
                    throw new Exception("Can't add user relationship because 'User' domain doesn't exists");
                }
                schema.HasUserRelationship = true;
                schema.AddProperty(new SchemaProperty(Definitions.DefaultAttributesSchemaNames.CreatedBy, SchemaProperty.PropertyTypes.ForeingKey, false)
                {
                    ForeingSchema = userSchema
                });
                schema.AddProperty(new SchemaProperty(Definitions.DefaultAttributesSchemaNames.ModifiedBy, SchemaProperty.PropertyTypes.ForeingKey, false)
                {
                    ForeingSchema = userSchema
                });

                schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.CreatedBy, false)
                                                                  .AddInputParameter(DomainInputType.Guid, "Id")
                                                                  .AddDefaultOutputViewParameter());
                schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.View, DefaultViewNames.ModifiedBy, false)
                                                                  .AddInputParameter(DomainInputType.Guid, "Id")
                                                                  .AddDefaultOutputViewParameter());
            }

            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.Create, DefaultRepositoryMethodNames.Create, false)
                                                              .AddInputParameter(DomainInputType.DomainEntity, "Entity")
                                                              .AddOutputParameter(DomainInputType.Guid, "Id"));

            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.DeleteByPk, DefaultRepositoryMethodNames.DeleteByPk, false)
                                                              .AddInputParameter(DomainInputType.Guid, "Id"));;

            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.Update, DefaultRepositoryMethodNames.Update, false)
                                                              .AddInputParameter(DomainInputType.DomainEntity, "Entity"));

            schema.GetDefaultRepository().AddRepositoryMethod(new RepositoryMethod(UseCase.UseCaseTypes.RetrieveByPk, DefaultRepositoryMethodNames.RetrieveByPk, false)
                                                              .AddInputParameter(DomainInputType.Guid, "Id")
                                                              .AddOutputParameter(DomainInputType.DomainEntity, "Entity"));

            var useCaseCreate       = GetCreateUseCase(domain, schema);
            var useCaseUpdate       = GetUpdateUseCase(domain, schema);
            var useCaseDeleteByPk   = GetDeleteByPkUseCase(domain, schema);
            var useCaseRetrieveByPk = GetRetrieveByPkUseCase(domain, schema);

            schema.AddUseCase(useCaseCreate);
            schema.AddUseCase(useCaseDeleteByPk);
            schema.AddUseCase(useCaseRetrieveByPk);
            schema.AddUseCase(useCaseUpdate);

            domain.AddSchema(schema);

            OverrideOutputParameter(NameParameter.Name, name);
        }