private void ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
        {
            // resolve variable from formulas model.
            var recursiveFormula = (from p in _model.Formulas where p.Name == e.VariableName select p).SingleOrDefault();

            if (recursiveFormula != null)
            {
                // this variable is a formula. Recurvsively execute this formula.
                e.VariableValue = FormulaExpressionContext.Evaluate(this, ref _context, ref recursiveFormula, ref _parameters, OnQuestion, ref _model).Value.Infer();
                //var context = new FormulaExpressionContext(ref _model, ref _parameters, recursiveFormula, OnQuestion);
                //e.VariableValue = context.Evaluate().Value.Infer();
            }
            else
            {
                if (_parameters.Find(p => p.Name == e.VariableName) != null)
                {
                    return;
                }
                // this variable is an input variable. Provide a question to the client for an answer.
                if (OnQuestion == null)
                {
                    throw new Exception($"In order to evaluate variable '${e.VariableName}', you need to provide a delegate callback to the client for providing an answer");
                }
                OnQuestion(this, new QuestionArgs("", new ParametersCollection()
                {
                    new Parameter(e.VariableName, null, TypeInference.Infer(e.VariableType).Type, ref _model)
                }));
            }
        }
        void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
        {
            if (Feature == null) return;

            var value = Feature[e.VariableName];
            //if(value == null && e.VariableType.IsValueType)
            e.VariableValue = Convert.ChangeType(value, e.VariableType);
            //e.VariableValue = value;
        }
 private void ResolveVariableValue_MatchReGroups_Evaluate(object sender, ResolveVariableValueEventArgs e)
 {
     if (e.VariableName == "_4a11d5af8466473892e0998b3d4ad37a")
     {
         e.VariableValue = "123";
     }
     else if (e.VariableName == "_337fc4e428e84e0492db0af1f8af4459")
     {
         e.VariableValue = new DateTime(1980, 1, 1);
     }
 }
