コード例 #1
0
        private static MediaUrlData ParseRenderUrl(string relativeUrl, out UrlKind urlKind)
        {
            try
            {
                var        queryParameters = new UrlBuilder(relativeUrl).GetQueryParameters();
                IMediaFile mediaFile       = MediaUrlHelper.GetFileFromQueryString(queryParameters);
                Verify.IsNotNull(mediaFile, "failed to get file from a query string");

                urlKind = UrlKind.Renderer;

                queryParameters.Remove("id");
                queryParameters.Remove("i");
                queryParameters.Remove("src");
                queryParameters.Remove("store");

                return(new MediaUrlData {
                    MediaId = mediaFile.Id, MediaStore = mediaFile.StoreId, QueryParameters = queryParameters
                });
            }
            catch (Exception)
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }
        }
コード例 #2
0
        public HyperLinkEqualsValidator(string url, UrlKind kind, bool strictQueryStringParamsOrder, params UriComponents[] components)
        {
            this.strictQueryStringParamsOrder = strictQueryStringParamsOrder;
            this.url  = url;
            this.kind = kind;
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }
            UriComponents tempComponent = components[0];

            components.ToList().ForEach(s => tempComponent |= s);
            finalComponent = tempComponent;

            if (this.strictQueryStringParamsOrder == false && (finalComponent & UriComponents.Query) > 0)
            {
                checkQueryStringParams = true;
                finalComponent         = finalComponent & ~UriComponents.Query;
            }
            else if (this.strictQueryStringParamsOrder == false && (finalComponent & UriComponents.PathAndQuery) > 0)
            {
                checkQueryStringParams = true;
                finalComponent         = finalComponent & ~UriComponents.PathAndQuery;
                finalComponent         = finalComponent | UriComponents.Path;
            }
        }
コード例 #3
0
        /// <summary>
        /// Compates current Url and given url.
        /// </summary>
        /// <param name="url">This url is compared with CurrentUrl.</param>
        /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
        /// <param name="components">Determine what parts of urls are compared.</param>
        public bool CompareUrl(string url, UrlKind urlKind, params UriComponents[] components)
        {
            var currentUri = new Uri(CurrentUrl);

            //support relative domain
            //(new Uri() cannot parse the url correctly when the host is missing
            if (urlKind == UrlKind.Relative)
            {
                url = url.StartsWith("/") ? $"{currentUri.Scheme}://{currentUri.Host}{url}" : $"{currentUri.Scheme}://{currentUri.Host}/{url}";
            }

            if (urlKind == UrlKind.Absolute && url.StartsWith("//"))
            {
                if (!string.IsNullOrWhiteSpace(currentUri.Scheme))
                {
                    url = currentUri.Scheme + ":" + url;
                }
            }

            var expectedUri = new Uri(url, UriKind.Absolute);

            if (components.Length == 0)
            {
                throw new BrowserLocationException($"Function CheckUrlCheckUrl(string, UriKind, params UriComponents) has to have one UriComponents at least.");
            }
            UriComponents finalComponent = components[0];

            components.ToList().ForEach(s => finalComponent |= s);

            return(Uri.Compare(currentUri, expectedUri, finalComponent, UriFormat.SafeUnescaped, StringComparison.OrdinalIgnoreCase) == 0);
        }
コード例 #4
0
 /// <summary>
 /// Checks url by its parts
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public BrowserWrapper CheckUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     if (!CompareUrl(url, urlKind, components))
     {
         throw new BrowserLocationException($"Current url is not expected. Current url: '{CurrentUrl}'. Expected url: '{url}'");
     }
     return(this);
 }
コード例 #5
0
 public BrowserWrapper CheckIfHyperLinkEquals(string selector, string url, UrlKind kind, params UriComponents[] components)
 {
     ForEach(selector, element =>
     {
         element.CheckIfHyperLinkEquals(url, kind, components);
     });
     return(this);
 }
コード例 #6
0
ファイル: PageUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="absoluteUrl">The absolute URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            if (absoluteUrl.StartsWith("http") && absoluteUrl.Contains("://"))
            {
                return UrlProvider.ParseUrl(absoluteUrl, out urlKind);
            }

            var context = HttpContext.Current;
            string hostname = context != null ? context.Request.Url.Host : null;
            var urlSpace = new UrlSpace(hostname, absoluteUrl);

            return UrlProvider.ParseUrl(absoluteUrl, urlSpace, out urlKind);
        }
