ToString() public method

public ToString ( ) : string
return string
 internal override Exception CheckValueFacets(XmlQualifiedName value, XmlSchemaDatatype datatype)
 {
     RestrictionFacets restriction = datatype.Restriction;
     RestrictionFlags flags = (restriction != null) ? restriction.Flags : ((RestrictionFlags) 0);
     if (flags != 0)
     {
         int length = value.ToString().Length;
         if (((flags & RestrictionFlags.Length) != 0) && (restriction.Length != length))
         {
             return new XmlSchemaException("Sch_LengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.MinLength) != 0) && (length < restriction.MinLength))
         {
             return new XmlSchemaException("Sch_MinLengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.MaxLength) != 0) && (restriction.MaxLength < length))
         {
             return new XmlSchemaException("Sch_MaxLengthConstraintFailed", string.Empty);
         }
         if (((flags & RestrictionFlags.Enumeration) != 0) && !this.MatchEnumeration(value, restriction.Enumeration))
         {
             return new XmlSchemaException("Sch_EnumerationConstraintFailed", string.Empty);
         }
     }
     return null;
 }
 internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas)
 {
     if (item == null)
     {
         return null;
     }
     if ((qname == null) || qname.IsEmpty)
     {
         return null;
     }
     string str = item.GetType().Name + ":" + qname.ToString();
     ArrayList list = (ArrayList) this.ObjectCache[str];
     if (list == null)
     {
         list = new ArrayList();
         this.ObjectCache[str] = list;
     }
     for (int i = 0; i < list.Count; i++)
     {
         XmlSchemaObject obj2 = (XmlSchemaObject) list[i];
         if (obj2 == item)
         {
             return obj2;
         }
         if (this.Match(obj2, item, true))
         {
             return obj2;
         }
         this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace }));
         this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string) this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string) this.looks[item]));
     }
     list.Add(item);
     return item;
 }
示例#3
0
 internal AttributeSetAction GetAttributeSet(XmlQualifiedName name) {
     AttributeSetAction action = (AttributeSetAction) this.attributeSetTable[name];
     if(action == null) {
         throw new XsltException(Res.Xslt_NoAttributeSet, name.ToString());
     }
     return action;
 }
示例#4
0
        XmlSchemaComplexType GetSchemaComplexType(XmlSchemaSet schemas, QName qname)
        {
            XmlSchemaComplexType type = schemas.GlobalTypes [qname] as XmlSchemaComplexType;

            Assert.IsNotNull(type, "ComplexType " + qname.ToString() + " not found.");

            return(type);
        }
示例#5
0
        // --------------------------- XsltContext -------------------
        //                Resolving variables and functions

        /// <include file='doc\XsltCompileContext.uex' path='docs/doc[@for="XsltCompileContext.ResolveVariable"]/*' />
        public override IXsltContextVariable ResolveVariable(string prefix, string name) {
            string namespaceURI = this.LookupNamespace(prefix);
            XmlQualifiedName qname = new XmlQualifiedName(name, namespaceURI);
            IXsltContextVariable variable = this.manager.VariableScope.ResolveVariable(qname);
            if (variable == null) {
                throw new XPathException(Res.Xslt_InvalidVariable, qname.ToString());
            }
            return variable;
        }
示例#6
0
        //Check the <element .. > in a sequence
        void CheckElementReference(XmlSchemaObject obj, string name, QName schema_type, bool nillable)
        {
            XmlSchemaElement element = obj as XmlSchemaElement;

            Assert.IsNotNull(element, "XmlSchemaElement not found for " + schema_type.ToString());

            Assert.AreEqual(name, element.Name, "#v1, Element name did not match");
            //FIXME: Assert.AreEqual (0, element.MinOccurs, "#v0, MinOccurs should be 0 for element '" + name + "'");
            Assert.AreEqual(schema_type, element.SchemaTypeName, "#v2, SchemaTypeName for element '" + element.Name + "' did not match.");
            Assert.AreEqual(nillable, element.IsNillable, "#v3, Element '" + element.Name + "', schema type = '" + schema_type + "' should have nillable = " + nillable);
        }
示例#7
0
        void resolveElement(QName qname, List <MessagePartDescription> parts, string ns)
        {
            XmlSchemaElement element = (XmlSchemaElement)xml_schemas.Find(qname, typeof(XmlSchemaElement));

            if (element == null)
            {
                //FIXME: What to do here?
                throw new Exception("Could not resolve : " + qname.ToString());
            }

            resolveParticle(schema_importer, element, parts, ns, 2);
        }
示例#8
0
        /// <summary>
        /// Gets the root element metadata for the reader's current XML node</summary>
        /// <param name="reader">XML reader</param>
        /// <param name="rootUri">URI of XML data</param>
        /// <returns>Root element metadata for the reader's current XML node</returns>
        protected override ChildInfo CreateRootElement(XmlReader reader, Uri rootUri)
        {
            ColladaSchemaTypeLoader colladaSchemaTypeLoader = TypeLoader as ColladaSchemaTypeLoader;

            if (colladaSchemaTypeLoader == null)
                return base.CreateRootElement(reader, rootUri);

            XmlQualifiedName rootElementName =
                new XmlQualifiedName(reader.LocalName, colladaSchemaTypeLoader.Namespace);

            return TypeLoader.GetRootElement(rootElementName.ToString());
        }
		void ImportPartsBySchemaElement (QName qname, List<MessagePartDescription> parts, string ns)
		{
			XmlSchemaElement element = (XmlSchemaElement) schema_set_in_use.GlobalElements [qname];
			if (element == null)
				//FIXME: What to do here?
				throw new Exception ("Could not resolve : " + qname.ToString ());

			var ct = element.ElementSchemaType as XmlSchemaComplexType;
			if (ct == null) // simple type
				parts.Add (CreateMessagePart (element));
			else // complex type
				foreach (var elem in GetElementsInParticle (ct.ContentTypeParticle))
					parts.Add (CreateMessagePart (elem));
		}
        /// <summary>
        /// Associates a local operation with the incoming method.
        /// </summary>
        /// <returns>
        /// The name of the operation to be associated with the <paramref name="message"/>.
        /// </returns>
        /// <param name="message">
        /// The incoming <see cref="T:System.ServiceModel.Channels.Message"/> to be associated with an
        ///     operation.
        /// </param>
        public string SelectOperation(ref Message message)
        {
            XmlDictionaryReader bodyReader = message.GetReaderAtBodyContents();
            var lookupQName = new XmlQualifiedName(bodyReader.LocalName, bodyReader.NamespaceURI);
            message = CreateMessageCopy(message, bodyReader);
            if (this._dispatchDictionary.ContainsKey(lookupQName))
            {
                return this._dispatchDictionary[lookupQName];
            }

            if (this._defaultOperationName == null)
            {
                throw new WebFaultException<string>(lookupQName.ToString(), HttpStatusCode.BadRequest);
            }

            return this._defaultOperationName;
        }
 private XmlSchemaSimpleType FindDataType(XmlQualifiedName name)
 {
     TypeDesc typeDesc = base.Scope.GetTypeDesc(name.Name, name.Namespace);
     if ((typeDesc != null) && (typeDesc.DataType is XmlSchemaSimpleType))
     {
         return (XmlSchemaSimpleType) typeDesc.DataType;
     }
     XmlSchemaSimpleType type = (XmlSchemaSimpleType) base.Schemas.Find(name, typeof(XmlSchemaSimpleType));
     if (type != null)
     {
         return type;
     }
     if (name.Namespace != "http://www.w3.org/2001/XMLSchema")
     {
         throw new InvalidOperationException(Res.GetString("XmlMissingDataType", new object[] { name.ToString() }));
     }
     return (XmlSchemaSimpleType) base.Scope.GetTypeDesc(typeof(string)).DataType;
 }
