public IAsyncResult BeginWaitForMessage(TimeSpan timeout, AsyncCallback callback, object state) { return(innerInputChannel.BeginWaitForMessage(timeout, callback, state)); }
private Message ReceiveMessage(IInputChannel channel, bool commit) { Message message = null; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { bool messageDetected = false; if (this.Parameters.AsyncWaitForMessage) { IAsyncResult result = channel.BeginWaitForMessage(this.Parameters.WaitForMessageTimeout, null, null); messageDetected = channel.EndWaitForMessage(result); } else { messageDetected = channel.WaitForMessage(this.Parameters.WaitForMessageTimeout); } if (this.Parameters.WaitForMessage) { lock (this.Results) { this.Results.Add(String.Format("WaitForMessage returned {0}", messageDetected)); } } if (messageDetected) { if (this.Parameters.AsyncReceive) { if (this.Parameters.TryReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); bool ret = channel.EndTryReceive(result, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { IAsyncResult result = channel.BeginReceive(this.Parameters.ReceiveTimeout, null, null); message = channel.EndReceive(result); } catch (TimeoutException) { message = null; } } } else { if (this.Parameters.TryReceive) { bool ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { message = channel.Receive(this.Parameters.ReceiveTimeout); } catch (TimeoutException) { message = null; } } } } else { if (this.Parameters.TryReceive) { bool ret = false; if (this.Parameters.AsyncReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); if (this.Parameters.TryReceiveNullIAsyncResult) { try { channel.EndTryReceive(null, out message); } catch (Exception e) { lock (this.Results) { this.Results.Add(String.Format("TryReceive threw {0}", e.GetType().Name)); } } } ret = channel.EndTryReceive(result, out message); } else { ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); } lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); this.Results.Add(String.Format("Message was {0}", (message == null ? "null" : "not null"))); } } message = null; } if (commit && message != null) { lock (this.Results) { this.Results.Add(String.Format("Received message with Action '{0}'", message.Headers.Action)); } ts.Complete(); } else { Transaction.Current.Rollback(); } } return message; }
private Message ReceiveMessage(IInputChannel channel, bool commit) { Message message = null; using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required)) { bool messageDetected = false; if (this.Parameters.AsyncWaitForMessage) { IAsyncResult result = channel.BeginWaitForMessage(this.Parameters.WaitForMessageTimeout, null, null); messageDetected = channel.EndWaitForMessage(result); } else { messageDetected = channel.WaitForMessage(this.Parameters.WaitForMessageTimeout); } if (this.Parameters.WaitForMessage) { lock (this.Results) { this.Results.Add(String.Format("WaitForMessage returned {0}", messageDetected)); } } if (messageDetected) { if (this.Parameters.AsyncReceive) { if (this.Parameters.TryReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); bool ret = channel.EndTryReceive(result, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { IAsyncResult result = channel.BeginReceive(this.Parameters.ReceiveTimeout, null, null); message = channel.EndReceive(result); } catch (TimeoutException) { message = null; } } } else { if (this.Parameters.TryReceive) { bool ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); } } else { try { message = channel.Receive(this.Parameters.ReceiveTimeout); } catch (TimeoutException) { message = null; } } } } else { if (this.Parameters.TryReceive) { bool ret = false; if (this.Parameters.AsyncReceive) { IAsyncResult result = channel.BeginTryReceive(this.Parameters.ReceiveTimeout, null, null); if (this.Parameters.TryReceiveNullIAsyncResult) { try { channel.EndTryReceive(null, out message); } catch (Exception e) { lock (this.Results) { this.Results.Add(String.Format("TryReceive threw {0}", e.GetType().Name)); } } } ret = channel.EndTryReceive(result, out message); } else { ret = channel.TryReceive(this.Parameters.ReceiveTimeout, out message); } lock (this.Results) { this.Results.Add(String.Format("TryReceive returned {0}", ret)); this.Results.Add(String.Format("Message was {0}", (message == null ? "null" : "not null"))); } } message = null; } if (commit && message != null) { lock (this.Results) { this.Results.Add(String.Format("Received message with Action '{0}'", message.Headers.Action)); } ts.Complete(); } else { Transaction.Current.Rollback(); } } return(message); }