public virtual void SetVariableValue(string name, string value) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Variable name cannot be null or empty.", nameof(name)); } var isGlobal = CustomVariablesConfiguration.IsGlobalVariable(name); var initialValue = default(string); if (isGlobal) { globalVariableMap.TryGetValue(name, out initialValue); globalVariableMap[name] = value; } else { localVariableMap.TryGetValue(name, out initialValue); localVariableMap[name] = value; } if (initialValue != value) { OnVariableUpdated?.Invoke(new CustomVariableUpdatedArgs(name, value, initialValue)); } }
public virtual string GetVariableValue(string name) { if (!VariableExists(name)) { return(null); } return(CustomVariablesConfiguration.IsGlobalVariable(name) ? globalVariableMap[name] : localVariableMap[name]); }
public virtual bool VariableExists(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Variable name cannot be null or empty.", nameof(name)); } return(CustomVariablesConfiguration.IsGlobalVariable(name) ? globalVariableMap.ContainsKey(name) : localVariableMap.ContainsKey(name)); }
public virtual void ResetGlobalVariables() { globalVariableMap?.Clear(); foreach (var varData in Configuration.PredefinedVariables) { if (!CustomVariablesConfiguration.IsGlobalVariable(varData.Name)) { continue; } var value = ExpressionEvaluator.Evaluate <string>(varData.Value, e => LogInitializeVarError(varData.Name, varData.Value, e)); SetVariableValue(varData.Name, value); } }
/// <summary> /// Attempts to retrieve value of a variable with the provided name and type. Variable names are case-insensitive. /// When no variables of the provided name are found or when the string value can't be parsed to the requested type, will return false. /// </summary> public static bool TryGetVariableValue <TValue> (this ICustomVariableManager manager, string name, out TValue value) { value = default; var stringValue = manager.GetVariableValue(name); if (stringValue is null) { return(false); } var objValue = CustomVariablesConfiguration.ParseVariableValue(stringValue); if (objValue is TValue) { value = (TValue)objValue; return(true); } return(false); }
public void SetVariableValue(string name, string value) { var isGlobal = CustomVariablesConfiguration.IsGlobalVariable(name); var initialValue = default(string); if (isGlobal) { globalVariableMap.TryGetValue(name, out initialValue); globalVariableMap[name] = value; } else { localVariableMap.TryGetValue(name, out initialValue); localVariableMap[name] = value; } if (initialValue != value) { OnVariableUpdated?.Invoke(new CustomVariableUpdatedArgs(name, value, initialValue)); } }
public CustomVariableManager(CustomVariablesConfiguration config) { this.config = config; globalVariableMap = new SerializableLiteralStringMap(); localVariableMap = new SerializableLiteralStringMap(); }
public bool VariableExists(string name) => CustomVariablesConfiguration.IsGlobalVariable(name) ? globalVariableMap.ContainsKey(name) : localVariableMap.ContainsKey(name);