public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // TODO: Complete the Rectangle area (success and failure cases)
            // TODO2: May want to also consider the square here

            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} may not be valid. Please try again",
                    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 if (InputInts[0] == InputInts[1])
            {
                var squareAreaResult = Convert.ToDecimal(Math.Pow(InputInts[0], 2));

                var successResultType = ResultTypes.SquareArea;
                var successResults    = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(squareAreaResult, 2).ToString(),
                    OutputMsg       = $"Given the inputs: {InputString}, the output = {decimal.Round(squareAreaResult, 2).ToString()}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResultType.GetDescription()
                };

                IMessageActivity squareSuccessReply = context.MakeMessage();
                var successResultsAdaptiveCard      = OperationResultsAdaptiveCard.GetCard(successResults);
                squareSuccessReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(successResultsAdaptiveCard)
                    }
                };

                await context.PostAsync(squareSuccessReply);
            }
            else
            {
                var rectangleAreaResult = Convert.ToDecimal(InputInts[0] * InputInts[1]);

                var successResultType = ResultTypes.RectangleArea;
                var successResults    = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(rectangleAreaResult, 2).ToString(),
                    OutputMsg       = $"Given the inputs: {InputString}, the output = {decimal.Round(rectangleAreaResult, 2).ToString()}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResultType.GetDescription()
                };

                IMessageActivity successReply  = context.MakeMessage();
                var successResultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResults);
                successReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(successResultsAdaptiveCard)
                    }
                };

                await context.PostAsync(successReply);
            }
        }
        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 = 0; i < InputInts.Length; i++)
                {
                    sum += InputInts[i];
                }

                var mean        = Convert.ToDouble(sum) / InputInts.Length;
                var variance    = CalculateVariance(mean, InputInts);
                var standardDev = Math.Sqrt((double)variance);

                var successResultType = ResultTypes.StandardDeviation;
                var results           = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = standardDev.ToString(),
                    OutputMsg       = $"Given the list: {InputString}; the standard deviation = {standardDev}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResultType.GetDescription()
                };

                // Sending out the reply
                IMessageActivity successReply = context.MakeMessage();
                var resultsAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(results);
                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 standard deviation. 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);
            }

            // Popping back after the completion of this 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];
                foreach (int item in InputInts)
                {
                    sum += item;
                }

                double  mean              = Convert.ToDouble(sum) / InputInts.Length;
                decimal variance          = CalculateVariance(mean, InputInts);
                var     successResultType = ResultTypes.Variance;

                #region Building the results
                var results = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(variance, 2).ToString(),
                    OutputMsg       = $"Given the list: {InputString}; the variance = {decimal.Round(variance, 2)}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResultType.GetDescription()
                };

                IMessageActivity resultsReply = context.MakeMessage();
                var resultsAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(results);
                resultsReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(resultsAdaptiveCard)
                    }
                };
                #endregion

                await context.PostAsync(resultsReply);
            }
            else
            {
                var errorResType = ResultTypes.Error;
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = "Your list may be too small to calculate the variance. 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);
            }

            // Popping back to the root dialog
            context.Done <object>(null);
        }
