/// <summary>
        /// Get banner settings from an Umbraco page using the <see cref="BannerDocumentType"/> document type
        /// </summary>
        /// <param name="bannerPage">The bannerPage.</param>
        /// <param name="urlListReader">The URL list reader.</param>
        private static Banner ReadBannerFromUmbraco(IPublishedContent bannerPage, IUrlListReader urlListReader)
        {
            var model = new Banner()
            {
                Inherit = bannerPage.GetPropertyValue <bool>("inherit_Content"),
                Cascade = bannerPage.GetPropertyValue <bool>("cascade_Content")
            };

            // Minimum requirement is just somewhere to display it. Return null if missing.
            // An image is not required because it's useful to set up a banner with no image as a way of stopping other banners.
            var imageData = bannerPage.GetPropertyValue <IPublishedContent>("bannerImage_Content");

            if (imageData != null)
            {
                model.BannerImage = new Image()
                {
                    AlternativeText = imageData.Name,
                    ImageUrl        = new Uri(imageData.Url, UriKind.Relative),
                    Width           = imageData.GetPropertyValue <int>("umbracoWidth"),
                    Height          = imageData.GetPropertyValue <int>("umbracoHeight")
                };
            }
            ((List <Uri>)model.TargetUrls).AddRange(urlListReader.ReadUrls(bannerPage, "whereToDisplayIt_Content", "whereElseToDisplayIt_Content"));
            if (model.TargetUrls.Count == 0)
            {
                return(null);
            }

            // URL to link to is optional, and can come from two possible fields
            var targetPage = bannerPage.GetPropertyValue <IPublishedContent>("targetPage_Content");

            if (targetPage != null)
            {
                model.BannerLink = new Uri(targetPage.UrlWithDomain());
            }
            else
            {
                try
                {
                    var urlString = bannerPage.GetPropertyValue <string>("targetUrl_Content");
                    if (!String.IsNullOrEmpty(urlString))
                    {
                        model.BannerLink = new Uri(urlString, UriKind.RelativeOrAbsolute);
                    }
                }
                catch (UriFormatException)
                {
                    // ignore invalid URLs
                }
            }

            return(model);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the web chat settings
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">content</exception>
        public Task <WebChatSettings> ReadWebChatSettings()
        {
            if (_content == null)
            {
                throw new ArgumentNullException("content");
            }

            var model = new WebChatSettings
            {
                PageUrl = new Uri(_content.Url, UriKind.RelativeOrAbsolute)
            };

            var webChatSettings = _content.AncestorOrSelf(1).Siblings().FirstOrDefault(sibling => sibling.DocumentTypeAlias == "WebChat");

            if (webChatSettings == null)
            {
                return(System.Threading.Tasks.Task.FromResult(model));
            }

            ((List <Uri>)model.WebChatUrls).AddRange(_targetUrlReader.ReadUrls(webChatSettings, "whereToDisplayIt_Content", "whereElseToDisplayIt_Content"));
            ((List <Uri>)model.ExcludedUrls).AddRange(_targetUrlReader.ReadUrls(webChatSettings, "whereToExclude_Content", "whereElseToExclude_Content"));
            return(System.Threading.Tasks.Task.FromResult(model));
        }
        /// <summary>
        /// Get banner settings from an Umbraco page using the <see cref="BannerDocumentType"/> document type
        /// </summary>
        /// <param name="bannerPage">The bannerPage.</param>
        /// <param name="urlListReader">The URL list reader.</param>
        private static Banner ReadBannerFromUmbraco(IPublishedContent bannerPage, IUrlListReader urlListReader)
        {
            var model = new Banner()
            {
                Inherit = bannerPage.GetPropertyValue<bool>("inherit_Content"),
                Cascade = bannerPage.GetPropertyValue<bool>("cascade_Content")
            };

            // Minimum requirements are an image and somewhere to display it. Return null if either of those missing.
            var imageData = bannerPage.GetPropertyValue<IPublishedContent>("bannerImage_Content");
            if (imageData == null) return null;

            model.BannerImage = new Image()
                {
                    AlternativeText = imageData.Name,
                    ImageUrl = new Uri(imageData.Url, UriKind.Relative),
                    Width = imageData.GetPropertyValue<int>("umbracoWidth"),
                    Height = imageData.GetPropertyValue<int>("umbracoHeight")
                };

            ((List<Uri>)model.TargetUrls).AddRange(urlListReader.ReadUrls(bannerPage, "whereToDisplayIt_Content", "whereElseToDisplayIt_Content"));
            if (model.TargetUrls.Count == 0) return null;

            // URL to link to is optional, and can come from two possible fields
            var targetPage = bannerPage.GetPropertyValue<IPublishedContent>("targetPage_Content");
            if (targetPage != null)
            {
                model.BannerLink = new Uri(targetPage.UrlWithDomain());
            }
            else
            {
                try
                {
                    var urlString = bannerPage.GetPropertyValue<string>("targetUrl_Content");
                    if (!String.IsNullOrEmpty(urlString))
                    {
                        model.BannerLink = new Uri(urlString, UriKind.RelativeOrAbsolute);
                    }
                }
                catch (UriFormatException) { 
                    // ignore invalid URLs
                }
            }

            return model;
        }
Beispiel #4
0
        /// <summary>
        /// Get alerts from Umbraco pages which are children of this one, which should all be using the Alert document type
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="alerts">The alerts.</param>
        /// <param name="urlListReader">The URL list reader.</param>
        private static void AddAlertsFromUmbraco(RenderModel model, List <AlertViewModel> alerts, IUrlListReader urlListReader)
        {
            foreach (var alertPage in model.Content.Children)
            {
                var alertModel = new AlertViewModel()
                {
                    Alert   = new HtmlString(alertPage.GetPropertyValue <string>("alert_Content")),
                    Append  = alertPage.GetPropertyValue <bool>("append_Content"),
                    Cascade = alertPage.GetPropertyValue <bool>("cascade_Content")
                };

                ((List <Uri>)alertModel.TargetUrls).AddRange(urlListReader.ReadUrls(alertPage, "whereToDisplayIt_Content", "whereElseToDisplayIt_Content"));

                if (alertModel.TargetUrls.Count > 0)
                {
                    alerts.Add(alertModel);
                }
            }
        }