當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.Replace方法代碼示例

本文整理匯總了C#中System.Uri.Replace方法的典型用法代碼示例。如果您正苦於以下問題:C# Uri.Replace方法的具體用法?C# Uri.Replace怎麽用?C# Uri.Replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Uri的用法示例。


在下文中一共展示了Uri.Replace方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetAttachmentUri

        /// <summary>
        /// Get the URI of an attachment view
        /// </summary>
        /// <param name="attachmentId"></param>
        /// <param name="viewId">default is "original"</param>
        /// <returns>uri</returns>
        public string GetAttachmentUri(string attachmentId, string viewId = "original")
        {
            if (attachmentId == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "attachmentId");
            }

            // Construct URL
            var _baseUrl = this.Client.BaseUri.AbsoluteUri;
            var url = new Uri(new Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v3/attachments/{attachmentId}/views/{viewId}").ToString();
            url = url.Replace("{attachmentId}", Uri.EscapeDataString(attachmentId));
            url = url.Replace("{vieWId}", Uri.EscapeDataString(viewId));
            return url;
        }
開發者ID:CHENShuang1994,項目名稱:BotBuilder,代碼行數:20,代碼來源:AttachmentsEx.cs

示例2: ResolveAssemblyDirectory

        private IList<string> ResolveAssemblyDirectory(Assembly assembly)
        {
            var fullUriPath = new Uri(assembly.GetName().CodeBase).LocalPath.ToUpper();
            var pathWithoutUnityFolder = fullUriPath.Replace(assembly.ManifestModule.Name.ToUpper(), "");
            var path = pathWithoutUnityFolder + @"Unity";

            if (!Directory.Exists(path)) return null;

            var files = Directory.GetFiles(path);
            return files;
        }
開發者ID:wil2200,項目名稱:sdk,代碼行數:11,代碼來源:FileRegisteringModuleExecutor.cs

示例3: AutoConf

 public void AutoConf()
 {
     PayloadDescription desc = new PayloadDescription();
     string assembly=Assembly.GetExecutingAssembly().CodeBase;
     if (Uri.IsWellFormedUriString(assembly,UriKind.Absolute))
     {
         assembly = new Uri(assembly).AbsolutePath;
         assembly = assembly.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
     }
     desc.AssemblyFullName = Path.GetFileName(assembly);
     desc.Class = typeof(HostTest).FullName;
     Assert.AreEqual(assembly+".config", desc.ConfigurationFile, "Config file should match default name");
     Assert.AreEqual(Path.GetDirectoryName(assembly), desc.BinaryFolder, "binary folder should be assembly folder");
 }
開發者ID:dupdob,項目名稱:SHON,代碼行數:14,代碼來源:DescriptionTests.cs

示例4: GetVimeoData

        /// <summary>
        /// Our site wide search action method
        /// </summary>
        public JsonResult GetVimeoData(string vimeoUrl)
        {
            if (!vimeoUrl.StartsWith("http://www.vimeo.com/") && !vimeoUrl.StartsWith("http://vimeo.com/"))
            {
                throw new Exception("Not a valid vimeo url");
            }

            //http://www.vimeo.com/20278551?ab = /20278551
            var videoUriWithoutQuery = new Uri(vimeoUrl).AbsolutePath;

            var videoID = videoUriWithoutQuery.Replace("/","");

            var vimeoData = new MediaService().GetVimeoVideoData(videoID);

            return Json(vimeoData);
        }
開發者ID:jkresner,項目名稱:Climbfind_v4_2011,代碼行數:19,代碼來源:_UtilityController.cs

示例5: ExecuteCommand

		internal static void ExecuteCommand (IProgressStatus monitor, string registryPath, string startupDir, string name, params string[] args)
		{
			string asm = new Uri (typeof(SetupProcess).Assembly.CodeBase).LocalPath;
			string verboseParam = monitor.LogLevel.ToString ();
			
			// Arguments string
			StringBuilder sb = new StringBuilder ();
			sb.Append (verboseParam).Append (' ').Append (name);
			foreach (string arg in args)
				sb.Append (" \"").Append (arg).Append ("\"");
			
			Process process = new Process ();
			if (Util.IsWindows)
				process.StartInfo = new ProcessStartInfo (asm, sb.ToString ());
			else {
				asm = asm.Replace(" ", @"\ ");
				process.StartInfo = new ProcessStartInfo ("mono", "--debug " + asm + " " + sb.ToString ());
			}
			process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
			process.StartInfo.UseShellExecute = false;
			process.StartInfo.RedirectStandardInput = true;
			process.StartInfo.RedirectStandardOutput = true;
			process.StartInfo.RedirectStandardError = true;
			process.EnableRaisingEvents = true;
			try {
				process.Start ();
			} catch (Exception ex) {
				Console.WriteLine (ex);
				throw;
			}
			
			process.StandardInput.WriteLine (registryPath);
			process.StandardInput.WriteLine (startupDir);
			process.StandardInput.Flush ();

//			string rr = process.StandardOutput.ReadToEnd ();
//			Console.WriteLine (rr);
			
			StringCollection progessLog = new StringCollection ();
			ProcessProgressStatus.MonitorProcessStatus (monitor, process.StandardOutput, progessLog);
			process.WaitForExit ();
			if (process.ExitCode != 0)
				throw new ProcessFailedException (progessLog);
		}
