コード例 #1
0
		/// <summary>
		/// Public ReadRootElement() method that deserializes a root-level ExampleModel instance from XML.
		/// </summary>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory ExampleModel instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="schemaResolver">An ISchemaResolver that allows the serializer to do schema validation on the root element (and everything inside it).</param>
		public override void ReadRootElement(DslModeling::SerializationContext serializationContext, DslModeling::ModelElement element, global::System.Xml.XmlReader reader, DslModeling::ISchemaResolver schemaResolver)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationContext != null);
			if (serializationContext == null)
				throw new global::System.ArgumentNullException("serializationContext");
			global::System.Diagnostics.Debug.Assert(reader != null);
			if (reader == null)
				throw new global::System.ArgumentNullException("reader");
			#endregion
	
			// Version check.
			CheckVersion(serializationContext, reader);
	
			if (!serializationContext.Result.Failed)
			{	// Check to see if schema validation is possible.
				if (schemaResolver != null)
				{
					string targetNamespace = reader.NamespaceURI;
					if (!string.IsNullOrEmpty(targetNamespace))
					{
						global::System.Collections.Generic.IList<string> schemas = schemaResolver.ResolveSchema(targetNamespace);
						if (schemas != null && schemas.Count > 0)
						{
							if (schemas.Count > 1)
							{
								AsyncDslSerializationBehaviorSerializationMessages.AmbiguousSchema(serializationContext, reader, targetNamespace, schemas[0]);
							}
							global::System.Xml.Schema.XmlSchemaSet schemaSet = new global::System.Xml.Schema.XmlSchemaSet(reader.NameTable);
							schemaSet.Add(targetNamespace, schemas[0]);
							global::System.Xml.XmlReaderSettings readerSettings = new global::System.Xml.XmlReaderSettings();
							readerSettings.ConformanceLevel = global::System.Xml.ConformanceLevel.Auto;
							readerSettings.ValidationType = global::System.Xml.ValidationType.Schema;
							readerSettings.Schemas = schemaSet;
							AsyncDslSerializationBehaviorSchemaValidationCallback validationCallback = new AsyncDslSerializationBehaviorSchemaValidationCallback(serializationContext);
							readerSettings.ValidationEventHandler += new global::System.Xml.Schema.ValidationEventHandler(validationCallback.Handler);
							// Wrap the given reader as a validating reader and carry out the normal deserialization.
							using (global::System.Xml.XmlReader validatingReader = global::System.Xml.XmlReader.Create(reader, readerSettings))
							{
								validationCallback.Reader = validatingReader;
								this.Read(serializationContext, element, validatingReader);
							}
							return;
						}
						else
						{
							AsyncDslSerializationBehaviorSerializationMessages.NoSchema(serializationContext, reader, targetNamespace);
						}
					}
				}
	
				// No schema information available, carry out the normal deserialization.
				this.Read(serializationContext, element, reader);
			}
		}
コード例 #2
0
		/// <summary>
		/// Attempts to resolve the supplied schema namespace
		/// </summary>
		/// <remarks>If the schema can be resolved it is added to the supplied schema set. Otherwise, a 
		/// warning will be written to serializationContext.
		/// </remarks>
		/// <returns>A flag indicating whether the schema was resolved or not</returns>
		protected static bool ResolveSchema(string targetNamespace, global::System.Xml.Schema.XmlSchemaSet schemaSet, DslModeling::ISchemaResolver schemaResolver, global::System.Xml.XmlReader reader, DslModeling::SerializationContext serializationContext)
		{
			global::System.Collections.Generic.IList<string> schemas = schemaResolver.ResolveSchema(targetNamespace);
			if (schemas != null && schemas.Count > 0)
			{
				if (schemas.Count > 1)
				{
					HostDesignerSerializationBehaviorSerializationMessages.AmbiguousSchema(serializationContext, reader, targetNamespace, schemas[0]);
				}
				schemaSet.Add(targetNamespace, schemas[0]);
				return true;
			}
	
			HostDesignerSerializationBehaviorSerializationMessages.NoSchema(serializationContext, reader, targetNamespace);
			return false;
		}