private static void EnsureFileHeaderIsValid( int templateCode, string fileName, ElementDescriptorType elementDescriptorType, Stream inputStream) { var fileFormat = DetectFileFormat(fileName); switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: BitmapImageValidator.ValidateBitmapImageHeader(templateCode, fileFormat, inputStream); break; case ElementDescriptorType.VectorImage: VectorImageValidator.ValidateVectorImageHeader(templateCode, fileFormat, inputStream); break; case ElementDescriptorType.Article: break; case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Not binary element descriptor type {elementDescriptorType}"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }
public void ValidOriginalSize(int width, int height, int minWidth, int minHeight, int maxWidth, int maxHeight) { var image = CreateImage(width, height, new PngEncoder()); const FileFormat PngFormat = FileFormat.Png; var constraints = CreateConstraints(minWidth, minHeight, maxWidth, maxHeight, PngFormat); BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, PngFormat, image); }
public void ValidOriginalFormat(FileFormat format) { var encoder = GetEncoder(format); var image = CreateImage(5, 5, encoder); var constraints = CreateConstraints(1, 1, 10, 10, format); BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, format, image); }
private static void EnsureFileHeaderIsValid( int templateCode, ElementDescriptorType elementDescriptorType, IElementConstraints elementConstraints, Stream inputStream, IUploadedFileMetadata uploadedFileMetadata) { var fileFormat = DetectFileFormat(uploadedFileMetadata.FileName); switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: BitmapImageValidator.ValidateBitmapImageHeader(templateCode, (BitmapImageElementConstraints)elementConstraints, fileFormat, inputStream); break; case ElementDescriptorType.CompositeBitmapImage: if (uploadedFileMetadata.FileType == FileType.SizeSpecificBitmapImage) { var imageMetadata = (UploadedImageMetadata)uploadedFileMetadata; BitmapImageValidator.ValidateSizeSpecificBitmapImageHeader( templateCode, (CompositeBitmapImageElementConstraints)elementConstraints, fileFormat, inputStream, imageMetadata.Size); } else { BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader( templateCode, (CompositeBitmapImageElementConstraints)elementConstraints, fileFormat, inputStream); } break; case ElementDescriptorType.VectorImage: VectorImageValidator.ValidateVectorImageHeader(templateCode, fileFormat, inputStream); break; case ElementDescriptorType.Article: break; case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Not binary element descriptor type {elementDescriptorType}"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }
public void ValidOriginalSize(int width, int height, int minWidth, int minHeight, int maxWidth, int maxHeight) { using (var image = TestHelpers.CreateImage(width, height, new PngEncoder())) { const FileFormat PngFormat = FileFormat.Png; var constraints = CreateConstraints(minWidth, minHeight, maxWidth, maxHeight, PngFormat); BitmapImageValidator.ValidateSizeRangedBitmapImageHeader(1, constraints, PngFormat, image); } }
public void InvalidOriginalSize(int width, int height, int minWidth, int minHeight, int maxWidth, int maxHeight) { var image = CreateImage(width, height, new GifEncoder()); const FileFormat GifFormat = FileFormat.Gif; var constraints = CreateConstraints(minWidth, minHeight, maxWidth, maxHeight, GifFormat); var ex = Assert.Throws <InvalidBinaryException>(() => BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, GifFormat, image)); Assert.IsType <ImageSizeOutOfRangeError>(ex.Error); }
public void InvalidOriginalFormat(FileFormat expectedFormat, FileFormat actualFormat) { var encoder = GetEncoder(actualFormat); var image = CreateImage(5, 5, encoder); var constraints = CreateConstraints(1, 1, 10, 10, expectedFormat); var ex = Assert.Throws <InvalidBinaryException>(() => BitmapImageValidator.ValidateCompositeBitmapImageOriginalHeader(1, constraints, actualFormat, image)); Assert.IsType <BinaryInvalidFormatError>(ex.Error); }
public void ValidOriginalFormat(FileFormat format) { var encoder = TestHelpers.GetImageEncoder(format); using (var image = TestHelpers.CreateImage(5, 5, encoder)) { var constraints = CreateConstraints(1, 1, 10, 10, format); BitmapImageValidator.ValidateSizeRangedBitmapImageHeader(1, constraints, format, image); } }
public void InvalidOriginalFormat(FileFormat expectedFormat, FileFormat actualFormat) { var encoder = TestHelpers.GetImageEncoder(actualFormat); using (var image = TestHelpers.CreateImage(5, 5, encoder)) { var constraints = CreateConstraints(1, 1, 10, 10, expectedFormat); var ex = Assert.Throws <InvalidBinaryException>(() => BitmapImageValidator.ValidateSizeRangedBitmapImageHeader(1, constraints, actualFormat, image)); Assert.IsType <BinaryInvalidFormatError>(ex.Error); } }
public void ValidSizeSpecificImage() { var width = 5; var height = 5; var image = CreateImage(width, height, new GifEncoder()); const FileFormat GifFormat = FileFormat.Gif; var constraints = CreateConstraints(1, 1, 10, 10, GifFormat); BitmapImageValidator.ValidateSizeSpecificBitmapImageHeader(1, constraints, GifFormat, image, new ImageSize { Width = width, Height = height }); }
public void ValidImage(FileFormat format) { var width = 5; var height = 5; var encoder = TestHelpers.GetImageEncoder(format); using (var image = TestHelpers.CreateImage(width, height, encoder)) { var constraints = CreateConstraints(1, 1, 10, 10, format); BitmapImageValidator.ValidateSizeRangedBitmapImageHeader(1, constraints, format, image); } }
public void SizeSpecificImageSizeNotEqualToTargetSize() { using (var image = TestHelpers.CreateImage(5, 5, new PngEncoder())) { const FileFormat PngFormat = FileFormat.Png; var constraints = CreateConstraints(1, 1, 10, 10, PngFormat); var ex = Assert.Throws <InvalidBinaryException>( () => BitmapImageValidator.ValidateSizeSpecificBitmapImageHeader(1, constraints, PngFormat, image, new ImageSize { Width = 4, Height = 4 })); Assert.IsType <SizeSpecificImageTargetSizeNotEqualToActualSizeError>(ex.Error); } }
public void NotSquaredSizeSpecificImage() { var width = 5; var height = 4; using (var image = TestHelpers.CreateImage(width, height, new JpegEncoder())) { const FileFormat JpegFormat = FileFormat.Jpeg; var constraints = CreateConstraints(1, 1, 10, 10, JpegFormat); var ex = Assert.Throws <InvalidBinaryException>( () => BitmapImageValidator.ValidateSizeSpecificBitmapImageHeader(1, constraints, JpegFormat, image, new ImageSize { Width = width, Height = height })); Assert.IsType <SizeSpecificImageIsNotSquareError>(ex.Error); } }
public static void EnsureFileContentIsValid( int templateCode, ElementDescriptorType elementDescriptorType, IElementConstraints elementConstraints, Stream inputStream, string fileName) { switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: BitmapImageValidator.ValidateBitmapImage(templateCode, (BitmapImageElementConstraints)elementConstraints, inputStream); break; case ElementDescriptorType.VectorImage: var fileFormat = DetectFileFormat(fileName); VectorImageValidator.ValidateVectorImage(templateCode, fileFormat, (VectorImageElementConstraints)elementConstraints, inputStream); break; case ElementDescriptorType.Article: ArticleValidator.ValidateArticle(templateCode, inputStream); break; case ElementDescriptorType.CompositeBitmapImage: break; case ElementDescriptorType.ScalableBitmapImage: break; case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Specified element descriptor type '{elementDescriptorType}' is non-binary"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }
private static string EnsureFileContentIsValid( int templateCode, string fileName, ElementDescriptorType elementDescriptorType, IElementConstraints elementConstraints, Stream inputStream) { switch (elementDescriptorType) { case ElementDescriptorType.BitmapImage: return(BitmapImageValidator.ValidateBitmapImage(templateCode, (BitmapImageElementConstraints)elementConstraints, inputStream)); case ElementDescriptorType.VectorImage: { var fileFormat = DetectFileFormat(fileName); VectorImageValidator.ValidateVectorImage(templateCode, fileFormat, (VectorImageElementConstraints)elementConstraints, inputStream); return(ContentTypesMap[fileFormat]); } case ElementDescriptorType.Article: ArticleValidator.ValidateArticle(templateCode, inputStream); return(ContentTypesMap[FileFormat.Chm]); case ElementDescriptorType.PlainText: case ElementDescriptorType.FormattedText: case ElementDescriptorType.FasComment: case ElementDescriptorType.Link: case ElementDescriptorType.Phone: case ElementDescriptorType.VideoLink: case ElementDescriptorType.Color: throw new NotSupportedException($"Not binary element descriptor type {elementDescriptorType}"); default: throw new ArgumentOutOfRangeException(nameof(elementDescriptorType), elementDescriptorType, "Unsupported element descriptor type"); } }