protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            IEnumerable <EpmTargetPathSegment> segmentsToSerialize;

            switch (kind)
            {
            case EpmSerializationKind.Attributes:
                segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == true);
                break;

            case EpmSerializationKind.Elements:
                segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == false);
                break;

            default:
                Debug.Assert(kind == EpmSerializationKind.All, "Must serialize everything");
                segmentsToSerialize = targetSegment.SubSegments;
                break;
            }

            foreach (EpmTargetPathSegment segment in segmentsToSerialize)
            {
                this.Serialize(segment, kind);
            }
        }
예제 #2
0
        /// <summary>
        /// Internal interface to be overridden in the subclasses.
        /// Goes through each subsegments and invokes itself for the children
        /// </summary>
        /// <param name="targetSegment">Current root segment in the target tree</param>
        /// <param name="kind">Which sub segments to serialize</param>
        /// <param name="provider">Data Service provider used for rights verification.</param>
        protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider)
#endif
        {
            IEnumerable <EpmTargetPathSegment> segmentsToSerialize;

            switch (kind)
            {
            case EpmSerializationKind.Attributes:
                segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == true);
                break;

            case EpmSerializationKind.Elements:
                segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == false);
                break;

            default:
                Debug.Assert(kind == EpmSerializationKind.All, "Must serialize everything");
                segmentsToSerialize = targetSegment.SubSegments;
                break;
            }

            foreach (EpmTargetPathSegment segment in segmentsToSerialize)
            {
#if ASTORIA_CLIENT
                this.Serialize(segment, kind);
#else
                this.Serialize(segment, kind, provider);
#endif
            }
        }
 protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
 {
     if (targetSegment.IsAttribute)
     {
         this.WriteAttribute(targetSegment);
     }
     else
     {
         this.WriteElement(targetSegment);
     }
 }
예제 #4
0
 protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
 {
     if (targetSegment.IsAttribute)
     {
         this.WriteAttribute(targetSegment);
     }
     else
     {
         this.WriteElement(targetSegment);
     }
 }
예제 #5
0
        /// <summary>
        /// Override of the base Visitor method, which actually performs mapping search and serialization
        /// </summary>
        /// <param name="targetSegment">Current segment being checked for mapping</param>
        /// <param name="kind">Which sub segments to serialize</param>
        /// <param name="provider">Data Service provider used for rights verification.</param>
        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
            }
        }
        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
            }
        }
