/// <summary> /// Begins a new display, tied to a unique RequestId on the server. /// </summary> /// <returns></returns> private async Task <string> GetNewRequestIdAsync() { using (var coresightClient = new CoresightHttpClient(_coresightBaseUri, _tokens, _credentials)) { HttpResponseMessage response = await coresightClient.HttpClient.GetAsync("Displays/NewDisplay"); response.EnsureSuccessStatusCode(); string newDisplayJson = await response.Content.ReadAsStringAsync(); DisplayInfo newDisplay = JsonConvert.DeserializeObject <DisplayInfo>(newDisplayJson); return(newDisplay.RequestId); } }
public async Task <DisplayRevision> SaveAsync() { using (var coresightClient = new CoresightHttpClient(_coresightBaseUri, _tokens, _credentials)) { string displayWrapperJson = JsonConvert.SerializeObject(DisplayWrapper); StringContent content = new StringContent(displayWrapperJson, Encoding.UTF8, "application/json"); HttpResponseMessage response = await coresightClient.HttpClient.PostAsync("Displays/SaveDisplay", content); response.EnsureSuccessStatusCode(); string responseContentJson = await response.Content.ReadAsStringAsync(); DisplayRevision displayRevision = JsonConvert.DeserializeObject <DisplayRevision>(responseContentJson); return(displayRevision); } }
/// <summary> /// Gets request verification tokens from the server /// </summary> /// <returns>An object with a field value and a cookie collection</returns> private async Task <CoresightRequestVerificationTokens> GetRequestVerificationTokensAsync() { CoresightRequestVerificationTokens tokens = new CoresightRequestVerificationTokens(); using (var client = new CoresightHttpClient(_coresightBaseUri, tokens, _credentials)) { Console.WriteLine("Getting Coresight verification tokens."); HttpResponseMessage response = await client.HttpClient.GetAsync(""); Console.WriteLine("Response: {0} - {1}", response.StatusCode, response.ReasonPhrase); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); Regex tokenFinder = new Regex(@"(?:window\.Coresight\.RequestVerificationToken)\s*?=\s*'([\w:-]+?)'"); tokens.HiddenInputToken = tokenFinder.Match(content).Groups[1].Captures[0].Value; return(tokens); } }