/// <summary> /// Initialises a new instance of <see cref="EastSussexGovUKTemplateRequest"/> /// </summary> /// <param name="httpContextAccessor">A method of getting the web request which requires a response with the template applied.</param> /// <param name="breadcrumbProvider">A method of getting the breadcrumb trail, which provides the context of the page requested within the site.</param> /// <param name="viewSelector">A method of selecting the layout view to be applied.</param> /// <param name="htmlProvider">A method of getting HTML to make up the template. If not set, the remote template will be loaded based on settings in <c>remoteMasterPageSettings</c>.</param> /// <param name="webChatSettingsService">A method of getting web chat configuration. If not set, they will be read from a URL specified in <c>webChatRequestSettings</c>.</param> /// <param name="textSize">A method of getting the current text size. If not set, this will be read from a cookie accessed via <c>httpContextAccessor</c>.</param> /// <param name="libraryContext">A method of determining whether this request comes from a catalogue machine situated in a library. If not set, this will be based on the user agent accessed via <c>httpContextAccessor</c>.</param> /// <exception cref="ArgumentNullException">httpContextAccessor or breadcrumbProvider or httpClientProvider or viewSelector</exception> public EastSussexGovUKTemplateRequest( IHttpContextAccessor httpContextAccessor, IViewSelector viewSelector, IHtmlControlProvider htmlProvider , IBreadcrumbProvider breadcrumbProvider, ILibraryCatalogueContext libraryContext, ITextSize textSize, IWebChatSettingsService webChatSettingsService) { _request = httpContextAccessor?.HttpContext?.Request ?? throw new ArgumentNullException(nameof(httpContextAccessor)); _requestUrl = new Uri(_request.GetDisplayUrl()); if (viewSelector == null) { throw new ArgumentNullException(nameof(viewSelector)); } _esccWebsiteView = viewSelector.CurrentViewIs(viewSelector.SelectView(_requestUrl, _request.Headers["User-Agent"].ToString())); _htmlProvider = htmlProvider ?? throw new ArgumentNullException(nameof(htmlProvider)); _breadcrumbProvider = breadcrumbProvider ?? throw new ArgumentNullException(nameof(breadcrumbProvider)); _libraryContext = libraryContext; _textSize = textSize; _webChatSettingsService = webChatSettingsService; }
/// <summary> /// Initialises a new instance of <see cref="EastSussexGovUKTemplateRequest"/> /// </summary> /// <param name="request">The web request which requires a response with the template applied.</param> /// <param name="esccWebsiteView">The layout to be applied. If not set or set to <see cref="EsccWebsiteView.Unknown"/>, the documented rules for selecting a layout using <see cref="MvcViewSelector"/> will be used.</param> /// <param name="htmlProvider">A method of getting HTML to make up the template. If not set, the remote template will be loaded based on settings in <c>web.config</c>.</param> /// <param name="webChatSettingsService">A method of getting web chat configuration. If not set, they will be read from a URL specified in <c>web.config</c>.</param> /// <param name="breadcrumbProvider">A method of getting the breadcrumb trail, which provides the context of the page requested within the site. If not set, the breadcrumb trail will be read from <c>web.config</c></param> /// <param name="textSize">A method of getting the current text size. If not set, this will be read from a cookie.</param> /// <param name="libraryContext">A method of determining whether this request comes from a catalogue machine situated in a library. If not set, this will be based on the user agent.</param> /// <param name="httpClientProvider">A method of getting an <c>HttpClient</c> to connect to remote resources. If not set, this will be an anonymous request using proxy connection information read from <c>web.config</c> according to the rules documented for <c>Escc.Net.Configuration</c></param> /// <exception cref="ArgumentNullException">request</exception> public EastSussexGovUKTemplateRequest(HttpRequestBase request, EsccWebsiteView esccWebsiteView = EsccWebsiteView.Unknown, IHtmlControlProvider htmlProvider = null, IWebChatSettingsService webChatSettingsService = null, IBreadcrumbProvider breadcrumbProvider = null, ITextSize textSize = null, ILibraryCatalogueContext libraryContext = null, IHttpClientProvider httpClientProvider = null) { _request = request ?? throw new ArgumentNullException(nameof(request)); _esccWebsiteView = esccWebsiteView; if (esccWebsiteView == EsccWebsiteView.Unknown) { var viewSelector = new MvcViewSelector(); _esccWebsiteView = viewSelector.CurrentViewIs(viewSelector.SelectView(request.Url, request.UserAgent)); } _textSize = textSize ?? new TextSize(request.Cookies?["textsize"]?.Value, request.QueryString); _libraryContext = libraryContext ?? new LibraryCatalogueContext(request.UserAgent); _breadcrumbProvider = breadcrumbProvider ?? new BreadcrumbTrailFromConfig(request.Url); if (httpClientProvider == null) { httpClientProvider = new HttpClientProvider(new ConfigurationProxyProvider()); } if (htmlProvider == null) { var masterPageSettings = new RemoteMasterPageSettingsFromConfig(); var forceCacheRefresh = (request.QueryString["ForceCacheRefresh"] == "1"); // Provide a way to force an immediate update of the cache _htmlProvider = new RemoteMasterPageHtmlProvider(masterPageSettings.MasterPageControlUrl(), httpClientProvider, request.UserAgent, new RemoteMasterPageMemoryCacheProvider() { CacheDuration = TimeSpan.FromMinutes(masterPageSettings.CacheTimeout()) }, forceCacheRefresh); } else { _htmlProvider = htmlProvider; } _webChatSettingsService = webChatSettingsService; if (_webChatSettingsService == null) { var webChatRequestSettings = new HostingEnvironmentContext(request.Url); if (webChatRequestSettings.WebChatSettingsUrl != null) { var webChatApiSettings = Options.Create(new WebChatApiSettings { WebChatSettingsUrl = webChatRequestSettings.WebChatSettingsUrl, CacheMinutes = webChatRequestSettings.WebChatSettingsCacheDuration }); _webChatSettingsService = new WebChatSettingsFromApi(webChatApiSettings, httpClientProvider, new ApplicationCacheStrategy <WebChatSettings>()); } } }
private static async Task <LandingViewModel> MapUmbracoContentToViewModel(HttpRequestBase request, IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, ISkinToApplyService skinService) { var model = new LandingViewModel(); model.Navigation.Sections = BuildLandingLinksViewModelFromUmbracoContent(content, relatedLinksService); model.Navigation.LandingNavigationLayout = LandingNavigationLayout.ThreeColumn; var selectedLayout = content.GetPropertyValue <string>("layout_Content"); if (!String.IsNullOrEmpty(selectedLayout)) { var selectedOption = umbraco.library.GetPreValueAsString(Int32.Parse(selectedLayout, CultureInfo.InvariantCulture)); if (selectedOption.ToUpperInvariant().Contains("TWO")) { model.Navigation.LandingNavigationLayout = LandingNavigationLayout.TwoColumn; } } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode, skinService); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
protected override async Task <LocationViewModel> MapUmbracoContentToViewModel(IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, IMediaUrlTransformer mediaUrlTransformer, ISkinToApplyService skinService) { var model = await base.MapUmbracoContentToViewModel(content, expiryDate, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, relatedLinksService, contentExperimentSettingsService, escisService, ratingSettings, mediaUrlTransformer, skinService); // Get the types of waste which have been selected for this recycling site var recycledTypes = content.GetPropertyValue <IEnumerable <string> >("wasteTypes_Content"); if (recycledTypes != null) { ((List <string>)model.WasteTypesRecycled).AddRange(recycledTypes); } var acceptedTypes = content.GetPropertyValue <IEnumerable <string> >("acceptedWasteTypes_Content"); if (acceptedTypes != null) { ((List <string>)model.WasteTypesAccepted).AddRange(acceptedTypes); } // Get the authority responsible for this site var preValueId = content.GetPropertyValue <int>("responsibleAuthority_Content"); if (preValueId > 0) { model.ResponsibleAuthority = umbraco.library.GetPreValueAsString(preValueId); } return(model); }
private static async Task <MicrosoftCmsViewModel> MapUmbracoContentToViewModel(HttpRequestBase request, IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, ISkinToApplyService skinService) { var model = new MicrosoftCmsViewModel(); var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode, skinService); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
private PersonViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IMediaUrlTransformer mediaUrlTransformer) { var model = new PersonViewModel { JobTitle = content.GetPropertyValue <string>("jobTitle_Content"), LeadingText = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("leadingText_Content"))), Subheading1 = content.GetPropertyValue <string>("subheading1_Content"), Content1 = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content1_Content"))), Subheading2 = content.GetPropertyValue <string>("subheading2_Content"), Content2 = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content2_Content"))), Contact = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("contact_Content"))) }; model.Metadata.PersonAbout.Name.Titles.Add(content.GetPropertyValue <string>("HonorificTitle_Content")); model.Metadata.PersonAbout.Name.GivenNames.Add(content.GetPropertyValue <string>("GivenName_Content")); model.Metadata.PersonAbout.Name.FamilyName = content.GetPropertyValue <string>("FamilyName_Content"); model.Metadata.PersonAbout.Name.Suffixes.Add(content.GetPropertyValue <string>("HonorificSuffix_Content")); model.Metadata.PersonAbout.EmailAddresses.Add(content.GetPropertyValue <string>("email_Content")); model.Metadata.PersonAbout.TelephoneNumbers.Add(content.GetPropertyValue <string>("phone_Content")); model.Metadata.Person = model.Metadata.PersonAbout.Name.ToString(); if (!String.IsNullOrEmpty(model.JobTitle)) { model.Metadata.Person += ", " + model.JobTitle; } var relatedLinksGroups = new RelatedLinksModelBuilder().OrganiseAsHeadingsAndSections(relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "relatedLinks_Content")); foreach (var linkGroup in relatedLinksGroups) { model.RelatedLinksGroups.Add(linkGroup); } var imageData = content.GetPropertyValue <IPublishedContent>("photo_Content"); if (imageData != null) { model.Photo = new Image() { AlternativeText = imageData.Name, ImageUrl = new Uri(imageData.Url, UriKind.Relative), Width = imageData.GetPropertyValue <int>("umbracoWidth"), Height = imageData.GetPropertyValue <int>("umbracoHeight") }; model.Metadata.PageImageUrl = new Uri(Request.Url, model.Photo.ImageUrl).ToString(); } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, escisService); return(model); }
private static MicrosoftCmsViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService) { var model = new MicrosoftCmsViewModel(); var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, escisService); return(model); }
protected override LocationViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IMediaUrlTransformer mediaUrlTransformer) { var model = base.MapUmbracoContentToViewModel(content, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, relatedLinksService, contentExperimentSettingsService, escisService, mediaUrlTransformer); // Get the types of waste which have been selected for this recycling site var recycledTypes = ReadWasteTypesFromProperty(content, "wasteTypes_Content"); if (recycledTypes != null) { ((List <string>)model.WasteTypesRecycled).AddRange(recycledTypes); } var acceptedTypes = ReadWasteTypesFromProperty(content, "acceptedWasteTypes_Content"); if (acceptedTypes != null) { ((List <string>)model.WasteTypesAccepted).AddRange(acceptedTypes); } // Get the authority responsible for this site var preValueId = content.GetPropertyValue <int>("responsibleAuthority_Content"); if (preValueId > 0) { model.ResponsibleAuthority = umbraco.library.GetPreValueAsString(preValueId); } return(model); }
/// <summary> /// Maps the Umbraco content to the view model. /// </summary> /// <param name="content">The content.</param> /// <param name="expiryDate">The expiry date.</param> /// <param name="latestService">The latest service.</param> /// <param name="socialMediaService">The social media service.</param> /// <param name="eastSussex1SpaceService">The East Sussex One Space service.</param> /// <param name="webChatSettingsService">The web chat settings service.</param> /// <param name="relatedLinksService">The related links service.</param> /// <param name="contentExperimentSettingsService">The content experiment settings service.</param> /// <param name="escisService">The escis service.</param> /// <param name="ratingSettings">The rating settings.</param> /// <param name="mediaUrlTransformer">The media URL transformer.</param> /// <param name="skinService">The skin service.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">content /// or /// latestService /// or /// socialMediaService /// or /// eastSussex1SpaceService /// or /// webChatSettingsService /// or /// relatedLinksService</exception> /// <exception cref="System.ArgumentNullException">content /// or /// latestService /// or /// socialMediaService /// or /// eastSussex1SpaceService /// or /// webChatSettingsService /// or /// relatedLinksService /// or /// contentExperimentSettingsService</exception> /// <remarks> /// Method is virtual so that document types which inherit from the 'Location' type can also inherit and extend the controller /// </remarks> protected virtual async Task <LocationViewModel> MapUmbracoContentToViewModel(IPublishedContent content, DateTime?expiryDate, latest.ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService, IRatingSettingsProvider ratingSettings, IMediaUrlTransformer mediaUrlTransformer, ISkinToApplyService skinService) { if (content == null) { throw new ArgumentNullException("content"); } if (latestService == null) { throw new ArgumentNullException("latestService"); } if (socialMediaService == null) { throw new ArgumentNullException("socialMediaService"); } if (eastSussex1SpaceService == null) { throw new ArgumentNullException("eastSussex1SpaceService"); } if (webChatSettingsService == null) { throw new ArgumentNullException("webChatSettingsService"); } if (relatedLinksService == null) { throw new ArgumentNullException("relatedLinksService"); } if (contentExperimentSettingsService == null) { throw new ArgumentNullException("contentExperimentSettingsService"); } if (ratingSettings == null) { throw new ArgumentNullException(nameof(ratingSettings)); } if (skinService == null) { throw new ArgumentNullException(nameof(skinService)); } var model = new LocationViewModel { Content = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("content_Content"))), OpeningHoursDetails = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("openingHoursDetails_Content"))), Tab1Title = content.GetPropertyValue <string>("tab1title_Content"), Tab1Content = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab1content_Content"))), Tab2Title = content.GetPropertyValue <string>("tab2title_Content"), Tab2Content = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab2content_Content"))), Tab3Title = content.GetPropertyValue <string>("tab3title_Content"), Tab3Content = new HtmlString(mediaUrlTransformer.ParseAndTransformMediaUrlsInHtml(content.GetPropertyValue <string>("tab3content_Content"))), Location = content.GetPropertyValue <AddressInfo>("location_Content"), Email1Label = content.GetPropertyValue <string>("email1label_Content"), Email2Label = content.GetPropertyValue <string>("email2label_Content"), Email1 = content.GetPropertyValue <string>("email1_Content"), Email2 = content.GetPropertyValue <string>("email2_Content"), Phone1Label = content.GetPropertyValue <string>("phone1label_Content"), Phone2Label = content.GetPropertyValue <string>("phone2label_Content"), Phone1 = content.GetPropertyValue <string>("phone1_Content"), Phone2 = content.GetPropertyValue <string>("phone2_Content"), Fax1Label = content.GetPropertyValue <string>("fax1label_Content"), Fax2Label = content.GetPropertyValue <string>("fax2label_Content"), Fax1 = content.GetPropertyValue <string>("fax1_Content"), Fax2 = content.GetPropertyValue <string>("fax2_Content") }; var relatedLinksGroups = new RelatedLinksModelBuilder().OrganiseAsHeadingsAndSections(relatedLinksService.BuildRelatedLinksViewModelFromUmbracoContent(content, "relatedLinks_Content")); foreach (var linkGroup in relatedLinksGroups) { model.RelatedLinksGroups.Add(linkGroup); } // Opening times model.OpeningHours = DeserialiseOpeningHours(content); WorkOutRelativeOpeningTimes(model); WorkOutNextOpenRelativeTime(model); // Photo var imageData = content.GetPropertyValue <IPublishedContent>("photo_Content"); if (imageData != null) { model.Photo = new Image() { AlternativeText = imageData.Name, ImageUrl = new Uri(imageData.Url, UriKind.Relative), Width = imageData.GetPropertyValue <int>("umbracoWidth"), Height = imageData.GetPropertyValue <int>("umbracoHeight") }; model.Metadata.PageImageUrl = new Uri(Request.Url, model.Photo.ImageUrl).ToString(); } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(new EastSussexGovUKTemplateRequest(Request, webChatSettingsService: webChatSettingsService)); await modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, expiryDate, UmbracoContext.Current.InPreviewMode, skinService); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, escisService, ratingSettings); return(model); }
/// <summary> /// Populates the properties of <see cref="BaseViewModel" /> which can be inherited from parent nodes /// </summary> /// <param name="model">The model.</param> /// <param name="latestService">The latest service.</param> /// <param name="socialMediaService">The social media service.</param> /// <param name="eastSussex1SpaceService">The east sussex1 space service.</param> /// <param name="webChatSettingsService">The web chat settings service.</param> /// <param name="escisService">The ESCIS service.</param> /// <exception cref="System.ArgumentNullException">model</exception> public void PopulateBaseViewModelWithInheritedContent(BaseViewModel model, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IEscisService escisService) { if (model == null) { throw new ArgumentNullException("model"); } if (latestService != null) { model.Latest = latestService.ReadLatestSettings().LatestHtml; } if (eastSussex1SpaceService != null) { model.ShowEastSussex1SpaceWidget = eastSussex1SpaceService.ShowSearch(); } if (escisService != null) { model.ShowEscisWidget = escisService.ShowSearch(); } if (socialMediaService != null) { model.SocialMedia = socialMediaService.ReadSocialMediaSettings(); } if (webChatSettingsService != null) { model.WebChat = webChatSettingsService.ReadWebChatSettings(); } }
private static LandingViewModel MapUmbracoContentToViewModel(IPublishedContent content, ILatestService latestService, ISocialMediaService socialMediaService, IEastSussex1SpaceService eastSussex1SpaceService, IWebChatSettingsService webChatSettingsService, IRelatedLinksService relatedLinksService, IContentExperimentSettingsService contentExperimentSettingsService, IEscisService escisService) { var model = new LandingViewModel(); model.Navigation.Sections = BuildLandingLinksViewModelFromUmbracoContent(content, relatedLinksService); model.Navigation.LandingNavigationLayout = LandingNavigationLayout.ThreeColumn; var selectedLayout = content.GetPropertyValue <string>("layout_Content"); if (!String.IsNullOrEmpty(selectedLayout)) { var selectedOption = umbraco.library.GetPreValueAsString(Int32.Parse(selectedLayout, CultureInfo.InvariantCulture)); if (selectedOption.ToUpperInvariant().Contains("TWO")) { model.Navigation.LandingNavigationLayout = LandingNavigationLayout.TwoColumn; } } // Add common properties to the model var modelBuilder = new BaseViewModelBuilder(); modelBuilder.PopulateBaseViewModel(model, content, contentExperimentSettingsService, UmbracoContext.Current.InPreviewMode); modelBuilder.PopulateBaseViewModelWithInheritedContent(model, latestService, socialMediaService, eastSussex1SpaceService, webChatSettingsService, escisService); return(model); }