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


C# Uri.IndexOf方法代码示例

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


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

示例1: GetDomain

        private static string GetDomain(IConfiguration settings)
        {
            var domain = new Uri(settings.GetSiteRoot(false)).DnsSafeHost;

            if (domain.IndexOf(':') >= 0)
            {
                domain = domain.Substring(0, domain.IndexOf(':'));
            }

            return domain;
        }
开发者ID:chocolatey,项目名称:chocolatey.org,代码行数:11,代码来源:MessageService.cs

示例2: TransformRobocode

        public static void TransformRobocode()
        {
            var w = new Uri("http://robocode.sourceforge.net/docs/robocode/allclasses-noframe.html").ToWebString();

            var zip = new ZIPFile();

            var o = 0;
            while (o >= 0)
            {
                const string pregfix = "<A HREF=\"";
                var i = w.IndexOf(pregfix, o);
                if (i >= 0)
                {
                    var j = w.IndexOf("\"", i + pregfix.Length);

                    if (j >= 0)
                    {
                        var type = w.Substring(i + pregfix.Length, j - (i + pregfix.Length));

                        const string suffix = ".html";

                        if (type.EndsWith(suffix))
                        {
                            o = j + 1;

                            type = type.Substring(0, type.Length - suffix.Length).Replace("/", ".");

                            Console.WriteLine(type);

                            zip.Add(type.Replace(".", "/") + ".cs",
                                new DefinitionProvider(
                                    type
                                //        "robocode.BattleRules"
                                //        //"java.net.InetSocketAddress"
                                //        //"java.net.ServerSocket"
                                //        //"java.nio.channels.ServerSocketChannel"
                                , k => k.ToWebString()).GetString()
                            );

                        }
                        else o = -1;
                    }
                    else o = -1;
                }
                else o = -1;
            }

            using (var ww = new BinaryWriter(File.OpenWrite("Robocode.zip")))
            {
                zip.WriteTo(ww);
            }
        }
开发者ID:BGCX261,项目名称:zproxygames-svn-to-git,代码行数:52,代码来源:Setup.cs

示例3: BeforeRequest

        public bool BeforeRequest(Session session, Rule rule)
        {
            Console.WriteLine(String.Format("Request ({0}) cached due to the rule: {1}", session.hostname, rule.Name));

            // TODO:
            // Cache-Control - Expires, MaxAge (private)
            // Age?
            //
            var querystring = new Uri(session.fullUrl).Query;
            var startindex = querystring.IndexOf("&url=");
            var length = querystring.IndexOf("&ei", startindex) - startindex;
            var url = querystring.Substring(startindex, length);
            session.fullUrl = Uri.UnescapeDataString(url);

            return false;
        }
开发者ID:bradrees,项目名称:HttpRules,代码行数:16,代码来源:CacheAction.cs

示例4: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
      if (String.IsNullOrEmpty(Request.QueryString["provider"]))
      {
        throw new ArgumentNullException("provider");
      }

      // build callback url
      string returnUrl = new Uri(Request.Url, "ExternalLoginResult.aspx").AbsoluteUri;

      // pop-up indicator for JavaScript code
      if (!String.IsNullOrEmpty(Request.QueryString["popup"]))
      {
        if (returnUrl.IndexOf("?") != -1)
        {
          returnUrl += "&";
        }
        else
        {
          returnUrl += "?";
        }
        returnUrl += "popup=true";
      }

      // redirect to authorization page of the specified provider
      OAuthWeb.RedirectToAuthorization(Request.QueryString["provider"], returnUrl);
    }
开发者ID:DreamerUA,项目名称:nemiro.oauth.dll,代码行数:27,代码来源:RedirectToAuth.aspx.cs

示例5: GetMediaId

 /// <summary>
 /// 取得媒體ID
 /// </summary>
 /// <param name="Url">網址</param>
 /// <returns>媒體ID</returns>
 private string GetMediaId(string Url) {
     string result = new Uri(Url).Segments.Last<string>();
     try {
         result = result.Substring(0, result.IndexOf("_"));
     } catch { }
     return result;
 }
开发者ID:XuPeiYao,项目名称:MediaGetCore,代码行数:12,代码来源:DailymotionExtractor.cs

示例6: CreateImageFolder

 public static void CreateImageFolder(this string itemName)
 {
     var path = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath;
     var mainPath = path.Substring(0, path.IndexOf("bin", 0));
     var imgPath = string.Format(@"{0}\Content\images\item\{1}", mainPath, itemName);
     if (!Directory.Exists(imgPath))
         Directory.CreateDirectory(imgPath);
 }
开发者ID:hakeemsm,项目名称:TheDessertHouse,代码行数:8,代码来源:Extensions.cs