コード例 #7
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="absoluteUrl">The absolute URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            if (absoluteUrl.StartsWith("http") && absoluteUrl.Contains("://"))
            {
                return(UrlProvider.ParseUrl(absoluteUrl, out urlKind));
            }

            var    context  = HttpContext.Current;
            string hostname = context != null ? context.Request.Url.Host : null;
            var    urlSpace = new UrlSpace(hostname, absoluteUrl);

            return(UrlProvider.ParseUrl(absoluteUrl, urlSpace, out urlKind));
        }
コード例 #8
0
        public HyperLinkEqualsValidator(string url, UrlKind kind, params UriComponents[] components)
        {
            this.url  = url;
            this.kind = kind;
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }
            UriComponents tempComponent = components[0];

            components.ToList().ForEach(s => tempComponent |= s);
            finalComponent = tempComponent;
        }
コード例 #9
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
            case UrlKind.Internal:
                return(BuildInternalUrl(mediaUrlData));

            case UrlKind.Renderer:
                return(BuildRendererUrl(mediaUrlData));

            case UrlKind.Public:
                return(BuildPublicUrl(mediaUrlData));
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
コード例 #10
0
        /// <summary>
        /// Checks href value of element A (hyperlink)
        /// </summary>
        /// <param name="url">Expected value of href.</param>
        /// <param name="kind">Type of url of expected href.</param>
        /// <param name="components">Determines what parts of url should be compared.</param>
        /// <returns></returns>
        public ElementWrapper CheckIfHyperLinkEquals(string url, UrlKind kind, params UriComponents[] components)
        {
            if (components.Length == 0)
            {
                components    = new UriComponents[1];
                components[0] = kind == UrlKind.Relative ? UriComponents.PathAndQuery : UriComponents.AbsoluteUri;
            }

            var providedHref = new Uri(WebElement.GetAttribute("href"));

            if (kind == UrlKind.Relative)
            {
                var host = BaseUrl;
                if (string.IsNullOrWhiteSpace(host))
                {
                    host = "http://example.com/";
                }
                else if (!host.EndsWith("/"))
                {
                    host += "/";
                }
                url = host + (url.StartsWith("/") ? url.Substring(1) : url);
            }
            if (kind == UrlKind.Absolute && url.StartsWith("//"))
            {
                url = providedHref.Scheme + ":" + url;
            }
            var           expectedHref   = new Uri(url);
            UriComponents finalComponent = components[0];

            components.ToList().ForEach(s => finalComponent |= s);

            if (Uri.Compare(providedHref, expectedHref, finalComponent, UriFormat.SafeUnescaped,
                            StringComparison.OrdinalIgnoreCase) != 0)
            {
                throw new UnexpectedElementStateException($"Link '{FullSelector}' provided value '{providedHref}' of attribute href. Provided value does not match with expected value '{url}'.");
            }

            return(this);
        }
コード例 #11
0
        /// <summary>
        /// Checks if browser can access given Url (browser returns status code 2??).
        /// </summary>
        /// <param name="url"></param>
        /// <param name="urlKind"></param>
        /// <returns></returns>
        public BrowserWrapper CheckIfUrlIsAccessible(string url, UrlKind urlKind)
        {
            var currentUri = new Uri(CurrentUrl);

            if (urlKind == UrlKind.Relative)
            {
                url = GetAbsoluteUrl(url);
            }

            if (urlKind == UrlKind.Absolute && url.StartsWith("//"))
            {
                if (!string.IsNullOrWhiteSpace(currentUri.Scheme))
                {
                    url = currentUri.Scheme + ":" + url;
                }
            }

            HttpWebResponse response = null;

            SeleniumTestBase.Log($"CheckIfUrlIsAccessible: Checking of url: '{url}'", 10);
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method = "HEAD";

            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                throw new WebException($"Unable to access {url}! {e.Status}", e);
            }
            finally
            {
                response?.Close();
            }
            return(this);
        }
コード例 #12
0
        public PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            Verify.ArgumentNotNullOrEmpty(absoluteUrl, "absoluteUrl");

            // Converting links
            // "http://localhost" to "http://localhost/"
            // "http://localhost?..." to "http://localhost/?..."
            if ((absoluteUrl.Count(c => c == '/') == 2) && absoluteUrl.Contains("//"))
            {
                int questionMarkIndex = absoluteUrl.IndexOf('?');
                if (questionMarkIndex > 0)
                {
                    absoluteUrl = absoluteUrl.Insert(questionMarkIndex, "/");
                }
                else
                {
                    absoluteUrl += "/";
                }
            }

            Uri uri = new Uri(absoluteUrl);

            string hostname = uri.DnsSafeHost;

            if (!IsKnownHostname(hostname))
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }

            string serverUrl   = new UrlBuilder(absoluteUrl).ServerUrl;
            string relativeUrl = absoluteUrl.Substring(serverUrl.Length - 1);

            var urlSpace = new UrlSpace(hostname, relativeUrl);

            return(ParseUrl(relativeUrl, urlSpace, out urlKind));
        }
