private void ResolveVariableType(object sender, ResolveVariableTypeEventArgs 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. // var context = new FormulaExpressionContext(ref _model, ref _parameters, recursiveFormula, OnQuestion); e.VariableType = typeof(double); } 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) })); } }
private static void Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { if (e.VariableName.StartsWith("VARBOOL")) { e.VariableType = typeof(bool); } else { e.VariableType = typeof(int); } }
private void ResolveVariableType_MatchReGroups_Evaluate(object sender, ResolveVariableTypeEventArgs e) { if (e.VariableName == "_4a11d5af8466473892e0998b3d4ad37a") { e.VariableType = typeof(string); } else if (e.VariableName == "_337fc4e428e84e0492db0af1f8af4459") { e.VariableType = typeof(DateTime); } }
private void Variables_ResolveVariableTypeNullableBool(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(bool?); }
private void Variables_ResolveVariableTypeDate(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(DateTime); }
private void Variables_ResolveVariableTypeDouble(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(double); }
private void Variables_ResolveVariableTypeIntNullable(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(int?); }
private void Variables_ResolveVariableTypeString(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(string); }
void Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { Type type = GetVariableType(e.VariableName); e.VariableType = type; }
private void Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { if(FeatureType != null) e.VariableType = FeatureType.GetAttributeType(e.VariableName); }
static void Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { // Simply supply the type of the column with the given name e.VariableType = MyTable.Columns[e.VariableName].DataType; }
void GetVariablesInternal_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(double); }
private void Formula_Simple_Calculation_Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(double); }
private void OnResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { e.VariableType = typeof(int); }
/// <summary> /// Return the type of the given variable if it exists in the data source. /// If the Return Type is Nothing, the evaluator assumes this is an invalid /// variable and tries other methods to get its value. /// </summary> /// <param name="sender">The sender that sent this event.</param> /// <param name="e">The event argument. Set e.VariableType.</param> protected void variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { BaseColumn col = null; // Returning Nothing indicates that we do not recognize this variable. e.VariableType = null; // If no DataSource was set, we do not have variables that we can use // directly. 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) { return; } switch (col.ColumnType) { case BaseColumn.ColumnTypes.Number: case BaseColumn.ColumnTypes.Percentage: case BaseColumn.ColumnTypes.Star: // By default, all our internal data types use Decimal. // This may result in problems when using the Math library // but it reduces the problem by allowing us to loosely-type // all data source properties. e.VariableType = typeof(decimal); break; case BaseColumn.ColumnTypes.Currency: // Convert currency into decimal to allow easier use in formulas e.VariableType = typeof(decimal); break; case BaseColumn.ColumnTypes.Boolean: // Boolean data types are maintained as Boolean and not // converted to Integer as the Binary data type is. e.VariableType = typeof(bool); break; case BaseColumn.ColumnTypes.Credit_Card_Date: case BaseColumn.ColumnTypes.Date: // Use DateTme even for Credit Card Date. e.VariableType = typeof(DateTime); 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: // For the purpose of formula's, all of the above field types // are treated as strings. e.VariableType = typeof(string); break; case BaseColumn.ColumnTypes.Binary: case BaseColumn.ColumnTypes.File: case BaseColumn.ColumnTypes.Image: // For the purpose of formula's we ignore BLOB fields since they // cannot be used in any calculations or string functions. e.VariableType = null; break; default: // Unknown data type. e.VariableType = 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. } }
/// <summary> /// Return the type of the given variable if it exists in the data source. /// If the Return Type is Nothing, the evaluator assumes this is an invalid /// variable and tries other methods to get its value. /// </summary> /// <param name="sender">The sender that sent this event.</param> /// <param name="e">The event argument. Set e.VariableType.</param> protected void variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e) { BaseColumn col = null; // Returning Nothing indicates that we do not recognize this variable. e.VariableType = null; // If no DataSource was set, we do not have variables that we can use // directly. 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) return; switch (col.ColumnType) { case BaseColumn.ColumnTypes.Number: case BaseColumn.ColumnTypes.Percentage: case BaseColumn.ColumnTypes.Star: // By default, all our internal data types use Decimal. // This may result in problems when using the Math library // but it reduces the problem by allowing us to loosely-type // all data source properties. e.VariableType = typeof(decimal); break; case BaseColumn.ColumnTypes.Currency: // Convert currency into decimal to allow easier use in formulas e.VariableType = typeof(decimal); break; case BaseColumn.ColumnTypes.Boolean: // Boolean data types are maintained as Boolean and not // converted to Integer as the Binary data type is. e.VariableType = typeof(bool); break; case BaseColumn.ColumnTypes.Credit_Card_Date: case BaseColumn.ColumnTypes.Date: // Use DateTme even for Credit Card Date. e.VariableType = typeof(DateTime); 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: // For the purpose of formula's, all of the above field types // are treated as strings. e.VariableType = typeof(string); break; case BaseColumn.ColumnTypes.Binary: case BaseColumn.ColumnTypes.File: case BaseColumn.ColumnTypes.Image: // For the purpose of formula's we ignore BLOB fields since they // cannot be used in any calculations or string functions. e.VariableType = null; break; default: // Unknown data type. e.VariableType = 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. } }