示例7: Download

        private HttpWebResponse Download (SafeUri uri, int nb_retries)
        {
            Hyena.ThreadAssist.AssertNotInMainThread ();

            while (true) {
                try {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create (uri.AbsoluteUri);
                    request.UserAgent = Banshee.Web.Browser.UserAgent;
                    request.KeepAlive = false;
                    request.Timeout = 5 * 1000;
                    request.AllowAutoRedirect = true;

                    // Parse out and set credentials, if any
                    string user_info = new Uri (uri.AbsoluteUri).UserInfo;
                    if (!String.IsNullOrEmpty (user_info)) {
                        string username = String.Empty;
                        string password = String.Empty;
                        int cIndex = user_info.IndexOf (":");
                        if (cIndex != -1) {
                            username = user_info.Substring (0, cIndex);
                            password = user_info.Substring (cIndex + 1);
                        } else {
                            username = user_info;
                        }
                        request.Credentials = new NetworkCredential (username, password);
                    }

                    var response = (HttpWebResponse)request.GetResponse ();
                    if (response.StatusCode == HttpStatusCode.GatewayTimeout) {
                        throw new WebException ("", WebExceptionStatus.Timeout);
                    }
                    return response;
                } catch (WebException e) {
                    if (e.Status == WebExceptionStatus.Timeout && nb_retries > 0) {
                        nb_retries--;
                        Log.InformationFormat ("Playlist download from {0} timed out, retrying in 1 second...", uri.AbsoluteUri);
                        System.Threading.Thread.Sleep (1000);
                    } else {
                        throw;
                    }
                }
            }
        }
开发者ID:fatman2021,项目名称:gnome-apps,代码行数:43,代码来源:PlaylistParser.cs

示例8: GetTrippinWebRoot

 private static string GetTrippinWebRoot(string serviceName)
 {
     var codeBase = new Uri(typeof(TrippinServiceFixture).Assembly.CodeBase).LocalPath;
     var parentPathLength = codeBase.IndexOf(EigenString) + EigenString.Length;
     return Path.Combine(codeBase.Substring(0, parentPathLength), serviceName);
 }
开发者ID:chinadragon0515,项目名称:RESTier,代码行数:6,代码来源:TrippinServiceFixture.cs

示例9: GetImgurImageOrAlbumFromUrl

        private async Task<List<ImageLink>> GetImgurImageOrAlbumFromUrl(Post post, string outputPath, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            var links = new List<ImageLink>();

            OutputLine($"\tGetting links from post: {post.Title}", true);

            var url = new Uri(post.Url.ToString()).GetLeftPart(UriPartial.Path).Replace(".gifv", ".gif");

            url = url.StartsWith("http://") ? url : "http://" + url.Substring(url.IndexOf(post.Url.DnsSafeHost, StringComparison.Ordinal));

            var name = Path.GetInvalidFileNameChars().Aggregate(post.AuthorName, (current, c) => current.Replace(c, '-'));

            var filepath = outputPath + "\\";

            if (_allAuthorsPosts)
                filepath += post.AuthorName;
            else
                filepath += post.SubredditName + "\\" + name;

            var filename = filepath + $"\\{name}_{post.SubredditName}_{post.Id}";

            var extention = GetExtention(url);

            if (!string.IsNullOrEmpty(extention))
            {
                OutputLine($"\tAdding Link {url}", true);
                links.Add(new ImageLink(post, url, filename));
                return links;
            }

            string htmlString = await GetHtml(url, token);
            if (string.IsNullOrWhiteSpace(htmlString)) return links;

            var caroselAlbum = htmlString.Contains(@"data-layout=""h""");

            if (caroselAlbum)
            {
                htmlString = await GetHtml(url + "/all", token);
                if (string.IsNullOrWhiteSpace(htmlString)) return links;
            }

            var gridAlbum = htmlString.Contains(@"data-layout=""g""");

            if (caroselAlbum && !gridAlbum) return links;

            var regPattern = new Regex(@"<img[^>]*?src\s*=\s*[""']?([^'"" >]+?)[ '""][^>]*?>", RegexOptions.IgnoreCase);

            var matchImageLinks = regPattern.Matches(htmlString);

            OutputLine($"\tFound {matchImageLinks.Count} image(s) from link.", true);

            foreach (Match m in matchImageLinks)
            {
                token.ThrowIfCancellationRequested();
                var imgurl = m.Groups[1].Value.Replace(".gifv", ".gif");

                if (!imgurl.Contains("imgur.com")) continue;

                if (gridAlbum)
                    imgurl = imgurl.Remove(imgurl.LastIndexOf('.') - 1, 1);
                var domain = new Uri(imgurl).DnsSafeHost;
                imgurl = imgurl.StartsWith("http://") ? imgurl : "http://" + imgurl.Substring(imgurl.IndexOf(domain, StringComparison.Ordinal));

                links.Add(new ImageLink(post, imgurl, filename));
            }

            return links;
        }
