Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Client / System / Data / Services / Client / Xml / XmlAtomErrorReader.cs / 1407647 / XmlAtomErrorReader.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a wrapping XmlReader that can detect in-line errors. // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Client.Xml { #region Namespaces. using System.Diagnostics; using System.Xml; #endregion Namespaces. ///Use this class to wrap an existing [DebuggerDisplay("XmlAtomErrorReader {NodeType} {Name} {Value}")] internal class XmlAtomErrorReader : XmlWrappingReader { ///. Initializes a new /// Reader to wrap. internal XmlAtomErrorReader(XmlReader baseReader) : base(baseReader) { Debug.Assert(baseReader != null, "baseReader != null"); this.Reader = baseReader; } #region Methods. ///instance. Reads the next node from the stream. ///true if the next node was read successfully; false if there are no more nodes to read. public override bool Read() { bool result = base.Read(); if (this.NodeType == XmlNodeType.Element && Util.AreSame(this.Reader, XmlConstants.XmlErrorElementName, XmlConstants.DataWebMetadataNamespace)) { string message = ReadErrorMessage(this.Reader); // In case of instream errors, the status code should be 500 (which is the default) throw new DataServiceClientException(Strings.Deserialize_ServerException(message)); } return result; } ///Reads an element string from the specified /// Reader to get value from. /// Whether a null attribute marker should be checked on the element. ///. The text value within the element, possibly null. ////// Simple values only are expected - mixed content will throw an error. /// Interspersed comments are ignored. /// internal static string ReadElementString(XmlReader reader, bool checkNullAttribute) { Debug.Assert(reader != null, "reader != null"); Debug.Assert(XmlNodeType.Element == reader.NodeType, "not positioned on Element"); string result = null; bool empty = checkNullAttribute && !Util.DoesNullAttributeSayTrue(reader); if (reader.IsEmptyElement) { return (empty ? String.Empty : null); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: return result ?? (empty ? String.Empty : null); case XmlNodeType.CDATA: case XmlNodeType.Text: case XmlNodeType.SignificantWhitespace: if (null != result) { throw Error.InvalidOperation(Strings.Deserialize_MixedTextWithComment); } result = reader.Value; break; case XmlNodeType.Comment: case XmlNodeType.Whitespace: break; case XmlNodeType.Element: default: throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } } // xml ended before EndElement? throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } ///With the reader positioned on an 'error' element, reads the text of the 'message' child. ///from which to read a WCF Data Service inline error message. /// The text of the 'message' child element, empty if not found. private static string ReadErrorMessage(XmlReader reader) { Debug.Assert(reader != null, "reader != null"); Debug.Assert(reader.NodeType == XmlNodeType.Element, "reader.NodeType == XmlNodeType.Element"); Debug.Assert(reader.LocalName == XmlConstants.XmlErrorElementName, "reader.LocalName == XmlConstants.XmlErrorElementName"); int depth = 1; while (depth > 0 && reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (!reader.IsEmptyElement) { depth++; } if (depth == 2 && Util.AreSame(reader, XmlConstants.XmlErrorMessageElementName, XmlConstants.DataWebMetadataNamespace)) { return ReadElementString(reader, false); } } else if (reader.NodeType == XmlNodeType.EndElement) { depth--; } } return String.Empty; } #endregion Methods. } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Provides a wrapping XmlReader that can detect in-line errors. // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Client.Xml { #region Namespaces. using System.Diagnostics; using System.Xml; #endregion Namespaces. ///Use this class to wrap an existing [DebuggerDisplay("XmlAtomErrorReader {NodeType} {Name} {Value}")] internal class XmlAtomErrorReader : XmlWrappingReader { ///. Initializes a new /// Reader to wrap. internal XmlAtomErrorReader(XmlReader baseReader) : base(baseReader) { Debug.Assert(baseReader != null, "baseReader != null"); this.Reader = baseReader; } #region Methods. ///instance. Reads the next node from the stream. ///true if the next node was read successfully; false if there are no more nodes to read. public override bool Read() { bool result = base.Read(); if (this.NodeType == XmlNodeType.Element && Util.AreSame(this.Reader, XmlConstants.XmlErrorElementName, XmlConstants.DataWebMetadataNamespace)) { string message = ReadErrorMessage(this.Reader); // In case of instream errors, the status code should be 500 (which is the default) throw new DataServiceClientException(Strings.Deserialize_ServerException(message)); } return result; } ///Reads an element string from the specified /// Reader to get value from. /// Whether a null attribute marker should be checked on the element. ///. The text value within the element, possibly null. ////// Simple values only are expected - mixed content will throw an error. /// Interspersed comments are ignored. /// internal static string ReadElementString(XmlReader reader, bool checkNullAttribute) { Debug.Assert(reader != null, "reader != null"); Debug.Assert(XmlNodeType.Element == reader.NodeType, "not positioned on Element"); string result = null; bool empty = checkNullAttribute && !Util.DoesNullAttributeSayTrue(reader); if (reader.IsEmptyElement) { return (empty ? String.Empty : null); } while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.EndElement: return result ?? (empty ? String.Empty : null); case XmlNodeType.CDATA: case XmlNodeType.Text: case XmlNodeType.SignificantWhitespace: if (null != result) { throw Error.InvalidOperation(Strings.Deserialize_MixedTextWithComment); } result = reader.Value; break; case XmlNodeType.Comment: case XmlNodeType.Whitespace: break; case XmlNodeType.Element: default: throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } } // xml ended before EndElement? throw Error.InvalidOperation(Strings.Deserialize_ExpectingSimpleValue); } ///With the reader positioned on an 'error' element, reads the text of the 'message' child. ///from which to read a WCF Data Service inline error message. /// The text of the 'message' child element, empty if not found. private static string ReadErrorMessage(XmlReader reader) { Debug.Assert(reader != null, "reader != null"); Debug.Assert(reader.NodeType == XmlNodeType.Element, "reader.NodeType == XmlNodeType.Element"); Debug.Assert(reader.LocalName == XmlConstants.XmlErrorElementName, "reader.LocalName == XmlConstants.XmlErrorElementName"); int depth = 1; while (depth > 0 && reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { if (!reader.IsEmptyElement) { depth++; } if (depth == 2 && Util.AreSame(reader, XmlConstants.XmlErrorMessageElementName, XmlConstants.DataWebMetadataNamespace)) { return ReadElementString(reader, false); } } else if (reader.NodeType == XmlNodeType.EndElement) { depth--; } } return String.Empty; } #endregion Methods. } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- EntityCommand.cs
- Thumb.cs
- TypeForwardedToAttribute.cs
- FixedSOMPageConstructor.cs
- TraceInternal.cs
- SafeSystemMetrics.cs
- CapacityStreamGeometryContext.cs
- ExpressionDumper.cs
- UnsafeNativeMethods.cs
- Region.cs
- BigInt.cs
- SignatureToken.cs
- TimeStampChecker.cs
- TextSearch.cs
- ExpressionPrefixAttribute.cs
- DateTimeFormat.cs
- SemaphoreSecurity.cs
- ServiceNameCollection.cs
- HasActivatableWorkflowEvent.cs
- ComponentResourceManager.cs
- NamedElement.cs
- TextOutput.cs
- Lasso.cs
- FrameworkElementFactoryMarkupObject.cs
- LowerCaseStringConverter.cs
- FactoryMaker.cs
- ProbeDuplexCD1AsyncResult.cs
- ByteStack.cs
- AbstractSvcMapFileLoader.cs
- ListenerConstants.cs
- PropertyChangedEventManager.cs
- EventRouteFactory.cs
- ToolBarButton.cs
- DataRowExtensions.cs
- PanelStyle.cs
- ExtendedProtectionPolicy.cs
- ReadContentAsBinaryHelper.cs
- OperationParameterInfo.cs
- OutputScopeManager.cs
- ToolZone.cs
- StdValidatorsAndConverters.cs
- HandleRef.cs
- NotificationContext.cs
- DataViewSetting.cs
- Nullable.cs
- CancellationScope.cs
- Viewport2DVisual3D.cs
- PenThread.cs
- AdornerHitTestResult.cs
- PathSegmentCollection.cs
- WebPartConnectionsConfigureVerb.cs
- ObjectIDGenerator.cs
- SchemaEntity.cs
- GuidConverter.cs
- ViewStateModeByIdAttribute.cs
- LineVisual.cs
- TraceAsyncResult.cs
- PageFunction.cs
- Package.cs
- Missing.cs
- CriticalExceptions.cs
- processwaithandle.cs
- TypeExtension.cs
- SoapServerProtocol.cs
- CaseCqlBlock.cs
- DesignerCategoryAttribute.cs
- EncodingInfo.cs
- ModuleConfigurationInfo.cs
- FrameworkElement.cs
- PageParserFilter.cs
- DataRowCollection.cs
- MD5CryptoServiceProvider.cs
- QilVisitor.cs
- Parser.cs
- templategroup.cs
- PropertyValueChangedEvent.cs
- ConfigurationConverterBase.cs
- HttpModuleActionCollection.cs
- NestedContainer.cs
- NameSpaceExtractor.cs
- DecimalKeyFrameCollection.cs
- LOSFormatter.cs
- SafeCryptoHandles.cs
- FullTrustAssembly.cs
- Line.cs
- SqlWriter.cs
- Track.cs
- QueryCoreOp.cs
- TableAdapterManagerHelper.cs
- IgnoreFileBuildProvider.cs
- UpdateCommand.cs
- DecoratedNameAttribute.cs
- HealthMonitoringSectionHelper.cs
- PageOrientation.cs
- SiteMapNode.cs
- RijndaelManagedTransform.cs
- EncodingTable.cs
- XmlIncludeAttribute.cs
- HandleInitializationContext.cs
- CircleHotSpot.cs