Beispiel #4
0
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var operationType = CalculationTypes.Geometric;

            if (InputInts.Length != 3)
            {
                var errorResultType = ResultTypes.Error;
                var errorResult     = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OperationType   = operationType.GetDescription(),
                    OutputMsg       = $"Your input list: {InputString} is not valid, please check the input list and try again",
                    ResultType      = errorResultType.GetDescription()
                };

                IMessageActivity errorReply = context.MakeMessage();
                var errorAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(errorResult);
                errorReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorAdaptiveCard)
                    }
                };

                await context.PostAsync(errorReply);
            }
            else
            {
                var isEquilateral = InputInts[0] == InputInts[1] && InputInts[1] == InputInts[2] && InputInts[0] == InputInts[2];

                // Add all sides - for the scalene and isoceles cases
                if (!isEquilateral)
                {
                    var perimeter       = InputInts.Sum();
                    var perimResultType = ResultTypes.TrianglePerimeter;
                    var perimResults    = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = perimeter.ToString(),
                        OperationType   = operationType.GetDescription(),
                        OutputMsg       = $"Given the inputs: {InputString}, the perimeter = {perimeter}",
                        ResultType      = perimResultType.GetDescription()
                    };

                    IMessageActivity perimSuccessReply = context.MakeMessage();
                    var perimSuccessAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(perimResults);
                    perimSuccessReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(perimSuccessAdaptiveCard)
                        }
                    };

                    await context.PostAsync(perimSuccessReply);
                }
                else
                {
                    var equiPerim       = 3 * InputInts[0];
                    var perimResultType = ResultTypes.TrianglePerimeter;
                    var perimResults    = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = equiPerim.ToString(),
                        OperationType   = operationType.GetDescription(),
                        OutputMsg       = $"Given the inputs: {InputString}, the perimeter = {equiPerim}",
                        ResultType      = perimResultType.GetDescription()
                    };

                    IMessageActivity equiPerimSuccessReply = context.MakeMessage();
                    var perimSuccessAdaptiveCard           = OperationResultsAdaptiveCard.GetCard(perimResults);
                    equiPerimSuccessReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(perimSuccessAdaptiveCard)
                        }
                    };

                    await context.PostAsync(equiPerimSuccessReply);
                }
            }
        }
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var operationType = CalculationTypes.Geometric;

            if (InputInts.Length > 3)
            {
                var errorResType = ResultTypes.Error;
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = "Your list may be too large to calculate the roots. Please try again later!",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorResType.GetDescription()
                };

                IMessageActivity errorListReply = context.MakeMessage();
                var errorListAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(errorResults);
                errorListReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorListAdaptiveCard)
                    }
                };
                await context.PostAsync(errorListReply);
            }
            else
            {
                double a = Convert.ToDouble(InputInts[0]);
                double b = Convert.ToDouble(InputInts[1]);
                double c = Convert.ToDouble(InputInts[2]);

                // The two roots of the quadratic equation
                double r1, r2;

                var discriminant = Math.Pow(b, 2) - (4 * a * c);

                int m;

                if (a == 0)
                {
                    m = 1;
                }
                else if (discriminant > 0)
                {
                    m = 2;
                }
                else if (discriminant == 0)
                {
                    m = 3;
                }
                else
                {
                    m = 4;
                }

                switch (m)
                {
                case 1:
                    var opsErrorResultType = ResultTypes.Error;
                    var opsError           = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = "0",
                        OutputMsg       = "The information provided may lead to a linear equation!",
                        OperationType   = CalculationTypes.Geometric.ToString(),
                        ResultType      = opsErrorResultType.GetDescription()
                    };

                    IMessageActivity opsErrorReply = context.MakeMessage();
                    var opsErrorAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(opsError);
                    opsErrorReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(opsErrorAdaptiveCard)
                        }
                    };
                    await context.PostAsync(opsErrorReply);

                    break;

                case 2:
                    r1 = (-b + Math.Sqrt(discriminant)) / (2 * a);
                    r2 = (-b - Math.Sqrt(discriminant)) / (2 * a);

                    var successResultType = ResultTypes.EquationRoots;
                    var successResults    = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = $"{r1}, {r2}",
                        OutputMsg       = $"The roots are Real and Distinct - Given the list of: {InputString}, the roots are [{r1}, {r2}]",
                        OperationType   = operationType.GetDescription(),
                        ResultType      = successResultType.GetDescription()
                    };

                    IMessageActivity opsSuccessReply = context.MakeMessage();
                    var resultsAdaptiveCard          = OperationResultsAdaptiveCard.GetCard(successResults);
                    opsSuccessReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(resultsAdaptiveCard)
                        }
                    };

                    await context.PostAsync(opsSuccessReply);

                    break;

                case 3:
                    r1 = r2 = (-b) / (2 * a);

                    var successOpsOneRootResultType = ResultTypes.EquationRoots;
                    var successOpsOneRoot           = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = $"{r1}, {r2}",
                        OutputMsg       = $"The roots are Real and Distinct - Given the list of: {InputString}, the roots are [{r1}, {r2}]",
                        OperationType   = operationType.GetDescription(),
                        ResultType      = successOpsOneRootResultType.GetDescription()
                    };

                    IMessageActivity opsSuccessOneRootReply = context.MakeMessage();
                    var successOpsOneRootAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(successOpsOneRoot);
                    opsSuccessOneRootReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(successOpsOneRootAdaptiveCard)
                        }
                    };
                    await context.PostAsync(opsSuccessOneRootReply);

                    break;

                case 4:
                    var rootsDesc = "Roots are imaginary";
                    r1 = (-b) / (2 * a);
                    r2 = Math.Sqrt(-discriminant) / (2 * a);

                    var root1Str = string.Format("First root is {0:#.##} + {1:#.##}i", r1, r2);
                    var root2Str = string.Format("Second root is {0:#.##} - {1:#.##}i", r1, r2);

                    var root1 = string.Format("{0:#.##} + {1:#.##}i", r1, r2);
                    var root2 = string.Format("{0:#.##} - {1:#.##}i", r1, r2);

                    var imaginaryRootsResult         = ResultTypes.EquationRoots;
                    var opsSuccessImaginRootsResults = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = $"{root1}, {root2}",
                        OutputMsg       = rootsDesc + " " + root1Str + " " + root2Str,
                        OperationType   = operationType.GetDescription(),
                        ResultType      = imaginaryRootsResult.GetDescription()
                    };

                    IMessageActivity opsSuccessImagReply = context.MakeMessage();
                    var opsSuccessImaginRootCard         = OperationResultsAdaptiveCard.GetCard(opsSuccessImaginRootsResults);
                    opsSuccessImagReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(opsSuccessImaginRootCard)
                        }
                    };

                    await context.PostAsync(opsSuccessImagReply);

                    break;

                default:
                    await context.PostAsync("Sorry I'm not sure what is going on here");

                    break;
                }
            }

            context.Done <object>(null);
        }