开发者ID:W1R3D-Code,项目名称:RedditRip,代码行数:69,代码来源:RedditRip.cs

示例10: ResolveUrl

        /// <summary>
        /// fully resolves any relative pathing inside the URL, and other URL oddities
        /// </summary>
        string ResolveUrl(string url)
        {
            // resolve any relative pathing
            try
            {
                url = new Uri(url).AbsoluteUri;
            }
            catch (UriFormatException ex)
            {
                throw new ArgumentException("'" + url + "' does not appear to be a valid URL.", ex);
            }

            // remove any anchor tags from the end of URLs
            if (url.IndexOf("#") > -1)
            {
                string jump = Regex.Match(url, "/[^/]*?(?<jump>#[^/?.]+$)").Groups["jump"].Value;
                if (jump != "")
                    url = url.Replace(jump, "");
            }

            return url;
        }
开发者ID:bittercoder,项目名称:reportingcloud,代码行数:25,代码来源:MhtWebFile.cs

示例11: WEBDAV

        public WEBDAV(string url, Dictionary<string, string> options)
        {
            Uri u = new Uri(url);

            if (!string.IsNullOrEmpty(u.UserInfo))
            {
                m_userInfo = new System.Net.NetworkCredential();
                if (u.UserInfo.IndexOf(":") >= 0)
                {
                    m_userInfo.UserName = u.UserInfo.Substring(0, u.UserInfo.IndexOf(":"));
                    m_userInfo.Password = u.UserInfo.Substring(u.UserInfo.IndexOf(":") + 1);
                }
                else
                {
                    m_userInfo.UserName = u.UserInfo;
                    if (options.ContainsKey("ftp-password"))
                        m_userInfo.Password = options["ftp-password"];
                }
            }
            else
            {
                if (options.ContainsKey("ftp-username"))
                {
                    m_userInfo = new System.Net.NetworkCredential();
                    m_userInfo.UserName = options["ftp-username"];
                    if (options.ContainsKey("ftp-password"))
                        m_userInfo.Password = options["ftp-password"];
                }
            }

            m_useIntegratedAuthentication = Utility.Utility.ParseBoolOption(options, "integrated-authentication");
            m_forceDigestAuthentication = Utility.Utility.ParseBoolOption(options, "force-digest-authentication");
            m_useSSL = Utility.Utility.ParseBoolOption(options, "use-ssl");

            m_url = (m_useSSL ? "https" : "http") + url.Substring(u.Scheme.Length);
            if (!m_url.EndsWith("/"))
                m_url += "/";

            m_path = new Uri(m_url).PathAndQuery;
            if (m_path.IndexOf("?") > 0)
                m_path = m_path.Substring(0, m_path.IndexOf("?"));

            m_path = System.Web.HttpUtility.UrlDecode(m_path);
            m_rawurl = (m_useSSL ? "https://" : "http://") + u.Host + m_path;

            int port = u.Port;
            if (port <= 0)
                port = m_useSSL ? 443 : 80;

            m_rawurlPort = (m_useSSL ? "https://" : "http://") + u.Host + ":" + port + m_path;
            m_sanitizedUrl = (m_useSSL ? "https://" : "http://") + u.Host + m_path;
            m_reverseProtocolUrl = (m_useSSL ? "http://" : "https://") + u.Host + m_path;
            options.TryGetValue("debug-propfind-file", out m_debugPropfindFile);
        }
开发者ID:pacificIT,项目名称:Duplicati,代码行数:54,代码来源:WEBDAV.cs

示例12: GetRootSolutionDirectoryPath

 private static string GetRootSolutionDirectoryPath()
 {
     var codebase = new Uri(typeof(NestDeployer).Assembly.CodeBase).AbsolutePath;
      return codebase.Substring(0, codebase.IndexOf(kRootSolutionName) + kRootSolutionName.Length);
 }
开发者ID:the-dargon-project,项目名称:dargon-root,代码行数:5,代码来源:NestDeployerConstants.cs