Exemple #4
0
 private static void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     if (e.VariableType == typeof(bool))
     {
         e.VariableValue = false;
     }
     else
     {
         e.VariableValue = 0;
     }
 }
        /// <summary>
        /// Return the value of the given variable if it exists in the data source
        /// </summary>
        /// <param name="sender">The input whose absolute value is to be found.</param>
        /// <param name="e">The input whose absolute value is to be found.</param>
        protected void variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
        {
            BaseColumn col = default(BaseColumn);

            // Default value is Nothing
            e.VariableValue = null;

            // If no DataSource was set, we do not have variables that we can use
            // directly. We should not get here since the request for Type should have
            // caught this.
            if (DataSource == null) return;

            try
            {
                // Find a column in the datasource using a variable name.
                col = DataSource.TableAccess.TableDefinition.ColumnList.GetByCodeName(e.VariableName);
                if (col == null)
                {
                    // if the variable name ended with "DefaultValue", remmove it and then try to get the column name again.
                    if (e.VariableName.ToLower().EndsWith("defaultvalue"))
                        col = DataSource.TableAccess.TableDefinition.ColumnList.GetByCodeName(e.VariableName.Substring(0, e.VariableName.Length - 12));

                    if (col != null)
                    {
                        switch (col.ColumnType)
                        {
                            case BaseColumn.ColumnTypes.Number:
                            case BaseColumn.ColumnTypes.Percentage:
                            case  BaseColumn.ColumnTypes.Star:
                                // The Number and Percentage values are saved as Single. So we first
                                // retrieve the Single value and then convert to Decimal. Our policy is
                                // always to return Decimal (never to return Single or Double) to be constent
                                // and avoid type conversion in the evaluator.
                                e.VariableValue = BaseFormulaUtils.ParseDecimal(col.DefaultValue);

                                break;
                            case BaseColumn.ColumnTypes.Currency:
                                e.VariableValue = BaseFormulaUtils.ParseDecimal(col.DefaultValue);

                                break;
                            case BaseColumn.ColumnTypes.Boolean:
                                e.VariableValue = col.DefaultValue;

                                break;
                            case BaseColumn.ColumnTypes.Credit_Card_Date:
                            case BaseColumn.ColumnTypes.Date:
                                e.VariableValue = BaseFormulaUtils.ParseDate(col.DefaultValue);

                                break;
                            case BaseColumn.ColumnTypes.Country:
                            case BaseColumn.ColumnTypes.Credit_Card_Number:
                            case BaseColumn.ColumnTypes.Email:
                            case BaseColumn.ColumnTypes.Password:
                            case BaseColumn.ColumnTypes.String:
                            case BaseColumn.ColumnTypes.Unique_Identifier:
                            case BaseColumn.ColumnTypes.USA_Phone_Number:
                            case BaseColumn.ColumnTypes.USA_State:
                            case BaseColumn.ColumnTypes.USA_Zip_Code:
                            case BaseColumn.ColumnTypes.Very_Large_String:
                            case BaseColumn.ColumnTypes.Web_Url:
                                e.VariableValue = col.DefaultValue;

                                break;
                            case BaseColumn.ColumnTypes.File:
                            case BaseColumn.ColumnTypes.Image:
                                // Can't do anything here.
                                e.VariableValue = null;

                                break;
                            default:
                                e.VariableValue = null;
                                break;
                        }
                    }
                }
                else
                {

                    switch (col.ColumnType)
                    {
                        case BaseColumn.ColumnTypes.Number:
                        case BaseColumn.ColumnTypes.Percentage:
                        case  BaseColumn.ColumnTypes.Star:
                            // The Number and Percentage values are saved as Single. So we first
                            // retrieve the Single value and then convert to Decimal. Our policy is
                            // always to return Decimal (never to return Single or Double) to be constent
                            // and avoid type conversion in the evaluator.
                            e.VariableValue = Decimal.Parse(this.DataSource.GetValue(col).ToDouble().ToString());

                            break;
                        case BaseColumn.ColumnTypes.Currency:
                            e.VariableValue = this.DataSource.GetValue(col).ToDecimal();

                            break;
                        case BaseColumn.ColumnTypes.Boolean:
                            e.VariableValue = this.DataSource.GetValue(col).ToBoolean();

                            break;
                        case BaseColumn.ColumnTypes.Credit_Card_Date:
                        case BaseColumn.ColumnTypes.Date:
                            e.VariableValue = this.DataSource.GetValue(col).ToDateTime();

                            break;
                        case BaseColumn.ColumnTypes.Country:
                        case BaseColumn.ColumnTypes.Credit_Card_Number:
                        case BaseColumn.ColumnTypes.Email:
                        case BaseColumn.ColumnTypes.Password:
                        case BaseColumn.ColumnTypes.String:
                        case BaseColumn.ColumnTypes.Unique_Identifier:
                        case BaseColumn.ColumnTypes.USA_Phone_Number:
                        case BaseColumn.ColumnTypes.USA_State:
                        case BaseColumn.ColumnTypes.USA_Zip_Code:
                        case BaseColumn.ColumnTypes.Very_Large_String:
                        case BaseColumn.ColumnTypes.Web_Url:
                            e.VariableValue = this.DataSource.GetValue(col).ToString();

                            break;
                        case BaseColumn.ColumnTypes.File:
                        case BaseColumn.ColumnTypes.Image:
                            // Can't do anything here.
                            e.VariableValue = null;

                            break;
                        default:
                            e.VariableValue = null;
                            break;
                    }

                }

            }
            catch (Exception)
            {
                // Ignore the error in case we cannot find the variable or its type - simply say that
                // the Variable Type is Nothing - implying that we do not recognize this variable.
            }
        }
Exemple #6
0
 void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = ResolveVariable(e.VariableName);
 }
