private void UploadData_(TaskListener <string> listener, byte[] bytes, string contentType, string mediaType, string[] testIds) { RenderingInfo renderingInfo = GetRenderingInfo(); string targetUrl = renderingInfo?.ResultsUrl?.AbsoluteUri; if (targetUrl == null) { listener.OnComplete(null); return; } Guid guid = Guid.NewGuid(); targetUrl = targetUrl.Replace("__random__", guid.ToString()); Logger.Log(TraceLevel.Info, testIds, Stage.General, StageType.UploadStart, new { mediaType, targetUrl }); HttpRequestMessage request = CreateHttpRequestMessageForUpload_(targetUrl, bytes, contentType, mediaType); httpClient_.SendAsyncRequest(new TaskListener <HttpResponseMessage>( response => { if (response == null) { throw new NullReferenceException("response is null"); } listener.OnComplete(targetUrl); }, ex => listener.OnFail(ex)), request, Logger, new BackoffProvider(2), TimeSpan.FromMinutes(2)); }
public virtual RenderingInfo GetRenderingInfo() { if (renderingInfo_ == null) { renderingInfo_ = GetFromPath(renderingInfo_, "api/sessions/renderinfo", "Render Info"); } return(renderingInfo_); }
public HttpRequestMessage CreateUfgHttpWebRequest_(string url, string fullAgentId = null, string method = "POST", string contentType = "application/json", string mediaType = "application/json", object content = null) { RenderingInfo renderingInfo = GetRenderingInfo(); return(CreateUfgHttpWebRequest_(url, renderingInfo, fullAgentId ?? AgentId, method, contentType, mediaType, content)); }
public HttpRequestMessage CreateUfgHttpWebRequest_(string url, RenderingInfo renderingInfo, string fullAgentId, string method = "POST", string contentType = "application/json", string mediaType = "application/json", object content = null) { Uri uri = new Uri(renderingInfo.ServiceUrl, url); HttpRequestMessage request = httpClient_.CreateHttpRequestMessage(uri, method, content, contentType, mediaType); request.Headers.Add("X-Auth-Token", renderingInfo.AccessToken); if (fullAgentId != null) { request.Headers.Add("x-applitools-eyes-client", fullAgentId); } request.Headers.Add("x-applitools-eyes-client-request-id", Guid.NewGuid().ToString()); return(request); }