Exemple #1
0
        //Calcuation Controller Action
        public void CalculateAction(List<CategoryViewModel> jCategory)
        {
            foreach (var group in jCategory)
            {
                foreach (var item in group.Functions)
                {
                    if (item.Function == "Input")
                    {
                        item.Output = InputFunctions.Output(item.Type, item.Output);
                        OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                    }
                    else
                    {
                        //Logic check at Column Level
                        string colLogic = null;
                        bool colLogicParse = true;
                        if(group.Logic != null)
                        {
                            foreach (var bit in group.Logic)
                            {
                                var grouplastLogic = group.Logic.Last();
                                string grouplastLogicOperator = grouplastLogic.Operator;
                                Logic Logic = new Logic();
                                colLogic = Logic.Output(jCategory, bit, group.ID, 0);
                                Expression ex = new Expression(colLogic);
                                try
                                {
                                    colLogicParse = Convert.ToBoolean(ex.Evaluate());
                                }
                                catch (Exception exception)
                                {
                                    logger.Error(exception);
                                    throw new HttpException(exception.ToString());
                                }

                                if (grouplastLogicOperator == "AND" && colLogicParse == false)
                                {
                                    break;
                                }
                                else if (grouplastLogicOperator == "OR" && colLogicParse == true)
                                {
                                    colLogicParse = true;
                                    break;
                                }

                            }
                        }
                        if (item.Parameter.Count > 0)
                        {
                            string logic = null;
                            bool logicparse = true;
                            string MathString = null;
                            bool PowOpen = false;
                            //Logic check at column level
                            if (colLogicParse == true)
                            {
                                foreach (var bit in item.Logic)
                                {
                                    var lastLogic = item.Logic.Last();
                                    string lastLogicOperator = lastLogic.Operator;
                                    Logic Logic = new Logic();
                                    logic = Logic.Output(jCategory, bit, group.ID, item.ID);
                                    Expression ex = new Expression(logic);

                                    try
                                    {
                                        logicparse = Convert.ToBoolean(ex.Evaluate());
                                    }
                                    catch (Exception exception)
                                    {
                                        logger.Error(exception);
                                        throw new HttpException(exception.ToString());
                                    }

                                    if (lastLogicOperator == "AND" && logicparse == false)
                                    {
                                        break;
                                    }
                                    else if (lastLogicOperator == "OR" && logicparse == true)
                                    {
                                        logicparse = true;
                                        break;
                                    }

                                }
                            }
                            else
                            {
                                logicparse = false;
                            }
                            //Run code if logic if met at column and row level
                            if (logicparse == true)
                            {
                                int paramCount = 1;
                                foreach (var param in item.Parameter)
                                {
                                    string jparameters = Newtonsoft.Json.JsonConvert.SerializeObject(param);
                                    logger.Debug("Column Name(" + group.ID + ") - " + group.Name + " || Row Name(" + item.ID +") - " + item.Name);
                                    if (item.Function == "Maths")
                                    {
                                        Maths Maths = new Maths();
                                        Maths parameters = (Maths)javaScriptSerializ­er.Deserialize(jparameters, typeof(Maths));
                                        MathString = Maths.Output(jparameters,jCategory,group.ID,item.ID,MathString,PowOpen);
                                        PowOpen = Maths.PowOpen(jparameters, PowOpen);
                                        if (paramCount == item.Parameter.Count)
                                        {
                                            Expression e = new Expression(MathString);
                                            var Calculation = e.Evaluate();
                                            bool DeciParse;
                                            decimal CalculationDeci;
                                            string Rounding;
                                            DeciParse = decimal.TryParse(Convert.ToString(Calculation), out CalculationDeci);
                                            Rounding = Convert.ToString(parameters.Rounding);

                                            if (Rounding == null || Rounding == "")
                                            {
                                                Rounding = "2";
                                            }
                                            if (DeciParse == true)
                                            {
                                                decimal Output = CalculationDeci;
                                                MathematicalFunctions MathematicalFunctions = new MathematicalFunctions();

                                                try
                                                {
                                                    Output = MathematicalFunctions.Rounding(Convert.ToString(parameters.RoundingType), Rounding, Output);
                                                }
                                                catch (Exception ex)
                                                {
                                                    logger.Error(ex);
                                                    throw new HttpException(ex.ToString());
                                                }

                                                item.Output = Convert.ToString(Output);
                                            }
                                            else
                                            {
                                                item.Output = "0";
                                            }
                                        }
                                        paramCount = paramCount + 1;
                                    }
                                    else if (item.Function == "ErrorsWarnings")
                                    {
                                        ErrorsWarnings Errors = new ErrorsWarnings();
                                        ErrorsWarnings parameters = (ErrorsWarnings)javaScriptSerializ­er.Deserialize(jparameters, typeof(ErrorsWarnings));
                                        item.Name = parameters.Type;
                                        item.Output = parameters.String1;
                                    }
                                    else if (item.Function == "Comments")
                                    {
                                        Comments Errors = new Comments();
                                        Comments parameters = (Comments)javaScriptSerializ­er.Deserialize(jparameters, typeof(Comments));
                                        item.Output = parameters.String1;
                                    }
                                    else if (item.Function == "Period")
                                    {
                                        DateFunctions DateFunctions = new DateFunctions();
                                        Period Periods = new Period();
                                        try
                                        {
                                            item.Output = Periods.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "Factors")
                                    {
                                        Factors Factors = new Factors();
                                        Factors parameters = (Factors)javaScriptSerializ­er.Deserialize(jparameters, typeof(Factors));
                                        try
                                        {
                                            item.Output = Factors.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        item.Type = parameters.OutputType;
                                    }
                                    else if (item.Function == "DateAdjustment")
                                    {
                                        Dates Dates = new Dates();
                                        try
                                        {
                                            item.Output = Dates.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "DatePart")
                                    {
                                        DatePart DateParts = new DatePart();
                                        try
                                        {
                                            item.Output = DateParts.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }

                                    else if (item.Function == "MathsFunctions")
                                    {
                                        MathsFunctions MathsFunctions = new MathsFunctions();
                                        try
                                        {
                                            item.Output = MathsFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }
                                    }
                                    else if (item.Function == "ArrayFunctions")
                                    {
                                        ArrayFunctions ArrayFunctions = new ArrayFunctions();
                                        ArrayFunctions parameters = (ArrayFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(ArrayFunctions));
                                        try
                                        {
                                            item.Output = ArrayFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        if(parameters.Function == "Count")
                                        {
                                            item.Type = "Decimal";
                                        }
                                        else
                                        {
                                            item.Type = parameters.LookupType;
                                        }

                                    }
                                    else if (item.Function == "StringFunctions")
                                    {
                                        StringFunctions StringFunctions = new StringFunctions();
                                        StringFunctions  parameters = (StringFunctions)javaScriptSerializ­er.Deserialize(jparameters, typeof(StringFunctions));
                                        try
                                        {
                                            item.Output = StringFunctions.Output(jparameters, jCategory, group.ID, item.ID);
                                        }
                                        catch (Exception ex)
                                        {
                                            logger.Error(ex);
                                            throw new HttpException(ex.ToString());
                                        }

                                        if(parameters.Type == "Len")
                                        {
                                            item.Type = "Decimal";
                                        }
                                        else
                                        {
                                            item.Type = "String";
                                        }
                                    }
                                }
                                //Expected results on the builder this sets the required ones
                                if (item.ExpectedResult == null || item.ExpectedResult == "")
                                {
                                    item.Pass = "******";
                                }
                                else if (item.ExpectedResult == item.Output)
                                {
                                    item.Pass = "******";
                                }
                                else
                                {
                                    item.Pass = "******";
                                }
                                OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                            }
                            else
                            {
                                //Ignores the row if logic is not met
                                dynamic LogicReplace = Config.VariableReplace(jCategory, item.Name, group.ID, item.ID);

                                if(Convert.ToString(LogicReplace) == Convert.ToString(item.Name))
                                {
                                    item.Output = null;
                                }
                                else
                                {
                                    item.Output = Convert.ToString(LogicReplace);
                                }
                                item.Pass = "******";

                                OutputList.Add(new OutputList { ID = Convert.ToString(item.ID), Field = item.Name, Value = item.Output, Group = group.Name });
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
 public static void Main(string [] args)
 {
     Maths mathie = new Maths();
     mathie.diffOfSumofSquare(100);
     Console.ReadKey();
 }