Beispiel #1
0
        public static bool GetVariableValue(Interpreter interpreter, string variableName, bool global, ref VariableWithValue result)
        {
            if (interpreter == null)
            {
                throw new ArgumentNullException(nameof(interpreter));
            }
            if (string.IsNullOrWhiteSpace(variableName))
            {
                throw new ArgumentException("Value cannot be null or whitespace.", nameof(variableName));
            }

            var        scopedName = $"{(global ? "::" : string.Empty)}{variableName}";
            ReturnCode code;
            Result     tclResult = null;

            if (ArrayExists(interpreter, scopedName))
            {
                IDictionary <string, string> arrayResult = new Dictionary <string, string>();
                code = ReadArray(interpreter, ref arrayResult, scopedName) ? ReturnCode.Ok : ReturnCode.Error;
                var singleResult = string.Join(", ", arrayResult.Select(kvp => $"{kvp.Key}: {kvp.Value}"));
                result = new VariableWithValue(variableName, singleResult, arrayResult.Select(kvp => new VariableWithValue(kvp.Key, kvp.Value)));
            }
            else
            {
                code   = interpreter.EvaluateScript($"set {scopedName}", ref tclResult);
                result = new VariableWithValue(variableName, tclResult);
            }

            return(code == ReturnCode.Ok);
        }
Beispiel #2
0
        public static IReadOnlyCollection <VariableWithValue> GetVariableValues(Interpreter interpreter, bool excludeReserved)
        {
            if (interpreter == null)
            {
                throw new ArgumentNullException(nameof(interpreter));
            }

            Result result = null;
            var    code   = interpreter.EvaluateScript("info vars", ref result);

            if (code != ReturnCode.Ok)
            {
                return(Enumerable.Empty <VariableWithValue>().ToList());
            }

            var variables           = result.String.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            var variablesWithValues = new List <VariableWithValue>();

            foreach (var variable in variables)
            {
                if (excludeReserved && TclReservedVariables.All.Contains(variable))
                {
                    //exclude reserved variable
                    continue;
                }
                VariableWithValue variableWithValue = null;
                if (GetVariableValue(interpreter, variable, true, ref variableWithValue) &&
                    !string.IsNullOrWhiteSpace(variableWithValue.Value))
                {
                    variablesWithValues.Add(variableWithValue);
                }
            }

            return(variablesWithValues);
        }
Beispiel #3
0
 public static WatchVariableViewModel Map(VariableWithValue variableWithValue)
 {
     if (variableWithValue.HasSubValues)
     {
         return(new WatchVariableViewModel(variableWithValue.Variable, variableWithValue.Value, variableWithValue.SubValues.Select(Map)));
     }
     return(new WatchVariableViewModel(variableWithValue.Variable, variableWithValue.Value));
 }