当前位置: 首页>>代码示例>>C#>>正文


C# Validation.ValidationContext类代码示例

本文整理汇总了C#中DocumentFormat.OpenXml.Validation.ValidationContext的典型用法代码示例。如果您正苦于以下问题:C# ValidationContext类的具体用法?C# ValidationContext怎么用?C# ValidationContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ValidationContext类属于DocumentFormat.OpenXml.Validation命名空间,在下文中一共展示了ValidationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            string minAttributeValue = context.Element.GetAttributeValueEx(_minAttributeLocalName, _minAttributeNamesapce);

            double minValue;

            //If value cannot be converted into double, that means attribute type is not correct.
            //That's job of schema validation, semantic validation will do nothing to avoid throw duplicated error.
            if (!double.TryParse(minAttributeValue, out minValue))
            {
                return null;
            }

            string maxAttributeValue = context.Element.GetAttributeValueEx(_maxAttributeLocalName, _maxAttributeNamesapce);

            double maxValue;

            //If value cannot be converted into double, that means attribute type is not correct.
            //That's job of schema validation, semantic validation will do nothing to avoid throw duplicated error.
            if (!double.TryParse(maxAttributeValue, out maxValue))
            {
                return null;
            }

            if (minValue <= maxValue)
            {
                return null;
            }

            string errorId = ""; //todo: add error id
            string errorMessage = ""; //todo: add error message

            return new ValidationErrorInfo() { Id = errorId, ErrorType = ValidationErrorType.Semantic, Node = context.Element, Description = errorMessage };
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:34,代码来源:AttributeMinMaxConstraint.cs

示例2: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            if (_values == null)
            {
                return null;
            }
            
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_attribute];

            //if the attribute is omited, semantic validation will do nothing 
            if (attributeValue == null || string.IsNullOrEmpty(attributeValue.InnerText))
            {
                return null;
            }

            if (_values.Where(v => string.Compare(v, attributeValue.InnerText, !_caseSensitive, System.Globalization.CultureInfo.InvariantCulture) == 0).Count() == 0)
            {
                _values.Add(attributeValue.InnerText);
                return null;
            }

            return new ValidationErrorInfo()
            {
                Id = "Sem_UniqueAttributeValue",
                ErrorType = ValidationErrorType.Semantic,
                Node = context.Element,
                Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sem_UniqueAttributeValue,
                                            GetAttributeQualifiedName(context.Element, _attribute), attributeValue.InnerText)
            };
        }
开发者ID:RicardoLo,项目名称:Open-XML-SDK,代码行数:30,代码来源:UniqueAttributeValueConstraint.cs

示例3: GetReferencedPart

        protected static OpenXmlPart GetReferencedPart(ValidationContext context, string path)
        {
            if (path == ".")
            {
                return context.Part;
            }

            string[] parts = path.Split('/');

            if (string.IsNullOrEmpty(parts[0]))
            {
                return GetPartThroughPartPath(context.Package.Parts, parts.Skip(1).ToArray()); //absolute path
            }
            else if (parts[0] == "..")
            {
                IEnumerable<OpenXmlPart> iterator = new OpenXmlPackagePartIterator(context.Package);

                IEnumerable<OpenXmlPart> refParts = iterator.Where(p => p.Parts.Select(r => r.OpenXmlPart.PackagePart.Uri)
                                                            .Contains(context.Part.PackagePart.Uri));

                Debug.Assert(refParts.Count() == 1);

                return refParts.First();
            }
            else
            {
                return GetPartThroughPartPath(context.Part.Parts, parts); //relative path
            }
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:29,代码来源:SemanticConstraint.cs

示例4: TryMatch

 /// <summary>
 /// Try match the particle.
 /// </summary>
 /// <param name="particleMatchInfo"></param>
 /// <param name="validationContext">The context information for validation.</param>
 public override void TryMatch(ParticleMatchInfo particleMatchInfo, ValidationContext validationContext)
 {
     // maxOccurs of xsd:any can only be 1
     Debug.Assert(this.ParticleConstraint.MaxOccurs == 1);
      
     this.TryMatchOnce(particleMatchInfo, validationContext);
 }
开发者ID:ErykJaroszewicz,项目名称:Open-XML-SDK,代码行数:12,代码来源:AllParticleValidator.cs

示例5: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_attribute];

            //if the attribute is omited, semantic validation will do nothing 
            if (attributeValue == null || string.IsNullOrEmpty(attributeValue.InnerText))
            {
                return null;
            }

            int index;
            if (!int.TryParse(attributeValue, out index))
            {
                return null; //if attribute is not int, schema validation will cover this error.
            }

            if (index < GetRefElementCount(context) + _indexBase)
            {
                return null;
            }

            return new ValidationErrorInfo()
            {
                Id = "Sem_MissingIndexedElement",
                ErrorType = ValidationErrorType.Semantic,
                Node = context.Element,
                RelatedPart = this._relatedPart,
                RelatedNode = null,
                Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sem_MissingIndexedElement, 
                                            _refElementName,context.Element.LocalName, 
                                            GetAttributeQualifiedName(context.Element, _attribute), 
                                            _relatedPart == null? _refPartType : _relatedPart.PackagePart.Uri.ToString(), index)
            };
        }
