/// <summary> /// Begin monitoring the variable with the specified name using this client. /// </summary> /// <param name="name">The name of the variable to monitor.</param> /// <returns>The variable being monitored if it was added successfully, or <c>null</c> otherwise.</returns> public ISimVariable AddVariable(string name) { if (SimVariables.byName.ContainsKey(name)) { // Do not re-add the variable if it was already added by another client ISimVariable addedVariable = SimVariables.byName[name]; if (!Variables.Contains(addedVariable)) { if (connection != null) { addedVariable.Register(connection); } lock (globalLock) { Variables.Add(addedVariable); LogMessage(SimConnectMessage.MessageStatus.Information, $"Started monitoring variable {name}."); } } return(addedVariable); } else { LogMessage(SimConnectMessage.MessageStatus.Warning, $"Cannot monitor nonexistent variable {name}."); return(null); } }
/// <summary>Execute a message of type <c>ADD_VARIABLE</c>.</summary> private void ExecuteAddVariable(Dictionary <string, object> request) { string name = (string)request["variable"]; ISimVariable variable = simClient.AddVariable(name); if (variable != null) { // Variable was added successfully, send the client its information SendMessage(new { type = "DECLARE_VARIABLE", name = variable.Name, id = variable.Id, unit = variable.Unit }); } else { // The user requested a nonexistent variable SendErrorMessage($"Cannot monitor unknown variable ${name}"); } }