Пример #1
0
        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));
            }
        }
Пример #2
0
 public virtual string GetVariableValue(string name)
 {
     if (!VariableExists(name))
     {
         return(null);
     }
     return(CustomVariablesConfiguration.IsGlobalVariable(name) ? globalVariableMap[name] : localVariableMap[name]);
 }
Пример #3
0
 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));
 }
Пример #4
0
        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);
            }
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        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));
            }
        }
Пример #7
0
 public CustomVariableManager(CustomVariablesConfiguration config)
 {
     this.config       = config;
     globalVariableMap = new SerializableLiteralStringMap();
     localVariableMap  = new SerializableLiteralStringMap();
 }
Пример #8
0
 public bool VariableExists(string name) => CustomVariablesConfiguration.IsGlobalVariable(name) ? globalVariableMap.ContainsKey(name) : localVariableMap.ContainsKey(name);