예제 #7
0
        protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            IEnumerable<EpmTargetPathSegment> segmentsToSerialize;
            switch (kind)
            {
                case EpmSerializationKind.Attributes:
                    segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == true);
                    break;
                case EpmSerializationKind.Elements:
                    segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == false);
                    break;
                default:
                    Debug.Assert(kind == EpmSerializationKind.All, "Must serialize everything");
                    segmentsToSerialize = targetSegment.SubSegments;
                    break;
            }

            foreach (EpmTargetPathSegment segment in segmentsToSerialize)
            {
                this.Serialize(segment, kind);
            }
        }
 /// <summary>
 /// Override of the base Visitor method, which actually performs mapping search and serialization
 /// </summary>
 /// <param name="targetSegment">Current segment being checked for mapping</param>
 /// <param name="kind">Which sub segments to serialize</param>
 protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                Object propertyValue;

                try
                {
                    propertyValue = epmInfo.PropValReader.DynamicInvoke(this.Element);
                }
                catch (System.Reflection.TargetInvocationException)
                {
                    throw;
                }

                String          contentType;
                Action <String> contentWriter;

                switch (epmInfo.Attribute.TargetTextContentKind)
                {
                case SyndicationTextContentKind.Html:
                    contentType   = "html";
                    contentWriter = this.Target.WriteString;
                    break;

                case SyndicationTextContentKind.Xhtml:
                    contentType   = "xhtml";
                    contentWriter = this.Target.WriteRaw;
                    break;

                default:
                    contentType   = "text";
                    contentWriter = this.Target.WriteString;
                    break;
                }

                Action <String, bool, bool> textSyndicationWriter = (c, nonTextPossible, atomDateConstruct) =>
                {
                    this.Target.WriteStartElement(c, XmlConstants.AtomNamespace);
                    if (nonTextPossible)
                    {
                        this.Target.WriteAttributeString(XmlConstants.AtomTypeAttributeName, String.Empty, contentType);
                    }

                    String textPropertyValue =
                        propertyValue != null?ClientConvert.ToString(propertyValue, atomDateConstruct) :
                            atomDateConstruct?ClientConvert.ToString(DateTime.MinValue, atomDateConstruct) :
                                String.Empty;

                    contentWriter(textPropertyValue);
                    this.Target.WriteEndElement();
                };

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.ContributorEmail:
                    textSyndicationWriter(XmlConstants.AtomEmailElementName, false, false);
                    break;

                case SyndicationItemProperty.AuthorName:
                case SyndicationItemProperty.ContributorName:
                    textSyndicationWriter(XmlConstants.AtomNameElementName, false, false);
                    this.authorNamePresent = true;
                    break;

                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorUri:
                    textSyndicationWriter(XmlConstants.AtomUriElementName, false, false);
                    break;

                case SyndicationItemProperty.Updated:
                    textSyndicationWriter(XmlConstants.AtomUpdatedElementName, false, true);
                    this.updatedPresent = true;
                    break;

                case SyndicationItemProperty.Published:
                    textSyndicationWriter(XmlConstants.AtomPublishedElementName, false, true);
                    break;

                case SyndicationItemProperty.Rights:
                    textSyndicationWriter(XmlConstants.AtomRightsElementName, true, false);
                    break;

                case SyndicationItemProperty.Summary:
                    textSyndicationWriter(XmlConstants.AtomSummaryElementName, true, false);
                    break;

                case SyndicationItemProperty.Title:
                    textSyndicationWriter(XmlConstants.AtomTitleElementName, true, false);
                    break;

                default:
                    Debug.Assert(false, "Unhandled SyndicationItemProperty enum value - should never get here.");
                    break;
                }
            }
            else
            {
                if (targetSegment.SegmentName == XmlConstants.AtomAuthorElementName)
                {
                    this.CreateAuthor(false);
                    base.Serialize(targetSegment, kind);
                    this.FinishAuthor();
                }
                else if (targetSegment.SegmentName == XmlConstants.AtomContributorElementName)
                {
                    this.Target.WriteStartElement(XmlConstants.AtomContributorElementName, XmlConstants.AtomNamespace);
                    base.Serialize(targetSegment, kind);
                    this.Target.WriteEndElement();
                }
                else
                {
                    Debug.Assert(false, "Only authors and contributors have nested elements");
                }
            }
        }
        /// <summary>
        /// Override of the base Visitor method, which actually performs mapping search and serialization
        /// </summary>
        /// <param name="targetSegment">Current segment being checked for mapping</param>
        /// <param name="kind">Which sub segments to serialize</param>
        /// <param name="provider">Data Service provider used for rights verification.</param>
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                Object propertyValue;
                
                try
                {
                    propertyValue = epmInfo.ReadPropertyValue(this.Element, provider);
                }
                catch (System.Reflection.TargetInvocationException e)
                {
                    ErrorHandler.HandleTargetInvocationException(e);
                    throw;
                }

                if (propertyValue == null)
                {
                    this.nullValuedProperties.Add(epmInfo);
                }

                String textPropertyValue = propertyValue != null ? PlainXmlSerializer.PrimitiveToString(propertyValue) : String.Empty;
                TextSyndicationContentKind contentKind = (TextSyndicationContentKind)epmInfo.Attribute.TargetTextContentKind;

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                    case SyndicationItemProperty.AuthorEmail:
                        this.CreateAuthor(false);
                        this.author.Email = textPropertyValue;
                        break;
                    case SyndicationItemProperty.AuthorName:
                        this.CreateAuthor(false);
                        this.author.Name = textPropertyValue;    
                        this.authorNamePresent = true;
                        break;
                    case SyndicationItemProperty.AuthorUri:
                        this.CreateAuthor(false);
                        this.author.Uri = textPropertyValue;
                        break;
                    case SyndicationItemProperty.ContributorEmail:
                    case SyndicationItemProperty.ContributorName:
                    case SyndicationItemProperty.ContributorUri:
                        this.SetContributorProperty(epmInfo.Attribute.TargetSyndicationItem, textPropertyValue);
                        break;
                    case SyndicationItemProperty.Updated:
                        this.Target.LastUpdatedTime = EpmSyndicationContentSerializer.GetDate(propertyValue, Strings.EpmSerializer_UpdatedHasWrongType);
                        break;
                    case SyndicationItemProperty.Published:
                        this.Target.PublishDate = EpmSyndicationContentSerializer.GetDate(propertyValue, Strings.EpmSerializer_PublishedHasWrongType);
                        break;
                    case SyndicationItemProperty.Rights:
                        this.Target.Copyright = new TextSyndicationContent(textPropertyValue, contentKind);
                        break;
                    case SyndicationItemProperty.Summary:
                        this.Target.Summary = new TextSyndicationContent(textPropertyValue, contentKind);
                        break;
                    case SyndicationItemProperty.Title:
                        this.Target.Title = new TextSyndicationContent(textPropertyValue, contentKind);
                        break;
                    default:
                        Debug.Fail("Unhandled SyndicationItemProperty enum value - should never get here.");
                        break;
                }
            }
            else
            {
                base.Serialize(targetSegment, kind, provider);
            }
        }
        protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider)