Beispiel #6
0
        public async Task StartAsync(IDialogContext context)
        {
            var calculationType = CalculationTypes.Arithmetic;

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (InputInts.Length > 1)
            {
                #region Before using adaptive cards
                int sum = InputInts[0];
                for (int i = 1; i < InputInts.Length; i++)
                {
                    sum += InputInts[i];
                }
                #endregion

                var resType = ResultTypes.Sum;
                var results = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = sum.ToString(),
                    OutputMsg       = $"Given the list of {InputString}; the sum = {sum}",
                    OperationType   = calculationType.GetDescription(),
                    ResultType      = resType.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 errorResType = ResultTypes.Error;
                // Building the error results object for the creation of the error card
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = $"The input list: {InputString} is too short - please provide more numbers",
                    OperationType   = calculationType.GetDescription(),
                    ResultType      = errorResType.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);
        }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var operationType = CalculationTypes.Statistical;

            if (InputInts.Length > 1)
            {
                int product = InputInts[0];
                for (int i = 1; i < InputInts.Length; i++)
                {
                    if (InputInts[i] != 0)
                    {
                        product *= InputInts[i];
                    }
                    else
                    {
                        break;
                    }
                }

                // Calculating the Geometric mean here
                decimal geometricMean = Convert.ToDecimal(Math.Pow(product, 1 / InputInts.Length));
                var     resultType    = ResultTypes.GeometricMean;

                var results = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(geometricMean, 2).ToString(),
                    OutputMsg       = $"Given the list: {InputString}; the geometric mean = ${geometricMean.ToString()}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = resultType.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)
                    }
                };
                await context.PostAsync(opsReply);
            }
            else
            {
                var errorResType = ResultTypes.Error;
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = "Your list may be too small to calculate the geometric mean. Please try again later",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorResType.GetDescription()
                };

                IMessageActivity errorReply = context.MakeMessage();
                var errorOpsAdaptiveCard    = OperationErrorAdaptiveCard.GetCard(errorResults);
                errorReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorOpsAdaptiveCard)
                    }
                };
                await context.PostAsync(errorReply);
            }

            // Returning 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.Geometric;

            if (InputInts.Length != 4)
            {
                var errorResultType = ResultTypes.Error;
                var errorResult     = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = $"Your input: {InputString} is not valid. Please try again later!",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorResultType.GetDescription()
                };

                IMessageActivity errorReply = context.MakeMessage();
                var errorAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(errorResult);
                errorReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorAdaptiveCard)
                    }
                };

                await context.PostAsync(errorReply);
            }
            else
            {
                // Looking to see if all the values are the same
                var isSquare = InputInts[0] == InputInts[1] && InputInts[1] == InputInts[2] && InputInts[2] == InputInts[3];

                if (!isSquare)
                {
                    var totalPerimeter       = InputInts.Sum();
                    var totalPerimResultType = ResultTypes.QuadPerimeter;

                    var totalPerimResult = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = totalPerimeter.ToString(),
                        OperationType   = operationType.GetDescription(),
                        OutputMsg       = $"Given the input list: {InputString}, the perimeter = {totalPerimeter}",
                        ResultType      = totalPerimResultType.GetDescription()
                    };

                    IMessageActivity perimeterReply = context.MakeMessage();
                    var totalPerimAdaptiveCard      = OperationResultsAdaptiveCard.GetCard(totalPerimResult);
                    perimeterReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(totalPerimAdaptiveCard)
                        }
                    };

                    await context.PostAsync(perimeterReply);
                }
                else
                {
                    var squarePerimeter      = 4 * InputInts[0];
                    var totalPerimResultType = ResultTypes.QuadPerimeter;

                    var squarePerimResult = new OperationResults()
                    {
                        Input           = InputString,
                        NumericalResult = squarePerimeter.ToString(),
                        OperationType   = operationType.GetDescription(),
                        OutputMsg       = $"Given the input list: {InputString}, the perimeter = {squarePerimeter}",
                        ResultType      = totalPerimResultType.GetDescription()
                    };

                    IMessageActivity squarePerimReply = context.MakeMessage();
                    var squarePerimAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(squarePerimResult);
                    squarePerimReply.Attachments = new List <Attachment>()
                    {
                        new Attachment()
                        {
                            ContentType = "application/vnd.microsoft.card.adaptive",
                            Content     = JsonConvert.DeserializeObject(squarePerimAdaptiveCard)
                        }
                    };

                    await context.PostAsync(squarePerimReply);
                }
            }
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #13
0
        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);
        }
