public SetVariableResponse HandleSetVariableRequest(SetVariableArguments args) { SampleVariable variable = this.variables.FirstOrDefault(v => String.Equals(v.Name, args.Name, StringComparison.Ordinal)); if (variable == null) { throw new ProtocolException(Invariant($"Scope '{this.Name}' (varRef: {this.VariableReference}) does not contain a variable called '{args.Name}'!")); } variable.SetValue(args.Value); variable.Invalidate(); return(new SetVariableResponse(value: variable.GetValue(args.Format?.Hex ?? false))); }
internal void AddChild(SampleVariable variable) { this.children.Add(variable); variable.SetContainer(this); }
internal void AddVariable(SampleVariable variable) { this.variables.Add(variable); variable.SetContainer(this); }
private EvaluateResponse Evaluate(string expression, string value, ValueFormat format) { ISampleVariableContainer container = null; string variableName = null; if (!expression.Contains("~")) { // Not a delimted expression = assume we're using the locals scope container = this.localsScope; variableName = expression; } else { List <string> evalParts = expression.Split('~').Select(p => p.Trim()).ToList(); variableName = evalParts.Last(); // Right now, we only support expressions that retrieve variables foreach (string part in evalParts.Take(evalParts.Count - 1)) { if (container == null) { container = this.AllScopes.FirstOrDefault(s => String.Equals(s.Name, part, StringComparison.Ordinal)); } else { container = container.ChildContainers.FirstOrDefault(c => String.Equals(c.Name, part, StringComparison.Ordinal)); } if (container == null) { throw new ProtocolException("Evaluation failed!"); } } } SampleVariable variable = container.Variables.FirstOrDefault(v => String.Equals(v.Name, variableName, StringComparison.Ordinal)); if (variable == null) { throw new ProtocolException("Evaluation failed!"); } if (value != null) { if (variable.IsReadOnly) { throw new ProtocolException("Expression is read-only."); } variable.SetValue(value); } VariablePresentationHint presentationHint = null; if (variable.IsReadOnly) { presentationHint = new VariablePresentationHint { Attributes = VariablePresentationHint.AttributesValue.ReadOnly }; } return(new EvaluateResponse( presentationHint: presentationHint, result: variable.GetValue(format?.Hex ?? false), variablesReference: variable.VariableReference, type: variable.Type)); }