Exemplo n.º 1
0
        private static void ValidateFieldNames(IUpsertCommand command, FieldNames?fields, string path, AddValidation e, Func <string, bool> isAllowed)
        {
            if (fields != null)
            {
                fields.Foreach((fieldName, fieldIndex) =>
                {
                    var fieldPrefix = $"{path}[{fieldIndex}]";

                    var field = command?.Fields?.FirstOrDefault(x => x.Name == fieldName);

                    if (string.IsNullOrWhiteSpace(fieldName))
                    {
                        e(Not.Defined("Field"), fieldPrefix);
                    }
                    else if (field == null && !isAllowed(fieldName))
                    {
                        e(T.Get("schemas.fieldNotInSchema"), fieldPrefix);
                    }
                    else if (field?.Properties?.IsUIProperty() == true)
                    {
                        e(T.Get("schemas.fieldCannotBeUIField"), fieldPrefix);
                    }
                });

                foreach (var duplicate in fields.Duplicates())
                {
                    if (!string.IsNullOrWhiteSpace(duplicate))
                    {
                        e(T.Get("schemas.duplicateFieldName", new { field = duplicate }), path);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static void ValidateUpsert(IUpsertCommand command, AddValidation e)
        {
            if (command.Fields?.Length > 0)
            {
                command.Fields.Foreach((field, fieldIndex) =>
                {
                    var fieldPrefix = $"Fields[{fieldIndex}]";

                    ValidateRootField(field, fieldPrefix, e);
                });

                foreach (var fieldName in command.Fields.Duplicates(x => x.Name))
                {
                    if (fieldName.IsPropertyName())
                    {
                        e(T.Get("schemas.duplicateFieldName", new { field = fieldName }), nameof(command.Fields));
                    }
                }
            }

            ValidateFieldNames(command, command.FieldsInLists, nameof(command.FieldsInLists), e, IsMetaField);
            ValidateFieldNames(command, command.FieldsInReferences, nameof(command.FieldsInReferences), e, IsNotAllowed);

            ValidateFieldRules(command.FieldRules, nameof(command.FieldRules), e);
        }
Exemplo n.º 3
0
        private static void ValidateUpsert(IUpsertCommand command, AddValidation e)
        {
            if (command.Fields?.Count > 0)
            {
                var fieldIndex  = 0;
                var fieldPrefix = string.Empty;

                foreach (var field in command.Fields)
                {
                    fieldIndex++;
                    fieldPrefix = $"Fields[{fieldIndex}]";

                    ValidateRootField(field, fieldPrefix, e);
                }

                foreach (var fieldName in command.Fields.Duplicates(x => x.Name))
                {
                    if (fieldName.IsPropertyName())
                    {
                        e($"Field '{fieldName}' has been added twice.", nameof(command.Fields));
                    }
                }
            }

            ValidateFieldNames(command, command.FieldsInLists, nameof(command.FieldsInLists), e, IsMetaField);
            ValidateFieldNames(command, command.FieldsInReferences, nameof(command.FieldsInReferences), e, IsNotAllowed);
        }
Exemplo n.º 4
0
        private static void ValidateFieldNames(IUpsertCommand command, FieldNames?fields, string path, AddValidation e, Func <string, bool> isAllowed)
        {
            if (fields != null)
            {
                var fieldIndex  = 0;
                var fieldPrefix = string.Empty;

                foreach (var fieldName in fields)
                {
                    fieldIndex++;
                    fieldPrefix = $"{path}[{fieldIndex}]";

                    var field = command?.Fields?.Find(x => x.Name == fieldName);

                    if (string.IsNullOrWhiteSpace(fieldName))
                    {
                        e(Not.Defined("Field"), fieldPrefix);
                    }
                    else if (field == null && !isAllowed(fieldName))
                    {
                        e("Field is not part of the schema.", fieldPrefix);
                    }
                    else if (field?.Properties?.IsUIProperty() == true)
                    {
                        e("Field cannot be an UI field.", fieldPrefix);
                    }
                }

                foreach (var duplicate in fields.Duplicates())
                {
                    if (!string.IsNullOrWhiteSpace(duplicate))
                    {
                        e($"Field '{duplicate}' has been added twice.", path);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public Schema BuildSchema()
        {
            IUpsertCommand self = this;

            return(self.ToSchema(Name, IsSingleton));
        }
Exemplo n.º 6
0
        public Schema BuildSchema(string name, bool isSingleton)
        {
            IUpsertCommand self = this;

            return(self.ToSchema(name, isSingleton));
        }
Exemplo n.º 7
0
        public Schema BuildSchema(string name, SchemaType type)
        {
            IUpsertCommand self = this;

            return(self.ToSchema(name, type));
        }