public void Ordinary_User_Agent_is_not_a_library_catalogue_machine()
        {
            const string internetExplorer11 = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; rv:11.0) like Gecko";
            var          context            = new LibraryCatalogueContext(internetExplorer11);

            var result = context.RequestIsFromLibraryCatalogueMachine();

            Assert.False(result);
        }
        public void Library_catalogue_User_Agent_is_detected()
        {
            const string customisedInternetExplorer11 = "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; rv:11.0) like Gecko; ESCC Libraries";
            var          context = new LibraryCatalogueContext(customisedInternetExplorer11);

            var result = context.RequestIsFromLibraryCatalogueMachine();

            Assert.True(result);
        }
        /// <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>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            // Ensure controls are visible by default
            this.Visible = true;

            // Look for various reasons why controls may need to be hidden

            // Hide based on master page
            var viewSelector = new WebFormsViewSelector();

            if (Desktop != null && Desktop.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.Desktop))
            {
                HideContents();
                return;
            }

            if (Plain != null && Plain.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.Plain))
            {
                HideContents();
                return;
            }

            if (FullScreen != null && FullScreen.Value != viewSelector.CurrentViewIs(Page.MasterPageFile, EsccWebsiteView.FullScreen))
            {
                HideContents();
                return;
            }

            // Hide based on user
            var libraryContext = new LibraryCatalogueContext(HttpContext.Current.Request.UserAgent);

            if (LibraryCatalogue != null && LibraryCatalogue.Value != libraryContext.RequestIsFromLibraryCatalogueMachine())
            {
                HideContents();
                return;
            }

            if (!String.IsNullOrEmpty(Groups))
            {
                var settings    = new ActiveDirectorySettingsFromConfiguration();
                var permissions = new LogonIdentityGroupMembershipChecker(settings.DefaultDomain, new ActiveDirectoryMemoryCache());
                if (!permissions.UserIsInGroup(Groups.SplitAndTrim(';')))
                {
                    HideContents();
                    return;
                }
            }

            // Hide based on location
            if (!String.IsNullOrEmpty(this.UrlMatch) && !Regex.IsMatch(HttpContext.Current.Request.Url.ToString(), this.UrlMatch, RegexOptions.IgnoreCase))
            {
                HideContents();
                return;
            }

            var context = new HostingEnvironmentContext(HttpContext.Current.Request.Url);

            if (Public != null && Public.Value != context.IsPublicUrl)
            {
                HideContents();
                return;
            }

            // Hide based on date
            if (this.After.HasValue && DateTime.Now.ToUkDateTime() <= this.After)
            {
                HideContents();
                return;
            }

            if (this.Before.HasValue && DateTime.Now.ToUkDateTime() >= this.Before)
            {
                HideContents();
                return;
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            var libraryContext = new LibraryCatalogueContext(Request.UserAgent);

            this.publicLibraries.Visible = libraryContext.RequestIsFromLibraryCatalogueMachine();
        }