当前位置: 首页>>代码示例>>C#>>正文


C# Uri.IsBaseOf方法代码示例

本文整理汇总了C#中Uri.IsBaseOf方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.IsBaseOf方法的具体用法?C# Uri.IsBaseOf怎么用?C# Uri.IsBaseOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Uri的用法示例。


在下文中一共展示了Uri.IsBaseOf方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Uri_IsBaseOf_NullParameter_ThrowsArgumentException

 public void Uri_IsBaseOf_NullParameter_ThrowsArgumentException()
 {
     Assert.Throws<ArgumentNullException>(() =>
   {
       Uri baseUri = new Uri("http://localhost/");
       Uri relUri = null;
       bool success = baseUri.IsBaseOf(relUri);
   });
 }
开发者ID:ChuangYang,项目名称:corefx,代码行数:9,代码来源:UriParameterValidationTest.cs

示例2: GetBaseUriToWrite

 internal static Uri GetBaseUriToWrite(Uri rootBase, Uri currentBase)
 {
     Uri uriToWrite;
     if (rootBase == currentBase || currentBase == null)
     {
         uriToWrite = null;
     }
     else if (rootBase == null)
     {
         uriToWrite = currentBase;
     }
     else
     {
         // rootBase != currentBase and both are not null
         // Write the relative base if possible
         if (rootBase.IsAbsoluteUri && currentBase.IsAbsoluteUri && rootBase.IsBaseOf(currentBase))
         {
             uriToWrite = rootBase.MakeRelativeUri(currentBase);
         }
         else
         {
             uriToWrite = currentBase;
         }
     }
     return uriToWrite;
 }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:26,代码来源:FeedUtils.cs

示例3: ProcessLinks

    /// <summary>
    /// after it gets the hyperlinks, it needs to process them, put them in a absolute uri format for the purpose
    /// of creating a sitemap and check if hyperlink is an internal hyperlink, if not trash it.
    /// it also creates a special queue for the purpose of displaying on web page. not really needed but useful to see what it crawled
    /// this allows me to see
    /// 
    /// -------------for future use, if it is external only get the base url. its easier that way-----------
    /// </summary>
    public void ProcessLinks()
    {
        Uri inMemory = new Uri(p, UriKind.RelativeOrAbsolute);

        while(qOfURls.Count > 0)
        {
            href = qOfURls.Dequeue().ToString();

        // this only excepts strings not uri objects and for the purpose of checking if internal i did it this way
        Uri validatr = new Uri(href, UriKind.RelativeOrAbsolute);

            // make relative urls absolute
            if (!validatr.IsAbsoluteUri)
            {
                validatr = new Uri(inMemory, validatr);

            }
        if(!StopLoopQ.Contains(validatr))
        {
            if (inMemory.IsBaseOf(validatr))
            {
                DisplayQ.Enqueue(validatr);
                loopingQ.Enqueue(validatr);
                StopLoopQ.Enqueue(validatr);
            }
        }
          }
    }
开发者ID:jaynav,项目名称:MyWebCrawler,代码行数:36,代码来源:Crawls.cs

示例4: IsBaseOf

 /// <summary>
 /// Check whether the <paramref name="baseUri"/> Uri is the base of the <paramref name="uri"/> Uri.
 /// </summary>
 /// <param name="baseUri">The candidate base Uri.</param>
 /// <param name="uri">The Uri to check.</param>
 /// <returns>True if the <paramref name="baseUri"/> is the base of the <paramref name="uri"/> Uri.</returns>
 private static bool IsBaseOf(Uri baseUri, Uri uri)
 {
     return baseUri.IsBaseOf(uri);
 }
开发者ID:rambo-returns,项目名称:MonoRail,代码行数:10,代码来源:UriUtils.cs