コード例 #13
0
        public string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind, UrlSpace urlSpace)
        {
            Verify.ArgumentCondition(urlKind != UrlKind.Undefined, "urlKind", "Url kind is undefined");

            /*var page = pageUrlData.Data;
             * Verify.ArgumentCondition(page != null, "urlData", "Failed to get page from UrlData<IPage>");*/

            if (urlKind == UrlKind.Public)
            {
                return(BuildPublicUrl(pageUrlData, urlSpace));
            }

            if (urlKind == UrlKind.Renderer)
            {
                return(BuildRenderUrl(pageUrlData));
            }

            if (urlKind == UrlKind.Internal)
            {
                return(BuildInternalUrl(pageUrlData));
            }

            throw new NotImplementedException("Only 'Public' and 'Internal' url types are supported.");
        }
コード例 #14
0
        public string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind, UrlSpace urlSpace)
        {
            Verify.ArgumentCondition(urlKind != UrlKind.Undefined, "urlKind", "Url kind is undefined");

            /*var page = pageUrlData.Data;
            Verify.ArgumentCondition(page != null, "urlData", "Failed to get page from UrlData<IPage>");*/

            if (urlKind == UrlKind.Public)
            {
                return BuildPublicUrl(pageUrlData, urlSpace);
            }

            if (urlKind == UrlKind.Renderer)
            {
                return BuildRenderUrl(pageUrlData);
            }

            if (urlKind == UrlKind.Internal)
            {
                return BuildInternalUrl(pageUrlData);
            }

            throw new NotImplementedException("Only 'Public' and 'Internal' url types are supported.");
        }
コード例 #15
0
 /// <summary>
 /// Checks if browser can access given Url (browser returns status code 2??).
 /// </summary>
 /// <param name="url"></param>
 /// <param name="urlKind"></param>
 /// <returns></returns>
 public IBrowserWrapperFluentApi CheckIfUrlIsAccessible(string url, UrlKind urlKind)
 {
     return((IBrowserWrapperFluentApi)EvaluateBrowserCheck <BrowserLocationException>(new UrlIsAccessibleValidator(url, urlKind)));
 }
コード例 #16
0
 /// <summary>
 /// Builds the URL.
 /// </summary>
 /// <param name="mediaFile">The media file.</param>
 /// <param name="urlKind">Kind of the URL.</param>
 /// <returns></returns>
 public static string BuildUrl(IMediaFile mediaFile, UrlKind urlKind = UrlKind.Public)
 {
     return(BuildUrl(new MediaUrlData(mediaFile), urlKind));
 }
コード例 #17
0
 /// <summary>
 /// Compates current Url and given url.
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public bool CompareUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     return(new UrlValidator(url, urlKind, components).CompareUrl(CurrentUrl));
 }
コード例 #18
0
 /// <summary>
 /// Checks href value of element A (hyperlink)
 /// </summary>
 /// <param name="url">Expected value of href.</param>
 /// <param name="kind">Type of url of expected href.</param>
 /// <param name="components">Determines what parts of url should be compared.</param>
 /// <returns></returns>
 public IElementWrapperFluentApi CheckIfHyperLinkEquals(string url, UrlKind kind, params UriComponents[] components)
 {
     return(EvaluateElementCheck <UnexpectedElementStateException>(
                new HyperLinkEqualsValidator(url, kind, true, components)));
 }
コード例 #19
0
ファイル: MediaUrls.cs プロジェクト: DBailey635/C1-CMS
 /// <summary>
 /// Builds the URL.
 /// </summary>
 /// <param name="mediaFile">The media file.</param>
 /// <param name="urlKind">Kind of the URL.</param>
 /// <returns></returns>
 public static string BuildUrl(IMediaFile mediaFile, UrlKind urlKind = UrlKind.Public)
 {
     return BuildUrl(new MediaUrlData(mediaFile), urlKind);
 }
