public SQRTViewModel() { TopTextBlock.Text = InstructionName; Model = new SQRTModel(); CommentArea.Children.Add(_commentTextBlocks[0]); CommentArea.Children.Add(_commentTextBlocks[1]); }
public static string SQRT(SQRTModel oSQRT, string sTrackingId) { var client = new RestClient(string.Concat(ConfigurationManager.AppSettings["ServiceURL"], "/calculator/sqrt")); var request = new RestRequest(Method.POST); setTracking(sTrackingId, request); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Content-Type", "application/json"); request.AddParameter("undefined", JsonConvert.SerializeObject(oSQRT), ParameterType.RequestBody); IRestResponse response = client.Execute(request); return(response.Content); }
public override Task <CommandResult> ExecuteAsync(CancellationToken cancel) { string sResult; try { Console.WriteLine("Calculating..."); SQRTModel oSquare = new SQRTModel(Number); sResult = Operations.SQRT(oSquare, TrackingID); Console.WriteLine(sResult); return(Task.FromResult(CommandResult.Success)); } catch (Exception ex) { Console.WriteLine("Something wrong happend, please check arguments are valid"); return(Task.FromResult(CommandResult.UsageError)); } }
public HttpResponseMessage Mult([FromBody] SQRTModel oSQRT) { SQRTResultModel oResult; string sTrackingID = null; try { oResult = new SQRTResultModel(); if (oSQRT != null && oSQRT.Number > 0) { // Operation is plus (+) because a less than zero value is expected as subtrahend oResult.Square = (int)Math.Round(Math.Sqrt(Convert.ToDouble(oSQRT.Number))); // Once result has been calculated, checks if Tracking ID exists // and in that case save operation and result sTrackingID = CommonUtils.checkTrackingID(Request); if (!string.IsNullOrEmpty(sTrackingID)) { CommonUtils.saveToJournal(sTrackingID, oSQRT, oResult); } return(Request.CreateResponse(HttpStatusCode.OK, oResult)); } // In other case input is not valid else { HttpError err = new HttpError("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."); return(Request.CreateResponse(HttpStatusCode.BadRequest, err)); } } catch (Exception ex) { // TODO: This exception should be logged somewhere // If something happens throws Internal Error HttpError err = new HttpError("An unexpected error condition was triggered which made impossible to fulfill the request. Please try again or contact support."); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, err)); } }