#endif
        {
            IEnumerable<EpmTargetPathSegment> segmentsToSerialize;
            switch (kind)
            {
                case EpmSerializationKind.Attributes:
                    segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == true);
                    break;
                case EpmSerializationKind.Elements:
                    segmentsToSerialize = targetSegment.SubSegments.Where(s => s.IsAttribute == false);
                    break;
                default:
                    Debug.Assert(kind == EpmSerializationKind.All, "Must serialize everything");
                    segmentsToSerialize = targetSegment.SubSegments;
                    break;
            }

            foreach (EpmTargetPathSegment segment in segmentsToSerialize)
            {
#if ASTORIA_CLIENT
                this.Serialize(segment, kind);
#else
                this.Serialize(segment, kind, provider);
#endif
            }
        }
 protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        /// <summary>
        /// Override of the base Visitor method, which actually performs mapping search and serialization
        /// </summary>
        /// <param name="targetSegment">Current segment being checked for mapping</param>
        /// <param name="kind">Which sub segments to serialize</param>
        /// <param name="provider">Data Service provider used for rights verification.</param>
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind, DataServiceProviderWrapper provider)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                Object propertyValue;

                try
                {
                    propertyValue = epmInfo.ReadPropertyValue(this.Element, provider);
                }
                catch (System.Reflection.TargetInvocationException e)
                {
                    ErrorHandler.HandleTargetInvocationException(e);
                    throw;
                }

                if (propertyValue == null)
                {
                    this.nullValuedProperties.Add(epmInfo);
                }

                String textPropertyValue = propertyValue != null?PlainXmlSerializer.PrimitiveToString(propertyValue) : String.Empty;

                TextSyndicationContentKind contentKind = (TextSyndicationContentKind)epmInfo.Attribute.TargetTextContentKind;

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                    this.CreateAuthor(false);
                    this.author.Email = textPropertyValue;
                    break;

                case SyndicationItemProperty.AuthorName:
                    this.CreateAuthor(false);
                    this.author.Name       = textPropertyValue;
                    this.authorNamePresent = true;
                    break;

                case SyndicationItemProperty.AuthorUri:
                    this.CreateAuthor(false);
                    this.author.Uri = textPropertyValue;
                    break;

                case SyndicationItemProperty.ContributorEmail:
                case SyndicationItemProperty.ContributorName:
                case SyndicationItemProperty.ContributorUri:
                    this.SetContributorProperty(epmInfo.Attribute.TargetSyndicationItem, textPropertyValue);
                    break;

                case SyndicationItemProperty.Updated:
                    this.Target.LastUpdatedTime = EpmSyndicationContentSerializer.GetDate(propertyValue, Strings.EpmSerializer_UpdatedHasWrongType);
                    break;

                case SyndicationItemProperty.Published:
                    this.Target.PublishDate = EpmSyndicationContentSerializer.GetDate(propertyValue, Strings.EpmSerializer_PublishedHasWrongType);
                    break;

                case SyndicationItemProperty.Rights:
                    this.Target.Copyright = new TextSyndicationContent(textPropertyValue, contentKind);
                    break;

                case SyndicationItemProperty.Summary:
                    this.Target.Summary = new TextSyndicationContent(textPropertyValue, contentKind);
                    break;

                case SyndicationItemProperty.Title:
                    this.Target.Title = new TextSyndicationContent(textPropertyValue, contentKind);
                    break;

                default:
                    Debug.Fail("Unhandled SyndicationItemProperty enum value - should never get here.");
                    break;
                }
            }
            else
            {
                base.Serialize(targetSegment, kind, provider);
            }
        }