Beispiel #14
0
        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;
            decimal quotient      = 0;

            if (InputInts.Length == 2 && InputInts[1] != 0)
            {
                quotient = Convert.ToDecimal(InputInts[0]) / InputInts[1];
                var resultsType = ResultTypes.Quotient;

                var results = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(quotient, 2).ToString(),
                    OutputMsg       = $"Given the list of {InputString}; the quotient = {decimal.Round(quotient, 2)}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = resultsType.GetDescription()
                };

                #region Creating the adaptive card
                IMessageActivity reply = context.MakeMessage();
                var resultsCard        = OperationResultsAdaptiveCard.GetCard(results);
                reply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(resultsCard)
                    }
                };
                #endregion

                await context.PostAsync(reply);
            }
            else
            {
                var errorType    = ResultTypes.Error;
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = "The list may be too long, or one of the elements could be 0 - please try again later.",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorType.GetDescription()
                };

                #region Creating the adaptive card
                IMessageActivity errorReply = context.MakeMessage();
                var errorResultsCard        = OperationErrorAdaptiveCard.GetCard(errorResults);
                errorReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorResultsCard)
                    }
                };
                #endregion

                // Send the message that you need more elements to calculate the sum
                await context.PostAsync(errorReply);
            }

            // Return back to the root dialog - popping this child dialog from the dialog stack
            context.Done <object>(null);
        }
Beispiel #16
0
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var operationType = CalculationTypes.Statistical;

            if (InputInts.Length >= 2)
            {
                var inputIntMax = InputInts.Max();

                var inputIntMin = InputInts.Min();

                // Conduct the range calculation as max - min
                var range = inputIntMax - inputIntMin;

                var successResType = ResultTypes.Range;
                var successResult  = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = range.ToString(),
                    OutputMsg       = $"Given the list: {InputString}; the range = {range}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResType.GetDescription()
                };

                #region Having the adaptive card created
                IMessageActivity reply  = context.MakeMessage();
                var resultsAdaptiveCard = OperationResultsAdaptiveCard.GetCard(successResult);
                reply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(resultsAdaptiveCard)
                    }
                };
                #endregion

                // Sending out the reply with the card
                await context.PostAsync(reply);
            }
            else
            {
                var errorResType = ResultTypes.Error;
                var errorResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = "The list may be too short, try again with more numbers.",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorResType.GetDescription()
                };

                #region Having the adaptive card created
                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

                // Sending the error card
                await context.PostAsync(errorReply);
            }

            // Popping back to the root dialog
            context.Done <object>(null);
        }
