Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Epm / EpmCustomContentWriterNodeData.cs / 1305376 / EpmCustomContentWriterNodeData.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Data held by each node in the EpmTargetTree containing information used // by the EpmCustomContentWriter visitor // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Common { using System; using System.IO; using System.Xml; #if !ASTORIA_CLIENT using System.ServiceModel.Syndication; using System.Data.Services.Serializers; using System.Data.Services.Providers; #else using System.Data.Services.Client; #endif ////// Data held by each node in the EpmTargetTree containing information used by the /// EpmCustomContentWriter visitor /// internal sealed class EpmCustomContentWriterNodeData : IDisposable { ////// IDisposable helper state /// private bool disposed; #if ASTORIA_CLIENT ///Initializes the per node data for custom serializer /// Segment in target tree corresponding to this node /// Object from which to read properties internal EpmCustomContentWriterNodeData(EpmTargetPathSegment segment, object element) #else ///Initializes the per node data for custom serializer /// Segment in target tree corresponding to this node /// Object from which to read properties /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentWriterNodeData(EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { this.XmlContentStream = new MemoryStream(); XmlWriterSettings customContentWriterSettings = new XmlWriterSettings(); customContentWriterSettings.OmitXmlDeclaration = true; customContentWriterSettings.ConformanceLevel = ConformanceLevel.Fragment; this.XmlContentWriter = XmlWriter.Create(this.XmlContentStream, customContentWriterSettings); #if ASTORIA_CLIENT this.PopulateData(segment, element); #else this.PopulateData(segment, element, nullValuedProperties, provider); #endif } #if ASTORIA_CLIENT ///Initializes the per node data for custom serializer /// Parent node whose xml writer we are going to reuse /// Segment in target tree corresponding to this node /// Object from which to read properties internal EpmCustomContentWriterNodeData(EpmCustomContentWriterNodeData parentData, EpmTargetPathSegment segment, object element) #else ///Initializes the per node data for custom serializer /// Parent node whose xml writer we are going to reuse /// Segment in target tree corresponding to this node /// Object from which to read properties /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentWriterNodeData(EpmCustomContentWriterNodeData parentData, EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { this.XmlContentStream = parentData.XmlContentStream; this.XmlContentWriter = parentData.XmlContentWriter; #if ASTORIA_CLIENT this.PopulateData(segment, element); #else this.PopulateData(segment, element, nullValuedProperties, provider); #endif } ////// Memory stream on top of which XmlWriter works /// internal MemoryStream XmlContentStream { get; private set; } ////// Xml writer used for holding custom content fragment /// internal XmlWriter XmlContentWriter { get; private set; } ///Data for current node internal String Data { get; private set; } ////// Closes XmlWriter and disposes the MemoryStream /// public void Dispose() { if (!this.disposed) { if (this.XmlContentWriter != null) { this.XmlContentWriter.Close(); this.XmlContentWriter = null; } if (this.XmlContentStream != null) { this.XmlContentStream.Dispose(); this.XmlContentStream = null; } this.disposed = true; } } ////// Adds the content generated through custom serialization to the SyndicationItem or XmlWriter /// /// SyndicationItem or XmlWriter being serialized [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "XmlReader on MemoryStream does not require disposal")] #if ASTORIA_CLIENT internal void AddContentToTarget(XmlWriter target) #else internal void AddContentToTarget(SyndicationItem target) #endif { #if ASTORIA_CLIENT Util.CheckArgumentNull(target, "target"); #else WebUtil.CheckArgumentNull(target, "target"); #endif this.XmlContentWriter.Close(); this.XmlContentWriter = null; this.XmlContentStream.Seek(0, SeekOrigin.Begin); XmlReaderSettings customContentReaderSettings = new XmlReaderSettings(); customContentReaderSettings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader reader = XmlReader.Create(this.XmlContentStream, customContentReaderSettings); this.XmlContentStream = null; #if ASTORIA_CLIENT target.WriteNode(reader, false); #else target.ElementExtensions.Add(reader); #endif } #if ASTORIA_CLIENT ////// Populates the data value corresponding to this node, also updates the list of null attributes /// in the parent null attribute list if current node is attribute with null value /// /// Segment being populated /// Object whose property will be read private void PopulateData(EpmTargetPathSegment segment, object element) #else ////// Populates the data value corresponding to this node, also updates the list of null attributes /// in the parent null attribute list if current node is attribute with null value /// /// Segment being populated /// Object whose property will be read /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void PopulateData(EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { if (segment.EpmInfo != null) { Object propertyValue; try { #if ASTORIA_CLIENT propertyValue = segment.EpmInfo.PropValReader.DynamicInvoke(element); #else propertyValue = segment.EpmInfo.PropValReader.DynamicInvoke(element, provider); #endif } catch #if ASTORIA_CLIENT (System.Reflection.TargetInvocationException) #else (System.Reflection.TargetInvocationException e) #endif { #if !ASTORIA_CLIENT ErrorHandler.HandleTargetInvocationException(e); #endif throw; } #if ASTORIA_CLIENT this.Data = propertyValue == null ? String.Empty : ClientConvert.ToString(propertyValue, false /* atomDateConstruct */); #else if (propertyValue == null || propertyValue == DBNull.Value) { this.Data = String.Empty; nullValuedProperties.Add(segment.EpmInfo); } else { this.Data = PlainXmlSerializer.PrimitiveToString(propertyValue); } #endif } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Data held by each node in the EpmTargetTree containing information used // by the EpmCustomContentWriter visitor // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Common { using System; using System.IO; using System.Xml; #if !ASTORIA_CLIENT using System.ServiceModel.Syndication; using System.Data.Services.Serializers; using System.Data.Services.Providers; #else using System.Data.Services.Client; #endif ////// Data held by each node in the EpmTargetTree containing information used by the /// EpmCustomContentWriter visitor /// internal sealed class EpmCustomContentWriterNodeData : IDisposable { ////// IDisposable helper state /// private bool disposed; #if ASTORIA_CLIENT ///Initializes the per node data for custom serializer /// Segment in target tree corresponding to this node /// Object from which to read properties internal EpmCustomContentWriterNodeData(EpmTargetPathSegment segment, object element) #else ///Initializes the per node data for custom serializer /// Segment in target tree corresponding to this node /// Object from which to read properties /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentWriterNodeData(EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { this.XmlContentStream = new MemoryStream(); XmlWriterSettings customContentWriterSettings = new XmlWriterSettings(); customContentWriterSettings.OmitXmlDeclaration = true; customContentWriterSettings.ConformanceLevel = ConformanceLevel.Fragment; this.XmlContentWriter = XmlWriter.Create(this.XmlContentStream, customContentWriterSettings); #if ASTORIA_CLIENT this.PopulateData(segment, element); #else this.PopulateData(segment, element, nullValuedProperties, provider); #endif } #if ASTORIA_CLIENT ///Initializes the per node data for custom serializer /// Parent node whose xml writer we are going to reuse /// Segment in target tree corresponding to this node /// Object from which to read properties internal EpmCustomContentWriterNodeData(EpmCustomContentWriterNodeData parentData, EpmTargetPathSegment segment, object element) #else ///Initializes the per node data for custom serializer /// Parent node whose xml writer we are going to reuse /// Segment in target tree corresponding to this node /// Object from which to read properties /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentWriterNodeData(EpmCustomContentWriterNodeData parentData, EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { this.XmlContentStream = parentData.XmlContentStream; this.XmlContentWriter = parentData.XmlContentWriter; #if ASTORIA_CLIENT this.PopulateData(segment, element); #else this.PopulateData(segment, element, nullValuedProperties, provider); #endif } ////// Memory stream on top of which XmlWriter works /// internal MemoryStream XmlContentStream { get; private set; } ////// Xml writer used for holding custom content fragment /// internal XmlWriter XmlContentWriter { get; private set; } ///Data for current node internal String Data { get; private set; } ////// Closes XmlWriter and disposes the MemoryStream /// public void Dispose() { if (!this.disposed) { if (this.XmlContentWriter != null) { this.XmlContentWriter.Close(); this.XmlContentWriter = null; } if (this.XmlContentStream != null) { this.XmlContentStream.Dispose(); this.XmlContentStream = null; } this.disposed = true; } } ////// Adds the content generated through custom serialization to the SyndicationItem or XmlWriter /// /// SyndicationItem or XmlWriter being serialized [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "XmlReader on MemoryStream does not require disposal")] #if ASTORIA_CLIENT internal void AddContentToTarget(XmlWriter target) #else internal void AddContentToTarget(SyndicationItem target) #endif { #if ASTORIA_CLIENT Util.CheckArgumentNull(target, "target"); #else WebUtil.CheckArgumentNull(target, "target"); #endif this.XmlContentWriter.Close(); this.XmlContentWriter = null; this.XmlContentStream.Seek(0, SeekOrigin.Begin); XmlReaderSettings customContentReaderSettings = new XmlReaderSettings(); customContentReaderSettings.ConformanceLevel = ConformanceLevel.Fragment; XmlReader reader = XmlReader.Create(this.XmlContentStream, customContentReaderSettings); this.XmlContentStream = null; #if ASTORIA_CLIENT target.WriteNode(reader, false); #else target.ElementExtensions.Add(reader); #endif } #if ASTORIA_CLIENT ////// Populates the data value corresponding to this node, also updates the list of null attributes /// in the parent null attribute list if current node is attribute with null value /// /// Segment being populated /// Object whose property will be read private void PopulateData(EpmTargetPathSegment segment, object element) #else ////// Populates the data value corresponding to this node, also updates the list of null attributes /// in the parent null attribute list if current node is attribute with null value /// /// Segment being populated /// Object whose property will be read /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void PopulateData(EpmTargetPathSegment segment, object element, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) #endif { if (segment.EpmInfo != null) { Object propertyValue; try { #if ASTORIA_CLIENT propertyValue = segment.EpmInfo.PropValReader.DynamicInvoke(element); #else propertyValue = segment.EpmInfo.PropValReader.DynamicInvoke(element, provider); #endif } catch #if ASTORIA_CLIENT (System.Reflection.TargetInvocationException) #else (System.Reflection.TargetInvocationException e) #endif { #if !ASTORIA_CLIENT ErrorHandler.HandleTargetInvocationException(e); #endif throw; } #if ASTORIA_CLIENT this.Data = propertyValue == null ? String.Empty : ClientConvert.ToString(propertyValue, false /* atomDateConstruct */); #else if (propertyValue == null || propertyValue == DBNull.Value) { this.Data = String.Empty; nullValuedProperties.Add(segment.EpmInfo); } else { this.Data = PlainXmlSerializer.PrimitiveToString(propertyValue); } #endif } } } } // 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
- FormParameter.cs
- SqlCacheDependency.cs
- PopupRoot.cs
- DescendantBaseQuery.cs
- DbSourceParameterCollection.cs
- Expr.cs
- RepeaterItemEventArgs.cs
- TraceSource.cs
- PerformanceCounter.cs
- EntityCommandExecutionException.cs
- MethodCallConverter.cs
- BitmapPalettes.cs
- RelationshipConverter.cs
- SecurityResources.cs
- CursorConverter.cs
- SqlNotificationEventArgs.cs
- Avt.cs
- HotSpotCollection.cs
- ToolboxComponentsCreatingEventArgs.cs
- RSAOAEPKeyExchangeDeformatter.cs
- SafeMILHandle.cs
- ContainsRowNumberChecker.cs
- SecurityTokenTypes.cs
- SqlDesignerDataSourceView.cs
- GroupQuery.cs
- GridViewUpdatedEventArgs.cs
- Selection.cs
- MeasurementDCInfo.cs
- SingleStorage.cs
- CodeNamespaceCollection.cs
- SecUtil.cs
- ImpersonateTokenRef.cs
- KoreanCalendar.cs
- InheritablePropertyChangeInfo.cs
- BaseDataBoundControl.cs
- SourceItem.cs
- TabItemAutomationPeer.cs
- MemberRelationshipService.cs
- SafeRightsManagementSessionHandle.cs
- DataGridItemCollection.cs
- SimpleRecyclingCache.cs
- mongolianshape.cs
- RepeaterCommandEventArgs.cs
- ContextMenuAutomationPeer.cs
- Psha1DerivedKeyGenerator.cs
- Command.cs
- KeyValueSerializer.cs
- IPAddress.cs
- ResourceProviderFactory.cs
- HtmlElementErrorEventArgs.cs
- HttpInputStream.cs
- PhoneCallDesigner.cs
- ConfigsHelper.cs
- ColorMap.cs
- MouseEventArgs.cs
- XmlSchemaProviderAttribute.cs
- SchemaCollectionCompiler.cs
- DbModificationCommandTree.cs
- HtmlToClrEventProxy.cs
- InfiniteTimeSpanConverter.cs
- AnnotationService.cs
- PriorityChain.cs
- BindingOperations.cs
- ToolStripButton.cs
- MetafileHeaderWmf.cs
- initElementDictionary.cs
- TabControlCancelEvent.cs
- MultipartIdentifier.cs
- CalendarData.cs
- StrongName.cs
- SamlAction.cs
- DrawingGroup.cs
- FormattedTextSymbols.cs
- XmlCodeExporter.cs
- DocumentSchemaValidator.cs
- NamedPipeDuplicateContext.cs
- DisplayMemberTemplateSelector.cs
- HtmlInputReset.cs
- xamlnodes.cs
- IPeerNeighbor.cs
- HtmlSelect.cs
- SizeChangedInfo.cs
- UnsafeNativeMethods.cs
- BaseTemplateBuildProvider.cs
- OdbcErrorCollection.cs
- DbMetaDataColumnNames.cs
- _RequestLifetimeSetter.cs
- IndexOutOfRangeException.cs
- EllipseGeometry.cs
- XmlWriter.cs
- UrlAuthorizationModule.cs
- CommandManager.cs
- D3DImage.cs
- RemoteWebConfigurationHostServer.cs
- RenderData.cs
- SizeFConverter.cs
- InheritanceContextChangedEventManager.cs
- TraversalRequest.cs
- DesignBindingPropertyDescriptor.cs
- XmlSchemaDatatype.cs