예제 #14
0
        /// <summary>
        /// Override of the base Visitor method, which actually performs mapping search and serialization
        /// </summary>
        /// <param name="targetSegment">Current segment being checked for mapping</param>
        /// <param name="kind">Which sub segments to serialize</param>
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                Object propertyValue;

                try
                {
                    propertyValue = epmInfo.ReadPropertyValue(this.Element);
                }
                catch (System.Reflection.TargetInvocationException)
                {
                    throw;
                }

                String          contentType;
                Action <String> contentWriter;

                switch (epmInfo.Attribute.TargetTextContentKind)
                {
                case SyndicationTextContentKind.Html:
                    contentType   = "html";
                    contentWriter = this.Target.WriteString;
                    break;

                case SyndicationTextContentKind.Xhtml:
                    contentType   = "xhtml";
                    contentWriter = this.Target.WriteRaw;
                    break;

                default:
                    contentType   = "text";
                    contentWriter = this.Target.WriteString;
                    break;
                }

                Action <String, bool, bool> textSyndicationWriter = (c, nonTextPossible, atomDateConstruct) =>
                {
                    this.Target.WriteStartElement(c, XmlConstants.AtomNamespace);
                    if (nonTextPossible)
                    {
                        this.Target.WriteAttributeString(XmlConstants.AtomTypeAttributeName, String.Empty, contentType);
                    }

                    // As per atomPub spec dateConstructs must contain valid datetime. Therefore we need to fill atom:updated/atom:published
                    // field with something (e.g. DateTimeOffset.MinValue) if the user wants to map null to either of these fields. This will
                    // satisfy protocol requirements and Syndication API. Note that the content will still contain information saying that the
                    // mapped property is supposed to be null - therefore the server will know that the actual value sent by the user is null.
                    // For all other elements we can use empty string since the content is not validated.
                    String textPropertyValue =
                        propertyValue != null?ClientConvert.ToString(propertyValue, atomDateConstruct) :
                            atomDateConstruct?ClientConvert.ToString(DateTime.MinValue, atomDateConstruct) :
                                String.Empty;

                    contentWriter(textPropertyValue);
                    this.Target.WriteEndElement();
                };

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                case SyndicationItemProperty.AuthorEmail:
                case SyndicationItemProperty.ContributorEmail:
                    textSyndicationWriter(XmlConstants.AtomEmailElementName, false, false);
                    break;

                case SyndicationItemProperty.AuthorName:
                case SyndicationItemProperty.ContributorName:
                    textSyndicationWriter(XmlConstants.AtomNameElementName, false, false);
                    this.authorNamePresent = true;
                    break;

                case SyndicationItemProperty.AuthorUri:
                case SyndicationItemProperty.ContributorUri:
                    textSyndicationWriter(XmlConstants.AtomUriElementName, false, false);
                    break;

                case SyndicationItemProperty.Updated:
                    textSyndicationWriter(XmlConstants.AtomUpdatedElementName, false, true);
                    this.updatedPresent = true;
                    break;

                case SyndicationItemProperty.Published:
                    textSyndicationWriter(XmlConstants.AtomPublishedElementName, false, true);
                    break;

                case SyndicationItemProperty.Rights:
                    textSyndicationWriter(XmlConstants.AtomRightsElementName, true, false);
                    break;

                case SyndicationItemProperty.Summary:
                    textSyndicationWriter(XmlConstants.AtomSummaryElementName, true, false);
                    break;

                case SyndicationItemProperty.Title:
                    textSyndicationWriter(XmlConstants.AtomTitleElementName, true, false);
                    break;

                default:
                    Debug.Assert(false, "Unhandled SyndicationItemProperty enum value - should never get here.");
                    break;
                }
            }
            else
            {
                if (targetSegment.SegmentName == XmlConstants.AtomAuthorElementName)
                {
                    this.CreateAuthor(false);
                    base.Serialize(targetSegment, kind);
                    this.FinishAuthor();
                }
                else if (targetSegment.SegmentName == XmlConstants.AtomContributorElementName)
                {
                    this.Target.WriteStartElement(XmlConstants.AtomContributorElementName, XmlConstants.AtomNamespace);
                    base.Serialize(targetSegment, kind);
                    this.Target.WriteEndElement();
                }
                else
                {
                    Debug.Assert(false, "Only authors and contributors have nested elements");
                }
            }
        }
