Esempio n. 1
0
        /// <summary>
        /// Loads all the dependent collection set for the given resource
        /// </summary>
        /// <param name="resource"> an resource object</param>
        /// <returns> loaded resource </returns>
        private static Core.Resource LoadResource(Core.Resource resource)
        {
            if (null == resource)
            {
                return(null);
            }

            ScholarlyWorks.ScholarlyWork scholarlyWork = resource as ScholarlyWorks.ScholarlyWork;
            if (null != scholarlyWork)
            {
                if (!scholarlyWork.Authors.IsLoaded)
                {
                    scholarlyWork.Authors.Load();
                }
                if (!scholarlyWork.Contributors.IsLoaded)
                {
                    scholarlyWork.Contributors.Load();
                }
                if (!scholarlyWork.Tags.IsLoaded)
                {
                    scholarlyWork.Tags.Load();
                }
            }

            return(resource);
        }
        /// <summary>
        /// Creates metadata element
        /// </summary>
        /// <param name="resource"> resource object </param>
        /// <returns> an instance of XElement </returns>
        internal static XElement GetMetadataElement(Core.Resource resource)
        {
            XElement metadata = null;

            metadata = new XElement(Metadata);

            if (!String.IsNullOrEmpty(resource.Title))
            {
                metadata.Add(MetadataProviderHelper.GetElement(Metadata_Title, resource.Title));
            }

            ScholarlyWorks.ScholarlyWork scholarlyWorks = resource as ScholarlyWorks.ScholarlyWork;
            if (null != scholarlyWorks)
            {
                if (scholarlyWorks.Authors != null)
                {
                    MetadataProviderHelper.AddResourceAuthors(metadata, scholarlyWorks);
                }
                if (scholarlyWorks.Contributors != null)
                {
                    MetadataProviderHelper.AddResourceContributors(metadata, scholarlyWorks);
                }
            }

            // TODO : 2.Currently Tags for a given resource are retrieved without
            //          checking any relationships, but the implementation needs to be changed if required
            ScholarlyWorks.ScholarlyWorkItem scholarlyWorkItem = resource as ScholarlyWorks.ScholarlyWorkItem;
            if (scholarlyWorkItem != null && scholarlyWorkItem.Tags != null)
            {
                MetadataProviderHelper.AddResourceTags(metadata, scholarlyWorkItem);
            }

            metadata.Add(MetadataProviderHelper.GetElement(Metadata_Description, resource.Description));

            if (!String.IsNullOrEmpty(resource.DateModified.Value.ToString()))
            {
                metadata.Add(MetadataProviderHelper.GetElement(Metadata_Date, resource.DateModified.Value.ToString(DateTimeGranularity, CultureInfo.InvariantCulture)));
            }
            return(metadata);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a <typeref name="System.ServiceModel.Syndication.SyndicationItem"/> item
        /// for the given resource.
        /// </summary>
        /// <param name="resource">The associated resource.</param>
        /// <returns>The SyndicationItem Object.</returns>
        private static SyndicationItem CreateSyndicationItem(Resource resource)
        {
            if (null == resource)
            {
                return(null);
            }

            SyndicationItem item = new SyndicationItem();

            ScholarlyWorks.ScholarlyWork scholarlyWork = resource as ScholarlyWorks.ScholarlyWork;
            if (null != scholarlyWork)
            {
                item = ZentityAtomPubStoreReader.GenerateSyndicationItem(new Uri(
                                                                             ConfigurationManager.AppSettings["ServiceHost"] +
                                                                             ConfigurationManager.AppSettings["AtomPubBaseUri"]), scholarlyWork);
            }
            else
            {
                //TODO: Would Title be Non Empty always.. If no then what would be the heading for the feed?
                item.Title = new TextSyndicationContent(
                    string.IsNullOrEmpty(resource.Title) ? string.Empty : resource.Title);
                item.Id      = "urn:guid:" + resource.Id.ToString();
                item.Summary = new TextSyndicationContent(resource.Description);

                if (null != resource.DateAdded &&
                    DateTime.MinValue != resource.DateAdded.Value)
                {
                    item.PublishDate = new DateTimeOffset(resource.DateAdded.Value);
                }
                if (null != resource.DateModified &&
                    DateTime.MinValue != resource.DateModified.Value)
                {
                    item.LastUpdatedTime = new DateTimeOffset(resource.DateModified.Value);
                }
            }

            return(item);
        }
        /// <summary>
        /// retrieves contributors of resource and adds them to the associated metadata element
        /// </summary>
        /// <param name="metadata">the associated metadata</param>
        /// <param name="scholarlyWorks">scholarlyWorks object whose contributors to be retrieved</param>
        private static void AddResourceContributors(XElement metadata, ScholarlyWorks.ScholarlyWork scholarlyWorks)
        {
            if (null == metadata || null == scholarlyWorks)
            {
                return;
            }

            scholarlyWorks.Contributors.ToList().ForEach(delegate(ScholarlyWorks.Contact contact)
            {
                ScholarlyWorks.Person person = contact as ScholarlyWorks.Person;
                string personDetails         = string.Empty;
                if (null != person)
                {
                    personDetails = CoreHelper.GetCompleteName(person.FirstName, person.MiddleName, person.LastName);
                    //In case if any other details are to be added then they can be added here
                }

                if (!string.IsNullOrEmpty(personDetails))
                {
                    metadata.Add(MetadataProviderHelper.GetElement(MetadataProviderHelper.Metadata_Contributor, personDetails));
                }
            });
        }
Esempio n. 5
0
        /// <summary>
        /// Creates the syndication item.
        /// </summary>
        /// <typeparam name="T">Type of resource.</typeparam>
        /// <param name="resource">The associated resource.</param>
        /// <returns>The SyndicationItem Object.</returns>
        private SyndicationItem CreateSyndicationItem <T>(T resource) where T : Core.Resource
        {
            if (null == resource)
            {
                return(null);
            }

            SyndicationItem item = new SyndicationItem();

            //TODO: Would Title be Non Empty always.. If no then what would be the heading for the feed?
            item.Title = new TextSyndicationContent(
                string.IsNullOrEmpty(resource.Title) ? string.Empty : resource.Title);

            //item.Summary = new TextSyndicationContent(
            //    string.IsNullOrEmpty(resource.Description) ? string.Empty : resource.Description);

            //TODO: How do we set the attributes for fields which are there only in Scholarly Works.
            ScholarlyWorks.ScholarlyWork scholarlyWork = resource as ScholarlyWorks.ScholarlyWork;
            if (null != scholarlyWork)
            {
                item.Copyright = new TextSyndicationContent(
                    string.IsNullOrEmpty(scholarlyWork.Copyright) ? PlatformSettings.Copyrights : scholarlyWork.Copyright);


                // add authors
                scholarlyWork.Authors.ToList().ForEach(delegate(ScholarlyWorks.Contact contact)
                {
                    ScholarlyWorks.Person person = contact as ScholarlyWorks.Person;
                    if (null != person)
                    {
                        string name = CoreHelper.GetCompleteName(person.FirstName, person.MiddleName, person.LastName);
                        item.Authors.Add(new SyndicationPerson(
                                             string.IsNullOrEmpty(person.Email) ? PlatformSettings.AuthorEmail : person.Email,
                                             name,
                                             string.IsNullOrEmpty(person.Uri) ? null : person.Uri));
                    }
                });

                // add Contributors
                scholarlyWork.Contributors.ToList().ForEach(delegate(ScholarlyWorks.Contact contact)
                {
                    ScholarlyWorks.Person person = contact as ScholarlyWorks.Person;
                    if (null != person)
                    {
                        string name = CoreHelper.GetCompleteName(person.FirstName, person.MiddleName, person.LastName);
                        item.Contributors.Add(new SyndicationPerson(
                                                  string.IsNullOrEmpty(person.Email) ? PlatformSettings.AuthorEmail : person.Email,
                                                  name,
                                                  string.IsNullOrEmpty(person.Uri) ? null : person.Uri));
                    }
                });
                // add tags as categories
                scholarlyWork.Tags.ToList().ForEach(delegate(ScholarlyWorks.Tag tag)
                {
                    item.Categories.Add(new SyndicationCategory(tag.Title));
                });
                scholarlyWork.CategoryNodes.ToList().ForEach(delegate(ScholarlyWorks.CategoryNode category)
                {
                    item.Categories.Add(new SyndicationCategory(category.Title));
                });
            }

            item.Id = resource.Id.ToString();
            if (null != resource.DateAdded &&
                DateTime.MinValue != resource.DateAdded.Value)
            {
                item.PublishDate = new DateTimeOffset(resource.DateAdded.Value);
            }
            if (null != resource.DateModified &&
                DateTime.MinValue != resource.DateModified.Value)
            {
                item.LastUpdatedTime = new DateTimeOffset(resource.DateModified.Value);
            }

            //TODO: Syndication Links to be implemented here.

            return(item);
        }