示例13: Application_AcquireRequestState

		/// <summary>Infuses the http handler (usually an aspx page) with the content page associated with the url if it implements the <see cref="IContentTemplate"/> interface.</summary>
		protected virtual void Application_AcquireRequestState(object sender, EventArgs e)
		{
			//TODO: Add ForceConsistentUrls property? Right now there is only this #if to turn it off by default.
#if SAFE_URL_HANDLING

			if (webContext.CurrentPath == null || webContext.CurrentPath.IsEmpty()) return;

			HttpContext httpContext = ((HttpApplication)sender).Context; // jamestharpe: webContext.Request causes Obsolete warning.
			Uri requestBaseUrl = new Uri(string.Format("{0}{1}{2}", httpContext.Request.Url.Scheme, Uri.SchemeDelimiter, httpContext.Request.Url.Authority));
			string
				rawUrl = new Uri(requestBaseUrl, httpContext.Request.RawUrl).ToString(),
				preferredUrl = GetPreferredUrl(webContext.CurrentPage, requestBaseUrl);

			if (!rawUrl.Equals(preferredUrl, StringComparison.InvariantCulture))
			{
				int queryStringIndex = rawUrl.IndexOf('?');
				if (queryStringIndex < 0) // Not equal to SafeUrl - redirect
					RedirectPermanent(httpContext.Response, preferredUrl);
				else if (queryStringIndex != preferredUrl.Length)
				{
					// There was a query string - this could have caused the difference
					string
						queryString = rawUrl.Substring(queryStringIndex),
						destination = preferredUrl + queryString;
					RedirectPermanent(httpContext.Response, destination);
				}
			}
			else
			{
				var adapter = adapters.ResolveAdapter<RequestAdapter>(webContext.CurrentPage);
				adapter.InjectCurrentPage(webContext.CurrentPath, webContext.HttpContext.Handler);
			}

#endif

		}
开发者ID:andy4711,项目名称:n2cms,代码行数:37,代码来源:RequestLifeCycleHandler.cs

示例14: Parse

        public bool Parse (SafeUri uri)
        {
            ThreadAssist.AssertNotInMainThread ();
            lock (this) {
                elements = null;
                HttpWebResponse response = null;
                Stream stream = null;
                Stream web_stream = null;
                bool partial_read = false;
                long saved_position = 0;

                if (uri.Scheme == "file") {
                    stream = Banshee.IO.File.OpenRead (uri);
                } else if (uri.Scheme == "http") {
                    HttpWebRequest request = (HttpWebRequest)WebRequest.Create (uri.AbsoluteUri);
                    request.UserAgent = Banshee.Web.Browser.UserAgent;
                    request.KeepAlive = false;
                    request.Timeout = 5 * 1000;
                    request.AllowAutoRedirect = true;

                    // Parse out and set credentials, if any
                    string user_info = new Uri (uri.AbsoluteUri).UserInfo;
                    if (!String.IsNullOrEmpty (user_info)) {
                        string username = String.Empty;
                        string password = String.Empty;
                        int cIndex = user_info.IndexOf (":");
                        if (cIndex != -1) {
                            username = user_info.Substring (0, cIndex);
                            password = user_info.Substring (cIndex + 1);
                        } else {
                            username = user_info;
                        }
                        request.Credentials = new NetworkCredential (username, password);
                    }

                    response = (HttpWebResponse)request.GetResponse ();
                    web_stream = response.GetResponseStream ();

                    try {
                        stream = new MemoryStream ();

                        byte [] buffer = new byte[4096];
                        int read;

                        // If we haven't read the whole stream and if
                        // it turns out to be a playlist, we'll read the rest
                        read = web_stream.Read (buffer, 0, buffer.Length);
                        stream.Write (buffer, 0, read);
                        if ((read = web_stream.Read (buffer, 0, buffer.Length)) > 0) {
                            partial_read = true;
                            stream.Write (buffer, 0, read);
                            saved_position = stream.Position;
                        }

                        stream.Position = 0;
                    } finally {
                        if (!partial_read) {
                            web_stream.Close ();
                            response.Close ();
                        }
                    }
                } else {
                    Hyena.Log.DebugFormat ("Not able to parse playlist at {0}", uri);
                    return false;
                }

                PlaylistFormatDescription matching_format = null;

                foreach (PlaylistFormatDescription format in playlist_formats) {
                    stream.Position = 0;

                    if (format.MagicHandler (new StreamReader (stream))) {
                        matching_format = format;
                        break;
                    }
                }

                if (matching_format == null) {
                    return false;
                }

                if (partial_read) {
                    try {
                        stream.Position = saved_position;
                        Banshee.IO.StreamAssist.Save (web_stream, stream, false);
                    } finally {
                        web_stream.Close ();
                        response.Close ();
                    }
                }
                stream.Position = 0;
                IPlaylistFormat playlist = (IPlaylistFormat)Activator.CreateInstance (matching_format.Type);
                playlist.BaseUri = BaseUri;
                playlist.Load (stream, false);
                stream.Dispose ();

                elements = playlist.Elements;
                Title = playlist.Title ?? Path.GetFileNameWithoutExtension (uri.LocalPath);
                return true;
            }
//.........这里部分代码省略.........
开发者ID:haugjan,项目名称:banshee-hacks,代码行数:101,代码来源:PlaylistParser.cs


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