示例#12
0
 /// <summary>
 /// Gets the root element metadata for the reader's current XML node</summary>
 /// <param name="reader">XML reader</param>
 /// <param name="rootUri">URI of XML data</param>
 /// <returns>Root element metadata for the reader's current XML node</returns>
 protected override ChildInfo CreateRootElement(XmlReader reader, Uri rootUri)
 {
     // ignore the ATGI version in the document, and use the loaded ATGI schema instead
     AtgiSchemaTypeLoader atgiSchemaTypeLoader = TypeLoader as AtgiSchemaTypeLoader;
     if (atgiSchemaTypeLoader != null)
     {
         XmlQualifiedName rootElementName =
             new XmlQualifiedName(reader.LocalName, atgiSchemaTypeLoader.Namespace);
         ChildInfo rootElement = TypeLoader.GetRootElement(rootElementName.ToString());
         // ID passed to TypeLoader.GetRootElement must be same format as in XmlSchemaTypeLoader.Load(XmlSchemaSet)
         // In XmlSchemaTypeLoader.cs look for "string name = element.QualifiedName.ToString();"
         return rootElement;
     }
     else
     {
         return base.CreateRootElement(reader, rootUri);
     }
 }
示例#13
0
        protected override void ImportPartsBySchemaElement(QName qname, List <MessagePartDescription> parts, Message msg, MessagePart part)
        {
            XmlSchemaElement element = (XmlSchemaElement)schema_set_in_use.GlobalElements [qname];

            if (element == null)
            {
                throw new InvalidOperationException("Could not resolve : " + qname.ToString());                   // this should have been rejected by CanImportOperation().
            }
            var ct = element.ElementSchemaType as XmlSchemaComplexType;

            if (ct == null)             // simple type
            {
                parts.Add(CreateMessagePart(element, msg, part));
            }
            else             // complex type
            {
                foreach (var elem in GetElementsInParticle(ct.ContentTypeParticle))
                {
                    parts.Add(CreateMessagePart(elem, msg, part));
                }
            }
        }
 private SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle)
 {
     SchemaElementDecl elementDecl = null;
     if (particle != null)
     {
         XmlSchemaElement element = particle as XmlSchemaElement;
         if (element != null)
         {
             elementDecl = element.ElementDecl;
         }
         else
         {
             XmlSchemaAny any = (XmlSchemaAny) particle;
             this.processContents = any.ProcessContentsCorrect;
         }
     }
     if ((elementDecl != null) || (this.processContents == XmlSchemaContentProcessing.Skip))
     {
         return elementDecl;
     }
     if (this.isRoot && (this.partialValidationType != null))
     {
         if (this.partialValidationType is XmlSchemaElement)
         {
             XmlSchemaElement partialValidationType = (XmlSchemaElement) this.partialValidationType;
             if (elementName.Equals(partialValidationType.QualifiedName))
             {
                 return partialValidationType.ElementDecl;
             }
             this.SendValidationEvent("Sch_SchemaElementNameMismatch", elementName.ToString(), partialValidationType.QualifiedName.ToString());
             return elementDecl;
         }
         if (this.partialValidationType is XmlSchemaType)
         {
             XmlSchemaType type = (XmlSchemaType) this.partialValidationType;
             return type.ElementDecl;
         }
         this.SendValidationEvent("Sch_ValidateElementInvalidCall", string.Empty);
         return elementDecl;
     }
     return this.compiledSchemaInfo.GetElementDecl(elementName);
 }
 private object ValidateElementContext(XmlQualifiedName elementName, out bool invalidElementInContext)
 {
     object element = null;
     int errorCode = 0;
     XmlSchemaElement substitutionGroupHead = null;
     invalidElementInContext = false;
     if (!this.context.NeedValidateChildren)
     {
         return element;
     }
     if (this.context.IsNill)
     {
         this.SendValidationEvent("Sch_ContentInNill", QNameString(this.context.LocalName, this.context.Namespace));
         return null;
     }
     if ((this.context.ElementDecl.ContentValidator.ContentType == XmlSchemaContentType.Mixed) && (this.context.ElementDecl.Presence == SchemaDeclBase.Use.Fixed))
     {
         this.SendValidationEvent("Sch_ElementInMixedWithFixed", QNameString(this.context.LocalName, this.context.Namespace));
         return null;
     }
     XmlQualifiedName qualifiedName = elementName;
     bool flag = false;
 Label_00AA:
     element = this.context.ElementDecl.ContentValidator.ValidateElement(qualifiedName, this.context, out errorCode);
     if (element == null)
     {
         if (errorCode == -2)
         {
             this.SendValidationEvent("Sch_AllElement", elementName.ToString());
             invalidElementInContext = true;
             this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip;
             return null;
         }
         flag = true;
         substitutionGroupHead = this.GetSubstitutionGroupHead(qualifiedName);
         if (substitutionGroupHead != null)
         {
             qualifiedName = substitutionGroupHead.QualifiedName;
             goto Label_00AA;
         }
     }
     if (flag)
     {
         XmlSchemaElement element2 = element as XmlSchemaElement;
         if (element2 == null)
         {
             element = null;
         }
         else if (element2.RefName.IsEmpty)
         {
             this.SendValidationEvent("Sch_InvalidElementSubstitution", BuildElementName(elementName), BuildElementName(element2.QualifiedName));
             invalidElementInContext = true;
             this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip;
         }
         else
         {
             element = this.compiledSchemaInfo.GetElement(elementName);
             this.context.NeedValidateChildren = true;
         }
     }
     if (element == null)
     {
         ElementValidationError(elementName, this.context, this.eventHandler, this.nsResolver, this.sourceUriString, this.positionInfo.LineNumber, this.positionInfo.LinePosition, this.schemaSet);
         invalidElementInContext = true;
         this.processContents = this.context.ProcessContents = XmlSchemaContentProcessing.Skip;
     }
     return element;
 }
 internal static void ElementValidationError(XmlQualifiedName name, ValidationState context, System.Xml.Schema.ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet)
 {
     ArrayList expected = null;
     if (context.ElementDecl != null)
     {
         ContentValidator contentValidator = context.ElementDecl.ContentValidator;
         XmlSchemaContentType contentType = contentValidator.ContentType;
         if ((contentType == XmlSchemaContentType.ElementOnly) || (((contentType == XmlSchemaContentType.Mixed) && (contentValidator != ContentValidator.Mixed)) && (contentValidator != ContentValidator.Any)))
         {
             bool getParticles = schemaSet != null;
             if (getParticles)
             {
                 expected = contentValidator.ExpectedParticles(context, false, schemaSet);
             }
             else
             {
                 expected = contentValidator.ExpectedElements(context, false);
             }
             if ((expected == null) || (expected.Count == 0))
             {
                 if (context.TooComplex)
                 {
                     SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementContentComplex", new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), Res.GetString("Sch_ComplexContentModel") }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                 }
                 else
                 {
                     SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementContent", new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                 }
             }
             else if (context.TooComplex)
             {
                 SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementContentExpectingComplex", new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), PrintExpectedElements(expected, getParticles), Res.GetString("Sch_ComplexContentModel") }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
             }
             else
             {
                 SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementContentExpecting", new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), PrintExpectedElements(expected, getParticles) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
             }
         }
         else if (contentType == XmlSchemaContentType.Empty)
         {
             SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementInEmptyEx", new string[] { QNameString(context.LocalName, context.Namespace), name.ToString() }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
         }
         else if (!contentValidator.IsOpen)
         {
             SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException("Sch_InvalidElementInTextOnlyEx", new string[] { QNameString(context.LocalName, context.Namespace), name.ToString() }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
         }
     }
 }
示例#17
0
        internal override Exception CheckValueFacets(XmlQualifiedName value, SimpleTypeValidator type)
        {             
            RestrictionFacets facets = type.RestrictionFacets;
            if (facets == null || !facets.HasValueFacets) {
                return null;
            }

            
            if (facets == null)
            {
                return null;
            }
            RestrictionFlags flags = facets.Flags;
            XmlSchemaDatatype datatype = type.DataType;


            if ((flags & RestrictionFlags.Enumeration) != 0)
            {
                ArrayList enums = facets.Enumeration;


                if (!MatchEnumeration(value, enums, datatype))
                {
                    return new LinqToXsdFacetException(RestrictionFlags.Enumeration,
                        facets.Enumeration,
                        value);
                }

            }

            string strValue = value.ToString();
            int length = strValue.Length;
            if ((flags & RestrictionFlags.Length) != 0)
            {
                if (length != facets.Length)
                {
                    return new LinqToXsdFacetException(RestrictionFlags.Length, facets.Length, value);
                }

            }

            if ((flags & RestrictionFlags.MaxLength) != 0)
            {
                if (length > facets.MaxLength)
                {
                    return new LinqToXsdFacetException(RestrictionFlags.MaxLength, facets.MaxLength, value);
                }
            }

            if ((flags & RestrictionFlags.MinLength) != 0)
            {
                if (length < facets.MinLength)
                {
                    return new LinqToXsdFacetException(RestrictionFlags.MinLength, facets.MinLength, value);
                }
            }

            return null;
                      
        }
        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo)
        {
            if (lName == null)
            {
                throw new ArgumentNullException("localName");
            }
            if (ns == null)
            {
                throw new ArgumentNullException("namespaceUri");
            }
            ValidatorState toState = (this.validationStack.Length > 1) ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            this.CheckStateTransition(toState, MethodNames[(int) toState]);
            object typedValue = null;
            this.attrValid = true;
            XmlSchemaValidity notKnown = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute schemaAttribute = null;
            XmlSchemaSimpleType xmlType = null;
            ns = this.nameTable.Add(ns);
            if (Ref.Equal(ns, this.NsXmlNs))
            {
                return null;
            }
            SchemaAttDef def = null;
            SchemaElementDecl elementDecl = this.context.ElementDecl;
            XmlQualifiedName key = new XmlQualifiedName(lName, ns);
            if (this.attPresence[key] != null)
            {
                this.SendValidationEvent("Sch_DuplicateAttribute", key.ToString());
                if (schemaInfo != null)
                {
                    schemaInfo.Clear();
                }
                return null;
            }
            if (Ref.Equal(ns, this.NsXsi))
            {
                lName = this.nameTable.Add(lName);
                if ((Ref.Equal(lName, this.xsiTypeString) || Ref.Equal(lName, this.xsiNilString)) || (Ref.Equal(lName, this.xsiSchemaLocationString) || Ref.Equal(lName, this.xsiNoNamespaceSchemaLocationString)))
                {
                    this.attPresence.Add(key, SchemaAttDef.Empty);
                }
                else
                {
                    this.attrValid = false;
                    this.SendValidationEvent("Sch_NotXsiAttribute", key.ToString());
                }
            }
            else
            {
                AttributeMatchState state2;
                object obj4;
                XmlSchemaObject partialValidationType = (this.currentState == ValidatorState.TopLevelAttribute) ? this.partialValidationType : null;
                def = this.compiledSchemaInfo.GetAttributeXsd(elementDecl, key, partialValidationType, out state2);
                switch (state2)
                {
                    case AttributeMatchState.AttributeFound:
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (this.wildID != null)
                        {
                            this.SendValidationEvent("Sch_MoreThanOneWildId", string.Empty);
                        }
                        else
                        {
                            this.wildID = def;
                            XmlSchemaComplexType schemaType = elementDecl.SchemaType as XmlSchemaComplexType;
                            if (!schemaType.ContainsIdAttribute(false))
                            {
                                break;
                            }
                            this.SendValidationEvent("Sch_AttrUseAndWildId", string.Empty);
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        if (((elementDecl != null) || (this.processContents != XmlSchemaContentProcessing.Strict)) || ((key.Namespace.Length == 0) || !this.compiledSchemaInfo.Contains(key.Namespace)))
                        {
                            if (this.processContents != XmlSchemaContentProcessing.Skip)
                            {
                                this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
                            }
                        }
                        else
                        {
                            this.attrValid = false;
                            this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
                        }
                        goto Label_0409;

                    case AttributeMatchState.UndeclaredAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_UndeclaredAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.AnyAttributeLax:
                        this.SendValidationEvent("Sch_NoAttributeSchemaFound", key.ToString(), XmlSeverityType.Warning);
                        goto Label_0409;

                    case AttributeMatchState.ProhibitedAnyAttribute:
                        def = this.CheckIsXmlAttribute(key);
                        if (def != null)
                        {
                            break;
                        }
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.ProhibitedAttribute:
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ProhibitedAttribute", key.ToString());
                        goto Label_0409;

                    case AttributeMatchState.AttributeNameMismatch:
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_SchemaAttributeNameMismatch", new string[] { key.ToString(), ((XmlSchemaAttribute) partialValidationType).QualifiedName.ToString() });
                        goto Label_0409;

                    case AttributeMatchState.ValidateAttributeInvalidCall:
                        this.currentState = ValidatorState.Start;
                        this.attrValid = false;
                        this.SendValidationEvent("Sch_ValidateAttributeInvalidCall", string.Empty);
                        goto Label_0409;

                    default:
                        goto Label_0409;
                }
                schemaAttribute = def.SchemaAttribute;
                if (elementDecl != null)
                {
                    this.attPresence.Add(key, def);
                }
                if (attributeValueGetter != null)
                {
                    obj4 = attributeValueGetter();
                }
                else
                {
                    obj4 = attributeStringValue;
                }
                typedValue = this.CheckAttributeValue(obj4, def);
                XmlSchemaDatatype dtype = def.Datatype;
                if ((dtype.Variety == XmlSchemaDatatypeVariety.Union) && (typedValue != null))
                {
                    XsdSimpleValue value2 = typedValue as XsdSimpleValue;
                    xmlType = value2.XmlType;
                    dtype = value2.XmlType.Datatype;
                    typedValue = value2.TypedValue;
                }
                this.CheckTokenizedTypes(dtype, typedValue, true);
                if (this.HasIdentityConstraints)
                {
                    this.AttributeIdentityConstraints(key.Name, key.Namespace, typedValue, obj4.ToString(), dtype);
                }
            }
        Label_0409:
            if (!this.attrValid)
            {
                notKnown = XmlSchemaValidity.Invalid;
            }
            else if (def != null)
            {
                notKnown = XmlSchemaValidity.Valid;
            }
            if (schemaInfo != null)
            {
                schemaInfo.SchemaAttribute = schemaAttribute;
                schemaInfo.SchemaType = (schemaAttribute == null) ? null : schemaAttribute.AttributeSchemaType;
                schemaInfo.MemberType = xmlType;
                schemaInfo.IsDefault = false;
                schemaInfo.Validity = notKnown;
            }
            if (this.ProcessSchemaHints && (this.validatedNamespaces[ns] == null))
            {
                this.validatedNamespaces.Add(ns, ns);
            }
            return typedValue;
        }
示例#19
0
        internal static Uri GetContractTypeNameScope(XmlQualifiedName contractTypeName)
        {
            Fx.Assert(contractTypeName != null, "The contractTypeName must be non null.");

            return new Uri(string.Format(CultureInfo.InvariantCulture, "urn:{0}", contractTypeName.ToString()));
        }
        internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) {
            if (item == null)
                return null;
            if (qname == null || qname.IsEmpty) 
                return null;

            string key = item.GetType().Name + ":" + qname.ToString();
            ArrayList list = (ArrayList)ObjectCache[key];
            if (list == null) {
                list = new ArrayList();
                ObjectCache[key] = list;
            }

            for (int i = 0; i < list.Count; i++) {
                XmlSchemaObject cachedItem = (XmlSchemaObject)list[i];
                if (cachedItem == item)
                    return cachedItem;

                if (Match(cachedItem, item, true)) {
                    return cachedItem;
                }
                else {
                    Warnings.Add(Res.GetString(Res.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
                    Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]);
                }
            }
            // no match found we need to insert the new type in the cache
            list.Add(item);
            return item;
        }
 private SchemaElementDecl FastGetElementDecl(XmlQualifiedName elementName, object particle) {
     SchemaElementDecl elementDecl = null;
     if (particle != null) {
         XmlSchemaElement element = particle as XmlSchemaElement;
         if (element != null) {
             elementDecl = element.ElementDecl;
         }
         else {
             XmlSchemaAny any = (XmlSchemaAny)particle;
             processContents = any.ProcessContentsCorrect;
         }
     }
     if (elementDecl == null && processContents != XmlSchemaContentProcessing.Skip) {
         if (isRoot && partialValidationType != null) {
             if (partialValidationType is XmlSchemaElement) {
                 XmlSchemaElement element = (XmlSchemaElement)partialValidationType;
                 if (elementName.Equals(element.QualifiedName)) {
                     elementDecl = element.ElementDecl;
                 }
                 else {
                     SendValidationEvent(Res.Sch_SchemaElementNameMismatch, elementName.ToString(), element.QualifiedName.ToString());
                 }
             }
             else if (partialValidationType is XmlSchemaType) { //Element name is wildcard
                 XmlSchemaType type = (XmlSchemaType)partialValidationType;
                 elementDecl = type.ElementDecl;
             }
             else { //its XmlSchemaAttribute
                 Debug.Assert(partialValidationType is XmlSchemaAttribute);
                 SendValidationEvent(Res.Sch_ValidateElementInvalidCall, string.Empty);
             }
         }
         else {
             elementDecl = compiledSchemaInfo.GetElementDecl(elementName);
         }
     }
     return elementDecl;
 }
        internal static void ElementValidationError(XmlQualifiedName name, ValidationState context, ValidationEventHandler eventHandler, object sender, string sourceUri, int lineNo, int linePos, XmlSchemaSet schemaSet) {
            ArrayList names = null;
            if (context.ElementDecl != null) {
                ContentValidator contentValidator = context.ElementDecl.ContentValidator;
                XmlSchemaContentType contentType = contentValidator.ContentType;
                if (contentType == XmlSchemaContentType.ElementOnly || (contentType == XmlSchemaContentType.Mixed && contentValidator != ContentValidator.Mixed && contentValidator != ContentValidator.Any)) {
                    Debug.Assert(contentValidator is DfaContentValidator || contentValidator is NfaContentValidator || contentValidator is RangeContentValidator || contentValidator is AllElementsContentValidator);
                    bool getParticles = schemaSet != null;
                    if (getParticles) {
                        names = contentValidator.ExpectedParticles(context, false, schemaSet);
                    }
                    else {
                        names = contentValidator.ExpectedElements(context, false);
                    }

                    if (names == null || names.Count == 0) {
                        if (context.TooComplex) {
                            SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementContentComplex, new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), Res.GetString(Res.Sch_ComplexContentModel) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                        }
                        else {
                            SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementContent, new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                        }
                    }
                    else {
                        Debug.Assert(names.Count > 0);
                        if (context.TooComplex) {
                            SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementContentExpectingComplex, new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), PrintExpectedElements(names, getParticles), Res.GetString(Res.Sch_ComplexContentModel) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                        }
                        else {
                            SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementContentExpecting, new string[] { BuildElementName(context.LocalName, context.Namespace), BuildElementName(name), PrintExpectedElements(names, getParticles) }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                        }
                    }
                }
                else { //Base ContentValidator: Empty || TextOnly || Mixed || Any
                    if (contentType == XmlSchemaContentType.Empty) {
                        SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementInEmptyEx, new string[] { QNameString(context.LocalName, context.Namespace), name.ToString() }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                    }
                    else if (!contentValidator.IsOpen) {
                        SendValidationEvent(eventHandler, sender, new XmlSchemaValidationException(Res.Sch_InvalidElementInTextOnlyEx, new string[] { QNameString(context.LocalName, context.Namespace), name.ToString() }, sourceUri, lineNo, linePos), XmlSeverityType.Error);
                    }
                }
            }
        }
        private object ValidateElementContext(XmlQualifiedName elementName, out bool invalidElementInContext) {
            object particle = null;
            int errorCode = 0;
            XmlQualifiedName head;
            XmlSchemaElement headElement = null;
            invalidElementInContext = false;

            if (context.NeedValidateChildren) {
                if (context.IsNill) {
                    SendValidationEvent(Res.Sch_ContentInNill, QNameString(context.LocalName, context.Namespace));
                    return null;
                }
                ContentValidator contentValidator = context.ElementDecl.ContentValidator;
                if (contentValidator.ContentType == XmlSchemaContentType.Mixed && context.ElementDecl.Presence == SchemaDeclBase.Use.Fixed) { //Mixed with default or fixed
                    SendValidationEvent(Res.Sch_ElementInMixedWithFixed, QNameString(context.LocalName, context.Namespace));
                    return null;
                }

                head = elementName;
                bool substitution = false;

                while (true) {
                    particle = context.ElementDecl.ContentValidator.ValidateElement(head, context, out errorCode);
                    if (particle != null) { //Match found
                        break;
                    }
                    if (errorCode == -2) { //ContentModel all group error
                        SendValidationEvent(Res.Sch_AllElement, elementName.ToString());
                        invalidElementInContext = true;
                        processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip;
                        return null;
                    }
                    //Match not found; check for substitutionGroup
                    substitution = true;
                    headElement = GetSubstitutionGroupHead(head);
                    if (headElement == null) {
                        break;
                    }
                    else {
                        head = headElement.QualifiedName;
                    }
                }

                if (substitution) {
                    XmlSchemaElement matchedElem = particle as XmlSchemaElement;
                    if (matchedElem == null) { //It matched an xs:any in that position
                        particle = null;
                    }
                    else if (matchedElem.RefName.IsEmpty) { //It is not element ref but a local element
                        //If the head and matched particle are not hte same, then this is not substitutable, duped by a localElement with same QName
                        SendValidationEvent(Res.Sch_InvalidElementSubstitution, BuildElementName(elementName), BuildElementName(matchedElem.QualifiedName));
                        invalidElementInContext = true;
                        processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip;
                    }
                    else { //Correct substitution head found
                        particle = compiledSchemaInfo.GetElement(elementName); //Re-assign correct particle
                        context.NeedValidateChildren = true; //This will be reset to false once member match is not found
                    }
                }
                if (particle == null) {
                    ElementValidationError(elementName, context, eventHandler, nsResolver, sourceUriString, positionInfo.LineNumber, positionInfo.LinePosition, schemaSet);
                    invalidElementInContext = true;
                    processContents = context.ProcessContents = XmlSchemaContentProcessing.Skip;
                }
            }
            return particle;
        }
 private XmlSchemaElement GetSubstitutionGroupHead(XmlQualifiedName member) {
     XmlSchemaElement memberElem = compiledSchemaInfo.GetElement(member);
     if (memberElem != null) {
         XmlQualifiedName head = memberElem.SubstitutionGroup;
         if(!head.IsEmpty) {
             XmlSchemaElement headElem = compiledSchemaInfo.GetElement(head);
             if (headElem != null) {
                 if ((headElem.BlockResolved & XmlSchemaDerivationMethod.Substitution) != 0) {
                     SendValidationEvent(Res.Sch_SubstitutionNotAllowed, new string[] {member.ToString(), head.ToString()});
                     return null;
                 }
                 if (!XmlSchemaType.IsDerivedFrom(memberElem.ElementSchemaType, headElem.ElementSchemaType, headElem.BlockResolved)) {
                     SendValidationEvent(Res.Sch_SubstitutionBlocked, new string[] {member.ToString(), head.ToString()});
                     return null;
                 }
                 return headElem;
             }
         }
     }
     return null;
 }
		//Check the <element .. > in a sequence
		void CheckElementReference (XmlSchemaObject obj, string name, QName schema_type, bool nillable)
		{
			XmlSchemaElement element = obj as XmlSchemaElement;
			Assert.IsNotNull (element, "XmlSchemaElement not found for " + schema_type.ToString ());

			Assert.AreEqual (name, element.Name, "#v1, Element name did not match");
			//FIXME: Assert.AreEqual (0, element.MinOccurs, "#v0, MinOccurs should be 0 for element '" + name + "'");
			Assert.AreEqual (schema_type, element.SchemaTypeName, "#v2, SchemaTypeName for element '" + element.Name + "' did not match.");
			Assert.AreEqual (nillable, element.IsNillable, "#v3, Element '" + element.Name + "', schema type = '" + schema_type + "' should have nillable = " + nillable);
		}
        public void InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
        {
            if (serviceHost.ImplementedContracts != null && serviceHost.ImplementedContracts.Count > 0)
            {
                EnsureThereAreApplicationEndpoints(description);
            }
            ValidateDescription(description, serviceHost);

            AspNetEnvironment.Current.AddHostingBehavior(serviceHost, description);

            ServiceBehaviorAttribute instanceSettings = description.Behaviors.Find<ServiceBehaviorAttribute>();
            InitializeServicePerformanceCounters(serviceHost);

            Dictionary<ListenUriInfo, StuffPerListenUriInfo> stuffPerListenUriInfo
                = new Dictionary<ListenUriInfo, StuffPerListenUriInfo>();
            Dictionary<EndpointAddress, Collection<EndpointInfo>> endpointInfosPerEndpointAddress
                = new Dictionary<EndpointAddress, Collection<EndpointInfo>>();

            // Ensure ListenUri and group endpoints per ListenUri
            for (int i = 0; i < description.Endpoints.Count; i++)
            {
                //Ensure ReceiveContextSettings before building channel
                bool requiresReceiveContext = false; //at least one operation had ReceiveContextEnabledAttribute
                ServiceEndpoint endpoint = description.Endpoints[i];

                foreach (OperationDescription operation in endpoint.Contract.Operations)
                {
                    if (operation.Behaviors.Find<ReceiveContextEnabledAttribute>() != null)
                    {
                        requiresReceiveContext = true;
                        break;
                    }
                }

                if (requiresReceiveContext)
                {
                    IReceiveContextSettings receiveContextSettings = endpoint.Binding.GetProperty<IReceiveContextSettings>(new BindingParameterCollection());

                    if (receiveContextSettings == null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                            new InvalidOperationException(
                            SR.GetString(SR.SFxReceiveContextSettingsPropertyMissing,
                            endpoint.Contract.Name,
                            typeof(ReceiveContextEnabledAttribute).Name,
                            endpoint.Address.Uri.AbsoluteUri,
                            typeof(IReceiveContextSettings).Name)));
                    }
                    //Enable ReceiveContext on the binding.
                    receiveContextSettings.Enabled = true;
                }

                ListenUriInfo listenUriInfo = GetListenUriInfoForEndpoint(serviceHost, endpoint);
                if (!stuffPerListenUriInfo.ContainsKey(listenUriInfo))
                {
                    stuffPerListenUriInfo.Add(listenUriInfo, new StuffPerListenUriInfo());
                }
                stuffPerListenUriInfo[listenUriInfo].Endpoints.Add(endpoint);
            }

            foreach (KeyValuePair<ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo)
            {
                Uri listenUri = stuff.Key.ListenUri;
                ListenUriMode listenUriMode = stuff.Key.ListenUriMode;
                BindingParameterCollection parameters = stuff.Value.Parameters;
                Binding binding = stuff.Value.Endpoints[0].Binding;
                EndpointIdentity identity = stuff.Value.Endpoints[0].Address.Identity;
                // same EndpointAddressTable instance must be shared between channelDispatcher and parameters
                ThreadSafeMessageFilterTable<EndpointAddress> endpointAddressTable = new ThreadSafeMessageFilterTable<EndpointAddress>();
                parameters.Add(endpointAddressTable);

                bool supportContextSession = false;
                // add service-level binding parameters
                foreach (IServiceBehavior behavior in description.Behaviors)
                {
                    if (behavior is IContextSessionProvider)
                    {
                        supportContextSession = true;
                    }
                    behavior.AddBindingParameters(description, serviceHost, stuff.Value.Endpoints, parameters);
                }
                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint = stuff.Value.Endpoints[i];
                    string viaString = listenUri.AbsoluteUri;

                    // ensure all endpoints with this ListenUriInfo have same binding
                    if (endpoint.Binding != binding)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.ABindingInstanceHasAlreadyBeenAssociatedTo1, viaString)));
                    }

                    // ensure all endpoints with this ListenUriInfo have same identity
                    if (!object.Equals(endpoint.Address.Identity, identity))
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                                                                                      SR.GetString(SR.SFxWhenMultipleEndpointsShareAListenUriTheyMustHaveSameIdentity, viaString)));
                    }

                    // add binding parameters (endpoint scope and below)
                    AddMsmqIntegrationContractInformation(endpoint);
                    SecurityContractInformationEndpointBehavior.ServerInstance.AddBindingParameters(endpoint, parameters);
                    AddBindingParameters(endpoint, parameters);
                }

                // build IChannelListener and ChannelDispatcher
                IChannelListener listener;
                Type channelType = this.BuildChannelListener(stuff.Value,
                                                             serviceHost,
                                                             listenUri,
                                                             listenUriMode,
                                                             supportContextSession,
                                                             out listener);

                XmlQualifiedName bindingQname = new XmlQualifiedName(binding.Name, binding.Namespace);
                ChannelDispatcher channelDispatcher = new ChannelDispatcher(listener, bindingQname.ToString(), binding);
                channelDispatcher.SetEndpointAddressTable(endpointAddressTable);
                stuff.Value.ChannelDispatcher = channelDispatcher;

                bool canReceiveInTransaction = false;   // at least one operation is TransactionScopeRequired
                int transactedBatchSize = int.MaxValue;

                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint = stuff.Value.Endpoints[i];
                    string viaString = listenUri.AbsoluteUri;

                    EndpointFilterProvider provider = new EndpointFilterProvider();
                    EndpointDispatcher dispatcher = DispatcherBuilder.BuildDispatcher(serviceHost, description, endpoint, endpoint.Contract, provider);

                    for (int j = 0; j < endpoint.Contract.Operations.Count; j++)
                    {
                        OperationDescription operation = endpoint.Contract.Operations[j];
                        OperationBehaviorAttribute operationBehavior = operation.Behaviors.Find<OperationBehaviorAttribute>();
                        if (null != operationBehavior && operationBehavior.TransactionScopeRequired)
                        {
                            canReceiveInTransaction = true;
                            break;
                        }
                    }

                    if (!endpointInfosPerEndpointAddress.ContainsKey(endpoint.Address))
                    {
                        endpointInfosPerEndpointAddress.Add(endpoint.Address, new Collection<EndpointInfo>());
                    }
                    endpointInfosPerEndpointAddress[endpoint.Address].Add(new EndpointInfo(endpoint, dispatcher, provider));

                    channelDispatcher.Endpoints.Add(dispatcher);

                    TransactedBatchingBehavior batchBehavior = endpoint.Behaviors.Find<TransactedBatchingBehavior>();
                    if (batchBehavior == null)
                    {
                        transactedBatchSize = 0;
                    }
                    else
                    {
                        if (!canReceiveInTransaction)
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.MsmqBatchRequiresTransactionScope)));
                        transactedBatchSize = System.Math.Min(transactedBatchSize, batchBehavior.MaxBatchSize);
                    }
                    if (PerformanceCounters.PerformanceCountersEnabled || PerformanceCounters.MinimalPerformanceCountersEnabled)
                    {
                        PerformanceCounters.AddPerformanceCountersForEndpoint(serviceHost, endpoint.Contract, dispatcher);
                    }
                } // end foreach "endpoint"

                if (canReceiveInTransaction)
                {
                    BindingElementCollection bindingElements = binding.CreateBindingElements();
                    foreach (BindingElement bindingElement in bindingElements)
                    {
                        ITransactedBindingElement txElement = bindingElement as ITransactedBindingElement;
                        if (null != txElement && txElement.TransactedReceiveEnabled)
                        {
                            channelDispatcher.IsTransactedReceive = true;
                            channelDispatcher.MaxTransactedBatchSize = transactedBatchSize;
                            break;
                        }
                    }
                }

                //Set the mode of operation for ChannelDispatcher based on binding Settings.
                IReceiveContextSettings receiveContextSettings = binding.GetProperty<IReceiveContextSettings>(new BindingParameterCollection());

                if (receiveContextSettings != null)
                {
                    channelDispatcher.ReceiveContextEnabled = receiveContextSettings.Enabled;
                }
                serviceHost.ChannelDispatchers.Add(channelDispatcher);
            } // end foreach "ListenUri/ChannelDispatcher" group

            // run service behaviors
            for (int i = 0; i < description.Behaviors.Count; i++)
            {
                IServiceBehavior serviceBehavior = description.Behaviors[i];
                serviceBehavior.ApplyDispatchBehavior(description, serviceHost);
            }

            foreach (KeyValuePair<ListenUriInfo, StuffPerListenUriInfo> stuff in stuffPerListenUriInfo)
            {
                for (int i = 0; i < stuff.Value.Endpoints.Count; i++)
                {
                    ServiceEndpoint endpoint = stuff.Value.Endpoints[i];
                    // rediscover which dispatcher goes with this endpoint
                    Collection<EndpointInfo> infos = endpointInfosPerEndpointAddress[endpoint.Address];
                    EndpointInfo info = null;
                    foreach (EndpointInfo ei in infos)
                    {
                        if (ei.Endpoint == endpoint)
                        {
                            info = ei;
                            break;
                        }
                    }
                    EndpointDispatcher dispatcher = info.EndpointDispatcher;
                    // run contract behaviors
                    for (int k = 0; k < endpoint.Contract.Behaviors.Count; k++)
                    {
                        IContractBehavior behavior = endpoint.Contract.Behaviors[k];
                        behavior.ApplyDispatchBehavior(endpoint.Contract, endpoint, dispatcher.DispatchRuntime);
                    }
                    // run endpoint behaviors
                    BindingInformationEndpointBehavior.Instance.ApplyDispatchBehavior(endpoint, dispatcher);
                    TransactionContractInformationEndpointBehavior.Instance.ApplyDispatchBehavior(endpoint, dispatcher);
                    for (int j = 0; j < endpoint.Behaviors.Count; j++)
                    {
                        IEndpointBehavior eb = endpoint.Behaviors[j];
                        eb.ApplyDispatchBehavior(endpoint, dispatcher);
                    }
                    // run operation behaviors
                    DispatcherBuilder.BindOperations(endpoint.Contract, null, dispatcher.DispatchRuntime);
                }
            }

            this.EnsureRequiredRuntimeProperties(endpointInfosPerEndpointAddress);

            // Warn about obvious demux conflicts
            foreach (Collection<EndpointInfo> endpointInfos in endpointInfosPerEndpointAddress.Values)
            {
                // all elements of endpointInfos share the same Address (and thus EndpointListener.AddressFilter)
                if (endpointInfos.Count > 1)
                {
                    for (int i = 0; i < endpointInfos.Count; i++)
                    {
                        for (int j = i + 1; j < endpointInfos.Count; j++)
                        {
                            // if not same ListenUri, won't conflict
                            // if not same ChannelType, may not conflict (some transports demux based on this)
                            // if they share a ChannelDispatcher, this means same ListenUri and same ChannelType
                            if (endpointInfos[i].EndpointDispatcher.ChannelDispatcher ==
                                endpointInfos[j].EndpointDispatcher.ChannelDispatcher)
                            {
                                EndpointFilterProvider iProvider = endpointInfos[i].FilterProvider;
                                EndpointFilterProvider jProvider = endpointInfos[j].FilterProvider;
                                // if not default EndpointFilterProvider, we won't try to throw, you're on your own
                                string commonAction;
                                if (iProvider != null && jProvider != null
                                    && HaveCommonInitiatingActions(iProvider, jProvider, out commonAction))
                                {
                                    // you will definitely get a MultipleFiltersMatchedException at runtime,
                                    // so let's go ahead and throw now
                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                                        new InvalidOperationException(
                                            SR.GetString(SR.SFxDuplicateInitiatingActionAtSameVia,
                                                         endpointInfos[i].Endpoint.ListenUri, commonAction)));
                                }
                            }
                        }
                    }
                }
            }
        }
