private async Task ReceiveEnvelopeAsync(Envelope envelope, Dispatcher dispatcher) { var envelopeViewModel = new EnvelopeViewModel(); envelopeViewModel.Envelope = envelope; envelopeViewModel.Direction = DataOperation.Receive; await await dispatcher.InvokeAsync(async () => { this.Envelopes.Add(envelopeViewModel); foreach (var macro in Macros.Where(m => m.IsActive)) { await macro.Macro.ProcessAsync(envelopeViewModel, this); } }); }
public static string ExecuteSerialization(IEnvelopeSerializer serializer, Envelope envelope, int count) { string json = null; var sw = System.Diagnostics.Stopwatch.StartNew(); for (int i = 0; i < count; i++) { json = serializer.Serialize(envelope); } sw.Stop(); System.Console.WriteLine("{0}: {1} ms", serializer.GetType().Name, sw.ElapsedMilliseconds); return json; }
/// <summary> /// Sends an envelope to /// the connected node /// </summary> /// <param name="envelope">Envelope to be transported</param> /// <param name="cancellationToken"></param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override async Task SendAsync(Envelope envelope, CancellationToken cancellationToken) { if (envelope == null) { throw new ArgumentNullException("envelope"); } if (_stream == null || !_stream.CanWrite) { throw new InvalidOperationException("Invalid stream state. Call OpenAsync first."); } var envelopeJson = _envelopeSerializer.Serialize(envelope); if (_traceWriter != null && _traceWriter.IsEnabled) { await _traceWriter.TraceAsync(envelopeJson, DataOperation.Send).ConfigureAwait(false); } var jsonBytes = Encoding.UTF8.GetBytes(envelopeJson); await _sendSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false); try { await _stream.WriteAsync(jsonBytes, 0, jsonBytes.Length, cancellationToken).ConfigureAwait(false); } finally { _sendSemaphore.Release(); } }
/// <summary> /// Gets the sender node of the envelope. /// </summary> /// <param name="envelope">The envelope.</param> /// <returns></returns> public static Node GetSender(this Envelope envelope) { return(envelope.Pp ?? envelope.From); }