public static async Task <CollatzGetResponseMessage> GetResponse(BigInteger value, int pauseTime) { var request = new CollatzGetRequestMessage { Value = value.ToString(), PauseTime = pauseTime }; var message = JsonConvert.SerializeObject(request, Formatting.Indented); var content = new StringContent(message, Encoding.Unicode, "application/json"); var postResponse = await new HttpClient().PostAsync("http://localhost:3514/api/collatz", content); return(JsonConvert.DeserializeObject <CollatzGetResponseMessage>( await postResponse.Content.ReadAsStringAsync())); }
// POST api/collatz public CollatzGetResponseMessage Post([FromBody] CollatzGetRequestMessage request) { var response = new CollatzGetResponseMessage { Value = request.Value }; BigInteger value = BigInteger.Zero; if (BigInteger.TryParse(request.Value, out value)) { response.Time = new Action( () => { if (request.PauseTime > 0) { Thread.Sleep(request.PauseTime); } response.Iterations = CollatzConjecture.Collatz(value); }).Time(); } return(response); }