Ejemplo n.º 1
0
        public Page GetPage(int pageNumber)
        {
            if (locatedPages.TryGetValue(pageNumber, out DictionaryToken targetPageDictionary))
            {
                // TODO: cache the page
                return(pageFactory.Create(pageNumber, targetPageDictionary, new PageTreeMembers(),
                                          isLenientParsing));
            }

            var observed = new List <int>();

            var pageTreeMembers = new PageTreeMembers();

            // todo: running a search for a different, unloaded, page number, results in a bug.
            var isFound = FindPage(rootPageDictionary, pageNumber, observed, pageTreeMembers);

            if (!isFound || !locatedPages.TryGetValue(pageNumber, out targetPageDictionary))
            {
                throw new ArgumentOutOfRangeException("Could not find the page with number: " + pageNumber);
            }

            var page = pageFactory.Create(pageNumber, targetPageDictionary, pageTreeMembers, isLenientParsing);

            locatedPages[pageNumber] = targetPageDictionary;

            return(page);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the page by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="includeChildren">(Optional) if set to <c>true</c> [include children].</param>
        /// <param name="includeRelatedData">(Optional) true to include, false to exclude the related data.</param>
        /// <returns>
        /// The by identifier.
        /// </returns>
        public virtual PageModel GetById(Guid id, bool includeChildren = true, bool includeRelatedData = true)
        {
            if (id == Guid.Empty)
            {
                return(null);
            }

            var siteMapNodeById = SiteMapBase.GetCurrentProvider()
                                  .FindSiteMapNodeFromKey(id.ToString());

            return(_pageModelFactory.Create(siteMapNodeById, true, includeChildren, includeRelatedData));
        }
Ejemplo n.º 3
0
        public T Page <T>() where T : BasePage <T>, new()
        {
            if (HasCreatedPageBefore <T>())
            {
                return(GetFromCache <T>());
            }

            var instance = _factory.Create <T>();

            AddToCache <T>(instance);
            return(instance);
        }
Ejemplo n.º 4
0
        public Page GetPage(int pageNumber)
        {
            if (pageNumber <= 0 || pageNumber > Count)
            {
                throw new ArgumentOutOfRangeException(nameof(pageNumber),
                                                      $"Page number {pageNumber} invalid, must be between 1 and {Count}.");
            }

            var pageNode  = catalog.GetPageNode(pageNumber);
            var pageStack = new Stack <PageTreeNode>();

            var currentNode = pageNode;

            while (currentNode != null)
            {
                pageStack.Push(currentNode);
                currentNode = currentNode.Parent;
            }

            var pageTreeMembers = new PageTreeMembers();

            while (pageStack.Count > 0)
            {
                currentNode = pageStack.Pop();

                if (currentNode.NodeDictionary.TryGet(NameToken.Resources, pdfScanner, out DictionaryToken resourcesDictionary))
                {
                    pageTreeMembers.ParentResources.Enqueue(resourcesDictionary);
                }

                if (currentNode.NodeDictionary.TryGet(NameToken.MediaBox, pdfScanner, out ArrayToken mediaBox))
                {
                    pageTreeMembers.MediaBox = new MediaBox(mediaBox.ToRectangle());
                }

                if (currentNode.NodeDictionary.TryGet(NameToken.Rotate, pdfScanner, out NumericToken rotateToken))
                {
                    pageTreeMembers.Rotation = rotateToken.Int;
                }
            }

            var page = pageFactory.Create(pageNumber, pageNode.NodeDictionary, pageTreeMembers, isLenientParsing);

            return(page);
        }
 public void OpenApplication()
 {
     _navigationService.NavigateTo(LoginPage.Url);
     _loginPage = _pageFactory.Create <LoginPage>();
 }
Ejemplo n.º 6
0
        /// <summary>
        ///     Executes the request internally.
        /// </summary>
        /// <typeparam name="T">
        ///     The type of page to return.
        /// </typeparam>
        /// <param name="request">
        ///     The request.
        /// </param>
        /// <param name="expectedStatusCode">
        ///     The expected status code.
        /// </param>
        /// <param name="pageFactory">
        ///     The page factory.
        /// </param>
        /// <returns>
        ///     A <typeparamref name="T" /> value.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="request" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentNullException">
        ///     The <paramref name="pageFactory" /> parameter is <c>null</c>.
        /// </exception>
        /// <exception cref="HttpOutcomeException">
        /// </exception>
        private T ExecuteInternal <T>(
            HttpRequestMessage request,
            HttpStatusCode expectedStatusCode,
            IPageFactory pageFactory) where T : IPage, new()
        {
            var page = default(T);

            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (pageFactory == null)
            {
                throw new ArgumentNullException("pageFactory");
            }

            request.Headers.Add("user-agent", UserAgent);

            var currentResourceLocation = request.RequestUri;

            var outcomes = new List <HttpOutcome>();

            var stopwatch = Stopwatch.StartNew();

            var task = _client.SendAsync(request);

            Uri  redirectLocation = null;
            bool requiresRedirect;

            using (var response = task.Result)
            {
                stopwatch.Stop();

                var outcome = new HttpOutcome(
                    currentResourceLocation,
                    response.RequestMessage.Method,
                    response.StatusCode,
                    response.ReasonPhrase,
                    stopwatch.Elapsed);

                outcomes.Add(outcome);

                requiresRedirect = IsRedirect(response);

                if (requiresRedirect)
                {
                    redirectLocation = response.Headers.Location;
                }
                else
                {
                    // This the final response
                    var result = new HttpResult(outcomes);

                    page = pageFactory.Create <T>(this, response, result);
                }
            }

            while (requiresRedirect)
            {
                // Get the redirect address
                Uri fullRedirectLocation;

                if (redirectLocation.IsAbsoluteUri)
                {
                    fullRedirectLocation = redirectLocation;
                }
                else
                {
                    fullRedirectLocation = new Uri(currentResourceLocation, redirectLocation);
                }

                currentResourceLocation = fullRedirectLocation;
                stopwatch = Stopwatch.StartNew();
                task      = _client.GetAsync(currentResourceLocation);

                using (var response = task.Result)
                {
                    stopwatch.Stop();

                    var outcome = new HttpOutcome(
                        currentResourceLocation,
                        response.RequestMessage.Method,
                        response.StatusCode,
                        response.ReasonPhrase,
                        stopwatch.Elapsed);

                    outcomes.Add(outcome);

                    requiresRedirect = IsRedirect(response);

                    if (requiresRedirect)
                    {
                        redirectLocation = response.Headers.Location;
                    }
                    else
                    {
                        // This the final response
                        var result = new HttpResult(outcomes);

                        page = pageFactory.Create <T>(this, response, result);
                    }
                }
            }

            SetCurrentPage(page);

            var lastOutcome = outcomes[outcomes.Count - 1];

            if (lastOutcome.StatusCode != expectedStatusCode)
            {
                var result = new HttpResult(outcomes);

                throw new HttpOutcomeException(result, expectedStatusCode);
            }

            // Validate that the final address matches the page
            if (page.IsOn(currentResourceLocation) == false)
            {
                var result = new HttpResult(outcomes);

                throw new HttpOutcomeException(result, page.TargetLocation);
            }

            return(page);
        }