コード例 #20
0
        private PageUrlData ParseInternalUrl(string relativeUrl, out UrlKind urlKind)
        {
            var urlBuilder = new UrlBuilder(relativeUrl);

            if (IsPageRendererRequest(urlBuilder.FilePath))
            {
                urlKind = UrlKind.Renderer;
                return ParseRendererUrl(urlBuilder);
            }

            urlKind = UrlKind.Undefined;

            string decodedPath = HttpUtility.UrlDecode(urlBuilder.FullPath);

            string prefix = InternalUrlPrefix;

            if (!decodedPath.StartsWith(prefix, true))
            {
                prefix = InternalUrlPrefixResolved;
                if (!decodedPath.StartsWith(prefix, true))
                {
                    return null;
                }
            }

            int closingBracketOffset = decodedPath.IndexOf(')');
            if (closingBracketOffset < 0)
            {
                return null;
            }

            Guid pageId;
            if (!Guid.TryParse(decodedPath.Substring(prefix.Length, closingBracketOffset - prefix.Length), out pageId))
            {
                return null;
            }

            string pathInfo = decodedPath.Substring(closingBracketOffset + 1);
            if (pathInfo.Length > 0 && pathInfo[0] != '/')
            {
                return null;
            }

            bool isUnpublished = pathInfo.Contains(UrlMarker_Unpublished);
            if (isUnpublished)
            {
                pathInfo = pathInfo.Replace(UrlMarker_Unpublished, string.Empty);
            }

            NameValueCollection queryString = urlBuilder.GetQueryParameters();
            string cultureInfoStr = queryString["cultureInfo"];

            CultureInfo cultureInfo;
            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            queryString.Remove("cultureInfo");

            urlKind = UrlKind.Internal;

            return new PageUrlData(pageId, isUnpublished ? PublicationScope.Unpublished : PublicationScope.Published, cultureInfo)
            {
                PathInfo = pathInfo,
                QueryParameters = queryString
            };
        }
コード例 #21
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="pageUrlData">The page URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(pageUrlData, "pageUrlData");

            return(UrlProvider.BuildUrl(pageUrlData, urlKind, urlSpace ?? new UrlSpace()));
        }
コード例 #22
0
 /// <summary>
 /// Checks url by its parts
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public IBrowserWrapperFluentApi CheckUrl(string url, UrlKind urlKind, params UriComponents[] components)
 {
     return((IBrowserWrapperFluentApi)EvaluateBrowserCheck <BrowserLocationException>(new UrlValidator(url, urlKind, components)));
 }
コード例 #23
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static MediaUrlData ParseUrl(string relativeUrl, out UrlKind urlKind)
        {
            relativeUrl = relativeUrl.Replace("%28", "(").Replace("%29", ")");

            if (relativeUrl.StartsWith(MediaUrl_RenderPrefix, StringComparison.OrdinalIgnoreCase) ||
                relativeUrl.StartsWith(MediaUrl_UnprocessedRenderPrefix, StringComparison.OrdinalIgnoreCase))
            {
                return(ParseRenderUrl(relativeUrl, out urlKind));
            }

            urlKind = UrlKind.Undefined;

            bool isInternalLink            = relativeUrl.StartsWith(MediaUrl_InternalPrefix, StringComparison.Ordinal);
            bool isInternalUnprocessedLink = !isInternalLink && relativeUrl.StartsWith(MediaUrl_UnprocessedInternalPrefix, StringComparison.Ordinal);

            if (isInternalLink || isInternalUnprocessedLink)
            {
                string prefix = isInternalLink ? MediaUrl_InternalPrefix : MediaUrl_UnprocessedInternalPrefix;

                var result = ParseInternalUrl(relativeUrl, prefix);
                if (result != null)
                {
                    urlKind = UrlKind.Internal;
                }

                return(result);
            }

            int minimumLengthOfPublicMediaUrl = MediaUrl_PublicPrefix.Length + 22; /* 2 - length of a compressed guid */

            if (relativeUrl.Length >= minimumLengthOfPublicMediaUrl &&
                relativeUrl.StartsWith(MediaUrl_PublicPrefix))
            {
                // Parsing urls like /<site root>/media/{MediaId}*
                Guid mediaId;

                if (TryExtractMediaId(relativeUrl, MediaUrl_PublicPrefix.Length, out mediaId))
                {
                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return(new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = DefaultMediaStore,
                        QueryParameters = queryParams
                    });
                }

                // Parsing urls like /<site root>/media/<MediaArchive>/{MediaId}*
                int slashOffset = relativeUrl.IndexOf('/', MediaUrl_PublicPrefix.Length + 1);

                if (slashOffset > MediaUrl_PublicPrefix.Length + 1 &&
                    TryExtractMediaId(relativeUrl, slashOffset + 1, out mediaId))
                {
                    string mediaStore = relativeUrl.Substring(MediaUrl_PublicPrefix.Length, slashOffset - MediaUrl_PublicPrefix.Length);

                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return(new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = mediaStore,
                        QueryParameters = queryParams
                    });
                }
            }

            return(null);
        }
