Ejemplo n.º 1
0
        /// <summary>
        /// Gets the resource property.
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>A <see cref="ResourceProperty"/>.</returns>
        internal static ResourceProperty GetResourceProperty(ScholarlyWork resource, string propertyName)
        {
            if (!resource.ResourceProperties.IsLoaded)
            {
                try
                {
                    resource.ResourceProperties.Load();

                    foreach (ResourceProperty resourceProperties in resource.ResourceProperties)
                    {
                        if (!resourceProperties.PropertyReference.IsLoaded)
                        {
                            resourceProperties.PropertyReference.Load();
                        }
                    }
                }
                catch (InvalidOperationException)
                {
                    // Do nothing if resource is not attached to the context.
                }
            }
            string propertyUri = AtomPubHelper.GetPropertyUri(propertyName);

            return(resource.ResourceProperties
                   .Where(tuple => tuple.Property.Uri == propertyUri)
                   .FirstOrDefault());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the property.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>A <see cref="Property"/> type.</returns>
        private static Property GetProperty(ZentityContext context, string propertyName)
        {
            string   propertyUri = AtomPubHelper.GetPropertyUri(propertyName);
            Property property    = context.Properties.FirstOrDefault(prp => prp.Uri == propertyUri);

            if (null == property)
            {
                property = new Property
                {
                    Name = propertyName,
                    Uri  = propertyUri
                };
            }

            return(property);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the resource properties.
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <returns>List of <see cref="ResourceProperty"/>.</returns>
        internal static List <ResourceProperty> GetResourceProperties(ScholarlyWork resource, string propertyName)
        {
            if (!resource.ResourceProperties.IsLoaded)
            {
                try
                {
                    resource.ResourceProperties.Load();
                }
                catch (InvalidOperationException)
                {
                    // Do nothing if resource is not attached to the context.
                }
            }
            string propertyUri = AtomPubHelper.GetPropertyUri(propertyName);

            return(resource.ResourceProperties
                   .Where(tuple => tuple.Property.Uri == propertyUri)
                   .ToList());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Gets the content.
        /// </summary>
        /// <typeparam name="T">Type of content.</typeparam>
        /// <param name="content">The content.</param>
        /// <param name="properties">The properties.</param>
        /// <param name="typeProperty">The type property.</param>
        /// <param name="isRequired">if set to <c>true</c> [is required].</param>
        /// <returns>Content of the required type.</returns>
        private static T GetContent <T>(
            string content,
            IEnumerable <ResourceProperty> properties,
            string typeProperty,
            bool isRequired) where T : SyndicationContent
        {
            if (string.IsNullOrEmpty(content))
            {
                if (isRequired)
                {
                    return(new TextSyndicationContent(string.Empty) as T);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                string           propertyUri         = AtomPubHelper.GetPropertyUri(typeProperty);
                ResourceProperty contentTypeProperty = properties
                                                       .Where(tuple => null != tuple.Property && tuple.Property.Uri == propertyUri)
                                                       .FirstOrDefault();

                SyndicationContent syndicationContent = null;

                if (null == contentTypeProperty)
                {
                    syndicationContent = new TextSyndicationContent(content, TextSyndicationContentKind.Plaintext);
                }
                else
                {
                    switch (contentTypeProperty.Value.ToUpperInvariant())
                    {
                    case "HTML":
                        syndicationContent = new TextSyndicationContent(content, TextSyndicationContentKind.Html);
                        break;

                    case "XHTML":
                        syndicationContent = new TextSyndicationContent(content, TextSyndicationContentKind.XHtml);
                        break;

                    case "TEXT":
                        syndicationContent = new TextSyndicationContent(content, TextSyndicationContentKind.Plaintext);
                        break;

                    default:

                        if (typeof(T) == typeof(UrlSyndicationContent))
                        {
                            Uri contentUrl = new Uri(content);
                            syndicationContent = SyndicationContent.CreateUrlContent(contentUrl, contentTypeProperty.Value);
                        }
                        else
                        {
                            syndicationContent = new XmlSyndicationContent(contentTypeProperty.Value, content, new NetDataContractSerializer());
                        }
                        break;
                    }
                }

                return(syndicationContent as T);
            }
        }