/// <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> /// Determines whether the currently selected master page or MVC layout is an instance of the given view. /// </summary> /// <param name="currentView">Path of current master page or MVC layout.</param> /// <param name="view">Check whether this view is currently selected.</param> /// <param name="viewEngine">The view engine.</param> /// <returns></returns> public static bool CurrentViewIs(string currentView, EsccWebsiteView view, ViewEngine viewEngine = ViewEngine.WebForms) { var generalSettings = ConfigurationManager.GetSection("Escc.EastSussexGovUK/GeneralSettings") as NameValueCollection; if (generalSettings == null) { generalSettings = ConfigurationManager.GetSection("EsccWebTeam.EastSussexGovUK/GeneralSettings") as NameValueCollection; } return(IsMasterPageInGroup(currentView, view.ToString(), generalSettings, viewEngine)); }
/// <summary> /// Determines whether the currently selected master page or MVC layout is an instance of the given view. /// </summary> /// <param name="currentView">Path of current master page or MVC layout.</param> /// <param name="view">Check whether this view is currently selected.</param> /// <returns></returns> public bool CurrentViewIs(string currentView, EsccWebsiteView view) { var generalSettings = ConfigurationManager.GetSection("Escc.EastSussexGovUK/GeneralSettings") as NameValueCollection; if (generalSettings == null) { generalSettings = ConfigurationManager.GetSection("EsccWebTeam.EastSussexGovUK/GeneralSettings") as NameValueCollection; } return(IsMasterPageInGroup(currentView, view + "MvcLayout", generalSettings?.AllKeys.ToDictionary(k => k, k => generalSettings[k]))); }
/// <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="CoronerSkin" /> class. /// </summary> /// <param name="currentView">The current view.</param> /// <param name="requestUrl">The request URL.</param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentException">requestUrl must be an absolute URL</exception> public CoronerSkin(EsccWebsiteView currentView, Uri requestUrl) : base(currentView) { if (requestUrl == null) { throw new ArgumentNullException(nameof(requestUrl)); } if (!requestUrl.IsAbsoluteUri) { throw new ArgumentException("requestUrl must be an absolute URL"); } _currentView = currentView; _requestUrl = requestUrl; }
/// <summary> /// Initializes a new instance of the <see cref="CustomerFocusSkin"/> class. /// </summary> /// <param name="currentView">The current view.</param> public CustomerFocusSkin(EsccWebsiteView currentView) { _currentView = currentView; }
/// <summary> /// Determines whether the currently selected master page or MVC layout is an instance of the given view. /// </summary> /// <param name="currentView">Path of current master page or MVC layout.</param> /// <param name="view">Check whether this view is currently selected.</param> /// <returns></returns> public bool CurrentViewIs(string currentView, EsccWebsiteView view) { return(IsMasterPageInGroup(currentView, view + "MvcLayout", _views)); }
/// <summary> /// Assigns the master page based on a user request /// </summary> /// <param name="generalSettings">The general settings.</param> /// <param name="configSettings">The config settings for specific master pages.</param> /// <param name="configSettingsGroup">The configuration settings group.</param> /// <param name="esccWebsiteView">The preferred view before this test.</param> /// <param name="requestedKey">The key supplied by the user to request the master page.</param> /// <returns></returns> private static EsccWebsiteView AssignMasterPageFromUserRequest(NameValueCollection generalSettings, Dictionary <EsccWebsiteView, NameValueCollection> configSettings, string configSettingsGroup, EsccWebsiteView esccWebsiteView, string requestedKey) { try { // Get the view requested by the user, and check that we have a master page registered to match it var requestedView = (EsccWebsiteView)Enum.Parse(typeof(EsccWebsiteView), requestedKey, true); if ((configSettings.ContainsKey(requestedView) && configSettings[requestedView] != null) || !String.IsNullOrEmpty(generalSettings[requestedView + configSettingsGroup])) { esccWebsiteView = requestedView; } } catch (ArgumentException) { // Requested key was invalid, ignore it } return(esccWebsiteView); }
public async Task EastSussexGovUKTemplateRequest_requests_control(string controlId, EsccWebsiteView view) { var httpContextAccessor = new Mock <IHttpContextAccessor>(); httpContextAccessor.Setup(x => x.HttpContext).Returns(CreateHttpContext()); var viewSelector = new Mock <IViewSelector>(); viewSelector.Setup(x => x.CurrentViewIs(It.IsAny <string>())).Returns(view); var htmlProvider = new Mock <IHtmlControlProvider>(); var breadcrumbProvider = new Mock <IBreadcrumbProvider>(); var templateRequest = new EastSussexGovUKTemplateRequest( httpContextAccessor.Object, viewSelector.Object, htmlProvider.Object, breadcrumbProvider.Object, null, null, null ); await templateRequest.RequestTemplateHtmlAsync(); htmlProvider.Verify(x => x.FetchHtmlForControl(It.IsAny <string>(), It.IsAny <Uri>(), controlId, breadcrumbProvider.Object, It.IsAny <int>(), It.IsAny <bool>())); }