コード例 #1
0
        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>
        /// 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);
            }
        }