開發者ID:guadalinex-archive,項目名稱:guadalinex-v6,代碼行數:44,代碼來源:SetupProcess.cs

示例6: ParseQueryString

        /// <summary>
        /// Get a Url's parameters leaving them url encoded
        /// </summary>
        /// <param name="urlString">The query string</param>
        /// <returns></returns>
        public static Dictionary<string, string> ParseQueryString(string urlString)
        {
            string queryString = new Uri(urlString).Query;
            Dictionary<string, string> kVParms = new Dictionary<string, string>();

            queryString.Replace("?", "");

            string[] keyValPairing = queryString.Split('&', '=');

            if ((keyValPairing.Length == 0) || (keyValPairing.Length % 2 != 0))
            {
                throw new Exception("Invalid input Url");
            }

            keyValPairing[0] = keyValPairing[0].TrimStart('?');

            for (int i = 0; i < keyValPairing.Length - 1; i++)
            {
                kVParms.Add(keyValPairing[i], keyValPairing[i + 1]);
            }

            return kVParms;
        }
開發者ID:Archetype,項目名稱:TwitterPostWP7,代碼行數:28,代碼來源:Helpers.cs

示例7: RemoveDuplicateSlashes

 private static string RemoveDuplicateSlashes(string url)
 {
     var path = new Uri(url).AbsolutePath;
     return path.Contains("//") ? url.Replace(path, path.Replace("//", "/")) : url;
 }
開發者ID:rabbal,項目名稱:Mvc5,代碼行數:5,代碼來源:NormalizationUrl.cs

示例8: FromUri

        /// <summary>
        /// Create a new SourceLineNumberCollection from a URI.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <returns>The new SourceLineNumberCollection.</returns>
        public static SourceLineNumberCollection FromUri(string uri)
        {
            if (null == uri || 0 == uri.Length)
            {
                return null;
            }

            string localPath = new Uri(uri).LocalPath;

            // make the local path really look like a normal local path
            if (localPath.StartsWith(Path.AltDirectorySeparatorChar.ToString(), StringComparison.Ordinal))
            {
                localPath = localPath.Substring(1);
            }
            localPath = localPath.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);

            return new SourceLineNumberCollection(localPath);
        }
開發者ID:bullshock29,項目名稱:Wix3.6Toolset,代碼行數:23,代碼來源:SourceLineNumberCollection.cs

示例9: GetUncFileName

 private static string GetUncFileName(string song)
 {
     string uncFilePath = new Uri(song).LocalPath;
     uncFilePath = uncFilePath.Replace("\\\\localhost\\", " ").Trim();
     return uncFilePath;
 }
