예제 #1
0
        public async Task <IDocument> GetDocument(string url)
        {
            var foundBrowsingContext = _browsingContext.FindChild(url);

            if (foundBrowsingContext == null)
            {
                var newBrowsingContext = _browsingContext.CreateChild(url, Sandboxes.None);
                // When I'm using await, it doesn't work, this is temporary solution
                var openedDocument = await newBrowsingContext.OpenAsync(url);

                return(openedDocument);
            }

            return(await foundBrowsingContext.OpenAsync(url));
        }
        /// <summary>
        /// Gets the specified target browsing context.
        /// </summary>
        /// <param name="context">The current context.</param>
        /// <param name="target">The specified target name.</param>
        /// <returns>
        /// The available context, or null, if the context does not exist yet.
        /// </returns>
        public static IBrowsingContext FindChildFor(this IBrowsingContext context, String target)
        {
            if (String.IsNullOrEmpty(target) || target.Is("_self"))
            {
                return(context);
            }
            else if (target.Is("_parent"))
            {
                return(context.Parent ?? context);
            }
            else if (target.Is("_top"))
            {
                return(context);
            }

            return(context.FindChild(target));
        }