Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the OpenXmlValidator.
        /// </summary>
        /// <param name="fileFormat">The target file format to be validated against.</param>
        /// <remarks>
        /// Default to FileFormat.Office2007.
        /// </remarks>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when the <paramref name="fileFormat"/> parameter is not a known format.</exception>
        public OpenXmlValidator(FileFormatVersions fileFormat)
        {
            fileFormat.ThrowExceptionIfFileFormatNotSupported(nameof(fileFormat));

            _settings = new ValidationSettings(fileFormat);
            _cache    = new ValidationCache(fileFormat);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Validate the specified part.
        /// </summary>
        /// <param name="part">The OpenXmlPart to be validated.</param>
        /// <param name="settings">The settings to be used during validation.</param>
        /// <returns></returns>
        public List <ValidationErrorInfo> Validate(OpenXmlPart part, ValidationSettings settings)
        {
            var context = new ValidationContext(settings, _cache);

            ValidatePart(part, context);

            return(context.Errors);
        }
Ejemplo n.º 3
0
        public ValidationContext(ValidationSettings settings, ValidationCache cache)
        {
            Cache     = cache ?? throw new ArgumentNullException(nameof(cache));
            Settings  = settings ?? throw new ArgumentNullException(nameof(settings));
            Errors    = new List <ValidationErrorInfo>();
            McContext = new MCContext(false);

            // Start off with a depth of 5
            _elements = new Stack <CurrentElement>(5);
            _elements.Push(new CurrentElement(null, default, false, Errors.Add));
Ejemplo n.º 4
0
        public ValidationContext(ValidationSettings settings, ValidationCache cache)
        {
            Cache     = cache ?? throw new ArgumentNullException(nameof(cache));
            Settings  = settings ?? throw new ArgumentNullException(nameof(settings));
            Errors    = new List <ValidationErrorInfo>();
            McContext = new MCContext(false);

            Stack = new ValidationStack();

            Stack.Push(Errors.Add);
        }
Ejemplo n.º 5
0
        public ValidationContext(ValidationSettings settings, ValidationCache cache, CancellationToken token)
        {
            _token = token;

            Cache     = cache ?? throw new ArgumentNullException(nameof(cache));
            Settings  = settings ?? throw new ArgumentNullException(nameof(settings));
            Errors    = new List <ValidationErrorInfo>();
            McContext = new MCContext(false);

            Stack = new ValidationStack();
            State = new StateManager(this);

            Stack.Push(Errors.Add);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Validate the specified document.
        /// </summary>
        /// <param name="document">The document to be validated.</param>
        /// <param name="settings">The settings to be used during validation.</param>
        /// <returns>Return results in ValidationResult.</returns>
        public List <ValidationErrorInfo> Validate(OpenXmlPackage document, ValidationSettings settings)
        {
            var context = new ValidationContext(settings, _cache);

            using (context.Stack.Push(document))
            {
                // integrate the package validation.
                ValidatePackageStructure(document, context);

                foreach (var part in PartsToBeValidated(document))
                {
                    // traverse from the part root element (by DOM or by Reader) in post-order
                    // that means validate the children first, then validate the parent
                    // the validation engine call bookkeep information
                    ValidatePart(part, context);
                }
            }

            return(context.Errors);
        }
 /// <summary>
 /// Initializes a new instance of the WordprocessingDocumentValidator.
 /// </summary>
 /// <param name="settings">The validation settings.</param>
 /// <param name="schemaValidator">The schema validator to be used for schema validation.</param>
 /// <param name="semanticValidator">The semantic validator to be used for semantic validation.</param>
 internal WordprocessingDocumentValidator(ValidationSettings settings, SchemaValidator schemaValidator, SemanticValidator semanticValidator)
     : base(settings, schemaValidator, semanticValidator)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the DocumentValidator.
 /// </summary>
 /// <param name="settings">The validation settings.</param>
 /// <param name="schemaValidator">The schema validator to be used for schema validation.</param>
 /// <param name="semanticValidator">The semantic validator to be used for semantic validation.</param>
 internal DocumentValidator(ValidationSettings settings, SchemaValidator schemaValidator, SemanticValidator semanticValidator)
 {
     this.SchemaValidator    = schemaValidator;
     this.SemanticValidator  = semanticValidator;
     this.ValidationSettings = settings;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the DocumentValidator.
 /// </summary>
 /// <param name="settings">The validation settings.</param>
 /// <param name="schemaValidator">The schema validator to be used for schema validation.</param>
 /// <param name="semanticValidator">The semantic validator to be used for semantic validation.</param>
 public DocumentValidator(ValidationSettings settings, SchemaValidator schemaValidator, SemanticValidator semanticValidator)
 {
     _schemaValidator    = schemaValidator;
     _semanticValidator  = semanticValidator;
     _validationSettings = settings;
 }
 /// <summary>
 /// Initializes a new instance of the OpenXmlValidator.
 /// </summary>
 /// <param name="fileFormat">The target filr format to be validated aginst.</param>
 /// <remarks>
 /// Default to FileFormat.Office2007.
 /// </remarks>
 /// <exception cref="ArgumentOutOfRangeException">Thrown when the "fileFormat" parameter is not FileFormat.Office2007, FileFormat.Office2010 or FileFormat.O15.</exception>
 public OpenXmlValidator(FileFormatVersions fileFormat)
 {
     fileFormat.ThrowExceptionIfFileFormatNotSupported("fileFormat");
     this._settings = new ValidationSettings(fileFormat);
 }
 /// <summary>
 /// Initializes a new instance of the SpreadsheetDocumentValidator.
 /// </summary>
 /// <param name="settings">The validation settings.</param>
 /// <param name="schemaValidator">The schema validator to be used for schema validation.</param>
 /// <param name="semanticValidator">The semantic validator to be used for semantic validation.</param>
 internal SpreadsheetDocumentValidator(ValidationSettings settings, SchemaValidator schemaValidator, SemanticValidator semanticValidator)
     : base(settings, schemaValidator, semanticValidator)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the PresentationDocumentValidator.
 /// </summary>
 /// <param name="settings">The validation settings.</param>
 /// <param name="schemaValidator">The schema validator to be used for schema validation.</param>
 /// <param name="semanticValidator">The semantic validator to be used for semantic validation.</param>
 internal PresentationDocumentValidator(ValidationSettings settings, SchemaValidator schemaValidator, SemanticValidator semanticValidator)
     : base(settings, schemaValidator, semanticValidator)
 {
 }