public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 1 && InputInts.Length == 4) { int x1 = InputInts[0]; int y1 = InputInts[1]; var point1 = $"({x1}, {y1})"; int x2 = InputInts[2]; int y2 = InputInts[3]; var point2 = $"({x2},{y2})"; var deltaX = x2 - x1; var deltaY = y2 - y1; var calculation = Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); var distanceFormula = Convert.ToDecimal(calculation); var resultsType = ResultTypes.Distance; var successResults = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(distanceFormula, 2).ToString(), OutputMsg = $"Given the points: {point1} and {point2}, the distance = {distanceFormula}", OperationType = operationType.GetDescription(), ResultType = resultsType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } else { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "There needs to be exactly 4 elements to calculate the midpoint. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } // Returning back to the main root dialog stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 2) { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} is too long. I need only 2 numbers to find the length of the hypotenuse", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } else { // Having the necessary calculations done double a = Convert.ToDouble(InputInts[0]); double b = Convert.ToDouble(InputInts[1]); var hypotenuseSqr = Math.Pow(a, 2) + Math.Pow(b, 2); double c = Math.Sqrt(hypotenuseSqr); var output = $"Given the legs of ${InputInts[0]} and ${InputInts[1]}, the hypotenuse of the right triangle is ${decimal.Round(decimal.Parse(c.ToString()), 2)}"; var resultType = ResultTypes.Hypotenuse; var successResults = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(decimal.Parse(c.ToString()), 2).ToString(), OutputMsg = output, OperationType = operationType.GetDescription(), ResultType = resultType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } // Returning back to the root dialog context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length > 1) { int sum = InputInts[0]; for (int i = 1; i < InputInts.Length; i++) { sum += InputInts[i]; } decimal mean = Convert.ToDecimal(sum) / InputInts.Length; var successResType = ResultTypes.Average; #region Building the results object and the card var results = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(mean, 2).ToString(), OutputMsg = $"Given the list: {InputString}; the average = {decimal.Round(mean, 2)}", OperationType = operationType.GetDescription(), ResultType = successResType.GetDescription() }; IMessageActivity opsReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); opsReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(opsReply); } else { #region Building the error object var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too small to calculate an average. Please try again later.", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; #endregion await context.PostAsync(errorReply); } // Return back to the RootDialog context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; // Performing some type of validation on the incoming data if (InputInts.Length > 2) { decimal median; int size = InputInts.Length; int[] copyArr = InputInts; // Sorting the array Array.Sort(copyArr); if (size % 2 == 0) { median = Convert.ToDecimal(copyArr[size / 2 - 1] + copyArr[size / 2]) / 2; } else { median = Convert.ToDecimal(copyArr[(size - 1) / 2]); } #region Building out the results object and the card var opsResultType = ResultTypes.Median; var opsResult = new OperationResults() { Input = InputString, NumericalResult = decimal.Round(median, 2).ToString(), OutputMsg = $"Given the list: {InputString}; the median = {decimal.Round(median, 2)}", OperationType = operationType.GetDescription(), ResultType = opsResultType.GetDescription() }; IMessageActivity opsReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(opsResult); opsReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(opsReply); } else { var errorResType = ResultTypes.Error; var errorResult = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"Please double check the input: {InputString} and try again", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResult); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; await context.PostAsync(errorReply); } // Making sure to return back to the RootDialog context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Arithmetic; if (InputInts.Length > 1) { int diff = InputInts[0]; for (int i = 1; i < InputInts.Length; i++) { diff -= InputInts[i]; } var resultType = ResultTypes.Difference; var results = new OperationResults() { Input = InputString, NumericalResult = diff.ToString(), OutputMsg = $"Given the list of {InputString}; the difference = {diff}", OperationType = operationType.GetDescription(), ResultType = resultType.GetDescription() }; #region Creating the adaptive card IMessageActivity reply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; #endregion await context.PostAsync(reply); } else { var resultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The input list: {InputString} is too short - please provide more numbers", OperationType = operationType.GetDescription(), ResultType = resultType.GetDescription() }; #region Creating the adaptive card IMessageActivity errorReply = context.MakeMessage(); var errorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorAdaptiveCard) } }; #endregion // Send the message that you need more elements to calculate the sum await context.PostAsync(errorReply); } // Return back to the RootDialog - popping this child dialog off the stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Geometric; if (InputInts.Length > 1 && InputInts.Length == 4) { int x1 = InputInts[0]; int y1 = InputInts[1]; int x2 = InputInts[2]; int y2 = InputInts[3]; var midX = (x1 + x2) / 2; var midY = (y1 + y2) / 2; // Successful midpoint calculation results var successResults = new OperationResults() { Input = InputString, NumericalResult = $"{midX}, {midY}", OutputMsg = $"Given the list of integers: {InputString}, the midpoint = ({midX}, {midY})", OperationType = CalculationTypes.Geometric.ToString(), ResultType = ResultTypes.Midpoint.ToString() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } else { var errorResultType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "There needs to be exactly 4 elements to calculate the midpoint. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorResultsAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorResultsAdaptiveCard) } }; await context.PostAsync(errorReply); } // Returning back to the main root dialog stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Arithmetic; if (InputInts.Length == 2 && InputInts[1] != 0) { int remainder = InputInts[0] % InputInts[1]; var results = new OperationResults() { Input = InputString, NumericalResult = remainder.ToString(), OutputMsg = $"Given the list {InputString}; the remainder = {remainder}", OperationType = operationType.GetDescription(), ResultType = ResultTypes.Remainder.ToString() }; // Building up the adaptive card IMessageActivity reply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(results); reply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(reply); } else { var errorResultType = ResultTypes.Error; // Building the error results object var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = $"The list: {InputString} may be invalid for this operation. Please double check, and try again", OperationType = operationType.GetDescription(), ResultType = errorResultType.GetDescription() }; // Now having the card IMessageActivity errorReply = context.MakeMessage(); var errorAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorAdaptiveCard) } }; await context.PostAsync(errorReply); } // Return to the RootDialog - making sure to pop this child dialog off the stack context.Done <object>(null); }
public async Task StartAsync(IDialogContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } var operationType = CalculationTypes.Statistical; if (InputInts.Length > 1) { var sumOfSquares = InputInts[0]; for (int i = 1; i < InputInts.Length; i++) { sumOfSquares += (int)Math.Pow(InputInts[i], 2); } var calculatedResult = Math.Sqrt(sumOfSquares / InputInts.Length); var successResType = ResultTypes.RootMeanSquare; var success = new OperationResults() { Input = InputString, NumericalResult = calculatedResult.ToString(), OutputMsg = $"Given the list: {InputString}, the RMS = {calculatedResult}", OperationType = operationType.GetDescription(), ResultType = successResType.GetDescription() }; IMessageActivity successReply = context.MakeMessage(); var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(success); successReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(resultsAdaptiveCard) } }; await context.PostAsync(successReply); } else { var errorResType = ResultTypes.Error; var errorResults = new OperationResults() { Input = InputString, NumericalResult = "0", OutputMsg = "Your list may be too small to calculate the root mean square. Please try again later", OperationType = operationType.GetDescription(), ResultType = errorResType.GetDescription() }; IMessageActivity errorReply = context.MakeMessage(); var errorReplyAdaptiveCard = OperationErrorAdaptiveCard.GetCard(errorResults); errorReply.Attachments = new List <Attachment>() { new Attachment() { ContentType = "application/vnd.microsoft.card.adaptive", Content = JsonConvert.DeserializeObject(errorReplyAdaptiveCard) } }; await context.PostAsync(errorReply); } context.Done <object>(null); }