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");
            }
        }
Ejemplo n.º 2
0
        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");
            }
        }