Example #1
0
        /// <summary>
        /// Reads the HTML controls required for the website template. The result is cached for the lifetime of this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <TemplateHtml> RequestTemplateHtmlAsync()
        {
            if (_templateHtml != null)
            {
                return(_templateHtml);
            }

            var textSize = _textSize?.CurrentTextSize();

            if (textSize == null)
            {
                textSize = 1;
            }
            var isLibraryCatalogueRequest = _libraryContext?.RequestIsFromLibraryCatalogueMachine() ?? false;

            _templateHtml = new TemplateHtml();
            var applicationId = String.IsNullOrEmpty(_request.PathBase.ToString()) ? "/" : _request.PathBase.ToString();

            if (_esccWebsiteView == EsccWebsiteView.Desktop)
            {
                var htmlTagTask     = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "HtmlTag", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var metadataTask    = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "MetadataDesktop", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var aboveHeaderTask = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "AboveHeaderDesktop", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var headerTask      = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "HeaderDesktop", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var footerTask      = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "FooterDesktop", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var scriptsTask     = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "ScriptsDesktop", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);

                var results = await Task.WhenAll(htmlTagTask, metadataTask, aboveHeaderTask, headerTask, footerTask, scriptsTask).ConfigureAwait(false);

                _templateHtml.HtmlTag     = new HtmlString(results[0]);
                _templateHtml.Metadata    = new HtmlString(results[1]);
                _templateHtml.AboveHeader = new HtmlString(results[2]);
                _templateHtml.Header      = new HtmlString(results[3]);
                _templateHtml.Footer      = new HtmlString(results[4]);
                _templateHtml.Scripts     = new HtmlString(results[5]);
            }
            else if (_esccWebsiteView == EsccWebsiteView.FullScreen)
            {
                var htmlTagTask  = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "HtmlTag", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var metadataTask = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "MetadataFullScreen", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var headerTask   = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "HeaderFullScreen", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);
                var scriptsTask  = _htmlProvider.FetchHtmlForControl(applicationId, _requestUrl, "ScriptsFullScreen", _breadcrumbProvider, textSize.Value, isLibraryCatalogueRequest);

                var results = await Task.WhenAll(htmlTagTask, metadataTask, headerTask, scriptsTask).ConfigureAwait(false);

                _templateHtml.HtmlTag  = new HtmlString(results[0]);
                _templateHtml.Metadata = new HtmlString(results[1]);
                _templateHtml.Header   = new HtmlString(results[2]);
                _templateHtml.Scripts  = new HtmlString(results[3]);
            }
            return(_templateHtml);
        }
        /// <summary>
        /// Gets a token which identifies the unique fragment of HTML to be stored in the cache.
        /// </summary>
        /// <returns></returns>
        protected string GetCacheToken()
        {
            // Sanitise selected section and use as a token, so we get a different cached version for each section if appropriate
            var sanitisedSection = String.IsNullOrEmpty(_selectedSection) ? String.Empty : "." + Regex.Replace(_selectedSection.ToLower(CultureInfo.CurrentCulture), "[^a-z]", String.Empty);

            // Add the user's text size to the token, because it affects the HTML of the header (bigger / smaller links are added / removed)
            var textSizeSetting = _textSize.CurrentTextSize();
            var textSize        = (textSizeSetting > 1) ? ".textsize" + textSizeSetting : String.Empty;

            // If user is on library catalogue PC, add that to token so that they get a separate cache
            var libraryUser = _libraryCatalogueContext.RequestIsFromLibraryCatalogueMachine() ? ".librarycatalogue" : String.Empty;

            // Add application path to the token, because it affects the path to /masterpages
            var sanitisedPath = "." + Regex.Replace(HttpRuntime.AppDomainAppVirtualPath.ToLower(CultureInfo.CurrentCulture), "[^a-z]", String.Empty);

            return(_control + sanitisedSection + textSize + libraryUser + sanitisedPath);
        }
        /// <summary>
        /// Reads the HTML controls required for the website template. The result is cached for the lifetime of this instance.
        /// </summary>
        /// <returns></returns>
        public async Task <TemplateHtml> RequestTemplateHtmlAsync()
        {
            if (_templateHtml != null)
            {
                return(_templateHtml);
            }

            var textSize = _textSize.CurrentTextSize();
            var isLibraryCatalogueRequest = _libraryContext.RequestIsFromLibraryCatalogueMachine();

            _templateHtml = new TemplateHtml();
            if (_esccWebsiteView == EsccWebsiteView.Desktop)
            {
                var htmlTagTask     = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "HtmlTag", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var metadataTask    = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "MetadataDesktop", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var aboveHeaderTask = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "AboveHeaderDesktop", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var headerTask      = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "HeaderDesktop", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var footerTask      = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "FooterDesktop", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var scriptsTask     = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "ScriptsDesktop", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);

                var results = await Task.WhenAll(htmlTagTask, metadataTask, aboveHeaderTask, headerTask, footerTask, scriptsTask).ConfigureAwait(false);

                _templateHtml.HtmlTag     = new HtmlString(results[0]);
                _templateHtml.Metadata    = new HtmlString(results[1]);
                _templateHtml.AboveHeader = new HtmlString(results[2]);
                _templateHtml.Header      = new HtmlString(results[3]);
                _templateHtml.Footer      = new HtmlString(results[4]);
                _templateHtml.Scripts     = new HtmlString(results[5]);
            }
            else if (_esccWebsiteView == EsccWebsiteView.FullScreen)
            {
                var htmlTagTask  = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "HtmlTag", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var metadataTask = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "MetadataFullScreen", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var headerTask   = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "HeaderFullScreen", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);
                var scriptsTask  = _htmlProvider.FetchHtmlForControl(HttpRuntime.AppDomainAppVirtualPath, _request.Url, "ScriptsFullScreen", _breadcrumbProvider, textSize, isLibraryCatalogueRequest);

                var results = await Task.WhenAll(htmlTagTask, metadataTask, headerTask, scriptsTask).ConfigureAwait(false);

                _templateHtml.HtmlTag  = new HtmlString(results[0]);
                _templateHtml.Metadata = new HtmlString(results[1]);
                _templateHtml.Header   = new HtmlString(results[2]);
                _templateHtml.Scripts  = new HtmlString(results[3]);
            }
            return(_templateHtml);
        }