Beispiel #1
0
        public Uri Navigate( DocumentLocator locator, ILocatorMacroResolver macroResolver )
        {
            Contract.RequiresNotNull( locator, "locator" );
            Contract.RequiresNotNull( macroResolver, "macroResolver" );

            return NavigateToFinalSite( locator.Fragments, macroResolver );
        }
        public void Navigate(DocumentType docType, DocumentLocator locator, ILocatorMacroResolver macroResolver)
        {
            var url = myNavigator.Navigate(locator, macroResolver);

            if (url == null)
            {
                return;
            }

            var loader = DocumentLoaderFactory.CreateLoader(docType, Browser);

            Document = loader.Load(url);
        }
Beispiel #3
0
        public void Navigate(DocumentType docType, DocumentLocator locator, ILocatorMacroResolver macroResolver)
        {
            var uri = myNavigator.Navigate(locator, macroResolver);

            myLogger.Info("Url from navigator: {0}", uri);

            var documentLoader = DocumentLoaderFactory.CreateLoader(docType);

            Document = documentLoader.Load(uri);

            if (DocumentCompleted != null)
            {
                DocumentCompleted(Document);
            }
        }
Beispiel #4
0
        public Uri Navigate(DocumentLocator locator, ILocatorMacroResolver macroResolver)
        {
            // TODO: key for caching would need include the locator with patterns + kind of hashcode from resolver
            // (e.g. including hash of all known macros)

            var key = macroResolver.CalculateLocationUID(locator);

            var uri = myCache.TryGet(key);

            if (uri == null)
            {
                uri = myNavigator.Navigate(locator, macroResolver);
                uri = myCache.Add(key, uri);
            }

            return(uri);
        }
Beispiel #5
0
        /// <summary>
        /// Navigates to the final site specified by the user steps and
        /// returns the Uri of the last site.
        /// Regular expressions in response URLs (embedded in {}) are matched. The
        /// resulting parameter is set to the next request URL using 
        /// string.Format() at placeholder {0}.
        /// </summary>
        private Uri NavigateToFinalSite( IEnumerable<DocumentLocationFragment> fragments, ILocatorMacroResolver macroResolver )
        {
            string param = null;

            var lastFragment = fragments.Last();
            if( lastFragment is Response )
            {
                // last step is a response - take the one before
                lastFragment = fragments.ElementAt( fragments.Count() - 2 );
            }

            Uri currentUrl = null;
            foreach( var origFragment in fragments )
            {
                var fragment = macroResolver.Resolve( origFragment );

                Contract.Requires( !macroResolver.UnresolvedMacros.Any(), 
                    "Failed to resolve macros: {0}", string.Join( ",", macroResolver.UnresolvedMacros ) );

                if( fragment is Request )
                {
                    string url = fragment.UrlString;
                    if( param != null )
                    {
                        url = string.Format( url, param );
                    }
                    else if( HasPlaceHolder( url ) )
                    {
                        var ex = new ApplicationException( "Counldn't find a parameter for placeholder" );
                        ex.Data[ "Url" ] = url;

                        throw ex;
                    }

                    currentUrl = new Uri( url );

                    if( fragment == lastFragment )
                    {
                        // we can stop here - we created the url for the last step
                        // furster navigation not necessary
                        break;
                    }

                    currentUrl = SendRequest( currentUrl );
                }
                else if( fragment is Response )
                {
                    // get param from response url if any
                    param = PatternMatching.MatchEmbeddedRegex( fragment.UrlString, currentUrl.ToString() );
                }
                else if( fragment is SubmitFormular )
                {
                    currentUrl = SubmitFormular( currentUrl, ( ( SubmitFormular )fragment ).Formular );
                }
                else
                {
                    throw new NotSupportedException( "UrlType: " + fragment.GetType() );
                }
            }

            return currentUrl;
        }