/// <summary> /// Informs the web service that the user has selected a code /// </summary> /// <param name="selection">VetCompassCodeSelection The details of their selection</param> /// <returns></returns> public Task <HttpWebResponse> RegisterSelection(VetCompassCodeSelection selection) { if (!IsStarted) { throw new Exception("Coding session not started"); } if (IsFaulted) { throw new Exception("Coding session is faulted"); } return(_sessionCreationTask.FlatMapSuccess(_ => PostSelection(selection))); }
private Task <HttpWebResponse> PostSelection(VetCompassCodeSelection selection) { var selectionAddress = new Uri(_sessionAddress + "selection"); //prepare the request var request = CreateRequest(selectionAddress); var requestBytes = RequestHelper.PreparePostRequest(request, selection, _clientId, _sharedSecret); //webrequest asynch methods require caller to implement timeouts, set up cancellation tokens var cancellationTokenSource = new CancellationTokenSource(); var ct = cancellationTokenSource.Token; //Asynchronously post the request var webTask = RequestHelper.PostAsynchronously(request, ct, requestBytes, HandleSessionCreationFailure); return(HonourTimeout(webTask, cancellationTokenSource).MapSuccess(response => (HttpWebResponse)response)); }