예제 #1
0
        private ValidationContext(
            Guid contentId,
            Guid schemaId,
            CheckContents checkContent,
            CheckContentsByIds checkContentByIds,
            CheckAssets checkAsset,
            ImmutableQueue <string> propertyPath,
            bool isOptional,
            ValidationMode mode = ValidationMode.Default)
        {
            Guard.NotNull(checkAsset);
            Guard.NotNull(checkContent);
            Guard.NotNull(checkContentByIds);

            this.propertyPath = propertyPath;

            this.checkContent      = checkContent;
            this.checkContentByIds = checkContentByIds;
            this.checkAsset        = checkAsset;
            this.contentId         = contentId;

            this.schemaId = schemaId;

            Mode = mode;

            IsOptional = isOptional;
        }
예제 #2
0
        public ReferencesValidator(IEnumerable <Guid>?schemaIds, CheckContentsByIds checkReferences)
        {
            Guard.NotNull(checkReferences, nameof(checkReferences));

            this.schemaIds = schemaIds;

            this.checkReferences = checkReferences;
        }
예제 #3
0
 public ValidationContext(
     Guid contentId,
     Guid schemaId,
     CheckContents checkContent,
     CheckContentsByIds checkContentsByIds,
     CheckAssets checkAsset)
     : this(contentId, schemaId, checkContent, checkContentsByIds, checkAsset, ImmutableQueue <string> .Empty, false)
 {
 }
예제 #4
0
        public IEnumerable <IValidator> CreateValueValidators(ValidatorContext context, IField field, ValidatorFactory createFieldValidator)
        {
            if (context.Mode == ValidationMode.Optimized)
            {
                yield break;
            }

            var isRequired = IsRequired(context, field.RawProperties);

            if (field is IField <AssetsFieldProperties> assetsField)
            {
                var checkAssets = new CheckAssets(async ids =>
                {
                    return(await assetRepository.QueryAsync(context.AppId.Id, null, Q.Empty.WithIds(ids)));
                });

                yield return(new AssetsValidator(isRequired, assetsField.Properties, checkAssets));
            }

            if (field is IField <ReferencesFieldProperties> referencesField)
            {
                var checkReferences = new CheckContentsByIds(async ids =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All));
                });

                yield return(new ReferencesValidator(isRequired, referencesField.Properties, checkReferences));
            }

            if (field is IField <NumberFieldProperties> numberField && numberField.Properties.IsUnique)
            {
                var checkUniqueness = new CheckUniqueness(async filter =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter));
                });

                yield return(new UniqueValidator(checkUniqueness));
            }

            if (field is IField <StringFieldProperties> stringField && stringField.Properties.IsUnique)
            {
                var checkUniqueness = new CheckUniqueness(async filter =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter));
                });

                yield return(new UniqueValidator(checkUniqueness));
            }
        }
예제 #5
0
        public ReferencesValidator(bool isRequired, ReferencesFieldProperties properties, CheckContentsByIds checkReferences)
        {
            Guard.NotNull(properties, nameof(properties));
            Guard.NotNull(checkReferences, nameof(checkReferences));

            this.properties = properties;

            if (isRequired || properties.MinItems != null || properties.MaxItems != null)
            {
                collectionValidator = new CollectionValidator(isRequired, properties.MinItems, properties.MaxItems);
            }

            if (!properties.AllowDuplicates)
            {
                uniqueValidator = new UniqueValuesValidator <DomainId>();
            }

            this.checkReferences = checkReferences;
        }
        public IEnumerable <IValidator> CreateValueValidators(ValidationContext context, IField field, FieldValidatorFactory createFieldValidator)
        {
            if (field is IField <AssetsFieldProperties> assetsField)
            {
                var checkAssets = new CheckAssets(async ids =>
                {
                    return(await assetRepository.QueryAsync(context.AppId.Id, new HashSet <Guid>(ids)));
                });

                yield return(new AssetsValidator(assetsField.Properties, checkAssets));
            }

            if (field is IField <ReferencesFieldProperties> referencesField)
            {
                var checkReferences = new CheckContentsByIds(async ids =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All));
                });

                yield return(new ReferencesValidator(referencesField.Properties.SchemaIds, checkReferences));
            }

            if (field is IField <NumberFieldProperties> numberField && numberField.Properties.IsUnique)
            {
                var checkUniqueness = new CheckUniqueness(async filter =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter));
                });

                yield return(new UniqueValidator(checkUniqueness));
            }

            if (field is IField <StringFieldProperties> stringField && stringField.Properties.IsUnique)
            {
                var checkUniqueness = new CheckUniqueness(async filter =>
                {
                    return(await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter));
                });

                yield return(new UniqueValidator(checkUniqueness));
            }
        }
예제 #7
0
        private ValidationContext(
            Guid contentId,
            Guid schemaId,
            CheckContents checkContent,
            CheckContentsByIds checkContentByIds,
            CheckAssets checkAsset,
            ImmutableQueue <string> propertyPath,
            bool isOptional)
        {
            Guard.NotNull(checkAsset, nameof(checkAsset));
            Guard.NotNull(checkContent, nameof(checkContent));
            Guard.NotNull(checkContentByIds, nameof(checkContentByIds));

            this.propertyPath = propertyPath;

            this.checkContent      = checkContent;
            this.checkContentByIds = checkContentByIds;
            this.checkAsset        = checkAsset;
            this.contentId         = contentId;

            this.schemaId = schemaId;

            IsOptional = isOptional;
        }