public void Intercept(IInvocation invocation) { object result = null; if (invocation.Method.Name.Trim().ToLower() == m_gateway_definition.Method.Trim().ToLower()) { this.GetChannels(invocation); this.ForwardToChannel(m_gateway_definition, invocation.Arguments); if (invocation.Method.ReturnType != typeof(void)) { var replyChannel = m_container.Resolve<IChannelRegistry>() .FindChannel(m_gateway_definition.ReplyChannel); if (!(replyChannel is NullChannel)) { IEnvelope message = new NullEnvelope(); if (m_gateway_definition.ReceiveTimeout != 0) message = replyChannel.Receive(m_gateway_definition.ReceiveTimeout); else { // note: default poll for five minutes (in seconds) for a response on gateway message = replyChannel.Receive(); } if (!(message is NullEnvelope)) result = message.Body.GetPayload<object>(); } } invocation.ReturnValue = result; } }
public override IEnvelope DoReceive() { IEnvelope receivedMessage = new NullEnvelope(); // since this is the "consuming" side of SQL messages, only SELECT is accepted: if (!m_sql_channel.ContextProvider.QueryText.Trim().ToLower().StartsWith("select")) return receivedMessage; try { using (var cxn = m_sql_channel.ContextProvider.GetConnection()) using (var cmd = new OleDbCommand(m_sql_channel.ContextProvider.QueryText, cxn)) { var dataSet = new DataSet(); var adapter = new OleDbDataAdapter(cmd); cxn.Open(); using (var txn = cxn.BeginTransaction()) { try { cmd.Transaction = txn; adapter.Fill(dataSet); //var reader = cmd.ExecuteReader(); receivedMessage = new Envelope(dataSet); if (dataSet.Tables.Count > 0) if (dataSet.Tables[0].Rows.Count > 0) receivedMessage.Header.SequenceSize = dataSet.Tables[0].Rows.Count; txn.Commit(); } catch (Exception exception) { txn.Rollback(); throw; } } } } catch (Exception exception) { throw; } return receivedMessage; }
/// <summary> /// This will poll a location for a message over a given interval in seconds. /// </summary> /// <param name="timeout">Interval in seconds (positive) to poll the location for a message.</param> /// <returns> /// /// </returns> /// <exception cref="ReceiveTimeoutPeriodExeceededException">Received timeout period exception.</exception> public IEnvelope Receive(int timeout) { IEnvelope envelope = new NullEnvelope(); Timer timer = null; try { if (timeout < 0) throw new ArgumentNullException("timeout", "The timeout value must be a positive integer representing the interval in seconds."); timer = new Timer(timeout * 1000); timer.Elapsed += TimerElasped; while (true) { timer.Start(); // retreive the enveloped message from the location: envelope = DoReceive(); if (envelope != null) break; if (m_is_duration_exceeded) break; System.Threading.Thread.Sleep(100); } timer.Elapsed -= TimerElasped; timer.Stop(); if (m_message_to_receive.GetType() != typeof(NullEnvelope)) { OnMessageReceived(m_message_to_receive); return m_message_to_receive; } if (m_is_duration_exceeded) throw new ReceiveTimeoutPeriodExeceededException(); // we have the message, trigger the listeners: OnMessageSent(envelope); } catch (Exception exception) { if (!OnChannelError(exception)) throw; } return envelope; }
static GATEnvelope() { nullEnvelope = new NullEnvelope(); }
public IEnvelope DoSendAndReceive(string sendLocation, string receiveLocation, IEnvelope message, int timeout) { IEnvelope retval = new NullEnvelope(); var wait = new ManualResetEvent(false); try { // send the message: this.DoSend(sendLocation, message); wait.WaitOne(TimeSpan.FromSeconds(timeout)); wait.Set(); // retrieve the message: retval = this.DoReceive(receiveLocation); } catch (Exception exception) { throw; } return retval; }