コード例 #24
0
        public PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            if (IsInternalUrl(relativeUrl))
            {
                return ParseInternalUrl(relativeUrl, out urlKind);
            }

            var urlBuilder = new UrlBuilder(relativeUrl);

            // Structure of a public url:
            // http://<hostname>[/ApplicationVirtualPath]{/languageCode}[/Path to a page][/c1mode(unpublished)][/c1mode(relative)][UrlSuffix]{/PathInfo}
           

            string filePathAndPathInfo = HttpUtility.UrlDecode(urlBuilder.FullPath);
            filePathAndPathInfo = RemoveUrlMarkers(filePathAndPathInfo, urlSpace);

            string pathWithoutLanguageCode;

            IHostnameBinding hostnameBinding = urlSpace.ForceRelativeUrls ? null : GetHostnameBindings().FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

            CultureInfo locale = GetCultureInfo(filePathAndPathInfo, hostnameBinding, out pathWithoutLanguageCode);
            if (locale == null)
            {
                urlKind = UrlKind.Undefined;
                return null;
            }

            var publicationScope = PublicationScope.Published;

            if (filePathAndPathInfo.Contains(UrlMarker_Unpublished))
            {
                publicationScope = PublicationScope.Unpublished;

                pathWithoutLanguageCode = pathWithoutLanguageCode.Replace(UrlMarker_Unpublished, string.Empty);
                if (pathWithoutLanguageCode == string.Empty)
                {
                    pathWithoutLanguageCode = "/";
                }
            }

            using (new DataScope(publicationScope, locale))
            {
                bool isObsolete = false;
                string pathToResolve = pathWithoutLanguageCode;

                // Supporting obsolete "*.aspx" urls
                if (!string.Equals(UrlSuffix, ".aspx", StringComparison.OrdinalIgnoreCase) 
                    && (pathToResolve.Contains(".aspx/") || pathToResolve.EndsWith(".aspx")))
                {
                    pathToResolve = pathToResolve.Replace(".aspx", UrlSuffix);
                    isObsolete = true;
                }

                PageUrlData data = ParsePagePath(pathToResolve, publicationScope, locale, hostnameBinding);
                if (data != null)
                {
                    urlKind = !isObsolete ? UrlKind.Public : UrlKind.Redirect;
                    data.QueryParameters = urlBuilder.GetQueryParameters();
                    return data;
                }

                Guid friendlyUrlPageId = ParseFriendlyUrlPath(pathWithoutLanguageCode);
                if (friendlyUrlPageId != Guid.Empty)
                {
                    urlKind = UrlKind.Friendly;
                    return new PageUrlData(friendlyUrlPageId, publicationScope, locale) {QueryParameters = urlBuilder.GetQueryParameters()};
                }
            }

            urlKind = UrlKind.Undefined;
            return null;
        }
コード例 #25
0
ファイル: PageUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="pageUrlData">The page URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(PageUrlData pageUrlData, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null) 
        {
            Verify.ArgumentNotNull(pageUrlData, "pageUrlData");

            return UrlProvider.BuildUrl(pageUrlData, urlKind, urlSpace ?? new UrlSpace());
        }
コード例 #26
0
ファイル: PageUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(IPage page, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(page, "page");

            return BuildUrl(new PageUrlData(page), urlKind, urlSpace ?? new UrlSpace());
        }
コード例 #27
0
ファイル: MediaUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static MediaUrlData ParseUrl(string relativeUrl, out UrlKind urlKind)
        {
            relativeUrl = relativeUrl.Replace("%28", "(").Replace("%29", ")");

            if(relativeUrl.StartsWith(MediaUrl_RenderPrefix, StringComparison.OrdinalIgnoreCase)
               || relativeUrl.StartsWith(MediaUrl_UnprocessedRenderPrefix, StringComparison.OrdinalIgnoreCase))
            {
                return ParseRenderUrl(relativeUrl, out urlKind);
            }

            urlKind = UrlKind.Undefined;

            bool isInternalLink = relativeUrl.StartsWith(MediaUrl_InternalPrefix, StringComparison.Ordinal);
            bool isInternalUnprocessedLink = !isInternalLink && relativeUrl.StartsWith(MediaUrl_UnprocessedInternalPrefix, StringComparison.Ordinal);

            if (isInternalLink || isInternalUnprocessedLink)
            {
                string prefix = isInternalLink ? MediaUrl_InternalPrefix : MediaUrl_UnprocessedInternalPrefix;

                var result = ParseInternalUrl(relativeUrl, prefix);
                if(result != null)
                {
                    urlKind = UrlKind.Internal;
                } 

                return result;
            }

            int minimumLengthOfPublicMediaUrl = MediaUrl_PublicPrefix.Length + 22; /* 2 - length of a compressed guid */
            if (relativeUrl.Length >= minimumLengthOfPublicMediaUrl
                && relativeUrl.StartsWith(MediaUrl_PublicPrefix))
            {
                // Parsing urls like /<site root>/media/{MediaId}*
                Guid mediaId;

                if (TryExtractMediaId(relativeUrl, MediaUrl_PublicPrefix.Length, out mediaId))
                {
                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = DefaultMediaStore,
                        QueryParameters = queryParams
                    };
                }

                // Parsing urls like /<site root>/media/<MediaArchive>/{MediaId}*
                int slashOffset = relativeUrl.IndexOf('/', MediaUrl_PublicPrefix.Length + 1);

                if (slashOffset > MediaUrl_PublicPrefix.Length + 1 
                    && TryExtractMediaId(relativeUrl, slashOffset + 1, out mediaId))
                {
                    string mediaStore = relativeUrl.Substring(MediaUrl_PublicPrefix.Length, slashOffset - MediaUrl_PublicPrefix.Length);

                    NameValueCollection queryParams = new UrlBuilder(relativeUrl).GetQueryParameters();

                    urlKind = UrlKind.Public;
                    return new MediaUrlData
                    {
                        MediaId = mediaId,
                        MediaStore = mediaStore,
                        QueryParameters = queryParams
                    };
                }
            }

            return null;
        }