开发者ID:RicardoLo,项目名称:Open-XML-SDK,代码行数:34,代码来源:IndexReferenceConstraint.cs

示例6: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_refAttribute];

            if (attributeValue == null || string.IsNullOrEmpty(attributeValue.InnerText))
            {
                return null;
            }

            if (GetReferencedAttributes(context).Contains(attributeValue.InnerText))
            {
                return null;
            }

            return new ValidationErrorInfo()
            {
                Id = "Sem_MissingReferenceElement",
                ErrorType = ValidationErrorType.Semantic,
                Node = context.Element,
                RelatedPart = this._relatedPart,
                RelatedNode = null,
                Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, 
                                            ValidationResources.Sem_MissingReferenceElement, _elementName, context.Element.LocalName, 
                                            GetAttributeQualifiedName(context.Element, _refAttribute), _relatedPart == null ? _partPath : _relatedPart.PackagePart.Uri.ToString(), attributeValue.InnerText)
            };
        }
开发者ID:ErykJaroszewicz,项目名称:Open-XML-SDK,代码行数:26,代码来源:ReferenceExistConstraint.cs

示例7: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_rIdAttribute];

            //if the attribute is omited, semantic validation will do nothing 
            if (attributeValue == null || string.IsNullOrEmpty(attributeValue.InnerText))
            {
                return null;
            }

            if (context.Part.PackagePart.RelationshipExists(attributeValue.InnerText))
            {
                return null;
            }
            else
            {
                string errorDescription = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sem_InvalidRelationshipId,
                                                        attributeValue, GetAttributeQualifiedName(context.Element, _rIdAttribute));

                return new ValidationErrorInfo()
                {
                    Id = "Sem_InvalidRelationshipId",
                    ErrorType = ValidationErrorType.Semantic,
                    Node = context.Element,
                    Description = errorDescription
                };
            }
        }
开发者ID:RicardoLo,项目名称:Open-XML-SDK,代码行数:28,代码来源:RelationshipExistConstraint.cs

示例8: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_attribute];

            //if the attribute is omited, semantic validation will do nothing 
            if (attributeValue == null || string.IsNullOrEmpty(attributeValue.InnerText))
            {
                return null;
            }

            Regex regex = new Regex(this._pattern);
            if (regex.IsMatch(attributeValue.InnerText))
            {
                return null;
            }

            string subMsg = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sch_PatternConstraintFailed, _pattern);
            return new ValidationErrorInfo()
            {
                Id = "Sem_AttributeValueDataTypeDetailed",
                ErrorType = ValidationErrorType.Schema,
                Node = context.Element,
                Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sem_AttributeValueDataTypeDetailed,
                                            GetAttributeQualifiedName(context.Element, _attribute), attributeValue.InnerText, subMsg)
            };
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:26,代码来源:AttributeValuePatternConstraint.cs

示例9: Validate

        public void Validate(ValidationContext validationContext)
        {
            Debug.Assert(validationContext != null);
            Debug.Assert(validationContext.Element != null);

            this._stopValidating = false;

            ValidationTraverser.ValidatingTraverse(validationContext, this.ValidateElement, OnContextValidationFinished, this.StopSignal);
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:9,代码来源:SemanticValidator.cs

示例10: ValidateElement

 private void ValidateElement(ValidationContext context)
 {
     if (_curReg != null)
     {
         foreach (var error in _curReg.CheckConstraints(context))
         {
             context.EmitError(error);
         }
     }
 }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:10,代码来源:SemanticValidator.cs

示例11: TryMatchOnce

        /// <summary>
        /// Try match the particle once.
        /// </summary>
        /// <param name="particleMatchInfo"></param>
        /// <param name="validationContext">The context information for validation.</param>
        public override void TryMatchOnce(ParticleMatchInfo particleMatchInfo, ValidationContext validationContext)
        {
            Debug.Assert(!(particleMatchInfo.StartElement is OpenXmlMiscNode));
            
            var next = particleMatchInfo.StartElement;

            particleMatchInfo.LastMatchedElement = null;
            particleMatchInfo.Match = ParticleMatch.Nomatch;

            ParticleConstraint childConstraint;
            int constraintIndex = 0;
            int constraintTotal = this.ParticleConstraint.ChildrenParticles.Length;

            while (constraintIndex < constraintTotal && next != null)
            {
                childConstraint = this.ParticleConstraint.ChildrenParticles[constraintIndex];

                // Use Reset() instead of new() to avoid heavy memory alloction and GC.
                _childMatchInfo.Reset(next);

                childConstraint.ParticleValidator.TryMatch(_childMatchInfo, validationContext);

                // if the _childMatchInfo.StartElement is changed, it means this method of this object is called more than once on the stack.
                Debug.Assert(_childMatchInfo.StartElement == next);

                switch (_childMatchInfo.Match)
                {
                    case ParticleMatch.Nomatch:
                        // continue trying match next child constraint.
                        constraintIndex++;
                        break;

                    case ParticleMatch.Matched:
                        particleMatchInfo.Match = ParticleMatch.Matched;
                        particleMatchInfo.LastMatchedElement = _childMatchInfo.LastMatchedElement;
                        return;

                    case ParticleMatch.Partial:
                        // partial match, incomplete children.
                        particleMatchInfo.Match = ParticleMatch.Partial;
                        particleMatchInfo.LastMatchedElement = _childMatchInfo.LastMatchedElement;
                        if (validationContext.CollectExpectedChildren)
                        {
                            particleMatchInfo.SetExpectedChildren(_childMatchInfo.ExpectedChildren);
                        }
                        return;
                }
            }

            // no match
            Debug.Assert(particleMatchInfo.Match == ParticleMatch.Nomatch);
            return;
        }
开发者ID:RicardoLo,项目名称:Open-XML-SDK,代码行数:58,代码来源:ChoiceParticleValidator.cs

示例12: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlSimpleType attributeValue = context.Element.Attributes[_requiredAttribute];

            if (attributeValue != null)
            {
                return null;
            }

            OpenXmlSimpleType conditionAttributeValue = context.Element.Attributes[_conditionAttribute];

            if (conditionAttributeValue == null)
            {
                return null;
            }

            foreach (string value in _values)
            {
                if (AttributeValueEquals(conditionAttributeValue, value, false))
                {
                    string valueString = "'" + _values[0] + "'";

                    if (_values.Length > 1)
                    {
                        for (int i = 1; i < _values.Length - 1; i++)
                        {
                            valueString += ", '" + _values[i] + "'";
                        }

                        valueString += " or '" + _values[_values.Length - 1] + "'";
                    }

                    

                    return new ValidationErrorInfo()
                    {
                        Id = "Sem_AttributeRequiredConditionToValue",
                        ErrorType = ValidationErrorType.Semantic,
                        Node = context.Element,
                        Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sem_AttributeRequiredConditionToValue,
                                                    GetAttributeQualifiedName(context.Element, _requiredAttribute),                            
                                                    GetAttributeQualifiedName(context.Element, _conditionAttribute),
                                                    valueString)
                    };
                }
            }

            return null;
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:49,代码来源:AttributeRequiredConditionToValue.cs

