Example #1
0
        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");
            }
        }
Example #2
0
        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");
            }
        }