コード例 #28
0
ファイル: MediaUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="mediaUrlData">The media URL data.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static string BuildUrl(MediaUrlData mediaUrlData, UrlKind urlKind)
        {
            Verify.ArgumentNotNull(mediaUrlData, "mediaUrlData");

            switch (urlKind)
            {
                case UrlKind.Internal:
                    return BuildInternalUrl(mediaUrlData);
                case UrlKind.Renderer:
                    return BuildRendererUrl(mediaUrlData);
                case UrlKind.Public:
                    return BuildPublicUrl(mediaUrlData);
            }

            throw new NotSupportedException("Not supported url kind. urlKind == '{0}'".FormatWith(urlKind));
        }
コード例 #29
0
        public IBrowserWrapperFluentApi CheckIfHyperLinkEquals(string selector, string url, UrlKind kind, params UriComponents[] components)
        {
            var elements  = FindElements(selector);
            var validator = new HyperLinkEqualsValidator(url, kind, components);
            var runner    = new AllOperationRunner <IElementWrapper>(elements);

            runner.Evaluate <UnexpectedElementStateException>(validator);

            return(this);
        }
コード例 #30
0
ファイル: PageUrls.cs プロジェクト: DBailey635/C1-CMS
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind) 
        {
            Verify.ArgumentNotNull(relativeUrl, "relativeUrl");

            return UrlProvider.ParseUrl(relativeUrl, urlSpace, out urlKind);
        }
コード例 #31
0
        /// <summary>
        /// Parses the URL.
        /// </summary>
        /// <param name="relativeUrl">The relative URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <returns></returns>
        public static PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            Verify.ArgumentNotNull(relativeUrl, "relativeUrl");

            return(UrlProvider.ParseUrl(relativeUrl, urlSpace, out urlKind));
        }
コード例 #32
0
        //TODO
        //public static void HyperLinkEquals(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, string url, UrlKind kind, params UriComponents[] components)
        //{
        //    var HyperLinkEquals = new HyperLinkEqualsValidator(selector, url, kind, components);
        //    operationRunner.Evaluate<UnexpectedElementStateException>(HyperLinkEquals);
        //}

        //public static void IsDisplayed(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, Expression<Func<string, By>> tmpSelectedMethod = null)
        //{
        //    var IsDisplayed = new IsDisplayed();
        //    operationRunner.Evaluate<UnexpectedElementStateException>(IsDisplayed);
        //}
        //public static void IsNotDisplayed(this IOperationRunner<IBrowserWrapper> operationRunner, string selector, Expression<Func<string, By>> tmpSelectedMethod = null)
        //{
        //    var IsNotDisplayed = new Checkers.BrowserWrapperCheckers.IsNotDisplayed(selector, tmpSelectedMethod);
        //    operationRunner.Evaluate<BrowserException>(IsNotDisplayed);
        //}

        public static void UrlIsAccessible(this IOperationRunner <IBrowserWrapper> operationRunner, string url, UrlKind urlKind)
        {
            var UrlIsAccessible = new UrlIsAccessibleValidator(url, urlKind);

            operationRunner.Evaluate <BrowserException>(UrlIsAccessible);
        }
コード例 #33
0
        /// <summary>
        /// Builds the URL.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="urlKind">Kind of the URL.</param>
        /// <param name="urlSpace">The URL space.</param>
        /// <returns></returns>
        public static string BuildUrl(IPage page, UrlKind urlKind = UrlKind.Public, UrlSpace urlSpace = null)
        {
            Verify.ArgumentNotNull(page, "page");

            return(BuildUrl(new PageUrlData(page), urlKind, urlSpace ?? new UrlSpace()));
        }