예제 #15
0
 /// <summary>
 /// Override of the base Visitor method, which actually performs mapping search and serialization
 /// </summary>
 /// <param name="targetSegment">Current segment being checked for mapping</param>
 /// <param name="kind">Which sub segments to serialize</param>
 protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
예제 #16
0
 /// <summary>
 /// Internal interface to be overridden in the subclasses.
 /// Goes through each subsegments and invokes itself for the children
 /// </summary>
 /// <param name="targetSegment">Current root segment in the target tree</param>
 /// <param name="kind">Which sub segments to serialize</param>
 protected virtual void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                object propertyValue;

                try
                {
                    propertyValue = epmInfo.ReadPropertyValue(this.Element);
                }
                catch (System.Reflection.TargetInvocationException)
                {
                    throw;
                }

                String contentType;
                Action<String> contentWriter;

                switch (epmInfo.Attribute.TargetTextContentKind)
                {
                    case SyndicationTextContentKind.Html:
                        contentType = "html";
                        contentWriter = this.Target.WriteString;
                        break;
                    case SyndicationTextContentKind.Xhtml:
                        contentType = "xhtml";
                        contentWriter = this.Target.WriteRaw;
                        break;
                    default:
                        contentType = "text";
                        contentWriter = this.Target.WriteString;
                        break;
                }

                Action<String, bool, bool> textSyndicationWriter = (c, nonTextPossible, atomDateConstruct) =>
                {
                    this.Target.WriteStartElement(c, XmlConstants.AtomNamespace);
                    if (nonTextPossible)
                    {
                        this.Target.WriteAttributeString(XmlConstants.AtomTypeAttributeName, String.Empty, contentType);
                    }

                    String textPropertyValue =
                        propertyValue != null   ? ClientConvert.ToString(propertyValue, atomDateConstruct) :
                        atomDateConstruct       ? ClientConvert.ToString(DateTime.MinValue, atomDateConstruct) :
                        String.Empty;

                    contentWriter(textPropertyValue);
                    this.Target.WriteEndElement();
                };

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                    case SyndicationItemProperty.AuthorEmail:
                    case SyndicationItemProperty.ContributorEmail:
                        textSyndicationWriter(XmlConstants.AtomEmailElementName, false, false);
                        break;
                    case SyndicationItemProperty.AuthorName:
                    case SyndicationItemProperty.ContributorName:
                        textSyndicationWriter(XmlConstants.AtomNameElementName, false, false);
                        this.authorNamePresent = true;
                        break;
                    case SyndicationItemProperty.AuthorUri:
                    case SyndicationItemProperty.ContributorUri:
                        textSyndicationWriter(XmlConstants.AtomUriElementName, false, false);
                        break;
                    case SyndicationItemProperty.Updated:
                        textSyndicationWriter(XmlConstants.AtomUpdatedElementName, false, true);
                        this.updatedPresent = true;
                        break;
                    case SyndicationItemProperty.Published:
                        textSyndicationWriter(XmlConstants.AtomPublishedElementName, false, true);
                        break;
                    case SyndicationItemProperty.Rights:
                        textSyndicationWriter(XmlConstants.AtomRightsElementName, true, false);
                        break;
                    case SyndicationItemProperty.Summary:
                        textSyndicationWriter(XmlConstants.AtomSummaryElementName, true, false);
                        break;
                    case SyndicationItemProperty.Title:
                        textSyndicationWriter(XmlConstants.AtomTitleElementName, true, false);
                        break;
                    default:
                        Debug.Assert(false, "Unhandled SyndicationItemProperty enum value - should never get here.");
                        break;
                }
            }
            else
            {
                if (targetSegment.SegmentName == XmlConstants.AtomAuthorElementName)
                {
                    this.CreateAuthor(false);
                    base.Serialize(targetSegment, kind);
                    this.FinishAuthor();
                }
                else if (targetSegment.SegmentName == XmlConstants.AtomContributorElementName)
                {
                    this.Target.WriteStartElement(XmlConstants.AtomContributorElementName, XmlConstants.AtomNamespace);
                    base.Serialize(targetSegment, kind);
                    this.Target.WriteEndElement();
                }
                else
                {
                    Debug.Assert(false, "Only authors and contributors have nested elements");
                }
            }
        }
        /// <summary>
        /// Override of the base Visitor method, which actually performs mapping search and serialization
        /// </summary>
        /// <param name="targetSegment">Current segment being checked for mapping</param>
        /// <param name="kind">Which sub segments to serialize</param>
        protected override void Serialize(EpmTargetPathSegment targetSegment, EpmSerializationKind kind)
        {
            if (targetSegment.HasContent)
            {
                EntityPropertyMappingInfo epmInfo = targetSegment.EpmInfo;
                Object propertyValue;

                try
                {
                    propertyValue = epmInfo.ReadPropertyValue(this.Element);
                }
                catch (System.Reflection.TargetInvocationException)
                {
                    throw;
                }

                String contentType;
                Action<String> contentWriter;

                switch (epmInfo.Attribute.TargetTextContentKind)
                {
                    case SyndicationTextContentKind.Html:
                        contentType = "html";
                        contentWriter = this.Target.WriteString;
                        break;
                    case SyndicationTextContentKind.Xhtml:
                        contentType = "xhtml";
                        contentWriter = this.Target.WriteRaw;
                        break;
                    default:
                        contentType = "text";
                        contentWriter = this.Target.WriteString;
                        break;
                }

                Action<String, bool, bool> textSyndicationWriter = (c, nonTextPossible, atomDateConstruct) =>
                {
                    this.Target.WriteStartElement(c, XmlConstants.AtomNamespace);
                    if (nonTextPossible)
                    {
                        this.Target.WriteAttributeString(XmlConstants.AtomTypeAttributeName, String.Empty, contentType);
                    }

                    // As per atomPub spec dateConstructs must contain valid datetime. Therefore we need to fill atom:updated/atom:published 
                    // field with something (e.g. DateTimeOffset.MinValue) if the user wants to map null to either of these fields. This will 
                    // satisfy protocol requirements and Syndication API. Note that the content will still contain information saying that the 
                    // mapped property is supposed to be null - therefore the server will know that the actual value sent by the user is null.
                    // For all other elements we can use empty string since the content is not validated.
                    String textPropertyValue = 
                        propertyValue != null   ? ClientConvert.ToString(propertyValue, atomDateConstruct) :
                        atomDateConstruct       ? ClientConvert.ToString(DateTime.MinValue, atomDateConstruct) : 
                        String.Empty;

                    contentWriter(textPropertyValue);
                    this.Target.WriteEndElement();
                };

                switch (epmInfo.Attribute.TargetSyndicationItem)
                {
                    case SyndicationItemProperty.AuthorEmail:
                    case SyndicationItemProperty.ContributorEmail:
                        textSyndicationWriter(XmlConstants.AtomEmailElementName, false, false);
                        break;
                    case SyndicationItemProperty.AuthorName:
                    case SyndicationItemProperty.ContributorName:
                        textSyndicationWriter(XmlConstants.AtomNameElementName, false, false);
                        this.authorNamePresent = true;
                        break;
                    case SyndicationItemProperty.AuthorUri:
                    case SyndicationItemProperty.ContributorUri:
                        textSyndicationWriter(XmlConstants.AtomUriElementName, false, false);
                        break;
                    case SyndicationItemProperty.Updated:
                        textSyndicationWriter(XmlConstants.AtomUpdatedElementName, false, true);
                        this.updatedPresent = true;
                        break;
                    case SyndicationItemProperty.Published:
                        textSyndicationWriter(XmlConstants.AtomPublishedElementName, false, true);
                        break;
                    case SyndicationItemProperty.Rights:
                        textSyndicationWriter(XmlConstants.AtomRightsElementName, true, false);
                        break;
                    case SyndicationItemProperty.Summary:
                        textSyndicationWriter(XmlConstants.AtomSummaryElementName, true, false);
                        break;
                    case SyndicationItemProperty.Title:
                        textSyndicationWriter(XmlConstants.AtomTitleElementName, true, false);
                        break;
                    default:
                        Debug.Assert(false, "Unhandled SyndicationItemProperty enum value - should never get here.");
                        break;
                }
            }
            else
            {
                if (targetSegment.SegmentName == XmlConstants.AtomAuthorElementName)
                {
                    this.CreateAuthor(false);
                    base.Serialize(targetSegment, kind);
                    this.FinishAuthor();
                }
                else if (targetSegment.SegmentName == XmlConstants.AtomContributorElementName)
                {
                    this.Target.WriteStartElement(XmlConstants.AtomContributorElementName, XmlConstants.AtomNamespace);
                    base.Serialize(targetSegment, kind);
                    this.Target.WriteEndElement();
                }
                else
                {
                    Debug.Assert(false, "Only authors and contributors have nested elements");
                }
            }
        }