Beispiel #1
0
        public static TCommand ToCommand <TCommand, TDto>(TDto dto, TCommand command) where TCommand : UpsertCommand where TDto : UpsertDto
        {
            SimpleMapper.Map(dto, command);

            if (dto.Properties != null)
            {
                command.Properties = new SchemaProperties();

                SimpleMapper.Map(dto.Properties, command.Properties);
            }

            if (dto.Scripts != null)
            {
                command.Scripts = new SchemaScripts();

                SimpleMapper.Map(dto.Scripts, command.Scripts);
            }

            if (dto.Fields != null)
            {
                command.Fields = new List <UpsertSchemaField>();

                foreach (var rootFieldDto in dto.Fields)
                {
                    var rootProps = rootFieldDto?.Properties.ToProperties();
                    var rootField = new UpsertSchemaField {
                        Properties = rootProps
                    };

                    SimpleMapper.Map(rootFieldDto, rootField);

                    if (rootFieldDto.Nested?.Count > 0)
                    {
                        rootField.Nested = new List <UpsertSchemaNestedField>();

                        foreach (var nestedFieldDto in rootFieldDto.Nested)
                        {
                            var nestedProps = nestedFieldDto?.Properties.ToProperties();
                            var nestedField = new UpsertSchemaNestedField {
                                Properties = nestedProps
                            };

                            SimpleMapper.Map(nestedFieldDto, nestedField);

                            rootField.Nested.Add(nestedField);
                        }
                    }

                    command.Fields.Add(rootField);
                }
            }

            return(command);
        }
        private UpsertSchemaField AddField <T>(string name) where T : FieldProperties, new()
        {
            var field = new UpsertSchemaField
            {
                Name       = name.ToCamelCase(),
                Properties = new T
                {
                    Label = name
                }
            };

            command.Fields = command.Fields ?? new List <UpsertSchemaField>();
            command.Fields.Add(field);

            return(field);
        }
Beispiel #3
0
        private static void ValidateRootField(UpsertSchemaField field, string prefix, AddValidation e)
        {
            if (field == null)
            {
                e(Not.Defined("Field"), prefix);
            }
            else
            {
                if (!field.Partitioning.IsValidPartitioning())
                {
                    e(Not.Valid("Partitioning"), $"{prefix}.{nameof(field.Partitioning)}");
                }

                ValidateField(field, prefix, e);

                if (field.Nested?.Count > 0)
                {
                    if (field.Properties is ArrayFieldProperties)
                    {
                        var nestedIndex  = 0;
                        var nestedPrefix = string.Empty;

                        foreach (var nestedField in field.Nested)
                        {
                            nestedIndex++;
                            nestedPrefix = $"{prefix}.Nested[{nestedIndex}]";

                            ValidateNestedField(nestedField, nestedPrefix, e);
                        }
                    }
                    else if (field.Nested.Count > 0)
                    {
                        e("Only array fields can have nested fields.", $"{prefix}.{nameof(field.Partitioning)}");
                    }

                    foreach (var fieldName in field.Nested.Duplicates(x => x.Name))
                    {
                        if (fieldName.IsPropertyName())
                        {
                            e($"Field '{fieldName}' has been added twice.", $"{prefix}.Nested");
                        }
                    }
                }
            }
        }
Beispiel #4
0
        private static void ValidateRootField(UpsertSchemaField field, string prefix, AddValidation e)
        {
            if (field == null)
            {
                e(Not.Defined("Field"), prefix);
            }
            else
            {
                if (!field.Partitioning.IsValidPartitioning())
                {
                    e(Not.Valid("Partitioning"), $"{prefix}.{nameof(field.Partitioning)}");
                }

                ValidateField(field, prefix, e);

                if (field.Nested?.Count > 0)
                {
                    if (field.Properties is ArrayFieldProperties)
                    {
                        var nestedIndex  = 0;
                        var nestedPrefix = string.Empty;

                        foreach (var nestedField in field.Nested)
                        {
                            nestedIndex++;
                            nestedPrefix = $"{prefix}.Nested[{nestedIndex}]";

                            ValidateNestedField(nestedField, nestedPrefix, e);
                        }
                    }
                    else if (field.Nested.Count > 0)
                    {
                        e("Only array fields can have nested fields.", $"{prefix}.{nameof(field.Partitioning)}");
                    }

                    if (field.Nested.Select(x => x.Name).Distinct().Count() != field.Nested.Count)
                    {
                        e("Fields cannot have duplicate names.", $"{prefix}.Nested");
                    }
                }
            }
        }
