public void TestDefaultHTMLRenderingwithCustomParameters() { Dictionary <string, string> paramDict = new Dictionary <string, string>(); paramDict.Add("param3", "value3"); paramDict.Add("param4", "value4"); IGetRenderingHtmlRequest request = ItemWebApiRequestBuilder.RenderingHtmlRequestWithSourceAndRenderingId("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}", "{220D559F-DEA5-42EA-9C1C-8A5DF7E70E22}") .AddRenderingParameterNameValue("param1", "value1") .AddRenderingParameterNameValue("param2", "value2") .AddRenderingParameterNameValue(paramDict) .Build(); IGetRenderingHtmlRequest autocompletedRequest = this.requestMerger.FillGetRenderingHtmlGaps(request); string result = this.builder.GetUrlForRequest(autocompletedRequest); string expected = "http://mobiledev1ua1.dk.sitecore.net:7119/" + "-/item/v234" + "%2fsitecore%2fshell/" + "-/actions/getrenderinghtml?" + "sc_database=web&" + "language=en&" + "sc_itemid=%7b110d559f-dea5-42ea-9c1c-8a5df7e70ef9%7d&" + "renderingid=%7b220d559f-dea5-42ea-9c1c-8a5df7e70e22%7d&" + "param1=value1&" + "param2=value2&" + "param3=value3&" + "param4=value4"; Assert.AreEqual(expected, result); }
protected virtual string GetHostUrlForRequest(IGetRenderingHtmlRequest request) { SessionConfigUrlBuilder sessionBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.webApiGrammar); string hostUrl = sessionBuilder.BuildUrlString(request.SessionSettings); return(hostUrl); }
public IGetRenderingHtmlRequest FillGetRenderingHtmlGaps(IGetRenderingHtmlRequest userRequest) { IItemSource mergedSource = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource); ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings); return new ReadRenderingHtmlParameters( mergedSessionConfig, mergedSource, userRequest.ParametersValuesByName, userRequest.SourceId, userRequest.RenderingId ); }
public IGetRenderingHtmlRequest FillGetRenderingHtmlGaps(IGetRenderingHtmlRequest userRequest) { IItemSource mergedSource = this.ItemSourceMerger.FillItemSourceGaps(userRequest.ItemSource); ISessionConfig mergedSessionConfig = this.SessionConfigMerger.FillSessionConfigGaps(userRequest.SessionSettings); return(new ReadRenderingHtmlParameters( mergedSessionConfig, mergedSource, userRequest.ParametersValuesByName, userRequest.SourceId, userRequest.RenderingId )); }
public async Task <Stream> ReadRenderingHtmlAsync(IGetRenderingHtmlRequest request, CancellationToken cancelToken = default(CancellationToken)) { IGetRenderingHtmlRequest requestCopy = request.DeepCopyGetRenderingHtmlRequest(); using (ICredentialsHeadersCryptor cryptor = await this.GetCredentialsCryptorAsync(cancelToken)) { IGetRenderingHtmlRequest autocompletedRequest = this.requestMerger.FillGetRenderingHtmlGaps(requestCopy); var urlBuilder = new RenderingHtmlUrlBuilder(this.restGrammar, this.webApiGrammar); var taskFlow = new GetRenderingHtmlTasks(urlBuilder, this.httpClient, cryptor); return(await RestApiCallFlow.LoadResourceFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken)); } }
private string GetSpecificPartForRequest(IGetRenderingHtmlRequest request) { string escapedSourceId = UrlBuilderUtils.EscapeDataString(request.SourceId); string escapedRenderingId = UrlBuilderUtils.EscapeDataString(request.RenderingId); string result = this.webApiGrammar.ItemIdParameterName + this.restGrammar.KeyValuePairSeparator + escapedSourceId + restGrammar.FieldSeparator + this.webApiGrammar.RenderingIdParameterName + this.restGrammar.KeyValuePairSeparator + escapedRenderingId; result = result.ToLowerInvariant(); //must be case sensitive result += this.GetCustomParametersString (request); return result; }
private string GetSpecificPartForRequest(IGetRenderingHtmlRequest request) { string escapedSourceId = UrlBuilderUtils.EscapeDataString(request.SourceId); string escapedRenderingId = UrlBuilderUtils.EscapeDataString(request.RenderingId); string result = this.webApiGrammar.ItemIdParameterName + this.restGrammar.KeyValuePairSeparator + escapedSourceId + restGrammar.FieldSeparator + this.webApiGrammar.RenderingIdParameterName + this.restGrammar.KeyValuePairSeparator + escapedRenderingId; result = result.ToLowerInvariant(); //must be case sensitive result += this.GetCustomParametersString(request); return(result); }
private string GetCustomParametersString(IGetRenderingHtmlRequest request) { string result = ""; if (null != request.ParametersValuesByName) { foreach (var param in request.ParametersValuesByName) { string escapedParamName = UrlBuilderUtils.EscapeDataString (param.Key); string escapedParamValue = UrlBuilderUtils.EscapeDataString (param.Value); result += this.restGrammar.FieldSeparator + escapedParamName + this.restGrammar.KeyValuePairSeparator + escapedParamValue; } } return result; }
public void TestDefaultHTMLRendering() { IGetRenderingHtmlRequest request = ItemWebApiRequestBuilder.RenderingHtmlRequestWithSourceAndRenderingId("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}", "{220D559F-DEA5-42EA-9C1C-8A5DF7E70E22}") .Build(); IGetRenderingHtmlRequest autocompletedRequest = this.requestMerger.FillGetRenderingHtmlGaps(request); string result = this.builder.GetUrlForRequest(autocompletedRequest); string expected = "http://mobiledev1ua1.dk.sitecore.net:7119/" + "-/item/v234" + "%2fsitecore%2fshell/" + "-/actions/getrenderinghtml?" + "sc_database=web&" + "language=en&" + "sc_itemid=%7b110d559f-dea5-42ea-9c1c-8a5df7e70ef9%7d&" + "renderingid=%7b220d559f-dea5-42ea-9c1c-8a5df7e70e22%7d"; Assert.AreEqual(expected, result); }
private string GetCustomParametersString(IGetRenderingHtmlRequest request) { string result = ""; if (null != request.ParametersValuesByName) { foreach (var param in request.ParametersValuesByName) { string escapedParamName = UrlBuilderUtils.EscapeDataString(param.Key); string escapedParamValue = UrlBuilderUtils.EscapeDataString(param.Value); result += this.restGrammar.FieldSeparator + escapedParamName + this.restGrammar.KeyValuePairSeparator + escapedParamValue; } } return(result); }
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()); }
public string GetUrlForRequest(IGetRenderingHtmlRequest request) { this.ValidateSpecificRequest(request); var actionBuilder = new WebApiActionBuilder(this.restGrammar, this.webApiGrammar); string hostUrl = actionBuilder.GetRenderingHtmlAction(request.SessionSettings); string baseParameters = this.GetCommonPartForRequest(request).ToLowerInvariant(); string specificParameters = this.GetSpecificPartForRequest(request); string allParameters = baseParameters; if (!string.IsNullOrEmpty(specificParameters)) { allParameters = allParameters + this.restGrammar.FieldSeparator + specificParameters; } 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 string GetUrlForRequest(IGetRenderingHtmlRequest request) { this.ValidateSpecificRequest(request); var actionBuilder = new WebApiActionBuilder(this.restGrammar, this.webApiGrammar); string hostUrl = actionBuilder.GetRenderingHtmlAction(request.SessionSettings); string baseParameters = this.GetCommonPartForRequest(request).ToLowerInvariant(); string specificParameters = this.GetSpecificPartForRequest(request); string allParameters = baseParameters; if (!string.IsNullOrEmpty(specificParameters)) { allParameters = allParameters + this.restGrammar.FieldSeparator + specificParameters; } 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; }
private async Task<string> GetStringResponse(ISitecoreWebApiReadonlySession session, IGetRenderingHtmlRequest request) { var stream = await session.ReadRenderingHtmlAsync(request); var response = this.StreamToString(stream); return response; }
private async Task <string> GetStringResponse(ISitecoreWebApiReadonlySession session, IGetRenderingHtmlRequest request) { var stream = await session.ReadRenderingHtmlAsync(request); var response = this.StreamToString(stream); return(response); }
protected void ValidateSpecificRequest(IGetRenderingHtmlRequest request) { ItemIdValidator.ValidateItemId(request.SourceId, this.GetType().Name + ".SourceId"); ItemIdValidator.ValidateItemId(request.RenderingId, this.GetType().Name + ".RenderingId"); }
public async Task<Stream> ReadRenderingHtmlAsync(IGetRenderingHtmlRequest request, CancellationToken cancelToken = default(CancellationToken)) { IGetRenderingHtmlRequest requestCopy = request.DeepCopyGetRenderingHtmlRequest(); using (ICredentialsHeadersCryptor cryptor = await this.GetCredentialsCryptorAsync(cancelToken)) { IGetRenderingHtmlRequest autocompletedRequest = this.requestMerger.FillGetRenderingHtmlGaps(requestCopy); var urlBuilder = new RenderingHtmlUrlBuilder(this.restGrammar, this.webApiGrammar); var taskFlow = new GetRenderingHtmlTasks(urlBuilder, this.httpClient, cryptor); return await RestApiCallFlow.LoadResourceFromNetworkFlow(autocompletedRequest, taskFlow, cancelToken); } }
protected virtual string GetHostUrlForRequest(IGetRenderingHtmlRequest request) { SessionConfigUrlBuilder sessionBuilder = new SessionConfigUrlBuilder(this.restGrammar, this.webApiGrammar); string hostUrl = sessionBuilder.BuildUrlString(request.SessionSettings); return hostUrl; }
protected void ValidateSpecificRequest(IGetRenderingHtmlRequest request) { ItemIdValidator.ValidateItemId(request.SourceId, this.GetType().Name + ".SourceId"); ItemIdValidator.ValidateItemId(request.RenderingId, this.GetType().Name + ".RenderingId"); }
public async Task <Stream> ReadRenderingHtmlAsync(IGetRenderingHtmlRequest request, CancellationToken cancelToken = default(CancellationToken)) { return(await this.InvokeNoThrow(this.workerSession.ReadRenderingHtmlAsync(request, cancelToken))); }
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(); }