Exemple #7
0
        /// <summary>
        /// Return the value of the given variable if it exists in the data source
        /// </summary>
        /// <param name="sender">The input whose absolute value is to be found.</param>
        /// <param name="e">The input whose absolute value is to be found.</param>
        protected void variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
        {
            BaseColumn col = default(BaseColumn);

            // Default value is Nothing
            e.VariableValue = null;

            // If no DataSource was set, we do not have variables that we can use
            // directly. We should not get here since the request for Type should have
            // caught this.
            if (DataSource == null)
            {
                return;
            }

            try
            {
                // Find a column in the datasource using a variable name.
                col = DataSource.TableAccess.TableDefinition.ColumnList.GetByCodeName(e.VariableName);
                if (col == null)
                {
                    // if the variable name ended with "DefaultValue", remmove it and then try to get the column name again.
                    if (e.VariableName.ToLower().EndsWith("defaultvalue"))
                    {
                        col = DataSource.TableAccess.TableDefinition.ColumnList.GetByCodeName(e.VariableName.Substring(0, e.VariableName.Length - 12));
                    }

                    if (col != null)
                    {
                        switch (col.ColumnType)
                        {
                        case BaseColumn.ColumnTypes.Number:
                        case BaseColumn.ColumnTypes.Percentage:
                        case  BaseColumn.ColumnTypes.Star:
                            // The Number and Percentage values are saved as Single. So we first
                            // retrieve the Single value and then convert to Decimal. Our policy is
                            // always to return Decimal (never to return Single or Double) to be constent
                            // and avoid type conversion in the evaluator.
                            e.VariableValue = BaseFormulaUtils.ParseDecimal(col.DefaultValue);

                            break;

                        case BaseColumn.ColumnTypes.Currency:
                            e.VariableValue = BaseFormulaUtils.ParseDecimal(col.DefaultValue);

                            break;

                        case BaseColumn.ColumnTypes.Boolean:
                            e.VariableValue = col.DefaultValue;

                            break;

                        case BaseColumn.ColumnTypes.Credit_Card_Date:
                        case BaseColumn.ColumnTypes.Date:
                            e.VariableValue = BaseFormulaUtils.ParseDate(col.DefaultValue);

                            break;

                        case BaseColumn.ColumnTypes.Country:
                        case BaseColumn.ColumnTypes.Credit_Card_Number:
                        case BaseColumn.ColumnTypes.Email:
                        case BaseColumn.ColumnTypes.Password:
                        case BaseColumn.ColumnTypes.String:
                        case BaseColumn.ColumnTypes.Unique_Identifier:
                        case BaseColumn.ColumnTypes.USA_Phone_Number:
                        case BaseColumn.ColumnTypes.USA_State:
                        case BaseColumn.ColumnTypes.USA_Zip_Code:
                        case BaseColumn.ColumnTypes.Very_Large_String:
                        case BaseColumn.ColumnTypes.Web_Url:
                            e.VariableValue = col.DefaultValue;

                            break;

                        case BaseColumn.ColumnTypes.File:
                        case BaseColumn.ColumnTypes.Image:
                            // Can't do anything here.
                            e.VariableValue = null;

                            break;

                        default:
                            e.VariableValue = null;
                            break;
                        }
                    }
                }
                else
                {
                    switch (col.ColumnType)
                    {
                    case BaseColumn.ColumnTypes.Number:
                    case BaseColumn.ColumnTypes.Percentage:
                    case  BaseColumn.ColumnTypes.Star:
                        // The Number and Percentage values are saved as Single. So we first
                        // retrieve the Single value and then convert to Decimal. Our policy is
                        // always to return Decimal (never to return Single or Double) to be constent
                        // and avoid type conversion in the evaluator.
                        e.VariableValue = Decimal.Parse(this.DataSource.GetValue(col).ToDouble().ToString());

                        break;

                    case BaseColumn.ColumnTypes.Currency:
                        e.VariableValue = this.DataSource.GetValue(col).ToDecimal();

                        break;

                    case BaseColumn.ColumnTypes.Boolean:
                        e.VariableValue = this.DataSource.GetValue(col).ToBoolean();

                        break;

                    case BaseColumn.ColumnTypes.Credit_Card_Date:
                    case BaseColumn.ColumnTypes.Date:
                        e.VariableValue = this.DataSource.GetValue(col).ToDateTime();

                        break;

                    case BaseColumn.ColumnTypes.Country:
                    case BaseColumn.ColumnTypes.Credit_Card_Number:
                    case BaseColumn.ColumnTypes.Email:
                    case BaseColumn.ColumnTypes.Password:
                    case BaseColumn.ColumnTypes.String:
                    case BaseColumn.ColumnTypes.Unique_Identifier:
                    case BaseColumn.ColumnTypes.USA_Phone_Number:
                    case BaseColumn.ColumnTypes.USA_State:
                    case BaseColumn.ColumnTypes.USA_Zip_Code:
                    case BaseColumn.ColumnTypes.Very_Large_String:
                    case BaseColumn.ColumnTypes.Web_Url:
                        e.VariableValue = this.DataSource.GetValue(col).ToString();

                        break;

                    case BaseColumn.ColumnTypes.File:
                    case BaseColumn.ColumnTypes.Image:
                        // Can't do anything here.
                        e.VariableValue = null;

                        break;

                    default:
                        e.VariableValue = null;
                        break;
                    }
                }
            }
            catch (Exception)
            {
                // Ignore the error in case we cannot find the variable or its type - simply say that
                // the Variable Type is Nothing - implying that we do not recognize this variable.
            }
        }
 static void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     // Supply the value of the column in the current row
     e.VariableValue = MyCurrentRow[e.VariableName];
 }
 void GetVariablesInternal_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = 0;
 }
Exemple #10
0
 private void Formula_Simple_Calculation_Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = Convert.ToDouble(7);
 }
 private void OnResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = 100;
 }
Exemple #12
0
 private static void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = "CZ12345678";
 }
Exemple #13
0
 void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     e.VariableValue = ResolveVariable(e.VariableName);
 }
Exemple #14
0
 static void Variables_ResolveVariableValue(object sender, ResolveVariableValueEventArgs e)
 {
     // Supply the value of the column in the current row
     e.VariableValue = MyCurrentRow[e.VariableName];
 }