示例5: GetAllPagesUnder

    /// <summary>
    /// Get every WebPage.Internal on a web site (or part of a web site) visiting all internal links just once
    /// plus every external page (or other Url) linked to the web site as a WebPage.External
    /// </summary>
    /// <remarks>
    /// Use .OfType WebPage.Internal to get just the internal ones if that's what you want
    /// </remarks>
    public static IEnumerable<WebPage> GetAllPagesUnder(Uri urlRoot)
    {
        var queue = new Queue<Uri>();
        var allSiteUrls = new HashSet<Uri>();

        queue.Enqueue(urlRoot);
        allSiteUrls.Add(urlRoot);

        while (queue.Count > 0)
        {
            Uri url = queue.Dequeue();

            HttpWebRequest oReq = (HttpWebRequest)WebRequest.Create(url);
            oReq.UserAgent = @"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.5) Gecko/20091102 Firefox/3.5.5";

            HttpWebResponse resp = (HttpWebResponse)oReq.GetResponse();

            WebPage result;

            if (resp.ContentType.StartsWith("text/html", StringComparison.InvariantCultureIgnoreCase))
            {
                HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                try
                {
                    var resultStream = resp.GetResponseStream();
                    doc.Load(resultStream); // The HtmlAgilityPack
                    result = new Internal() { Url = url, HtmlDocument = doc };
                }
                catch (System.Net.WebException ex)
                {
                    result = new WebPage.Error() { Url = url, Exception = ex };
                }
                catch (Exception ex)
                {
                    ex.Data.Add("Url", url);    // Annotate the exception with the Url
                    throw;
                }

                // Success, hand off the page
                yield return new WebPage.Internal() { Url = url, HtmlDocument = doc };

                // And and now queue up all the links on this page
                foreach (HtmlNode link in doc.DocumentNode.SelectNodes(@"//a[@href]"))
                {
                    HtmlAttribute att = link.Attributes["href"];
                    if (att == null) continue;
                    string href = att.Value;
                    if (href.StartsWith("javascript", StringComparison.InvariantCultureIgnoreCase)) continue;      // ignore javascript on buttons using a tags

                    Uri urlNext = new Uri(href, UriKind.RelativeOrAbsolute);

                    // Make it absolute if it's relative
                    if (!urlNext.IsAbsoluteUri)
                    {
                        urlNext = new Uri(urlRoot, urlNext);
                    }

                    if (!allSiteUrls.Contains(urlNext))
                    {
                        allSiteUrls.Add(urlNext);               // keep track of every page we've handed off

                        if (urlRoot.IsBaseOf(urlNext))
                        {
                            queue.Enqueue(urlNext);
                        }
                        else
                        {
                            yield return new WebPage.External() { Url = urlNext };
                        }
                    }
                }
            }
        }
    }
开发者ID:riskypathak,项目名称:WebSpider,代码行数:81,代码来源:WebPage.cs

示例6: TestIsBaseOf

    public static void TestIsBaseOf()
    {
        bool b;
        Uri uri, uri2;

        uri = new Uri("http://host/path/path/file?query");

        uri2 = new Uri(@"http://host/path/path/file/");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri(@"http://host/path/path/#fragment");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri("http://host/path/path/MoreDir/\"");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri(@"http://host/path/path/OtherFile?Query");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri(@"http://host/path/path/");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri(@"http://host/path/path/file");
        b = uri.IsBaseOf(uri2);
        Assert.True(b);

        uri2 = new Uri(@"http://host/path/path");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);

        uri2 = new Uri(@"http://host/path/path?query");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);

        uri2 = new Uri(@"http://host/path/path#Fragment");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);

        uri2 = new Uri(@"http://host/path/path2/");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);

        uri2 = new Uri(@"http://host/path/path2/MoreDir");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);

        uri2 = new Uri(@"http://host/path/File");
        b = uri.IsBaseOf(uri2);
        Assert.False(b);
    }
开发者ID:johnhhm,项目名称:corefx,代码行数:55,代码来源:Uri.cs

示例7: IsBaseOf

 internal static bool IsBaseOf(Uri baseUriWithSlash, Uri requestUri)
 {
     return baseUriWithSlash.IsBaseOf(requestUri);
 }
开发者ID:smasonuk,项目名称:odata-sparql,代码行数:4,代码来源:XmlUtil.cs

