Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Web / System / Web / Services / Discovery / SchemaReference.cs / 1305376 / SchemaReference.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Discovery { using System; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System.IO; using System.Web.Services.Protocols; using System.ComponentModel; using System.Text; using System.Threading; using System.Collections; using System.Globalization; using System.Diagnostics; using System.Web.Services.Diagnostics; ////// /// [XmlRoot("schemaRef", Namespace=SchemaReference.Namespace)] public sealed class SchemaReference : DiscoveryReference { ///[To be supplied.] ////// /// public const string Namespace = "http://schemas.xmlsoap.org/disco/schema/"; private string reference; private string targetNamespace; ///[To be supplied.] ////// /// public SchemaReference() { } ///[To be supplied.] ////// /// public SchemaReference(string url) { Ref = url; } ///[To be supplied.] ////// /// [XmlAttribute("ref")] public string Ref { get { return reference == null ? "" : reference; } set { reference = value; } } ///[To be supplied.] ////// /// [XmlAttribute("targetNamespace"), DefaultValue(null)] public string TargetNamespace { get { return targetNamespace; } set { targetNamespace = value; } } ///[To be supplied.] ////// /// [XmlIgnore] public override string Url { get { return Ref; } set { Ref = value; } } internal XmlSchema GetSchema() { try { return Schema; } catch(Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. ClientProtocol.Errors[Url] = e; if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "GetSchema", e); } return null; } internal override void LoadExternals(Hashtable loadedExternals) { LoadExternals(GetSchema(), Url, ClientProtocol, loadedExternals); } internal static void LoadExternals(XmlSchema schema, string url, DiscoveryClientProtocol client, Hashtable loadedExternals) { if (schema == null) return; foreach (XmlSchemaExternal external in schema.Includes) { if (external.SchemaLocation == null || external.SchemaLocation.Length == 0 || external.Schema != null) continue; if (external is XmlSchemaInclude || external is XmlSchemaRedefine) { string location = UriToString(url, external.SchemaLocation); if (client.References[location] is SchemaReference) { SchemaReference externalRef = (SchemaReference)client.References[location]; external.Schema = externalRef.GetSchema(); if (external.Schema != null) loadedExternals[location] = external.Schema; externalRef.LoadExternals(loadedExternals); } } } } ///[To be supplied.] ////// /// public override void WriteDocument(object document, Stream stream) { ((XmlSchema)document).Write(new StreamWriter(stream, new UTF8Encoding(false))); } ///[To be supplied.] ////// /// public override object ReadDocument(Stream stream) { XmlTextReader reader = new XmlTextReader(this.Url, stream); reader.XmlResolver = null; return XmlSchema.Read(reader, null); } ///[To be supplied.] ////// /// [XmlIgnore] public override string DefaultFilename { get { string fileName = MakeValidFilename(Schema.Id); if (fileName == null || fileName.Length == 0) { fileName = FilenameFromUrl(Url); } return Path.ChangeExtension(fileName, ".xsd"); } } ///[To be supplied.] ////// /// [XmlIgnore] public XmlSchema Schema { get { if (ClientProtocol == null) throw new InvalidOperationException(Res.GetString(Res.WebMissingClientProtocol)); object document = ClientProtocol.InlinedSchemas[Url]; if (document == null) { document = ClientProtocol.Documents[Url]; } if (document == null) { Resolve(); document = ClientProtocol.Documents[Url]; } XmlSchema schema = document as XmlSchema; if (schema == null) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidDocType, typeof(XmlSchema).FullName, document == null? string.Empty: document.GetType().FullName, Url)); } return schema; } } ///[To be supplied.] ////// /// protected internal override void Resolve(string contentType, Stream stream) { if (ContentType.IsHtml(contentType)) ClientProtocol.Errors[Url] = new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType); XmlSchema schema = ClientProtocol.Documents[Url] as XmlSchema; if( schema == null ) { if (ClientProtocol.Errors[Url] != null) throw (Exception)ClientProtocol.Errors[Url]; schema = (XmlSchema)ReadDocument(stream); ClientProtocol.Documents[Url] = schema; } if (ClientProtocol.References[Url] != this) ClientProtocol.References[Url] = this; // now resolve references in the schema. foreach (XmlSchemaExternal external in schema.Includes) { string location = null; try { if (external.SchemaLocation != null && external.SchemaLocation.Length > 0) { location = UriToString(Url, external.SchemaLocation); SchemaReference externalRef = new SchemaReference(location); externalRef.ClientProtocol = ClientProtocol; ClientProtocol.References[location] = externalRef; externalRef.Resolve(); } } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } throw new InvalidDocumentContentsException(Res.GetString(Res.TheSchemaDocumentContainsLinksThatCouldNotBeResolved, location), e); } } return; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //[To be supplied.] ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Web.Services.Discovery { using System; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System.IO; using System.Web.Services.Protocols; using System.ComponentModel; using System.Text; using System.Threading; using System.Collections; using System.Globalization; using System.Diagnostics; using System.Web.Services.Diagnostics; ////// /// [XmlRoot("schemaRef", Namespace=SchemaReference.Namespace)] public sealed class SchemaReference : DiscoveryReference { ///[To be supplied.] ////// /// public const string Namespace = "http://schemas.xmlsoap.org/disco/schema/"; private string reference; private string targetNamespace; ///[To be supplied.] ////// /// public SchemaReference() { } ///[To be supplied.] ////// /// public SchemaReference(string url) { Ref = url; } ///[To be supplied.] ////// /// [XmlAttribute("ref")] public string Ref { get { return reference == null ? "" : reference; } set { reference = value; } } ///[To be supplied.] ////// /// [XmlAttribute("targetNamespace"), DefaultValue(null)] public string TargetNamespace { get { return targetNamespace; } set { targetNamespace = value; } } ///[To be supplied.] ////// /// [XmlIgnore] public override string Url { get { return Ref; } set { Ref = value; } } internal XmlSchema GetSchema() { try { return Schema; } catch(Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } // don't let the exception out - keep going. Just add it to the list of errors. ClientProtocol.Errors[Url] = e; if (Tracing.On) Tracing.ExceptionCatch(TraceEventType.Warning, this, "GetSchema", e); } return null; } internal override void LoadExternals(Hashtable loadedExternals) { LoadExternals(GetSchema(), Url, ClientProtocol, loadedExternals); } internal static void LoadExternals(XmlSchema schema, string url, DiscoveryClientProtocol client, Hashtable loadedExternals) { if (schema == null) return; foreach (XmlSchemaExternal external in schema.Includes) { if (external.SchemaLocation == null || external.SchemaLocation.Length == 0 || external.Schema != null) continue; if (external is XmlSchemaInclude || external is XmlSchemaRedefine) { string location = UriToString(url, external.SchemaLocation); if (client.References[location] is SchemaReference) { SchemaReference externalRef = (SchemaReference)client.References[location]; external.Schema = externalRef.GetSchema(); if (external.Schema != null) loadedExternals[location] = external.Schema; externalRef.LoadExternals(loadedExternals); } } } } ///[To be supplied.] ////// /// public override void WriteDocument(object document, Stream stream) { ((XmlSchema)document).Write(new StreamWriter(stream, new UTF8Encoding(false))); } ///[To be supplied.] ////// /// public override object ReadDocument(Stream stream) { XmlTextReader reader = new XmlTextReader(this.Url, stream); reader.XmlResolver = null; return XmlSchema.Read(reader, null); } ///[To be supplied.] ////// /// [XmlIgnore] public override string DefaultFilename { get { string fileName = MakeValidFilename(Schema.Id); if (fileName == null || fileName.Length == 0) { fileName = FilenameFromUrl(Url); } return Path.ChangeExtension(fileName, ".xsd"); } } ///[To be supplied.] ////// /// [XmlIgnore] public XmlSchema Schema { get { if (ClientProtocol == null) throw new InvalidOperationException(Res.GetString(Res.WebMissingClientProtocol)); object document = ClientProtocol.InlinedSchemas[Url]; if (document == null) { document = ClientProtocol.Documents[Url]; } if (document == null) { Resolve(); document = ClientProtocol.Documents[Url]; } XmlSchema schema = document as XmlSchema; if (schema == null) { throw new InvalidOperationException(Res.GetString(Res.WebInvalidDocType, typeof(XmlSchema).FullName, document == null? string.Empty: document.GetType().FullName, Url)); } return schema; } } ///[To be supplied.] ////// /// protected internal override void Resolve(string contentType, Stream stream) { if (ContentType.IsHtml(contentType)) ClientProtocol.Errors[Url] = new InvalidContentTypeException(Res.GetString(Res.WebInvalidContentType, contentType), contentType); XmlSchema schema = ClientProtocol.Documents[Url] as XmlSchema; if( schema == null ) { if (ClientProtocol.Errors[Url] != null) throw (Exception)ClientProtocol.Errors[Url]; schema = (XmlSchema)ReadDocument(stream); ClientProtocol.Documents[Url] = schema; } if (ClientProtocol.References[Url] != this) ClientProtocol.References[Url] = this; // now resolve references in the schema. foreach (XmlSchemaExternal external in schema.Includes) { string location = null; try { if (external.SchemaLocation != null && external.SchemaLocation.Length > 0) { location = UriToString(Url, external.SchemaLocation); SchemaReference externalRef = new SchemaReference(location); externalRef.ClientProtocol = ClientProtocol; ClientProtocol.References[location] = externalRef; externalRef.Resolve(); } } catch (Exception e) { if (e is ThreadAbortException || e is StackOverflowException || e is OutOfMemoryException) { throw; } throw new InvalidDocumentContentsException(Res.GetString(Res.TheSchemaDocumentContainsLinksThatCouldNotBeResolved, location), e); } } return; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.[To be supplied.] ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- HtmlToClrEventProxy.cs
- PositiveTimeSpanValidator.cs
- cookie.cs
- PKCS1MaskGenerationMethod.cs
- MasterPageBuildProvider.cs
- GiveFeedbackEvent.cs
- GreenMethods.cs
- XmlSchemaImport.cs
- FileInfo.cs
- ItemsControl.cs
- _AutoWebProxyScriptHelper.cs
- SelectionRange.cs
- StringStorage.cs
- PrincipalPermission.cs
- RoutedEventArgs.cs
- WebAdminConfigurationHelper.cs
- WebServiceClientProxyGenerator.cs
- ResXBuildProvider.cs
- BaseProcessor.cs
- StylusPoint.cs
- ColumnReorderedEventArgs.cs
- ObjectStateFormatter.cs
- StackSpiller.cs
- ConfigXmlDocument.cs
- DataGridViewCellValueEventArgs.cs
- Console.cs
- ExternalDataExchangeClient.cs
- ImageDesigner.cs
- safesecurityhelperavalon.cs
- PeerValidationBehavior.cs
- WhitespaceRuleLookup.cs
- CachingHintValidation.cs
- InternalConfigEventArgs.cs
- TypeDescriptor.cs
- DataGridViewHeaderCell.cs
- HtmlTableRowCollection.cs
- COM2IManagedPerPropertyBrowsingHandler.cs
- HyperlinkAutomationPeer.cs
- MetadataArtifactLoaderCompositeFile.cs
- MessageSecurityOverMsmq.cs
- PatternMatchRules.cs
- DeviceContexts.cs
- SQLMembershipProvider.cs
- DataGridBoolColumn.cs
- ObjectStateManager.cs
- XmlDataSourceNodeDescriptor.cs
- CollectionViewGroup.cs
- UserControl.cs
- ProxyFragment.cs
- UInt64Converter.cs
- DesignerUtility.cs
- SoapFaultCodes.cs
- HtmlGenericControl.cs
- AttachInfo.cs
- SchemaObjectWriter.cs
- IntPtr.cs
- VirtualDirectoryMapping.cs
- WebPartActionVerb.cs
- ReliabilityContractAttribute.cs
- BaseServiceProvider.cs
- PrintPageEvent.cs
- ToolboxItemSnapLineBehavior.cs
- DesignerDataTableBase.cs
- QilIterator.cs
- MouseEventArgs.cs
- MenuItemCollection.cs
- XmlElementElement.cs
- SchemaObjectWriter.cs
- HtmlShim.cs
- SolidColorBrush.cs
- Freezable.cs
- SmiXetterAccessMap.cs
- RulePatternOps.cs
- XhtmlCssHandler.cs
- HttpConfigurationContext.cs
- TextEndOfLine.cs
- AssemblyAssociatedContentFileAttribute.cs
- _SingleItemRequestCache.cs
- HotSpotCollection.cs
- MeasureItemEvent.cs
- ThreadAttributes.cs
- CalendarBlackoutDatesCollection.cs
- TransformerInfoCollection.cs
- IODescriptionAttribute.cs
- XsltException.cs
- HyperLinkStyle.cs
- WorkflowWebService.cs
- CLRBindingWorker.cs
- ErrorFormatterPage.cs
- EditModeSwitchButton.cs
- CornerRadius.cs
- OrthographicCamera.cs
- COM2PictureConverter.cs
- GridViewUpdateEventArgs.cs
- elementinformation.cs
- ExpanderAutomationPeer.cs
- HttpHostedTransportConfiguration.cs
- JoinGraph.cs
- PageThemeParser.cs
- RuntimeWrappedException.cs