コード例 #34
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="url">This url is compared with CurrentUrl.</param>
 /// <param name="urlKind">Determine whether url parameter contains relative or absolute path.</param>
 /// <param name="components">Determine what parts of urls are compared.</param>
 public UrlValidator(string url, UrlKind urlKind, params UriComponents[] components)
 {
     this.url        = url;
     this.urlKind    = urlKind;
     this.components = components;
 }
コード例 #35
0
        public PageUrlData ParseUrl(string absoluteUrl, out UrlKind urlKind)
        {
            Verify.ArgumentNotNullOrEmpty(absoluteUrl, "absoluteUrl");

            // Converting links 
            // "http://localhost" to "http://localhost/"
            // "http://localhost?..." to "http://localhost/?..."
            if((absoluteUrl.Count(c => c == '/') == 2) && absoluteUrl.Contains("//"))
            {
                int questionMarkIndex = absoluteUrl.IndexOf('?');
                if(questionMarkIndex > 0)
                {
                    absoluteUrl = absoluteUrl.Insert(questionMarkIndex, "/");
                }
                else
                {
                    absoluteUrl += "/";
                }
            }

            Uri uri = new Uri(absoluteUrl);

            string hostname = uri.DnsSafeHost;
            if(!IsKnownHostname(hostname))
            {
                urlKind = UrlKind.Undefined;
                return null;
            }

            string serverUrl = new UrlBuilder(absoluteUrl).ServerUrl;
            string relativeUrl = absoluteUrl.Substring(serverUrl.Length - 1);

            var urlSpace = new UrlSpace(hostname, relativeUrl);

            return ParseUrl(relativeUrl, urlSpace, out urlKind);
        }
コード例 #36
0
ファイル: MediaUrls.cs プロジェクト: DBailey635/C1-CMS
        private static MediaUrlData ParseRenderUrl(string relativeUrl, out UrlKind urlKind)
        {
            try
            {
                var queryParameters = new UrlBuilder(relativeUrl).GetQueryParameters();
                IMediaFile mediaFile = MediaUrlHelper.GetFileFromQueryString(queryParameters);
                Verify.IsNotNull(mediaFile, "failed to get file from a query string");

                urlKind = UrlKind.Renderer;

                queryParameters.Remove("id");
                queryParameters.Remove("i");
                queryParameters.Remove("src");
                queryParameters.Remove("store");

                return new MediaUrlData { MediaId = mediaFile.Id, MediaStore = mediaFile.StoreId, QueryParameters = queryParameters };
            }
            catch(Exception)
            {
                urlKind = UrlKind.Undefined;
                return null;
            }
        }
コード例 #37
0
        private PageUrlData ParseInternalUrl(string relativeUrl, out UrlKind urlKind)
        {
            var urlBuilder = new UrlBuilder(relativeUrl);

            if (IsPageRendererRequest(urlBuilder.FilePath))
            {
                urlKind = UrlKind.Renderer;
                return(ParseRendererUrl(urlBuilder));
            }

            urlKind = UrlKind.Undefined;

            string decodedPath = HttpUtility.UrlDecode(urlBuilder.FullPath);

            string prefix = InternalUrlPrefix;

            if (!decodedPath.StartsWith(prefix, true))
            {
                prefix = InternalUrlPrefixResolved;
                if (!decodedPath.StartsWith(prefix, true))
                {
                    return(null);
                }
            }

            int closingBracketOffset = decodedPath.IndexOf(')');

            if (closingBracketOffset < 0)
            {
                return(null);
            }

            Guid pageId;

            if (!Guid.TryParse(decodedPath.Substring(prefix.Length, closingBracketOffset - prefix.Length), out pageId))
            {
                return(null);
            }

            string pathInfo = decodedPath.Substring(closingBracketOffset + 1);

            bool isUnpublished = pathInfo.Contains(UrlMarker_Unpublished);

            if (isUnpublished)
            {
                pathInfo = pathInfo.Replace(UrlMarker_Unpublished, string.Empty);
            }

            NameValueCollection queryString = urlBuilder.GetQueryParameters();
            string cultureInfoStr           = queryString["cultureInfo"];

            CultureInfo cultureInfo;

            if (!cultureInfoStr.IsNullOrEmpty())
            {
                cultureInfo = new CultureInfo(cultureInfoStr);
            }
            else
            {
                cultureInfo = LocalizationScopeManager.CurrentLocalizationScope;
                if (cultureInfo.Equals(CultureInfo.InvariantCulture))
                {
                    cultureInfo = DataLocalizationFacade.DefaultLocalizationCulture;
                }
            }

            queryString.Remove("cultureInfo");

            urlKind = UrlKind.Internal;

            return(new PageUrlData(pageId, isUnpublished ? PublicationScope.Unpublished : PublicationScope.Published, cultureInfo)
            {
                PathInfo = pathInfo,
                QueryParameters = queryString
            });
        }