Beispiel #5
0
        private static void ValidateRootField(UpsertSchemaField field, string prefix, AddValidation e)
        {
            if (field == null)
            {
                e(Not.Defined("Field"), prefix);
            }
            else
            {
                if (!field.Partitioning.IsValidPartitioning())
                {
                    e(Not.Valid(nameof(field.Partitioning)), $"{prefix}.{nameof(field.Partitioning)}");
                }

                ValidateField(field, prefix, e);

                if (field.Nested?.Length > 0)
                {
                    if (field.Properties is ArrayFieldProperties)
                    {
                        field.Nested.Foreach((nestedField, nestedIndex) =>
                        {
                            var nestedPrefix = $"{prefix}.Nested[{nestedIndex}]";

                            ValidateNestedField(nestedField, nestedPrefix, e);
                        });
                    }
                    else if (field.Nested.Length > 0)
                    {
                        e(T.Get("schemas.onlyArraysHaveNested"), $"{prefix}.{nameof(field.Partitioning)}");
                    }

                    foreach (var fieldName in field.Nested.Duplicates(x => x.Name))
                    {
                        if (fieldName.IsPropertyName())
                        {
                            e(T.Get("schemas.duplicateFieldName", new { field = fieldName }), $"{prefix}.Nested");
                        }
                    }
                }
            }
        }
Beispiel #6
0
        private UpsertSchemaField AddField <T>(string name) where T : FieldProperties, new()
        {
            var field = new UpsertSchemaField
            {
                Name       = name.ToCamelCase(),
                Properties = new T
                {
                    Label = name
                }
            };

            if (command.Fields == null)
            {
                command.Fields = new[] { field };
            }
            else
            {
                command.Fields = command.Fields.Union(Enumerable.Repeat(field, 1)).ToArray();
            }

            return(field);
        }
Beispiel #7
0
 public AssetFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #8
0
 public NumberFieldBuilder(UpsertSchemaField field, UpsertCommand schema)
     : base(field, schema)
 {
 }
 public BooleanFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #10
0
 public AssetFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
Beispiel #11
0
 public BooleanFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
Beispiel #12
0
 protected FieldBuilder(UpsertSchemaField field, CreateSchema schema)
 {
     this.field  = field;
     this.schema = schema;
 }
 public DateTimeFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
Beispiel #14
0
 public DateTimeFieldBuilder(UpsertSchemaField field, UpsertCommand schema)
     : base(field, schema)
 {
 }
Beispiel #15
0
 public AssetFieldBuilder(UpsertSchemaField field, UpsertCommand schema)
     : base(field, schema)
 {
 }
Beispiel #16
0
 public NumberFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
Beispiel #17
0
 protected FieldBuilder(UpsertSchemaField field, UpsertCommand schema)
 {
     this.field  = field;
     this.schema = schema;
 }
Beispiel #18
0
 protected FieldBuilder(UpsertSchemaField field)
 {
     this.field = field;
 }
Beispiel #19
0
 public StringFieldBuilder(UpsertSchemaField field, UpsertCommand schema)
     : base(field, schema)
 {
 }
Beispiel #20
0
 public JsonFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #21
0
 public NumberFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #22
0
 public TagsFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #23
0
 public DateTimeFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #24
0
 public StringFieldBuilder(UpsertSchemaField field)
     : base(field)
 {
 }
Beispiel #25
0
 public StringFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
 public ReferencesFieldBuilder(UpsertSchemaField field, CreateSchema schema)
     : base(field, schema)
 {
 }
Beispiel #27
0
 public BooleanFieldBuilder(UpsertSchemaField field, UpsertCommand schema)
     : base(field, schema)
 {
 }