示例8: Create

        /// <summary>
        /// This function is used in both parser and f&o library, so just strictly map valid literals to XmlCollation.
        /// Set compare options one by one:
        ///     0, false: no effect; 1, true: yes
        /// Disregard unrecognized options.
        /// </summary>
        internal static XmlCollation Create(string collationLiteral) {
            Debug.Assert(collationLiteral != null, "collation literal should not be null");

            if (collationLiteral == XmlReservedNs.NsCollCodePoint) {
                return CodePointCollation;
            }

            XmlCollation coll = new XmlCollation();
            Uri collationUri = new Uri(collationLiteral);

            string authority = collationUri.GetLeftPart(UriPartial.Authority);
            if (authority == XmlReservedNs.NsCollationBase) {
                // Language
                // at least a '/' will be returned for Uri.LocalPath
                string lang = collationUri.LocalPath.Substring(1);
                if (lang.Length == 0) {
                    // Use default culture of current thread (cultinfo = null)
                } else {
                    // Create culture from RFC 1766 string
                    try {
                        coll.cultinfo = new CultureInfo(lang);
                    }
                    catch (ArgumentException) {
                        throw new XslTransformException(Res.Coll_UnsupportedLanguage, lang);
                    }
                }
            } else if (collationUri.IsBaseOf(new Uri(XmlReservedNs.NsCollCodePoint))) {
                // language with codepoint collation is not allowed
                coll.compops = CompareOptions.Ordinal;
            } else {
                // Unrecognized collation
                throw new XslTransformException(Res.Coll_Unsupported, collationLiteral);
            }

            // Sort & Compare option
            // at least a '?' will be returned for Uri.Query if not empty
            string query = collationUri.Query;
            string sort = null;

            if (query.Length != 0) {
                foreach (string option in query.Substring(1).Split('&')) {
                    string[] pair = option.Split('=');

                    if (pair.Length != 2)
                        throw new XslTransformException(Res.Coll_BadOptFormat, option);

                    string optionName = pair[0].ToUpper(CultureInfo.InvariantCulture);
                    string optionValue = pair[1].ToUpper(CultureInfo.InvariantCulture);

                    if (optionName == sortStr) {
                        sort = optionValue;
                    }
                    else if (optionValue == "1" || optionValue == "TRUE") {
                        switch (optionName) {
                        case ignoreCaseStr:        coll.compops |= CompareOptions.IgnoreCase; break;
                        case ignoreKanatypeStr:    coll.compops |= CompareOptions.IgnoreKanaType; break;
                        case ignoreNonspaceStr:    coll.compops |= CompareOptions.IgnoreNonSpace; break;
                        case ignoreSymbolsStr:     coll.compops |= CompareOptions.IgnoreSymbols; break;
                        case ignoreWidthStr:       coll.compops |= CompareOptions.IgnoreWidth; break;
                        case upperFirstStr:        coll.upperFirst = true; break;
                        case emptyGreatestStr:     coll.emptyGreatest = true; break;
                        case descendingOrderStr:   coll.descendingOrder = true; break;
                        default:
                            throw new XslTransformException(Res.Coll_UnsupportedOpt, pair[0]);
                        }
                    }
                    else if (optionValue == "0" || optionValue == "FALSE") {
                        switch (optionName) {
                        case ignoreCaseStr:        coll.compops &= ~CompareOptions.IgnoreCase; break;
                        case ignoreKanatypeStr:    coll.compops &= ~CompareOptions.IgnoreKanaType; break;
                        case ignoreNonspaceStr:    coll.compops &= ~CompareOptions.IgnoreNonSpace; break;
                        case ignoreSymbolsStr:     coll.compops &= ~CompareOptions.IgnoreSymbols; break;
                        case ignoreWidthStr:       coll.compops &= ~CompareOptions.IgnoreWidth; break;
                        case upperFirstStr:        coll.upperFirst = false; break;
                        case emptyGreatestStr:     coll.emptyGreatest = false; break;
                        case descendingOrderStr:   coll.descendingOrder = false; break;
                        default:
                            throw new XslTransformException(Res.Coll_UnsupportedOpt, pair[0]);
                        }
                    }
                    else {
                        throw new XslTransformException(Res.Coll_UnsupportedOptVal, pair[0], pair[1]);
                    }
                }
            }

            // upperfirst option is only meaningful when not ignore case
            if (coll.upperFirst && (coll.compops & CompareOptions.IgnoreCase) != 0)
                coll.upperFirst = false;

            // other CompareOptions are only meaningful if Ordinal comparison is not being used
            if ((coll.compops & CompareOptions.Ordinal) != 0) {
                coll.compops = CompareOptions.Ordinal;
                coll.upperFirst = false;
//.........这里部分代码省略.........
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:101,代码来源:xmlcollation.cs

示例9: IsBaseOf

 public void IsBaseOf(Uri uri1, Uri uri2, bool expected)
 {
     Assert.Equal(expected, uri1.IsBaseOf(uri2));
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:4,代码来源:Uri.MethodsTests.cs


注:本文中的Uri.IsBaseOf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。