Esempio n. 1
0
        public override async Task ValidatedAsync(ValidateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName  = typePartDefinition.PartDefinition.Name;
                var activator = _contentPartFactory.GetTypeActivator(partName);

                var part = context.ContentItem.Get(activator.Type, typePartDefinition.Name) as ContentPart;

                if (part != null)
                {
                    var partHandlers = _contentPartHandlerResolver.GetHandlers(partName);
                    await partHandlers.InvokeAsync((handler, context, part) => handler.ValidatedAsync(context, part), context, part, _logger);

                    // TODO: This can be removed in a future release as the recommended way is to use ContentOptions.
                    // Iteratate existing handler registrations as multiple handlers maybe not be registered with ContentOptions.
                    await _partHandlers.InvokeAsync((handler, context, part) => handler.ValidatedAsync(context, part), context, part, _logger);
                }
            }
        }
Esempio n. 2
0
 public static void Fail(this ValidateContentContext context, string errorMessage, params string[] memberNames)
 {
     if (memberNames != null && memberNames.Any())
     {
         context.ContentValidateResult.Fail(new ValidationResult(errorMessage, memberNames));
     }
     else
     {
         context.ContentValidateResult.Fail(new ValidationResult(errorMessage));
     }
 }
        public override async Task ValidatedAsync(ValidateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName  = typePartDefinition.PartDefinition.Name;
                var activator = _contentPartFactory.GetTypeActivator(partName);

                var part = context.ContentItem.Get(activator.Type, typePartDefinition.Name) as ContentPart;

                if (part != null)
                {
                    var partHandlers = _contentPartHandlerResolver.GetHandlers(partName);
                    await partHandlers.InvokeAsync((handler, context, part) => handler.ValidatedAsync(context, part), context, part, _logger);
                }
            }
        }
Esempio n. 4
0
 Task IContentPartHandler.ValidatedAsync(ValidateContentContext context, ContentPart part)
 {
     return(part is TPart tpart
         ? ValidatedAsync(context, tpart)
         : Task.CompletedTask);
 }
Esempio n. 5
0
 public virtual Task ValidatedAsync(ValidateContentContext context, TPart instance) => Task.CompletedTask;
Esempio n. 6
0
 public static void Fail(this ValidateContentContext context, ValidationResult error)
 {
     context.ContentValidateResult.Fail(error);
 }
 public virtual Task ValidatedAsync(ValidateContentContext context)
 {
     return(Task.CompletedTask);
 }