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
        }
        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
        }
 /// <summary>
 /// Constructor initializes the base class be identifying itself as a custom content serializer
 /// </summary>
 /// <param name="targetTree">Target tree containing mapping information</param>
 /// <param name="element">Object to be serialized</param>
 /// <param name="target">SyndicationItem to which content will be added</param>
 /// <param name="nullValuedProperties">Null valued properties found during serialization</param>
 /// <param name="provider">Data Service provider used for rights verification.</param>
 internal EpmCustomContentSerializer(EpmTargetTree targetTree, object element, SyndicationItem target, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider)
     : base(targetTree, false, element, target)
 {
     this.InitializeVisitorContent(nullValuedProperties, provider);
 }
 /// <summary>Initialize the visitor content for all of root's grandchildren and beyond</summary>
 /// <param name="subSegment">One of root's children</param>
 /// <param name="nullValuedProperties">Null valued properties found during serialization</param>
 /// <param name="provider">Data Service provider used for rights verification.</param>
 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);
     }
 }
        /// <summary>Initializes content for the serializer visitor</summary>
        /// <param name="nullValuedProperties">Null valued properties found during serialization</param>
        /// <param name="provider">Data Service provider used for rights verification.</param>
        private void InitializeVisitorContent(EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties, DataServiceProviderWrapper provider)
        {
            this.visitorContent = new Dictionary<EpmTargetPathSegment, EpmCustomContentWriterNodeData>(ReferenceEqualityComparer<EpmTargetPathSegment>.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);
            }
        }
 /// <summary>
 /// Constructor initializes the base class be identifying itself as a syndication serializer
 /// </summary>
 /// <param name="tree">Target tree containing mapping information</param>
 /// <param name="element">Object to be serialized</param>
 /// <param name="target">SyndicationItem to which content will be added</param>
 /// <param name="nullValuedProperties">Null valued properties found during serialization</param>
 internal EpmSyndicationContentSerializer(EpmTargetTree tree, object element, SyndicationItem target, EpmContentSerializer.EpmNullValuedPropertyTree nullValuedProperties)
     : base(tree, true, element, target)
 {
     this.nullValuedProperties = nullValuedProperties;
 }
        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.ReadPropertyValue(element);
#else
                    propertyValue = segment.EpmInfo.ReadPropertyValue(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);
#else
                if (propertyValue == null || propertyValue == DBNull.Value)
                {
                    this.Data = String.Empty;
                    nullValuedProperties.Add(segment.EpmInfo);
                }
                else
                {
                    this.Data = PlainXmlSerializer.PrimitiveToString(propertyValue);
                }
#endif
            }
        }
    }
        /// <summary>Write the entry element.</summary>
        /// <param name="expanded">Expanded result provider for the specified <paramref name="element"/>.</param>
        /// <param name="element">element representing the entry element</param>
        /// <param name="expectedType">expected type of the entry element</param>
        /// <param name="absoluteUri">absolute uri for the entry element</param>
        /// <param name="relativeUri">relative uri for the entry element</param>
        /// <param name="target">Target to write to.</param>
        private void WriteEntryElement(IExpandedResult expanded, object element, ResourceType expectedType, Uri absoluteUri, string relativeUri, SyndicationItem target)
        {
            Debug.Assert(element != null || (absoluteUri != null && !String.IsNullOrEmpty(relativeUri)), "Uri's must be specified for null values");
            Debug.Assert(target != null, "target != null");

            this.IncrementSegmentResultCount();

            string title, fullName;
            if (expectedType == null)
            {
                // If the request uri is targetting some open type properties, then we don't know the type of the resource
                // Hence we assume it to be of object type. The reason we do this is that if the value is null, there is
                // no way to know what the type of the property would be, and then we write it out as object. If the value
                // is not null, then we do get the resource type from the instance and write out the actual resource type.
                title = typeof(object).Name;
                fullName = typeof(object).FullName;
            }
            else
            {
                title = expectedType.Name;
                fullName = expectedType.FullName;
            }

            target.Title = new TextSyndicationContent(String.Empty);
            if (element == null)
            {
                SetEntryTypeName(target, fullName);
                target.AttributeExtensions[QualifiedNullAttribute] = XmlConstants.XmlTrueLiteral;
                this.WriteOtherElements(
                    element,
                    expectedType,
                    title,
                    absoluteUri,
                    relativeUri,
                    null,
                    target);

                // Don't know when we hit this code path, keeping existing behaviour in this case
                target.Authors.Add(EmptyPerson);
            }
            else
            {
                absoluteUri = Serializer.GetUri(element, this.Provider, this.CurrentContainer, this.AbsoluteServiceUri);
                Debug.Assert(absoluteUri.AbsoluteUri.StartsWith(this.AbsoluteServiceUri.AbsoluteUri, StringComparison.Ordinal), "absoluteUri.AbsoluteUri.StartsWith(this.AbsoluteServiceUri.AbsoluteUri, StringComparison.Ordinal))");
                relativeUri = absoluteUri.AbsoluteUri.Substring(this.AbsoluteServiceUri.AbsoluteUri.Length);
                ResourceType actualResourceType = WebUtil.GetNonPrimitiveResourceType(this.Provider, element);

                string mediaETag = null;
                Uri readStreamUri = null;
                string mediaContentType = null;
                if (actualResourceType.IsMediaLinkEntry)
                {
                    this.Service.StreamProvider.GetStreamDescription(element, this.Service.OperationContext, relativeUri, out mediaETag, out readStreamUri, out mediaContentType);
                }

                SetEntryTypeName(target, actualResourceType.FullName);
                this.WriteOtherElements(
                    element,
                    actualResourceType,
                    title,
                    absoluteUri,
                    relativeUri,
                    mediaETag,
                    target);

                // Write the etag property, if the type has etag properties
                string etag = this.GetETagValue(element);
                if (etag != null)
                {
                    target.AttributeExtensions[new XmlQualifiedName(XmlConstants.AtomETagAttributeName, XmlConstants.DataWebMetadataNamespace)]
                        = etag;
                }

                DictionaryContent content = new DictionaryContent(actualResourceType.Properties.Count);

                using (EpmContentSerializer epmSerializer = new EpmContentSerializer(actualResourceType, element, target, this.Provider))
                {
                    this.WriteObjectProperties(expanded, element, actualResourceType, absoluteUri, relativeUri, target, content, actualResourceType.HasEntityPropertyMappings ? actualResourceType.EpmSourceTree.Root : null);
                    epmSerializer.Serialize(content, this.Provider);
                }

                if (actualResourceType.IsMediaLinkEntry)
                {
                    // Write <content type="..." src="..." />
                    Debug.Assert(readStreamUri != null, "readStreamUri != null");
                    Debug.Assert(!string.IsNullOrEmpty(mediaContentType), "!string.IsNullOrEmpty(mediaContentType)");
                    target.Content = new UrlSyndicationContent(readStreamUri, mediaContentType);
                    if (!content.IsEmpty)
                    {
                        // Since UrlSyndicationContent must have empty content, we write the <m:property /> node as SyndicationElementExtension.
                        target.ElementExtensions.Add(content.GetPropertyContentsReader());
                    }
                }
                else
                {
                    target.Content = content;
                }
            }

#if ASTORIA_FF_CALLBACKS
            this.Service.InternalOnWriteItem(target, element);
#endif                
        }