Beispiel #17
0
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var operationType = CalculationTypes.Statistical;

            // Again making sure to conduct the appropriate things
            if (InputInts.Length > 2)
            {
                List <int> originalList = new List <int>(InputInts);
                List <int> modesList    = new List <int>();

                // Using LINQ in the lines below
                var query = from numbers in originalList
                            group numbers by numbers
                            into groupedNumbers
                            select new
                {
                    Number = groupedNumbers.Key,
                    Count  = groupedNumbers.Count()
                };

                int max = query.Max(g => g.Count);

                if (max == 1)
                {
                    int mode = 0;
                    modesList.Add(mode);
                }
                else
                {
                    modesList = query.Where(x => x.Count == max).Select(x => x.Number).ToList();
                }

                var outputArray    = modesList.ToArray();
                var successResType = ResultTypes.Mode;
                #region Having the results object
                var successResult = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = outputArray.Length > 1 ? string.Join(",", outputArray) : outputArray[0].ToString(),
                    OutputMsg       = $"Given the list: {InputString}; the mode = {(outputArray.Length > 1 ? string.Join(",", outputArray) : outputArray[0].ToString())}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResType.GetDescription()
                };

                IMessageActivity successReply = context.MakeMessage();
                var resultsAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(successResult);
                successReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(resultsAdaptiveCard)
                    }
                };
                #endregion

                await context.PostAsync(successReply);
            }
            else
            {
                var errorResType = ResultTypes.Error;
                // Building out the error object, reply and card
                var errorResult = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = $"Please check your input list: {InputString} and try again later",
                    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);
            }

            // Returning 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 > 3)
            {
                var errorListTooLongResType = ResultTypes.Error;
                // Error condition here
                var errorListTooLongResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "DNE",
                    OutputMsg       = $"The input list: {InputString} could be too long - there needs to be 3 numbers exactly",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorListTooLongResType.GetDescription()
                };

                IMessageActivity errorListTooLongReply = context.MakeMessage();
                var errorListTooLongAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(errorListTooLongResults);
                errorListTooLongReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorListTooLongAdaptiveCard)
                    }
                };
                await context.PostAsync(errorListTooLongReply);
            }
            else if (InputInts.Length < 3)
            {
                var errorListTooShortResType = ResultTypes.Error;
                var errorListTooShortResults = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "DNE",
                    OutputMsg       = $"The input list: {InputString} could be too short - there needs to be 3 numbers exactly",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = errorListTooShortResType.GetDescription()
                };

                IMessageActivity errorListTooShortReply = context.MakeMessage();
                var errorListTooShortAdaptiveCard       = OperationErrorAdaptiveCard.GetCard(errorListTooShortResults);
                errorListTooShortReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(errorListTooShortAdaptiveCard)
                    }
                };
                await context.PostAsync(errorListTooShortReply);
            }
            else
            {
                int a = InputInts[0];
                int b = InputInts[1];
                int c = InputInts[2];

                int discriminantValue = FindDiscriminant(a, b, c);
                var resultMsg         = "";
                var resultsType       = ResultTypes.Discriminant;

                if (discriminantValue > 0)
                {
                    resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there are 2 roots";
                }
                else if (discriminantValue == 0)
                {
                    resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there is 1 root";
                }
                else
                {
                    resultMsg = $"Given your values: a = {a}, b = {b}, c = {c} - the discriminant = {discriminantValue} which means there are no real roots";
                }

                #region Generate the reply, operation results, card, and send out the message
                var discrimResults = new OperationResults()
                {
                    Input           = InputString,
                    OperationType   = operationType.GetDescription(),
                    OutputMsg       = resultMsg,
                    NumericalResult = discriminantValue.ToString(),
                    ResultType      = resultsType.GetDescription()
                };

                IMessageActivity discrimReply = context.MakeMessage();
                var resultsAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(discrimResults);
                discrimReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(resultsAdaptiveCard)
                    }
                };

                await context.PostAsync(discrimReply);

                #endregion
            }

            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)
            {
                var errorResultType = ResultTypes.Error;
                var errorResults    = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = $"The input list: {InputString} may not be valid. Please try again",
                    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 if (InputInts.Length == 1 && InputInts[0] == 0)
            {
                var noCircumError = ResultTypes.Error;
                var errorResults  = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = "0",
                    OutputMsg       = $"The input list: {InputString} may not be valid. Please try again",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = noCircumError.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
            {
                var circumferenceResult = Convert.ToDecimal(2 * Math.PI * InputInts[0]);
                var successResultType   = ResultTypes.Circumference;
                var successResult       = new OperationResults()
                {
                    Input           = InputString,
                    NumericalResult = decimal.Round(circumferenceResult, 2).ToString(),
                    OutputMsg       = $"Given the input: {InputString}, the circumference = {decimal.Round(circumferenceResult, 2).ToString()}",
                    OperationType   = operationType.GetDescription(),
                    ResultType      = successResultType.GetDescription()
                };

                IMessageActivity successReply = context.MakeMessage();
                var successAdaptiveCard       = OperationResultsAdaptiveCard.GetCard(successResult);
                successReply.Attachments = new List <Attachment>()
                {
                    new Attachment()
                    {
                        ContentType = "application/vnd.microsoft.card.adaptive",
                        Content     = JsonConvert.DeserializeObject(successAdaptiveCard)
                    }
                };

                await context.PostAsync(successReply);
            }
        }
Beispiel #20
0
        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);
        }