/// <summary> /// Performs the action, querying the state of the aircraft and typing the message /// </summary> /// <returns>False if an error occured, otherwise true</returns> bool performCoverMe() { try { Logger.log("Querying JSON-file for indicators"); string content = RemoteFile.Fetch("http://localhost:8111/indicators"); Logger.log("Succesfully retrieved JSON-file"); Logger.log("Deserializing JSON"); IndicatorsData data = IndicatorsData.FromJsonString(content); Logger.log("Done Deserializing"); if (!data.isValid()) { Logger.log("Data is invalid, aborting"); return(false); } int i_alt_in_m = data.getAltitudeMeters(); int i_alt_in_ft = (int)(i_alt_in_m / Helpers.METER_PER_FEET); Logger.log("-> Altitude_Meter = " + i_alt_in_m.ToString()); Logger.log("-> Altitude_Feet = " + i_alt_in_ft.ToString()); if (!data.isGoodAltiude()) { Logger.log("Altitude is exceeding the reasonable range, aborting"); return(false); } StringBuilder sb = new StringBuilder(); sb.Append(Helpers.RoundPreDecimal(i_alt_in_m, 2)); sb.Append(" m / "); sb.Append(Helpers.RoundPreDecimal(i_alt_in_ft, 2)); sb.Append(" ft"); if (typeHeading) { int hdg = data.getHeading(); Logger.log("-> Heading = " + hdg.ToString()); if (hdg != -1) { sb.Append(" HDG "); sb.Append(hdg); } else { Logger.log("Warning! Heading is -1, not appending"); } } else { Logger.log("-> Heading = Disabled"); } Logger.log("Sending virtual keystrokes"); if ((errorCode = SpecialKeyHelper.SimulateLongReturnPress()) != 0) { Logger.log("Could not insert InputEvents, ErrorCode " + errorCode.ToString()); return(false); } WindowsInput.InputSimulator.SimulateTextEntry(sb.ToString()); if ((errorCode = SpecialKeyHelper.SimulateLongReturnPress()) != 0) { Logger.log("Could not insert InputEvents, ErrorCode " + errorCode.ToString()); return(false); } return(true); } catch (Exception ex) { Logger.logException("Exception while fetching data", ex); return(false); } }