コード例 #1
0
        /// <summary>
        /// Validates information supplied to create a new image.
        /// </summary>
        /// <param name="model">Create image details.</param>
        /// <param name="keyPrefix">Validation key prefix.</param>
        /// <returns>Width and height of image.</returns>
        public Size?ValidateCreateImage(CreateUploadModel model, string keyPrefix)
        {
            // Perform generic upload checks
            ValidateCreateUpload(model, keyPrefix);

            // Check that upload is image
            Size?size = _imageAnalysisService.GetImageDimensions(model.Content);

            if (size == null)
            {
                throw new ValidationErrorException(new ValidationError(UploadPropertyNames.Content, UploadResource.ImageInvalidMessage, keyPrefix));
            }

            // Return dimensions of image
            return(size);
        }
コード例 #2
0
        public Size ValidatePrepareImages(long tenantId, long masterPageId, CreateUploadModel model, string keyPrefix = null)
        {
            // Check that content type identifies an image
            UploadType uploadType = _uploadService.GetUploadType(model.ContentType);

            if (uploadType != UploadType.Image)
            {
                throw new ValidationErrorException(new ValidationError(HtmlPropertyNames.Image, ElementResource.HtmlImageInvalidMessage, keyPrefix));
            }

            // Check that supplied upload is an image
            Size?size = _imageAnalysisService.GetImageDimensions(model.Content);

            if (size == null)
            {
                throw new ValidationErrorException(new ValidationError(HtmlPropertyNames.Image, ElementResource.HtmlImageInvalidMessage, keyPrefix));
            }

            // Return result
            return(size.Value);
        }
コード例 #3
0
        /// <summary>
        /// Validates avatar upload details before images can be prepared for a user.
        /// </summary>
        /// <param name="tenantId">Website that user belongs to.</param>
        /// <param name="model">Uploaded image.</param>
        /// <param name="keyPrefix">Validation key prefix.</param>
        /// <returns>Useful information retrieved during validation.</returns>
        public AuthenticationValidateResult ValidatePrepareImages(long tenantId, CreateUploadModel model, string keyPrefix = null)
        {
            // Check that website allows avatars
            Web web = _webRepository.Read(tenantId);

            if (!web.UserHasImage)
            {
                throw new ValidationErrorException(new ValidationError(AuthenticationPropertyNames.Image, AuthenticationResource.UpdateUserImageNotAllowedMessage, keyPrefix));
            }

            // Check that content type identifies an image
            UploadType uploadType = _uploadService.GetUploadType(model.ContentType);

            if (uploadType != UploadType.Image)
            {
                throw new ValidationErrorException(new ValidationError(AuthenticationPropertyNames.Image, AuthenticationResource.UpdateUserImageInvalidMessage, keyPrefix));
            }

            // Check that supplied upload is an image
            Size?size = _imageAnalysisService.GetImageDimensions(model.Content);

            if (size == null)
            {
                throw new ValidationErrorException(new ValidationError(AuthenticationPropertyNames.Image, AuthenticationResource.UpdateUserImageInvalidMessage, keyPrefix));
            }

            // Check image dimension constraints (minimum width and height)
            if (size.Value.Width < web.UserImageMinWidth.Value || size.Value.Height < web.UserImageMinHeight.Value)
            {
                throw new ValidationErrorException(new ValidationError(AuthenticationPropertyNames.Image, string.Format(AuthenticationResource.UpdateUserImageDimensionsInvalidMessage, web.UserImageMinWidth.Value, web.UserImageMinHeight.Value), keyPrefix));
            }

            // Return result
            return(new AuthenticationValidateResult {
                Web = web, Size = size.Value
            });
        }
コード例 #4
0
        /// <summary>
        /// Validates page, master page and file upload details before images can be prepared for a page.
        /// </summary>
        /// <param name="tenantId">Website that page belongs to.</param>
        /// <param name="masterPageId">Master page containing image upload rules.</param>
        /// <param name="model">Uploaded image.</param>
        /// <param name="keyPrefix">Validation key prefix.</param>
        /// <returns>Useful information retrieved during validation.</returns>
        public ValidatePrepareImagesResult ValidatePrepareImages(long tenantId, long masterPageId, CreateUploadModel model, string keyPrefix = null)
        {
            // Check that master page associated with page allows images
            MasterPage masterPage = _masterPageRepository.Read(tenantId, masterPageId);

            if (!masterPage.HasImage)
            {
                throw new ValidationErrorException(new ValidationError(PagePropertyNames.Image, PageResource.ImageNotAllowedMessage, keyPrefix));
            }

            // Check that content type identifies an image
            UploadType uploadType = _uploadService.GetUploadType(model.ContentType);

            if (uploadType != UploadType.Image)
            {
                throw new ValidationErrorException(new ValidationError(PagePropertyNames.Image, PageResource.ImageInvalidMessage, keyPrefix));
            }

            // Check that supplied upload is an image
            Size?size = _imageAnalysisService.GetImageDimensions(model.Content);

            if (size == null)
            {
                throw new ValidationErrorException(new ValidationError(PagePropertyNames.Image, PageResource.ImageInvalidMessage, keyPrefix));
            }

            // Check image dimension constraints (minimum width and height)
            if (size.Value.Width < masterPage.ImageMinWidth.Value || size.Value.Height < masterPage.ImageMinHeight.Value)
            {
                throw new ValidationErrorException(new ValidationError(PagePropertyNames.Image, string.Format(PageResource.ImageDimensionsInvalidMessage, masterPage.ImageMinWidth.Value, masterPage.ImageMinHeight.Value), keyPrefix));
            }

            // Return result
            return(new ValidatePrepareImagesResult {
                MasterPage = masterPage, Size = size.Value
            });
        }
コード例 #5
0
        public void ValidatePrepareImages(long tenantId, long elementId, CreateUploadModel model, string keyPrefix = null)
        {
            // Check that content type identifies an image
            UploadType uploadType = _uploadService.GetUploadType(model.ContentType);

            if (uploadType != UploadType.Image)
            {
                throw new ValidationErrorException(new ValidationError(CarouselPropertyNames.Image, ElementResource.CarouselImageInvalidMessage, keyPrefix));
            }

            // Check that supplied upload is an image
            Size?size = _imageAnalysisService.GetImageDimensions(model.Content);

            if (size == null)
            {
                throw new ValidationErrorException(new ValidationError(CarouselPropertyNames.Image, ElementResource.CarouselImageInvalidMessage, keyPrefix));
            }

            // Check image dimension constraints (minimum width and height)
            if (size.Value.Width < ImageMinWidth || size.Value.Height < ImageMinHeight)
            {
                throw new ValidationErrorException(new ValidationError(CarouselPropertyNames.Image, string.Format(ElementResource.CarouselImageDimensionsInvalidMessage, ImageMinWidth, ImageMinHeight), keyPrefix));
            }
        }