public async void ExecuteCalculatorMultiplyRequest() { MultiplyRequest request = new MultiplyRequest() { intA = UnityEngine.Random.Range(-byte.MaxValue, byte.MaxValue), intB = UnityEngine.Random.Range(-byte.MaxValue, byte.MaxValue) }; MultiplyResponse response = await Multiply.Execute(_calculatorClient, request); if (response != null) { _results.text = string.Format("{0} * {1} = {2}", request.intA, request.intB, response.Value) + Environment.NewLine; } }
public IHttpActionResult Multiply(MultiplyRequest request) { logger.Trace("Service called: multiply"); // An invalid request has been received // This may mean the HTTP requests and/or the HTTP body may contains some errors which should be fixed if (request.Factors == null) { logger.Error(HttpStatusCode.BadRequest); throw new HttpResponseException(HttpStatusCode.BadRequest); } try { MultiplyResponse result = new MultiplyResponse(); // Execute operation: Multiplication string dataJournal = ""; foreach (int number in request.Factors) { result.Product *= number; dataJournal += number + " * "; } dataJournal = dataJournal.Substring(0, dataJournal.Length - 3); dataJournal += " = " + result.Product; logger.Trace("Multiply success!!"); IEnumerable <string> headerValues; if (Request.Headers.TryGetValues("X-Evi-Tracking-Id", out headerValues)) { string id; id = headerValues.FirstOrDefault(); var operation = new Operation() { Name = "multiplication", Calculation = dataJournal, Date = DateTime.Now }; Journal.Store(id, operation); } return(Ok(result)); } catch (Exception ex) { logger.Error(ex); // An unexpected error condition was triggered which made impossible to fulfill the request throw new HttpResponseException(HttpStatusCode.InternalServerError); } }