示例#27
0
        /// <summary>
        /// Prepare metadata for the module type, to be used by the palette and circuit drawing engine</summary>
        /// <param name="name"> Schema full name of the DomNodeType for the module type</param>
        /// <param name="displayName">Display name for the module type</param>
        /// <param name="description"></param>
        /// <param name="imageName">Image name </param>
        /// <param name="inputs">Define input pins for the module type</param>
        /// <param name="outputs">Define output pins for the module type</param>
        /// <param name="loader">XML schema loader </param>
        /// <param name="domNodeType">optional DomNode type for the module type</param>
        /// <returns>DomNodeType that was created (or the domNodeType parameter, if it wasn't null)</returns>
        protected DomNodeType DefineModuleType(
            XmlQualifiedName name,
            string displayName,
            string description,
            string imageName,
            ElementType.Pin[] inputs,
            ElementType.Pin[] outputs,
            SchemaLoader loader,
            DomNodeType domNodeType = null)
        {
            if (domNodeType == null)
                // create the type
                domNodeType = new DomNodeType(
                name.ToString(),
                Schema.moduleType.Type,
                EmptyArray<AttributeInfo>.Instance,
                EmptyArray<ChildInfo>.Instance,
                EmptyArray<ExtensionInfo>.Instance);

            DefineCircuitType(domNodeType, displayName, imageName, inputs, outputs);

            // add it to the schema-defined types
            loader.AddNodeType(name.ToString(), domNodeType);

            // add the type to the palette
            m_paletteService.AddItem(
                new NodeTypePaletteItem(
                    domNodeType,
                    displayName,
                    description,
                    imageName),
                PaletteCategory,
                this);

            return domNodeType;
        }
 private XmlSchemaElement GetSubstitutionGroupHead(XmlQualifiedName member)
 {
     XmlSchemaElement element = this.compiledSchemaInfo.GetElement(member);
     if (element != null)
     {
         XmlQualifiedName substitutionGroup = element.SubstitutionGroup;
         if (!substitutionGroup.IsEmpty)
         {
             XmlSchemaElement element2 = this.compiledSchemaInfo.GetElement(substitutionGroup);
             if (element2 != null)
             {
                 if ((element2.BlockResolved & XmlSchemaDerivationMethod.Substitution) != XmlSchemaDerivationMethod.Empty)
                 {
                     this.SendValidationEvent("Sch_SubstitutionNotAllowed", new string[] { member.ToString(), substitutionGroup.ToString() });
                     return null;
                 }
                 if (!XmlSchemaType.IsDerivedFrom(element.ElementSchemaType, element2.ElementSchemaType, element2.BlockResolved))
                 {
                     this.SendValidationEvent("Sch_SubstitutionBlocked", new string[] { member.ToString(), substitutionGroup.ToString() });
                     return null;
                 }
                 return element2;
             }
         }
     }
     return null;
 }
        private object ValidateAttribute(string lName, string ns, XmlValueGetter attributeValueGetter, string attributeStringValue, XmlSchemaInfo schemaInfo) {
            if (lName == null) {
                throw new ArgumentNullException("localName");
            }
            if (ns == null) {
                throw new ArgumentNullException("namespaceUri");
            }

            ValidatorState toState = validationStack.Length > 1 ? ValidatorState.Attribute : ValidatorState.TopLevelAttribute;
            CheckStateTransition(toState, MethodNames[(int)toState]);

            object typedVal = null;
            attrValid = true;
            XmlSchemaValidity localValidity = XmlSchemaValidity.NotKnown;
            XmlSchemaAttribute localAttribute = null;
            XmlSchemaSimpleType localMemberType = null;

            ns = nameTable.Add(ns);
            if(Ref.Equal(ns,NsXmlNs)) {
                return null;
            }

            SchemaAttDef attributeDef = null;
            SchemaElementDecl currentElementDecl = context.ElementDecl;
            XmlQualifiedName attQName = new XmlQualifiedName(lName, ns);
            if (attPresence[attQName] != null) { //this attribute already checked as it is duplicate;
                SendValidationEvent(Res.Sch_DuplicateAttribute, attQName.ToString());
                if (schemaInfo != null) {
                    schemaInfo.Clear();
                }
                return null;
            }

            if (!Ref.Equal(ns,NsXsi)) { //
                XmlSchemaObject pvtAttribute = currentState == ValidatorState.TopLevelAttribute ? partialValidationType : null;
                AttributeMatchState attributeMatchState;
                attributeDef = compiledSchemaInfo.GetAttributeXsd(currentElementDecl, attQName, pvtAttribute, out attributeMatchState);

                switch (attributeMatchState) {
                    case AttributeMatchState.UndeclaredElementAndAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) { //Try for xml attribute
                            goto case AttributeMatchState.AttributeFound;
                        }
                        if (currentElementDecl == null
                            && processContents == XmlSchemaContentProcessing.Strict
                            && attQName.Namespace.Length != 0
                            && compiledSchemaInfo.Contains(attQName.Namespace)
                        ) {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        else if (processContents != XmlSchemaContentProcessing.Skip) {
                            SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                        }
                        break;

                    case AttributeMatchState.UndeclaredAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_UndeclaredAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAnyAttribute:
                        if((attributeDef = CheckIsXmlAttribute(attQName)) != null) {
                            goto case AttributeMatchState.AttributeFound;
                        }
                        else {
                            attrValid = false;
                            SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        }
                        break;

                    case AttributeMatchState.ProhibitedAttribute:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ProhibitedAttribute, attQName.ToString());
                        break;

                    case AttributeMatchState.AttributeNameMismatch:
                        attrValid = false;
                        SendValidationEvent(Res.Sch_SchemaAttributeNameMismatch, new string[] { attQName.ToString(), ((XmlSchemaAttribute)pvtAttribute).QualifiedName.ToString()});
                        break;

                    case AttributeMatchState.ValidateAttributeInvalidCall:
                        Debug.Assert(currentState == ValidatorState.TopLevelAttribute); //Re-set state back to start on error with partial validation type
                        currentState = ValidatorState.Start;
                        attrValid = false;
                        SendValidationEvent(Res.Sch_ValidateAttributeInvalidCall, string.Empty);
                        break;

                    case AttributeMatchState.AnyIdAttributeFound:
                        if (wildID == null) {
                            wildID = attributeDef;
                            Debug.Assert(currentElementDecl != null);
                            XmlSchemaComplexType ct = currentElementDecl.SchemaType as XmlSchemaComplexType;
                            Debug.Assert(ct != null);
                            if (ct.ContainsIdAttribute(false)) {
                                SendValidationEvent(Res.Sch_AttrUseAndWildId, string.Empty);
                            }
                            else {
                                goto case AttributeMatchState.AttributeFound;
                            }
                        }
                        else { //More than one attribute per element cannot match wildcard if both their types are derived from ID
                            SendValidationEvent(Res.Sch_MoreThanOneWildId, string.Empty);
                        }
                        break;

                    case AttributeMatchState.AttributeFound:
                        Debug.Assert(attributeDef != null);
                        localAttribute = attributeDef.SchemaAttribute;
                        if (currentElementDecl != null) { //Have to add to hashtable to check whether to add default attributes
                            attPresence.Add(attQName, attributeDef);
                        }
                        object attValue;
                        if (attributeValueGetter != null) {
                            attValue = attributeValueGetter();
                        }
                        else {
                            attValue = attributeStringValue;
                        }
                        typedVal = CheckAttributeValue(attValue, attributeDef);
                        XmlSchemaDatatype datatype = attributeDef.Datatype;
                        if (datatype.Variety == XmlSchemaDatatypeVariety.Union && typedVal != null) { //Unpack the union
                            XsdSimpleValue simpleValue = typedVal as XsdSimpleValue;
                            Debug.Assert(simpleValue != null);

                            localMemberType = simpleValue.XmlType;
                            datatype = simpleValue.XmlType.Datatype;
                            typedVal = simpleValue.TypedValue;
                        }
                        CheckTokenizedTypes(datatype, typedVal, true);
                        if (HasIdentityConstraints) {
                            AttributeIdentityConstraints(attQName.Name, attQName.Namespace, typedVal, attValue.ToString(), datatype);
                        }
                        break;

                    case AttributeMatchState.AnyAttributeLax:
                        SendValidationEvent(Res.Sch_NoAttributeSchemaFound, attQName.ToString(), XmlSeverityType.Warning);
                        break;

                    case AttributeMatchState.AnyAttributeSkip:
                        break;

                    default:
                        break;
                }
            }
            else { //Attribute from xsi namespace
                lName = nameTable.Add(lName);
                if (Ref.Equal(lName, xsiTypeString) || Ref.Equal(lName, xsiNilString) || Ref.Equal(lName, xsiSchemaLocationString) || Ref.Equal(lName, xsiNoNamespaceSchemaLocationString)) {
                    attPresence.Add(attQName, SchemaAttDef.Empty);
                }
                else {
                    attrValid = false;
                    SendValidationEvent(Res.Sch_NotXsiAttribute, attQName.ToString());
                }
            }

            if (!attrValid) {
                localValidity = XmlSchemaValidity.Invalid;
            }
            else if (attributeDef != null) {
                localValidity = XmlSchemaValidity.Valid;
            }
            if (schemaInfo != null) {
                schemaInfo.SchemaAttribute = localAttribute;
                schemaInfo.SchemaType = localAttribute == null ? null : localAttribute.AttributeSchemaType;
                schemaInfo.MemberType = localMemberType;
                schemaInfo.IsDefault = false;
                schemaInfo.Validity = localValidity;
            }
            if (ProcessSchemaHints) {
                if (validatedNamespaces[ns] == null) {
                    validatedNamespaces.Add(ns, ns);
                }
            }
            return typedVal;
        }
