private bool xpExecute(string commandlist) { bool success = true; string[] commands = commandlist.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries); //process conditionals bool conditional = true; foreach (string command in commands) { if (command.Contains("?")) { string[] symbols = command.Trim(new char[] { '?' }).Split(new string[] { "=" }, StringSplitOptions.None); if (symbols.Length == 2) { bool invert = false; bool lt = false; bool gt = false; if (symbols[0].Contains('!')) { invert = true; symbols[0] = symbols[0].Replace("!", ""); } if (symbols[0].Contains('<')) { lt = true; symbols[0] = symbols[0].Replace("<", ""); } if (symbols[0].Contains('>')) { gt = true; symbols[0] = symbols[0].Replace(">", ""); } Debug.Print(symbols[0]); Debug.Print(symbols[1]); string refname = symbols[0]; double value = stringToDouble(symbols[1]); double result = 0; try { int type = xplm.XPLMGetDataRefTypes(refname); if (type == 1) { result = xplm.XPLMGetDatai(refname); } else if (type == 2) { result = xplm.XPLMGetDataf(refname); } else if (type == 4) { result = xplm.XPLMGetDatad(refname); } else { xpInitMessage = "Unknown type " + Convert.ToString(type) + ": " + refname; Debug.Print(xpInitMessage); success = false; conditional = false; } } catch (Exception ex) { xpInitMessage = ex.Message; success = false; conditional = false; } if (success) { conditional = (result == value); if (lt) { conditional = (result <= value); } if (gt) { conditional = (result >= value); } if (invert) { conditional = !conditional; } } } } } // process commands if (conditional) { foreach (string command in commands) { if (!command.Contains("?")) { string[] symbols = command.Split(new string[] { "=" }, StringSplitOptions.None); if (symbols.Length == 2) { string refname = symbols[0]; double value = stringToDouble(symbols[1]); bool canWrite = false; for (int i = 0; i < 2 && !canWrite; i++) { canWrite = (xplm.XPLMCanWriteDataRef(refname) > 0); } if (canWrite) { try { int type = xplm.XPLMGetDataRefTypes(refname); if (type == 1) { xplm.XPLMSetDatai(refname, Convert.ToInt16(value)); } else if (type == 2) { xplm.XPLMSetDataf(refname, Convert.ToSingle(value)); } else if (type == 4) { xplm.XPLMSetDatad(refname, value); } else { xpInitMessage = "Unknown type " + Convert.ToString(type) + ": " + refname; Debug.Print(xpInitMessage); success = false; } } catch (Exception ex) { xpInitMessage = ex.Message; Debug.Print(xpInitMessage); success = false; } } else { xpInitMessage = "Not writeable: " + refname; Debug.Print(xpInitMessage); success = false; } } } } } else { Debug.Print("skipping previous step because conditional evaluated to false"); } return(success); }
private void btXPLMGetDataRefTypes_Click(object sender, EventArgs e) { int res = da.XPLMGetDataRefTypes(tbDataRef.Text); this.textBox1.Text = res.ToString(); }