Example #1
0
        /// <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>());
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteMasterPageCacheProviderBase" /> class.
 /// </summary>
 /// <param name="control">A key identifying the control to cache.</param>
 /// <param name="selectedSection">A key representing the selected section of the site.</param>
 /// <param name="libraryCatalogueContext">The library catalogue context.</param>
 /// <param name="textSize">The site's text size feature.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 protected RemoteMasterPageCacheProviderBase(string control, string selectedSection, ILibraryCatalogueContext libraryCatalogueContext, ITextSize textSize)
 {
     if (libraryCatalogueContext == null)
     {
         throw new ArgumentNullException(nameof(libraryCatalogueContext));
     }
     if (textSize == null)
     {
         throw new ArgumentNullException(nameof(textSize));
     }
     _control                 = control;
     _selectedSection         = selectedSection;
     _libraryCatalogueContext = libraryCatalogueContext;
     _textSize                = textSize;
     SupportsAsync            = false;
 }
Example #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RemoteMasterPageMemoryCacheProvider" /> class.
 /// </summary>
 /// <param name="control">A key identifying the control to cache.</param>
 /// <param name="selectedSection">A key representing the selected section of the site.</param>
 /// <param name="libraryCatalogueContext">The library catalogue context.</param>
 /// <param name="textSize">The site's text size feature.</param>
 public RemoteMasterPageMemoryCacheProvider(string control, string selectedSection, ILibraryCatalogueContext libraryCatalogueContext, ITextSize textSize)
     : base(control, selectedSection, libraryCatalogueContext, textSize)
 {
     _cacheToken          = GetCacheToken();
     CachedVersionExists  = (HttpContext.Current.Cache[_cacheToken] != null);
     CachedVersionIsFresh = CachedVersionExists;
 }