Ejemplo n.º 1
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 <NavigatorUrl> navigationSteps)
        {
            string param = null;

            Uri currentUrl = null;

            foreach (NavigatorUrl navUrl in navigationSteps)
            {
                this.Require(x => navUrl.UrlType != UriType.None);

                if (navUrl.UrlType == UriType.Request)
                {
                    string url = navUrl.UrlString;
                    if (param != null)
                    {
                        url = string.Format(url, param);
                    }
                    else if (HasPlaceHolder(url))
                    {
                        var ex = new ApplicationException("Did not find a parameter for placeholder");
                        ex.Data["Url"] = url;

                        throw ex;
                    }

                    currentUrl = new Uri(url);

                    if (navUrl != navigationSteps.Last())
                    {
                        // dont sent the request - we reached the end and we are not interested in the response url
                        currentUrl = SendRequest(currentUrl);
                    }
                }
                else if (navUrl.UrlType == UriType.Response)
                {
                    // get param from response url if any
                    param = PatternMatching.MatchEmbeddedRegex(navUrl.UrlString, currentUrl.ToString());
                }
                else if (navUrl.UrlType == UriType.SubmitFormular)
                {
                    currentUrl = SubmitFormular(currentUrl, navUrl.Formular);
                }
                else
                {
                    throw new NotSupportedException("UrlType: " + navUrl.UrlType);
                }
            }

            return(currentUrl);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Navigates to the final site specified by the user steps and
        /// returns the Uri of the last site.
        /// </summary>
        private string NavigateToFinalSite(IEnumerable <NavigatorUrl> navigationSteps)
        {
            IHtmlDocument doc   = null;
            string        param = null;

            var last = navigationSteps.Last().UrlString;

            foreach (NavigatorUrl navUrl in navigationSteps)
            {
                this.Require(x => navUrl.UrlType != UriType.None);

                if (navUrl.UrlType == UriType.Request)
                {
                    string url = navUrl.UrlString;
                    if (param != null)
                    {
                        url = string.Format(url, param);
                    }
                    else if (HasPlaceHolder(url))
                    {
                        var ex = new ApplicationException("Did not find a parameter for placeholder");
                        ex.Data["Url"] = url;

                        throw ex;
                    }

                    if (navUrl.UrlString == last)
                    {
                        return(url);
                    }
                    else
                    {
                        doc = LoadDocument(url);
                    }
                }
                else
                {
                    // get param from response url if any
                    param = PatternMatching.MatchEmbeddedRegex(navUrl.UrlString, doc.Url.ToString());
                }
            }

            // list empty?
            return(null);
        }