private async Task SendAsync() { await ExecuteAsync(async() => { AddStatusMessage("Sending..."); if (ParseBeforeSend) { this.InputJson = ParseInput(this.InputJson, this.Variables); } var timeoutCancellationToken = _operationTimeout.ToCancellationToken(); var envelopeViewModel = new EnvelopeViewModel(false); envelopeViewModel.Json = InputJson; var envelope = envelopeViewModel.Envelope; envelopeViewModel.Direction = DataOperation.Send; if (SendAsRaw) { envelopeViewModel.IsRaw = true; var stream = TcpClient.GetStream(); var envelopeBytes = Encoding.UTF8.GetBytes(envelopeViewModel.Json); await stream.WriteAsync(envelopeBytes, 0, envelopeBytes.Length, timeoutCancellationToken); } else { await Transport.SendAsync(envelope, timeoutCancellationToken); envelopeViewModel.IndentJson(); } this.Envelopes.Add(envelopeViewModel); if (this.ClearAfterSent) { this.InputJson = string.Empty; } AddStatusMessage(string.Format("{0} envelope sent", envelope.GetType().Name)); }); }
private async Task SendAsync() { await ExecuteAsync(async () => { AddStatusMessage("Sending..."); if (ParseBeforeSend) { this.InputJson = ParseInput(this.InputJson, this.Variables); } var timeoutCancellationToken = _operationTimeout.ToCancellationToken(); var envelopeViewModel = new EnvelopeViewModel(false); envelopeViewModel.Json = InputJson; var envelope = envelopeViewModel.Envelope; envelopeViewModel.Direction = DataOperation.Send; if (SendAsRaw) { envelopeViewModel.IsRaw = true; var stream = TcpClient.GetStream(); var envelopeBytes = Encoding.UTF8.GetBytes(envelopeViewModel.Json); await stream.WriteAsync(envelopeBytes, 0, envelopeBytes.Length, timeoutCancellationToken); } else { await Transport.SendAsync(envelope, timeoutCancellationToken); envelopeViewModel.IndentJson(); } this.Envelopes.Add(envelopeViewModel); if (this.ClearAfterSent) { this.InputJson = string.Empty; } AddStatusMessage(string.Format("{0} envelope sent", envelope.GetType().Name)); }); }
private async Task SendAsync(object parameter) { var times = 0; var repeatCountVariable = Variables.FirstOrDefault(v => v.Name == "repeatCount"); if (repeatCountVariable == null) { repeatCountVariable = new VariableViewModel() { Name = "repeatCount" }; Variables.Add(repeatCountVariable); } do { repeatCountVariable.Value = (times + 1).ToString(); await ExecuteAsync(async() => { AddStatusMessage("Sending..."); var inputJson = parameter.ToString(); if (ParseBeforeSend) { inputJson = ParseInput(inputJson, Variables); } var timeoutCancellationToken = _operationTimeout.ToCancellationToken(); var envelopeViewModel = new EnvelopeViewModel(false); envelopeViewModel.Json = inputJson; var envelope = envelopeViewModel.Envelope; envelopeViewModel.Direction = DataOperation.Send; if (SendAsRaw) { envelopeViewModel.IsRaw = true; var stream = TcpClient.GetStream(); var envelopeBytes = Encoding.UTF8.GetBytes(envelopeViewModel.Json); await stream.WriteAsync(envelopeBytes, 0, envelopeBytes.Length, timeoutCancellationToken); } else { await Transport.SendAsync(envelope, timeoutCancellationToken); envelopeViewModel.IndentJson(); } Envelopes.Add(envelopeViewModel); if (ClearAfterSent) { InputJson = string.Empty; } AddStatusMessage(string.Format("{0} envelope sent", envelope.GetType().Name)); }); } while (Repeat && RepeatTimes > ++times); }