示例#30
0
 internal SchemaAttDef GetAttributeXdr(SchemaElementDecl ed, XmlQualifiedName qname) {
     SchemaAttDef attdef = null;
     if (ed != null) {
         attdef = ed.GetAttDef(qname);;
         if (attdef == null) {
             if (!ed.ContentValidator.IsOpen || qname.Namespace.Length == 0) {
                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
             }
             if (!attributeDecls.TryGetValue(qname, out attdef) && targetNamespaces.ContainsKey(qname.Namespace)) {
                 throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());
             }
         }
     }
     return attdef;
 }
示例#31
0
        /// <summary>
        /// Converts a qualified name into a locally unique (on the type) field name</summary>
        /// <param name="qualifiedName">XML qualified name</param>
        /// <returns>Unique field name</returns>
        protected virtual string GetFieldName(XmlQualifiedName qualifiedName)
        {
            XmlSchemaTypeCollection typeCollection;
            if (m_typeCollections.TryGetValue(qualifiedName.Namespace, out typeCollection))
            {
                if (qualifiedName.Namespace == typeCollection.TargetNamespace)
                    return qualifiedName.Name;
            }

            return qualifiedName.ToString();
        }
 XmlSchemaSimpleType FindDataType(XmlQualifiedName name) {
     TypeDesc typeDesc = Scope.GetTypeDesc(name.Name, name.Namespace);
     if (typeDesc != null && typeDesc.DataType is XmlSchemaSimpleType)
         return (XmlSchemaSimpleType)typeDesc.DataType;
     XmlSchemaSimpleType dataType = (XmlSchemaSimpleType)Schemas.Find(name, typeof(XmlSchemaSimpleType));
     if (dataType != null) {
         return dataType;
     }
     if (name.Namespace == XmlSchema.Namespace)
         return (XmlSchemaSimpleType)Scope.GetTypeDesc(typeof(string)).DataType;
     else 
         throw new InvalidOperationException(Res.GetString(Res.XmlMissingDataType, name.ToString()));
 }
