Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / DataWeb / Server / System / Data / Services / Epm / EpmCustomContentSerializer.cs / 1305376 / EpmCustomContentSerializer.cs
//---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Class used for serializing custom EntityPropertyMappingAttribute content // for non-syndication mappings // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Common { using System.Collections.Generic; using System.Diagnostics; #if !ASTORIA_CLIENT using System.ServiceModel.Syndication; using System.Data.Services.Providers; #else using System.Data.Services.Client; using System.Xml; #endif ////// Base visitor class for performing serialization of custom content in the feed entry whose mapping /// is provided through EntityPropertyMappingAttributes /// internal sealed class EpmCustomContentSerializer : EpmContentSerializerBase, IDisposable { ///IDisposable helper state private bool disposed; ////// Dictionary mapping visitor content and with target paths /// private DictionaryvisitorContent; #if ASTORIA_CLIENT /// /// Constructor initializes the base class be identifying itself as a custom content serializer /// /// Target tree containing mapping information /// Object to be serialized /// SyndicationItem to which content will be added internal EpmCustomContentSerializer(EpmTargetTree targetTree, object element, XmlWriter target) : base(targetTree, false, element, target) { this.InitializeVisitorContent(); } #else ////// Constructor initializes the base class be identifying itself as a custom content serializer /// /// Target tree containing mapping information /// Object to be serialized /// SyndicationItem to which content will be added /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentSerializer(EpmTargetTree targetTree, object element, SyndicationItem target, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) : base(targetTree, false, element, target) { this.InitializeVisitorContent(nullValuedProperties, provider); } #endif ////// Closes all the XmlWriter and MemoryStream objects in the tree and adds them to the SyndicationItem /// as ElementExtensions. Invokes the NodeDataCleaner to dispose off any existing memory stream and /// XmlWriter objects /// public void Dispose() { if (!this.disposed) { foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { EpmCustomContentWriterNodeData c = this.visitorContent[subSegmentOfRoot]; Debug.Assert(c != null, "Must have custom data for all the children of root"); if (this.Success) { c.AddContentToTarget(this.Target); } c.Dispose(); } this.disposed = true; } } #if ASTORIA_CLIENT ////// Override of the base Visitor method, which actually performs mapping search and serialization /// /// Current segment being checked for mapping /// Which sub segments to serialize protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind) #else ////// Override of the base Visitor method, which actually performs mapping search and serialization /// /// Current segment being checked for mapping /// Which sub segments to serialize /// Data Service provider used for rights verification. protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider) #endif { if (targetSegment.IsAttribute) { this.WriteAttribute(targetSegment); } else { #if ASTORIA_CLIENT this.WriteElement(targetSegment); #else this.WriteElement(targetSegment, provider); #endif } } ////// Given a segment, writes the attribute to xml writer corresponding to it /// /// Segment being written private void WriteAttribute(EpmTargetPathSegment targetSegment) { // Content to be written in an attribute Debug.Assert(targetSegment.HasContent, "Must have content for attributes"); EpmCustomContentWriterNodeData currentContent = this.visitorContent[targetSegment]; currentContent.XmlContentWriter.WriteAttributeString( targetSegment.SegmentNamespacePrefix, targetSegment.SegmentName.Substring(1), targetSegment.SegmentNamespaceUri, currentContent.Data); } #if ASTORIA_CLIENT ////// Given a segment, writes the element to xml writer corresponding to it, works recursively to write child elements/attributes /// /// Segment being written private void WriteElement(EpmTargetPathSegment targetSegment) #else ////// Given a segment, writes the element to xml writer corresponding to it, works recursively to write child elements/attributes /// /// Segment being written /// Data Service provider used for rights verification. private void WriteElement(EpmTargetPathSegment targetSegment, DataServiceProviderWrapper provider) #endif { // Content to be written in an element EpmCustomContentWriterNodeData currentContent = this.visitorContent[targetSegment]; currentContent.XmlContentWriter.WriteStartElement( targetSegment.SegmentNamespacePrefix, targetSegment.SegmentName, targetSegment.SegmentNamespaceUri); #if ASTORIA_CLIENT // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Attributes); #else // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Attributes, provider); #endif if (targetSegment.HasContent) { Debug.Assert(currentContent.Data != null, "Must always have non-null data content value"); currentContent.XmlContentWriter.WriteString(currentContent.Data); } #if ASTORIA_CLIENT // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Elements); #else // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Elements, provider); #endif currentContent.XmlContentWriter.WriteEndElement(); } #if ASTORIA_CLIENT ///Initializes content for the serializer visitor private void InitializeVisitorContent() { this.visitorContent = new Dictionary(ReferenceEqualityComparer .Instance); // Initialize all the root's children's xml writers foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { this.visitorContent.Add(subSegmentOfRoot, new EpmCustomContentWriterNodeData(subSegmentOfRoot, this.Element)); this.InitializeSubSegmentVisitorContent(subSegmentOfRoot); } } /// Initialize the visitor content for all of root's grandchildren and beyond /// One of root's children private void InitializeSubSegmentVisitorContent(EpmTargetPathSegment subSegment) { foreach (EpmTargetPathSegment segment in subSegment.SubSegments) { this.visitorContent.Add(segment, new EpmCustomContentWriterNodeData(this.visitorContent[subSegment], segment, this.Element)); this.InitializeSubSegmentVisitorContent(segment); } } #else ///Initializes content for the serializer visitor /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void InitializeVisitorContent(EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) { this.visitorContent = new Dictionary(ReferenceEqualityComparer .Instance); // Initialize all the root's children's xml writers foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { this.visitorContent.Add(subSegmentOfRoot, new EpmCustomContentWriterNodeData(subSegmentOfRoot, this.Element, nullValuedProperties, provider)); this.InitializeSubSegmentVisitorContent(subSegmentOfRoot, nullValuedProperties, provider); } } /// Initialize the visitor content for all of root's grandchildren and beyond /// One of root's children /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void InitializeSubSegmentVisitorContent(EpmTargetPathSegment subSegment, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) { foreach (EpmTargetPathSegment segment in subSegment.SubSegments) { this.visitorContent.Add(segment, new EpmCustomContentWriterNodeData(this.visitorContent[subSegment], segment, this.Element, nullValuedProperties, provider)); this.InitializeSubSegmentVisitorContent(segment, nullValuedProperties, provider); } } #endif } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------------- //// Copyright (c) Microsoft Corporation. All rights reserved. // //// Class used for serializing custom EntityPropertyMappingAttribute content // for non-syndication mappings // // // @owner [....] //--------------------------------------------------------------------- namespace System.Data.Services.Common { using System.Collections.Generic; using System.Diagnostics; #if !ASTORIA_CLIENT using System.ServiceModel.Syndication; using System.Data.Services.Providers; #else using System.Data.Services.Client; using System.Xml; #endif ////// Base visitor class for performing serialization of custom content in the feed entry whose mapping /// is provided through EntityPropertyMappingAttributes /// internal sealed class EpmCustomContentSerializer : EpmContentSerializerBase, IDisposable { ///IDisposable helper state private bool disposed; ////// Dictionary mapping visitor content and with target paths /// private DictionaryvisitorContent; #if ASTORIA_CLIENT /// /// Constructor initializes the base class be identifying itself as a custom content serializer /// /// Target tree containing mapping information /// Object to be serialized /// SyndicationItem to which content will be added internal EpmCustomContentSerializer(EpmTargetTree targetTree, object element, XmlWriter target) : base(targetTree, false, element, target) { this.InitializeVisitorContent(); } #else ////// Constructor initializes the base class be identifying itself as a custom content serializer /// /// Target tree containing mapping information /// Object to be serialized /// SyndicationItem to which content will be added /// Null valued properties found during serialization /// Data Service provider used for rights verification. internal EpmCustomContentSerializer(EpmTargetTree targetTree, object element, SyndicationItem target, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) : base(targetTree, false, element, target) { this.InitializeVisitorContent(nullValuedProperties, provider); } #endif ////// Closes all the XmlWriter and MemoryStream objects in the tree and adds them to the SyndicationItem /// as ElementExtensions. Invokes the NodeDataCleaner to dispose off any existing memory stream and /// XmlWriter objects /// public void Dispose() { if (!this.disposed) { foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { EpmCustomContentWriterNodeData c = this.visitorContent[subSegmentOfRoot]; Debug.Assert(c != null, "Must have custom data for all the children of root"); if (this.Success) { c.AddContentToTarget(this.Target); } c.Dispose(); } this.disposed = true; } } #if ASTORIA_CLIENT ////// Override of the base Visitor method, which actually performs mapping search and serialization /// /// Current segment being checked for mapping /// Which sub segments to serialize protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind) #else ////// Override of the base Visitor method, which actually performs mapping search and serialization /// /// Current segment being checked for mapping /// Which sub segments to serialize /// Data Service provider used for rights verification. protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider) #endif { if (targetSegment.IsAttribute) { this.WriteAttribute(targetSegment); } else { #if ASTORIA_CLIENT this.WriteElement(targetSegment); #else this.WriteElement(targetSegment, provider); #endif } } ////// Given a segment, writes the attribute to xml writer corresponding to it /// /// Segment being written private void WriteAttribute(EpmTargetPathSegment targetSegment) { // Content to be written in an attribute Debug.Assert(targetSegment.HasContent, "Must have content for attributes"); EpmCustomContentWriterNodeData currentContent = this.visitorContent[targetSegment]; currentContent.XmlContentWriter.WriteAttributeString( targetSegment.SegmentNamespacePrefix, targetSegment.SegmentName.Substring(1), targetSegment.SegmentNamespaceUri, currentContent.Data); } #if ASTORIA_CLIENT ////// Given a segment, writes the element to xml writer corresponding to it, works recursively to write child elements/attributes /// /// Segment being written private void WriteElement(EpmTargetPathSegment targetSegment) #else ////// Given a segment, writes the element to xml writer corresponding to it, works recursively to write child elements/attributes /// /// Segment being written /// Data Service provider used for rights verification. private void WriteElement(EpmTargetPathSegment targetSegment, DataServiceProviderWrapper provider) #endif { // Content to be written in an element EpmCustomContentWriterNodeData currentContent = this.visitorContent[targetSegment]; currentContent.XmlContentWriter.WriteStartElement( targetSegment.SegmentNamespacePrefix, targetSegment.SegmentName, targetSegment.SegmentNamespaceUri); #if ASTORIA_CLIENT // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Attributes); #else // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Attributes, provider); #endif if (targetSegment.HasContent) { Debug.Assert(currentContent.Data != null, "Must always have non-null data content value"); currentContent.XmlContentWriter.WriteString(currentContent.Data); } #if ASTORIA_CLIENT // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Elements); #else // Serialize the attributes and children before serializing the data itself base.Serialize(targetSegment, EpmSerializationKind.Elements, provider); #endif currentContent.XmlContentWriter.WriteEndElement(); } #if ASTORIA_CLIENT ///Initializes content for the serializer visitor private void InitializeVisitorContent() { this.visitorContent = new Dictionary(ReferenceEqualityComparer .Instance); // Initialize all the root's children's xml writers foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { this.visitorContent.Add(subSegmentOfRoot, new EpmCustomContentWriterNodeData(subSegmentOfRoot, this.Element)); this.InitializeSubSegmentVisitorContent(subSegmentOfRoot); } } /// Initialize the visitor content for all of root's grandchildren and beyond /// One of root's children private void InitializeSubSegmentVisitorContent(EpmTargetPathSegment subSegment) { foreach (EpmTargetPathSegment segment in subSegment.SubSegments) { this.visitorContent.Add(segment, new EpmCustomContentWriterNodeData(this.visitorContent[subSegment], segment, this.Element)); this.InitializeSubSegmentVisitorContent(segment); } } #else ///Initializes content for the serializer visitor /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void InitializeVisitorContent(EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) { this.visitorContent = new Dictionary(ReferenceEqualityComparer .Instance); // Initialize all the root's children's xml writers foreach (EpmTargetPathSegment subSegmentOfRoot in this.Root.SubSegments) { this.visitorContent.Add(subSegmentOfRoot, new EpmCustomContentWriterNodeData(subSegmentOfRoot, this.Element, nullValuedProperties, provider)); this.InitializeSubSegmentVisitorContent(subSegmentOfRoot, nullValuedProperties, provider); } } /// Initialize the visitor content for all of root's grandchildren and beyond /// One of root's children /// Null valued properties found during serialization /// Data Service provider used for rights verification. private void InitializeSubSegmentVisitorContent(EpmTargetPathSegment subSegment, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider) { foreach (EpmTargetPathSegment segment in subSegment.SubSegments) { this.visitorContent.Add(segment, new EpmCustomContentWriterNodeData(this.visitorContent[subSegment], segment, this.Element, nullValuedProperties, provider)); this.InitializeSubSegmentVisitorContent(segment, nullValuedProperties, provider); } } #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
- CodeParameterDeclarationExpressionCollection.cs
- ProcessInputEventArgs.cs
- XmlTextReaderImpl.cs
- XmlArrayItemAttributes.cs
- XmlUtil.cs
- ApplicationSettingsBase.cs
- InertiaTranslationBehavior.cs
- MouseCaptureWithinProperty.cs
- DispatcherSynchronizationContext.cs
- DesignerValidatorAdapter.cs
- MdbDataFileEditor.cs
- MemberRelationshipService.cs
- TypeListConverter.cs
- WebPartEditorOkVerb.cs
- TextEffect.cs
- MetadataArtifactLoaderCompositeFile.cs
- XmlDomTextWriter.cs
- SerializationSectionGroup.cs
- Wildcard.cs
- LogSwitch.cs
- EncoderBestFitFallback.cs
- EventlogProvider.cs
- EndpointPerformanceCounters.cs
- TableLayoutStyleCollection.cs
- PhysicalOps.cs
- SchemaLookupTable.cs
- IxmlLineInfo.cs
- NativeMethods.cs
- MessagePropertyFilter.cs
- DesigntimeLicenseContext.cs
- BaseUriHelper.cs
- PeerNameRecord.cs
- HttpListenerResponse.cs
- Image.cs
- LabelTarget.cs
- UrlAuthFailedErrorFormatter.cs
- DbException.cs
- ApplyTemplatesAction.cs
- SQLCharsStorage.cs
- Rect3DValueSerializer.cs
- TrackingWorkflowEventArgs.cs
- X509CertificateStore.cs
- BStrWrapper.cs
- UIElementCollection.cs
- ProvidersHelper.cs
- HttpPostedFileBase.cs
- SendingRequestEventArgs.cs
- NullToBooleanConverter.cs
- CodeIdentifiers.cs
- IgnoreFlushAndCloseStream.cs
- SoapAttributeAttribute.cs
- ControlIdConverter.cs
- Bits.cs
- LinqToSqlWrapper.cs
- XPathBinder.cs
- ContextBase.cs
- UrlMappingCollection.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- StylusPointDescription.cs
- TokenFactoryBase.cs
- PrincipalPermission.cs
- CodeStatementCollection.cs
- base64Transforms.cs
- StateMachine.cs
- lengthconverter.cs
- SubtreeProcessor.cs
- DriveInfo.cs
- CornerRadius.cs
- ChannelServices.cs
- CheckableControlBaseAdapter.cs
- LinkGrep.cs
- CodeCommentStatement.cs
- XmlAnyElementAttribute.cs
- COM2TypeInfoProcessor.cs
- CommentAction.cs
- Rules.cs
- BamlResourceDeserializer.cs
- HttpProfileBase.cs
- MembershipUser.cs
- querybuilder.cs
- HttpGetClientProtocol.cs
- StringPropertyBuilder.cs
- OracleConnectionString.cs
- XPathSelfQuery.cs
- ConnectionStringsExpressionBuilder.cs
- CompiledRegexRunner.cs
- MembershipValidatePasswordEventArgs.cs
- XmlDataSource.cs
- RangeValidator.cs
- ScriptResourceAttribute.cs
- AppModelKnownContentFactory.cs
- DateTimeConverter.cs
- XamlDebuggerXmlReader.cs
- CodeSnippetCompileUnit.cs
- DateBoldEvent.cs
- TaskHelper.cs
- InvalidComObjectException.cs
- PaginationProgressEventArgs.cs
- TraceHandlerErrorFormatter.cs
- GeneratedView.cs