開發者ID:xantilas,項目名稱:ghalager-videobrowser-20120129,代碼行數:6,代碼來源:iTunesLibrary.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: GeneratevpnclientpackageWithHttpMessagesAsync

        /// <summary>
        /// The Generatevpnclientpackage operation generates Vpn client package for
        /// P2S client of the virtual network gateway in the specified resource group
        /// through Network resource provider.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// The name of the resource group.
        /// </param>
        /// <param name='virtualNetworkGatewayName'>
        /// The name of the virtual network gateway.
        /// </param>
        /// <param name='parameters'>
        /// Parameters supplied to the Begin Generating  Virtual Network Gateway Vpn
        /// client package operation through Network resource provider.
        /// </param>
        /// <param name='customHeaders'>
        /// Headers that will be added to request.
        /// </param>
        /// <param name='cancellationToken'>
        /// The cancellation token.
        /// </param>
        public async Task<AzureOperationResponse<string>> GeneratevpnclientpackageWithHttpMessagesAsync(string resourceGroupName, string virtualNetworkGatewayName,
            VpnClientParameters parameters, Dictionary<string, List<string>> customHeaders = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            #region 1. Send Async request to generate vpn client package

            // 1. Send Async request to generate vpn client package          
            string baseUrl = NetworkManagementClient.BaseUri.ToString();
            string apiVersion = NetworkManagementClient.ApiVersion;

            if (resourceGroupName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "resourceGroupName");
            }
            if (virtualNetworkGatewayName == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "virtualNetworkGatewayName");
            }
            if (parameters == null)
            {
                throw new ValidationException(ValidationRules.CannotBeNull, "parameters");
            }

            // Construct URL
            var url = new Uri(new Uri(baseUrl + (baseUrl.EndsWith("/") ? "" : "/")), "subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/" +
                "providers/Microsoft.Network/virtualnetworkgateways/{virtualNetworkGatewayName}/generatevpnclientpackage").ToString();
            url = url.Replace("{resourceGroupName}", Uri.EscapeDataString(resourceGroupName));
            url = url.Replace("{virtualNetworkGatewayName}", Uri.EscapeDataString(virtualNetworkGatewayName));
            url = url.Replace("{subscriptionId}", Uri.EscapeDataString(NetworkManagementClient.SubscriptionId));
            url += "?" + string.Join("&", string.Format("api-version={0}", Uri.EscapeDataString(apiVersion)));

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = new HttpRequestMessage();
            httpRequest.Method = new HttpMethod("POST");
            httpRequest.RequestUri = new Uri(url);
            // Set Headers
            httpRequest.Headers.TryAddWithoutValidation("x-ms-client-request-id", Guid.NewGuid().ToString());

            // Serialize Request
            string requestContent = JsonConvert.SerializeObject(parameters, NetworkManagementClient.SerializationSettings);
            httpRequest.Content = new StringContent(requestContent, Encoding.UTF8);
            httpRequest.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

            // Set Credentials
            if (NetworkManagementClient.Credentials != null)
            {
                cancellationToken.ThrowIfCancellationRequested();
                await NetworkManagementClient.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);
            }
            // Send Request
            cancellationToken.ThrowIfCancellationRequested();

            var client = this.NetworkManagementClient as NetworkManagementClient;
            HttpClient httpClient = client.HttpClient;
            HttpResponseMessage httpResponse = await httpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

            HttpStatusCode statusCode = httpResponse.StatusCode;
            cancellationToken.ThrowIfCancellationRequested();
            if ((int)statusCode != 202)
            {
                string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
                throw new Exception(string.Format("Get-AzureRmVpnClientPackage Operation returned an invalid status code '{0}' with Exception:{1}",
                    statusCode, string.IsNullOrEmpty(responseContent) ? "NotAvailable" : responseContent));
            }

            // Create Result
            var result = new AzureOperationResponse<string>();
            result.Request = httpRequest;
            result.Response = httpResponse;
            string locationResultsUrl = string.Empty;

            // Retrieve the location from LocationUri
            if (httpResponse.Headers.Contains("Location"))
            {
                locationResultsUrl = httpResponse.Headers.GetValues("Location").FirstOrDefault();
            }
            else
            {
                throw new Exception(string.Format("Get-AzureRmVpnClientPackage Operation Failed as no valid Location header received in response!"));
            }
//.........這裏部分代碼省略.........
開發者ID:Azure,項目名稱:azure-powershell,代碼行數:101,代碼來源:NetworkClient.cs

示例12: CalculateRelativePathToSlimjimPackages

 public static string CalculateRelativePathToSlimjimPackages(string packagesPath, string csProjPath)
 {
     var relativeUri = new Uri(csProjPath).MakeRelativeUri(new Uri(packagesPath)).OriginalString;
     return relativeUri.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar);
 }
開發者ID:themotleyfool,項目名稱:SlimJim,代碼行數:5,代碼來源:HintPathConverter.cs

示例13: ButtonClicked

        private void ButtonClicked(object sender, EventArgs e)
        {
            Project currentProject = GetSelectedProjects().ElementAt(0);
            var projects = _dte.Solution.GetAllNonWebProjects();
            var names = from p in projects
                        where p.UniqueName != currentProject.UniqueName
                        select p.Name;

            ProjectSelector2 selector = new ProjectSelector2(names);
            bool? isSelected = selector.ShowDialog();

            if (isSelected.HasValue && isSelected.Value)
            {
                WebJobCreator creator = new WebJobCreator();
                var selectedProject = projects.First(p => p.Name == selector.SelectedProjectName);
                creator.AddReference(currentProject, selectedProject);
                var relativePath = new Uri(currentProject.FullName).MakeRelativeUri(new Uri(selectedProject.FullName)).ToString();
                relativePath = relativePath.Replace("/", "\\");
                creator.CreateFolders(currentProject, selector.Schedule, selector.SelectedProjectName, relativePath);

                // ensure that the NuGet package is installed in the project as well
                InstallWebJobsNuGetPackage(currentProject);
            }
        }
開發者ID:modulexcite,項目名稱:webjobsvs,代碼行數:24,代碼來源:WebJobsVsPackage.cs

示例14: IsExternalLink

 private bool IsExternalLink(string url)
 {
     try
     {
         var link = new Uri(url).Host;
         link = link.Replace("www.", string.Empty);
         return !link.StartsWith(_hostOfOriginalUrl);
     }
     catch (FormatException)
     {
         return false;
     }
 }
開發者ID:ncpenn,項目名稱:FindBrokenLinksCommandLine,代碼行數:13,代碼來源:Spider.cs


注:本文中的System.Uri.Replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。