예제 #1
0
        public void ParseArguments(string[] args)
        {
            if (args != null)
            {
                foreach (string str in args)
                {
                    if (IsArgument(str))
                    {
                        string argumentValue;
                        var    argumentName = GetArgumentName(str, out argumentValue);
                        if (!string.IsNullOrEmpty(argumentName) && ArgumentsMap.ContainsKey(argumentName))
                        {
                            ArgumentsMap[argumentName].SetValue(ArgumentsSource, argumentValue);
                        }
                        else
                        {
                            ArgumentsSource.OnUnknownArgument(argumentName, argumentValue);
                        }
                    }
                    else
                    {
                        ArgumentsSource.OnInvalidArgument(str);
                    }
                }
            }

            ParseConfigArguments();
        }
예제 #2
0
 private void ParseConfigArguments()
 {
     foreach (var allKey in ConfigurationManager.AppSettings.AllKeys)
     {
         var upperInvariant = allKey.ToUpperInvariant();
         var appSetting     = ConfigurationManager.AppSettings[allKey];
         if (ArgumentsMap.ContainsKey(upperInvariant) && !ArgumentsMap[upperInvariant].IsSet)
         {
             ArgumentsMap[upperInvariant].SetValue(ArgumentsSource, appSetting);
         }
     }
 }
        public static double Calculate(TreeNode Node, ArgumentsMap Arguments)
        {
            if (Node is NumberNode)
            {
                return(((NumberNode)Node).Number);
            }
            else if (Node is ParameterNode)
            {
                string parameterName = ((ParameterNode)Node).Name;

                if (!Arguments.ContainsKey(parameterName))
                {
                    throw new System.Exception("Parameter [" + parameterName + "] doesn't supplied");
                }

                return(Arguments[parameterName]);
            }
            else if (Node is FunctionNode)
            {
                FunctionNode node = (FunctionNode)Node;

                return(PredefinedFunctions.Calculate(node.Name, node.Parameters, Arguments));
            }
            else if (Node is LogicalOperatorNode)
            {
                LogicalOperatorNode node = (LogicalOperatorNode)Node;

                double leftValue  = Calculate(node.LeftNode, Arguments);
                double rightValue = Calculate(node.RightNode, Arguments);

                switch (node.Operator)
                {
                case LogicalOperatorNode.Operators.Equal:
                    return(leftValue == rightValue ? 1 : 0);

                case LogicalOperatorNode.Operators.Greater:
                    return(leftValue > rightValue ? 1 : 0);

                case LogicalOperatorNode.Operators.Less:
                    return(leftValue < rightValue ? 1 : 0);

                case LogicalOperatorNode.Operators.GreaterEqual:
                    return(leftValue >= rightValue ? 1 : 0);

                case LogicalOperatorNode.Operators.LessEqual:
                    return(leftValue <= rightValue ? 1 : 0);

                default:
                    throw new System.Exception("Unknown Logical Operator type");
                }
            }
            else if (Node is ArithmeticOperatorNode)
            {
                ArithmeticOperatorNode node = (ArithmeticOperatorNode)Node;

                double leftValue  = Calculate(node.LeftNode, Arguments);
                double rightValue = Calculate(node.RightNode, Arguments);

                switch (node.Operator)
                {
                case ArithmeticOperatorNode.Operators.Addition:
                    return(leftValue + rightValue);

                case ArithmeticOperatorNode.Operators.Subtraction:
                    return(leftValue - rightValue);

                case ArithmeticOperatorNode.Operators.Multiplication:
                    return(leftValue * rightValue);

                case ArithmeticOperatorNode.Operators.Division:
                    return(leftValue / rightValue);

                case ArithmeticOperatorNode.Operators.Remainder:
                    return(leftValue % rightValue);

                case ArithmeticOperatorNode.Operators.Power:
                    return(System.Math.Pow(leftValue, rightValue));

                default:
                    throw new System.Exception("Unknown Arithmetic Operator type");
                }
            }

            throw new System.Exception("Unknown TreeNode type");
        }