Пример #1
0
        public ContentArticleResponse Get(string bucketSlug, string contentSlug)
        {
            //Execute the query
            ContentArticleResponse content;

            try
            {
                content = _client.Content.GetContent(bucketSlug, contentSlug, new GetContentOptions
                {
                    IncludeBody = true
                });
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == HttpStatusCode.Forbidden)
                {
                    throw new Exception("Content not available in license.  The default license used in the example is a demo license with limited content.  Replace the license information in the web.config with your specific license information to see the full experience.", ex);
                }
                else
                {
                    throw;
                }
            }

            if (content.Segments != null)
            {
                ContentLinkConverter linkConverter = new ContentLinkConverter();
                foreach (var segment in content.Segments)
                {
                    segment.Body = linkConverter.ConvertContentLinksToRealLinks(segment.Body);
                }
            }

            return(content);
        }
Пример #2
0
        //
        // GET: /Display Article\Video/
        public ActionResult Index()
        {
            ContentWithRelationshipModel model = new ContentWithRelationshipModel();

            //Try to get the slug objects
            object bucketSlug  = ControllerContext.RouteData.Values["bucketSlug"];
            object contentSlug = ControllerContext.RouteData.Values["contentSlug"];

            if (bucketSlug == null || contentSlug == null)
            {
                return(HttpNotFound("Sorry, the content was not found."));
            }

            //Ensure the slugs are valid
            string bucketSlugValue  = bucketSlug.ToString();
            string contentSlugValue = contentSlug.ToString();

            if (string.IsNullOrEmpty(bucketSlugValue))
            {
                return(HttpNotFound("Sorry, the content was not found."));
            }
            if (string.IsNullOrEmpty(contentSlugValue))
            {
                return(HttpNotFound("Sorry, the content was not found."));
            }

            //Request the specific article.  If you intend to display the full article you must send the flag "IncludeBody"
            try
            {
                model.Article = _client.Content.GetContent(bucketSlugValue, contentSlugValue, new GetContentOptions
                {
                    IncludeBody = true
                });

                //If the article is streaming media then we need to get more details about the content
                //so that we can render the video tag.
                if (model.Article.Type == ContentType.StreamingMedia)
                {
                    model.StreamingMedia = _client.StreamingMedia.GetStreamingMedia(bucketSlugValue, contentSlugValue, new GetContentOptions
                    {
                        IncludeBody = true
                    }, false);
                }

                //If segments are present convert all internal links to real links
                if (model.Article.Segments != null)
                {
                    ContentLinkConverter linkConverter = new ContentLinkConverter();
                    foreach (ContentSegmentResponse segment in model.Article.Segments)
                    {
                        segment.Body = linkConverter.ConvertContentLinksToRealLinks(segment.Body);
                    }
                }
            }
            catch (ServiceException ex)
            {
                if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    return(HttpNotFound("Sorry, the content was not found."));
                }
                else
                {
                    throw ex;
                }
            }

            //Get the relations
            model.RelatedContent = GetRelatedContentGrouped(model.Article);
            model.RelatedContent.AddRange(GetRelatedServicesGrouped(model.Article));

            return(View(model));
        }