/// <summary> /// Fetches the master page control from a remote URL. /// </summary> private void LoadRemoteControl() { // Add the current section parsed from the breadcrumb trail var selectedSection = String.Empty; if (BreadcrumbProvider == null) { BreadcrumbProvider = new BreadcrumbTrailFromConfig(); } var trail = BreadcrumbProvider.BuildTrail(); if (trail != null && trail.Count > 1) { selectedSection = new List <string>(trail.Keys)[1].ToUpperInvariant(); } // Cache remote template elements using the application cache RemoteMasterPageCacheProviderBase cacheProvider = new RemoteMasterPageMemoryCacheProvider(Control, selectedSection, new LibraryCatalogueContext(Page.Request.UserAgent), new TextSize(Page.Request.Cookies, Page.Request.QueryString)); // Provide a way to force an immediate update of the cache var forceCacheRefresh = (Page.Request.QueryString["ForceCacheRefresh"] == "1"); // Update the cached control if it's missing or too old if (!cacheProvider.CachedVersionExists || !cacheProvider.CachedVersionIsFresh || forceCacheRefresh) { RequestRemoteHtml(cacheProvider, selectedSection); } // Output the HTML this.Controls.Add(new LiteralControl(cacheProvider.ReadHtmlFromCache())); }
/// <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> /// Creates a new <see cref="ViewModelDefaultValuesProvider"/> /// </summary> /// <param name="metadata">The default sitewide metadata, usually loaded from configuration</param> /// <param name="mvcSettings">Settings used to configure MVC views</param> /// <param name="breadcrumb">The breadcrumb provider which identifies the context within the site hierarchy</param> /// <param name="httpContextAccessor">Access to the current request URL</param> public ViewModelDefaultValuesProvider(IOptions <Metadata.Metadata> metadata, IOptions <MvcSettings> mvcSettings, IBreadcrumbProvider breadcrumb, IHttpContextAccessor httpContextAccessor) { Metadata = metadata?.Value; Breadcrumb = breadcrumb; var request = httpContextAccessor?.HttpContext?.Request ?? throw new ArgumentNullException(nameof(httpContextAccessor)); Metadata.CanonicalPageUrl = new Uri(request.GetDisplayUrl()); ClientFileBaseUrl = mvcSettings?.Value?.ClientFileBaseUrl; ClientFileVersion = mvcSettings?.Value?.ClientFileVersion; }
/// <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>()); } } }
/// <summary> /// Initializes a new instance of the <see cref="BaseViewModel"/> class. /// </summary> /// <param name="breadcrumbProvider">The breadcrumb provider to replace the default <see cref="BreadcrumbTrailFromConfig"/>.</param> /// <exception cref="System.ArgumentNullException"></exception> protected BaseViewModel(IBreadcrumbProvider breadcrumbProvider) { if (breadcrumbProvider == null) { throw new ArgumentNullException(nameof(breadcrumbProvider)); } IsPublicView = true; EsccWebsiteSkin = new DefaultSkin(); Metadata = new Metadata(); BreadcrumbProvider = breadcrumbProvider; }
/// <summary> /// Initializes a new instance of the <see cref="BaseViewModel"/> class. /// </summary> /// <param name="breadcrumbProvider">The breadcrumb provider to replace the default <see cref="BreadcrumbTrailFromConfig"/>.</param> /// <exception cref="System.ArgumentNullException"></exception> protected BaseViewModel(IBreadcrumbProvider breadcrumbProvider) { if (breadcrumbProvider == null) { throw new ArgumentNullException(nameof(breadcrumbProvider)); } IsPublicView = true; EsccWebsiteSkin = new CustomerFocusSkin(); Metadata = new Metadata.Metadata { SiteName = "East Sussex County Council", TitlePattern = "{0} – East Sussex County Council", LicenceUri = new Uri("http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/") }; Metadata.PageImage.ImageUrl = new Uri("https://www.eastsussex.gov.uk/img/logo-for-facebook.png"); Metadata.PageImage.AlternativeText = "East Sussex County Council"; Metadata.Facebook.OpenGraphType = "article"; Metadata.Facebook.FacebookAppId = "169406409819518"; Metadata.Twitter.TwitterAccount = "@eastsussexcc"; BreadcrumbProvider = breadcrumbProvider; }
/// <summary> /// Fetches the master page control from a remote URL. /// </summary> private void LoadRemoteControl() { if (BreadcrumbProvider == null) { BreadcrumbProvider = new BreadcrumbTrailFromConfig(HttpContext.Current.Request.Url); } var textSize = new TextSize(Page.Request.Cookies?["textsize"]?.Value, Page.Request.QueryString).CurrentTextSize(); var isLibraryCatalogueRequest = new LibraryCatalogueContext(Page.Request.UserAgent).RequestIsFromLibraryCatalogueMachine(); var html = HtmlControlProvider.FetchHtmlForControl( HttpRuntime.AppDomainAppVirtualPath, HttpContext.Current.Request.Url, Control, BreadcrumbProvider, textSize, isLibraryCatalogueRequest ).Result; // Output the HTML this.Controls.Add(new LiteralControl(html)); }
/// <summary> /// Fetches the master page control from a remote URL. /// </summary> /// <param name="applicationId">A string which identifies the application making the request</param> /// <param name="forUrl">The page to request the control for (usually the current page)</param> /// <param name="controlId">A key identifying the control to cache.</param> /// <param name="breadcrumbProvider">The provider for working out the current context within the site's information architecture.</param> /// <param name="textSize">The current setting for the site's text size feature.</param> /// <param name="isLibraryCatalogueRequest"><c>true</c> if the request is from a public catalogue machine in a library</param> public async Task <string> FetchHtmlForControl(string applicationId, Uri forUrl, string controlId, IBreadcrumbProvider breadcrumbProvider, int textSize, bool isLibraryCatalogueRequest) { // Check parameters if (string.IsNullOrEmpty(applicationId)) { throw new ArgumentException("applicationId should be be a string uniquely identifying the application", nameof(applicationId)); } if (forUrl == null) { throw new ArgumentNullException(nameof(forUrl)); } if (string.IsNullOrEmpty(controlId)) { throw new ArgumentException("controlId must be specified to load the control", nameof(controlId)); } if (breadcrumbProvider == null) { throw new ArgumentNullException(nameof(breadcrumbProvider)); } // Add the current section parsed from the breadcrumb trail var selectedSection = String.Empty; var trail = breadcrumbProvider.BuildTrail(); if (trail != null && trail.Count > 1) { selectedSection = new List <string>(trail.Keys)[1].ToUpperInvariant(); } // Update the cached control if it's missing or too old if (_cacheProvider == null || !_cacheProvider.CachedVersionExists(applicationId, forUrl.Host, controlId, selectedSection, textSize, isLibraryCatalogueRequest) || !_cacheProvider.CachedVersionIsFresh(applicationId, forUrl.Host, controlId, selectedSection, textSize, isLibraryCatalogueRequest) || _forceCacheRefresh) { return(await RequestRemoteHtml(applicationId, forUrl, controlId, selectedSection, textSize, isLibraryCatalogueRequest).ConfigureAwait(false)); } // Return the HTML return(_cacheProvider.ReadHtmlFromCache(applicationId, forUrl.Host, controlId, selectedSection, textSize, isLibraryCatalogueRequest)); }
/// <summary> /// Nested list indicating position within information architecture, which appears on every page on the East Sussex County Council website. /// </summary> public BreadcrumbTrail() : base("nav") { this.BreadcrumbProvider = new BreadcrumbTrailFromConfig(HttpContext.Current.Request.Url); }
/// <summary> /// Creates a new <see cref="BreadcrumbTrailMobile"/> /// </summary> public BreadcrumbTrailMobile() : base("nav") { this.BreadcrumbProvider = new BreadcrumbTrailFromConfig(); }