コード例 #38
0
        public static void HyperLineEquals(this IOperationRunner <IElementWrapper> operationRunner, string url, UrlKind kind, params UriComponents[] components)
        {
            var HyperLinkEquals = new HyperLinkEqualsValidator(url, kind, true, components);

            operationRunner.Evaluate <UnexpectedElementStateException>(HyperLinkEquals);
        }
コード例 #39
0
        public PageUrlData ParseUrl(string relativeUrl, UrlSpace urlSpace, out UrlKind urlKind)
        {
            if (IsInternalUrl(relativeUrl))
            {
                return(ParseInternalUrl(relativeUrl, out urlKind));
            }

            var urlBuilder = new UrlBuilder(relativeUrl);

            // Structure of a public url:
            // http://<hostname>[/ApplicationVirtualPath]{/languageCode}[/Path to a page][/c1mode(unpublished)][/c1mode(relative)][UrlSuffix]{/PathInfo}


            string filePathAndPathInfo = HttpUtility.UrlDecode(urlBuilder.FullPath);

            filePathAndPathInfo = RemoveUrlMarkers(filePathAndPathInfo, urlSpace);

            string pathWithoutLanguageCode;

            IHostnameBinding hostnameBinding = urlSpace.ForceRelativeUrls ? null : GetHostnameBindings().FirstOrDefault(b => b.Hostname == urlSpace.Hostname);

            CultureInfo locale = GetCultureInfo(filePathAndPathInfo, hostnameBinding, out pathWithoutLanguageCode);

            if (locale == null)
            {
                urlKind = UrlKind.Undefined;
                return(null);
            }

            var publicationScope = PublicationScope.Published;

            if (filePathAndPathInfo.Contains(UrlMarker_Unpublished))
            {
                publicationScope = PublicationScope.Unpublished;

                pathWithoutLanguageCode = pathWithoutLanguageCode.Replace(UrlMarker_Unpublished, string.Empty);
                if (pathWithoutLanguageCode == string.Empty)
                {
                    pathWithoutLanguageCode = "/";
                }
            }

            using (new DataScope(publicationScope, locale))
            {
                bool   isObsolete    = false;
                string pathToResolve = pathWithoutLanguageCode;

                // Supporting obsolete "*.aspx" urls
                if (!string.Equals(UrlSuffix, ".aspx", StringComparison.OrdinalIgnoreCase) &&
                    (pathToResolve.Contains(".aspx/") || pathToResolve.EndsWith(".aspx")))
                {
                    pathToResolve = pathToResolve.Replace(".aspx", UrlSuffix);
                    isObsolete    = true;
                }

                PageUrlData data = ParsePagePath(pathToResolve, publicationScope, locale, hostnameBinding);
                if (data != null)
                {
                    urlKind = !isObsolete ? UrlKind.Public : UrlKind.Redirect;
                    data.QueryParameters = urlBuilder.GetQueryParameters();
                    return(data);
                }

                Guid friendlyUrlPageId = ParseFriendlyUrlPath(pathWithoutLanguageCode);
                if (friendlyUrlPageId != Guid.Empty)
                {
                    urlKind = UrlKind.Friendly;
                    return(new PageUrlData(friendlyUrlPageId, publicationScope, locale)
                    {
                        QueryParameters = urlBuilder.GetQueryParameters()
                    });
                }
            }

            urlKind = UrlKind.Undefined;
            return(null);
        }
コード例 #40
0
        public static void Url(this IOperationRunner <IBrowserWrapper> operationRunner, string url, UrlKind urlKind, params UriComponents[] components)
        {
            var checkUrl = new UrlValidator(url, urlKind, components);

            operationRunner.Evaluate <BrowserLocationException>(checkUrl);
        }
コード例 #41
0
 public UrlIsAccessibleValidator(string url, UrlKind urlKind)
 {
     this.url     = url;
     this.urlKind = urlKind;
 }
コード例 #42
0
ファイル: AssertUI.cs プロジェクト: paulsuen/selenium-utils
        public static void UrlIsAccessible(IBrowserWrapper wrapper, string url, UrlKind urlKind)
        {
            var urlIsAccessible = new UrlIsAccessibleValidator(url, urlKind);

            EvaluateValidator <BrowserException, IBrowserWrapper>(wrapper, urlIsAccessible);
        }