示例#33
0
        internal SchemaAttDef GetAttributeXsd(SchemaElementDecl ed, XmlQualifiedName qname, ref bool skip) {
            AttributeMatchState attributeMatchState;

            SchemaAttDef attDef = GetAttributeXsd(ed, qname, null, out attributeMatchState);
            switch(attributeMatchState) {
                case AttributeMatchState.UndeclaredAttribute:
                    throw new XmlSchemaException(Res.Sch_UndeclaredAttribute, qname.ToString());

                case AttributeMatchState.ProhibitedAnyAttribute:
                case AttributeMatchState.ProhibitedAttribute:
                    throw new XmlSchemaException(Res.Sch_ProhibitedAttribute, qname.ToString());

                case AttributeMatchState.AttributeFound:
                case AttributeMatchState.AnyIdAttributeFound:
                case AttributeMatchState.AnyAttributeLax:
                case AttributeMatchState.UndeclaredElementAndAttribute:
                    break;

                case AttributeMatchState.AnyAttributeSkip:
                    skip = true;
                    break;

                default:
                    Debug.Assert(false);
                    break;
            }
            return attDef;
        }
 protected void WriteAttribute(string localName, string ns, XmlQualifiedName value) {
     if (value.IsEmpty)
         return;
     WriteAttribute(localName, ns, value.ToString());
 }
 ServiceDescription GetServiceDescription(XmlQualifiedName name) {
     ServiceDescription serviceDescription = this[name.Namespace];
     if (serviceDescription == null) {
         throw new ArgumentException(Res.GetString(Res.WebDescriptionMissing, name.ToString(), name.Namespace), "name");
     }
     return serviceDescription;
 }