Exemplo n.º 1
0
        /// <summary>
        /// Sets the extension property.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="propertyValue">The property value.</param>
        private static void SetExtensionProperty(
            ZentityContext context,
            ScholarlyWork resource,
            string propertyName,
            string propertyValue)
        {
            ResourceProperty resourceProperty = ZentityAtomPubStoreReader.GetResourceProperty(resource, propertyName);

            if (null == resourceProperty)
            {
                Property extensionProperty = GetProperty(context, propertyName);
                resourceProperty = new ResourceProperty
                {
                    Property = extensionProperty,
                    Resource = resource,
                };
            }

            resourceProperty.Value = propertyValue;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the resource property.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="resource">The resource.</param>
        /// <param name="atomEntry">The atom entry.</param>
        private static void UpdateResourceProperty(
            ZentityContext context,
            ScholarlyWork resource,
            AtomEntryDocument atomEntry)
        {
            resource.Title = atomEntry.Title.Text;
            SetContentType(context, resource, atomEntry.Title.Type, AtomPubConstants.TitleTypeProperty);
            resource.DateModified = DateTime.Now;
            Publication publication = resource as Publication;

            if (null != publication && atomEntry.PublishDate != DateTimeOffset.MinValue)
            {
                publication.DatePublished = atomEntry.PublishDate.DateTime;
            }

            if (null != atomEntry.Copyright)
            {
                resource.Copyright = atomEntry.Copyright.Text;
                SetContentType(context, resource, atomEntry.Copyright.Type, AtomPubConstants.CopyrightTypeProperty);
            }

            if (null != atomEntry.Summary && !string.IsNullOrEmpty(atomEntry.Summary.Text))
            {
                SetExtensionProperty(context, resource, AtomPubConstants.SummaryProperty, atomEntry.Summary.Text);
                SetContentType(context, resource, atomEntry.Summary.Type, AtomPubConstants.SummaryTypeProperty);
            }

            if (null != atomEntry.Content)
            {
                UrlSyndicationContent urlContent = atomEntry.Content as UrlSyndicationContent;

                if (null != urlContent)
                {
                    resource.Description = null;
                    SetExtensionProperty(context, resource, AtomPubConstants.ContentUrlProperty, urlContent.Url.AbsoluteUri);
                }
                else
                {
                    ResourceProperty urlContentProperty = ZentityAtomPubStoreReader.GetResourceProperty(resource, AtomPubConstants.ContentUrlProperty);

                    if (null != urlContentProperty)
                    {
                        resource.ResourceProperties.Remove(urlContentProperty);
                    }

                    TextSyndicationContent textDescription = atomEntry.Content as TextSyndicationContent;

                    if (null != textDescription)
                    {
                        resource.Description = textDescription.Text;
                    }
                    else
                    {
                        XmlSyndicationContent content = atomEntry.Content as XmlSyndicationContent;

                        if (null != content)
                        {
                            XmlDictionaryReader contentReader = content.GetReaderAtContent();
                            StringBuilder       contentValue  = new StringBuilder(151);

                            try
                            {
                                while (contentReader.Read())
                                {
                                    contentValue.Append(contentReader.Value);
                                }
                            }
                            finally
                            {
                                contentReader.Close();
                            }

                            resource.Description = contentValue.ToString();
                        }
                    }
                }

                SetContentType(context, resource, atomEntry.Content.Type, AtomPubConstants.DescriptionTypeProperty);
            }

            if (null != atomEntry.Source)
            {
                ResourceProperty source = ZentityAtomPubStoreReader.GetResourceProperty(resource, AtomPubConstants.SourceProperty);

                if (null == source)
                {
                    Property sourceProperty = GetProperty(context, AtomPubConstants.SourceProperty);
                    source = new ResourceProperty
                    {
                        Property = sourceProperty,
                        Resource = resource,
                    };
                }

                source.Value = atomEntry.Source;
            }

            #region Add Links

            List <ResourceProperty> links = ZentityAtomPubStoreReader.GetResourceProperties(resource, AtomPubConstants.LinksProperty);

            if (0 == atomEntry.XmlLinks.Count && null != links)
            {
                foreach (var item in links)
                {
                    resource.ResourceProperties.Remove(item);
                }
            }

            Property linkProperty = GetProperty(context, AtomPubConstants.LinksProperty);

            foreach (string xmlLink in atomEntry.XmlLinks)
            {
                resource.ResourceProperties.Add(new ResourceProperty
                {
                    Resource = resource,
                    Property = linkProperty,
                    Value    = xmlLink
                });
            }

            #endregion


            var authors = atomEntry.Authors.Select(author => new Person
            {
                Title = author.Name,
                Email = author.Email,
                Uri   = author.Uri
            });
            // Bug Fix : 177689 - AtomPub (M2): Author node is appending after every PUT request instead
            //                    of overwriting it.
            // Remove previous authors.
            resource.Authors.Clear();
            AddPersons(context, resource.Authors, authors);

            resource.Contributors.Clear();
            var contributors = atomEntry.Contributors.Select(author => new Person
            {
                Title = author.Name,
                Email = author.Email,
                Uri   = author.Uri
            });
            AddPersons(context, resource.Contributors, contributors);
        }