示例13: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            OpenXmlElement parent = context.Element.Parent;

            if (parent == null)
            {
                return null;
            }

            if (parent.GetType() == this._parentType ^ !this._isValid) //TODO: (junzha) need to take ac-block into account.
            {
                return null;
            }

            return new ValidationErrorInfo() { Id = "", ErrorType = ValidationErrorType.Semantic, Node = context.Element, Description = "" };
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:16,代码来源:ParentTypeConstraint.cs

示例14: Validate

        public override ValidationErrorInfo Validate(ValidationContext context)
        {
            if (context.Element.Attributes[_attribute] != null)
            {
                return null;
            }

            return new ValidationErrorInfo() 
            { 
                Id = "Sem_MissRequiredAttribute", 
                ErrorType = ValidationErrorType.Schema, 
                Node = context.Element,
                Description = string.Format(System.Globalization.CultureInfo.CurrentUICulture, ValidationResources.Sch_MissRequiredAttribute, 
                                            GetAttributeQualifiedName(context.Element, _attribute)) 
            };
        }
开发者ID:RicardoLo,项目名称:Open-XML-SDK,代码行数:16,代码来源:AttributeCannotOmitConstraint.cs

示例15: TryMatchOnce

        // ***********************************************************
        //<xsd:group ref="..." /> is valid under <xsd:complexType>
        //<xsd:complexType name="CT_HdrFtr">
        //  <xsd:group ref="EG_BlockLevelElts" minOccurs="1" maxOccurs="unbounded" />
        //</xsd:complexType>
        // ***********************************************************

        ///// <summary>
        ///// Be called on root particle of complex type.
        ///// </summary>
        ///// <param name="validationContext"></param>
        ///// <returns></returns>
        //internal override SchemaValidationResult Validate(ValidationContext validationContext)
        //{
        //    throw new InvalidOperationException();
        //}


        /// <summary>
        /// Try match the particle once.
        /// </summary>
        /// <param name="particleMatchInfo"></param>
        /// <param name="validationContext">The context information for validation.</param>
        public override void TryMatchOnce(ParticleMatchInfo particleMatchInfo, ValidationContext validationContext)
        {
            Debug.Assert(!(particleMatchInfo.StartElement is OpenXmlMiscNode));
            
            // group only contains xsd:all, xsd:choice or xsd:sequence
            Debug.Assert(this.ParticleConstraint.ChildrenParticles.Length == 1);

            var childParticle = this.ParticleConstraint.ChildrenParticles[0];

            Debug.Assert(childParticle.ParticleType == ParticleType.All ||
                        childParticle.ParticleType == ParticleType.Choice ||
                        childParticle.ParticleType == ParticleType.Sequence);

            childParticle.ParticleValidator.TryMatch(particleMatchInfo, validationContext);

            return;
        }
开发者ID:eriawan,项目名称:Open-XML-SDK,代码行数:40,代码来源:GroupParticleValidator.cs


注:本文中的DocumentFormat.OpenXml.Validation.ValidationContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。