private async Task <int> executeCommandAsync(string command, string data = null, bool getResponse = true, bool force = false) { ConnectTicker = 0; if (IsCanceled && !force) { commandIn = false; return(0); } int response = 0; string fullCommand; if (data.NullEmpty()) { fullCommand = command; } else { fullCommand = command + ' ' + data; } if (commandIn) { while (commandIn && !IsCanceled) { await Task.Delay(200); } } commandIn = true; byte[] buffer = _encoding.GetBytes(fullCommand + "\r\n"); try { await ControlStream.WriteAsync(buffer, 0, buffer.Length); } catch { commandIn = false; return(0); } if (getResponse) { bool notify = true; if ("PASS FEAT CLNT SYST".Contains(command)) { if (command == "PASS") { InfoMessage("PASS *** Hidden ***", MessageType.Sent); } else { notify = false; } } else { InfoMessage(fullCommand, MessageType.Sent); } response = await getResponseAsync(notify, force); } commandIn = false; return(response); }
public async Task WriteElevationRequest(ElevationRequest elevationRequest) { // Using Binary instead of Newtonsoft.JSON to reduce load times. var ms = new System.IO.MemoryStream(); new BinaryFormatter() { TypeFormat = System.Runtime.Serialization.Formatters.FormatterTypeStyle.TypesAlways, Binder = new MySerializationBinder() } .Serialize(ms, elevationRequest); ms.Seek(0, System.IO.SeekOrigin.Begin); byte[] lengthArray = BitConverter.GetBytes(ms.Length); Logger.Instance.Log($"ElevationRequest length {ms.Length}", LogLevel.Debug); await ControlStream.WriteAsync(lengthArray, 0, sizeof(int)).ConfigureAwait(false); await ControlStream.WriteAsync(ms.ToArray(), 0, (int)ms.Length).ConfigureAwait(false); await ControlStream.FlushAsync().ConfigureAwait(false); }