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


C# StringBuilder.AppendUrlPath方法代码示例

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


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

示例1: TestAppendUrlPathBasePathDoesNotEndInForwardSlashAppendedPathDoesNotBeginWithForwardSlash

        public void TestAppendUrlPathBasePathDoesNotEndInForwardSlashAppendedPathDoesNotBeginWithForwardSlash()
        {
            var sb = new StringBuilder("/some");

            Assert.AreEqual(sb, sb.AppendUrlPath("path"));

            Assert.AreEqual("/some/path", sb.ToString());
        }
开发者ID:xsIceman,项目名称:LiveSDK-for-Windows,代码行数:8,代码来源:StringBuilderExtensionTest.cs

示例2: TestAppendUrlPathBasePathIsEmpty

        public void TestAppendUrlPathBasePathIsEmpty()
        {
            var sb = new StringBuilder();

            Assert.AreEqual(sb, sb.AppendUrlPath("some/path"));

            Assert.AreEqual("some/path", sb.ToString());
        }
开发者ID:xsIceman,项目名称:LiveSDK-for-Windows,代码行数:8,代码来源:StringBuilderExtensionTest.cs

示例3: TestAppendUrlPathNull

        public void TestAppendUrlPathNull()
        {
            var sb = new StringBuilder("/some/path");

            Assert.AreEqual(sb, sb.AppendUrlPath(null));

            Assert.AreEqual("/some/path", sb.ToString());
        }
开发者ID:xsIceman,项目名称:LiveSDK-for-Windows,代码行数:8,代码来源:StringBuilderExtensionTest.cs

示例4: TestAppendUrlPathStringEmpty

        public void TestAppendUrlPathStringEmpty()
        {
            var sb = new StringBuilder("/some/path");

            Assert.AreEqual(sb, sb.AppendUrlPath(string.Empty));

            Assert.AreEqual("/some/path/", sb.ToString());
        }
开发者ID:xsIceman,项目名称:LiveSDK-for-Windows,代码行数:8,代码来源:StringBuilderExtensionTest.cs

示例5: GetResourceUri

        internal Uri GetResourceUri(string path, ApiMethod method)
        {
            try
            {
                if ((path.StartsWith("https://", StringComparison.OrdinalIgnoreCase) &&
                   !path.StartsWith(this.ApiEndpoint, StringComparison.OrdinalIgnoreCase)) ||
                    path.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
                {
                    return new Uri(path, UriKind.Absolute);
                }

                StringBuilder sb;
                if (path.StartsWith(this.ApiEndpoint, StringComparison.OrdinalIgnoreCase))
                {
                    sb = new StringBuilder(path);
                }
                else
                {
                    sb = new StringBuilder(this.ApiEndpoint);
                    sb = sb.AppendUrlPath(path);
                }

                var resourceUrl = new Uri(sb.ToString(), UriKind.Absolute);
                sb.Append(string.IsNullOrEmpty(resourceUrl.Query) ? "?" : "&");

                if (method != ApiMethod.Download)
                {
                    sb.AppendQueryParam(QueryParameters.SuppressResponseCodes, "true");
                    sb.Append("&").AppendQueryParam(QueryParameters.SuppressRedirects, "true");
                }

                return new Uri(sb.ToString(), UriKind.Absolute);
            }
            catch (FormatException)
            {
                throw new ArgumentException(
                    String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("UrlInvalid"), path),
                    "path");
            }
        }
开发者ID:d20021,项目名称:LiveSDK-for-Windows,代码行数:40,代码来源:LiveConnectClient.cs

示例6: ConstructUploadUri

        private Uri ConstructUploadUri(string uploadLocation)
        {
            Uri resourceUrl;
            try
            {
                // Do not forget to append the query string that was originally sent.
                // this.Url contains the original query string plus suppress_response_codes and suppress_redirects.
                // We will just reuse that.
                string originalQueryString = this.Url.Query;

                if (!string.IsNullOrWhiteSpace(originalQueryString))
                {
                    // Uri.Query return contains "?" (e.g., ?key=value)
                    int indexOfQuestion = originalQueryString.IndexOf('?');
                    if (indexOfQuestion != -1)
                    {
                        originalQueryString = originalQueryString.Substring(indexOfQuestion + 1);
                    }

                    uploadLocation = uploadLocation.Contains("?")
                                         ? uploadLocation + "&" + originalQueryString
                                         : uploadLocation + "?" + originalQueryString;
                }

                resourceUrl = new Uri(uploadLocation, UriKind.Absolute);
            }
            catch (FormatException exp)
            {
                throw new LiveConnectException(
                    ApiOperation.ApiClientErrorCode,
                    ResourceHelper.GetString("NoUploadLinkFound"),
                    exp);
            }

            string query = resourceUrl.Query;
            string url = resourceUrl.GetComponents(
                UriComponents.SchemeAndServer | UriComponents.Path | UriComponents.KeepDelimiter, 
                UriFormat.SafeUnescaped);

            var sb = new StringBuilder(url);
            if (!this.IsFilePath)
            {
                sb.AppendUrlPath(Uri.EscapeDataString(this.FileName));
            }

            bool hasQuery = !string.IsNullOrEmpty(query);
            if (hasQuery)
            {
                sb.Append(query);
            }

            // Only add the overwrite parameter for folder uploads,
            // since overwrite does not make sense on file path uploads (because they are always overwriting).
            if (!this.IsFilePath)
            {
                sb.Append(hasQuery ? '&' : '?');
                sb.AppendQueryParam(QueryParameters.Overwrite, QueryParameters.GetOverwriteValue(this.OverwriteOption));
            }

            try
            {
                return new Uri(sb.ToString(), UriKind.Absolute);
            }
            catch (FormatException exp)
            {
                throw new LiveConnectException(
                    ApiOperation.ApiClientErrorCode,
                    String.Format(CultureInfo.CurrentUICulture, ResourceHelper.GetString("FileNameInvalid"), "fileName"),
                    exp);
            }
        }
开发者ID:harunpehlivan,项目名称:LiveSDK-for-Windows,代码行数:71,代码来源:GetUploadLinkOperation.cs


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