public virtual string GetUrlForRequest(IMediaResourceUploadRequest request) { string hostUrl = this.GetHostUrlForRequest(request); string baseUrl = this.GetCommonPartForRequest(request).ToLowerInvariant(); hostUrl = hostUrl + baseUrl; ItemSourceUrlBuilder sourceBuilder = new ItemSourceUrlBuilder(this.restGrammar, this.webApiGrammar, request.ItemSource); string itemSourceArgs = sourceBuilder.BuildUrlQueryString(); string allParameters = itemSourceArgs; allParameters = allParameters + this.SpecificParametersForRequest(request); bool shouldTruncateBaseUrl = (!string.IsNullOrEmpty(allParameters) && allParameters.StartsWith(this.restGrammar.FieldSeparator)); while (shouldTruncateBaseUrl) { allParameters = allParameters.Substring(1); shouldTruncateBaseUrl = (!string.IsNullOrEmpty(allParameters) && allParameters.StartsWith(this.restGrammar.FieldSeparator)); } string result = hostUrl; if (!string.IsNullOrEmpty(allParameters)) { result = result + this.restGrammar.HostAndArgsSeparator + allParameters; } return result; }
public virtual string GetUrlForRequest(IMediaResourceUploadRequest request) { string hostUrl = this.GetHostUrlForRequest(request); string baseUrl = this.GetCommonPartForRequest(request).ToLowerInvariant(); hostUrl = hostUrl + baseUrl; ItemSourceUrlBuilder sourceBuilder = new ItemSourceUrlBuilder(this.restGrammar, this.webApiGrammar, request.ItemSource); string itemSourceArgs = sourceBuilder.BuildUrlQueryString(); string allParameters = itemSourceArgs; allParameters = allParameters + this.SpecificParametersForRequest(request); bool shouldTruncateBaseUrl = (!string.IsNullOrEmpty(allParameters) && allParameters.StartsWith(this.restGrammar.FieldSeparator)); while (shouldTruncateBaseUrl) { allParameters = allParameters.Substring(1); shouldTruncateBaseUrl = (!string.IsNullOrEmpty(allParameters) && allParameters.StartsWith(this.restGrammar.FieldSeparator)); } string result = hostUrl; if (!string.IsNullOrEmpty(allParameters)) { result = result + this.restGrammar.HostAndArgsSeparator + allParameters; } return(result); }
public void TestUrlBuilderExcapesArgs() { ItemSource data = new ItemSource("{master}", "da???", 123); ItemSourceUrlBuilder builder = new ItemSourceUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters(), data); string expected = "sc_database=%7bmaster%7d&language=da%3f%3f%3f&sc_itemversion=123"; Assert.AreEqual(expected, builder.BuildUrlQueryString()); }
public void TestSerializationSupportsVersion() { ItemSource data = new ItemSource("master", "da", 100500); ItemSourceUrlBuilder builder = new ItemSourceUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters(), data); string expected = "sc_database=master&language=da&sc_itemversion=100500"; Assert.AreEqual(expected, builder.BuildUrlQueryString()); }
public void TestSerializeDafaultSource() { ItemSource data = LegacyConstants.DefaultSource(); ItemSourceUrlBuilder builder = new ItemSourceUrlBuilder(RestServiceGrammar.ItemWebApiV2Grammar(), WebApiUrlParameters.ItemWebApiV2UrlParameters(), data); string expected = "sc_database=web&language=en"; Assert.AreEqual(expected, builder.BuildUrlQueryString()); }
public void TestSerializationSupportsVersion() { ItemSource data = new ItemSource("master", "da", 100500); ItemSourceUrlBuilder builder = new ItemSourceUrlBuilder(RestServiceGrammar.ItemSSCV2Grammar(), SSCUrlParameters.ItemSSCV2UrlParameters(), data); string expected = "database=master&language=da&version=100500"; string actual = builder.BuildUrlQueryString(); Assert.AreEqual(expected, actual); }
private string GetCommonPartForRequest(IGetRenderingHtmlRequest request) { ItemSourceUrlBuilder sourceBuilder = new ItemSourceUrlBuilder(this.restGrammar, this.webApiGrammar, request.ItemSource); string itemSourceArgs = sourceBuilder.BuildUrlQueryString(); string result = string.Empty; string[] restSubQueries = { itemSourceArgs }; foreach (string currentSubQuery in restSubQueries) { if (!string.IsNullOrEmpty(currentSubQuery)) { result = result + this.restGrammar.FieldSeparator + currentSubQuery; } } return(result.ToLowerInvariant()); }
private string GetCommonPartForRequest(IGetRenderingHtmlRequest request) { ItemSourceUrlBuilder sourceBuilder = new ItemSourceUrlBuilder(this.restGrammar, this.webApiGrammar, request.ItemSource); string itemSourceArgs = sourceBuilder.BuildUrlQueryString(); string result = string.Empty; string[] restSubQueries = { itemSourceArgs }; foreach (string currentSubQuery in restSubQueries) { if (!string.IsNullOrEmpty(currentSubQuery)) { result = result + this.restGrammar.FieldSeparator + currentSubQuery; } } return result.ToLowerInvariant(); }