Ejemplo n.º 1
0
        /// <summary>
        /// Sends the with return.
        /// </summary>
        /// <param name="executeTimeout">The execute timeout.</param>
        /// <param name="endpoint">The endpoint.</param>
        /// <param name="messages">The messages.</param>
        /// <returns></returns>
        public override int SendWithReturn(int executeTimeout, IServiceBusEndpoint endpoint, params object[] messages)
        {
            if (messages == null || messages.Length == 0 || messages[0] == null)
            {
                throw new ArgumentNullException("messages", "Please include at least one message.");
            }
            IAsyncResult asyncResult;

            try
            {
                if (endpoint == null)
                {
                    asyncResult = Bus.Send(NServiceBusTransport.Wrap(messages)).Register(state => { }, null);
                }
                if (endpoint != ServiceBus.SelfEndpoint)
                {
                    asyncResult = Bus.Send(NServiceBusTransport.Cast(endpoint), NServiceBusTransport.Wrap(messages)).Register(state => { }, null);
                }
                else
                {
                    throw new NotSupportedException();
                }
            }
            catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); }
            if (!asyncResult.AsyncWaitHandle.WaitOne(executeTimeout))
            {
                throw new TimeoutException();
            }
            return(((CompletionResult)asyncResult.AsyncState).ErrorCode);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Subscribes the specified message type.
        /// </summary>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="predicate">The predicate.</param>
        public override void Subscribe(Type messageType, Predicate <object> predicate)
        {
            if (messageType == null)
            {
                throw new ArgumentNullException("messageType");
            }
            try
            {
                if (predicate == null)
                {
                    Bus.Subscribe(NServiceBusTransport.Wrap(messageType));
                }
                else
                {
                    Bus.Subscribe(NServiceBusTransport.Wrap(messageType),
#if !CLR4
                                  NServiceBusTransport.Cast(predicate)
#else
                                  predicate
#endif
                                  );
                }
            }
            catch (Exception ex) { throw new ServiceBusMessageException(messageType, ex); }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Unsubscribes the specified message type.
 /// </summary>
 /// <param name="messageType">Type of the message.</param>
 public override void Unsubscribe(Type messageType)
 {
     if (messageType == null)
     {
         throw new ArgumentNullException("messageType");
     }
     try { Bus.Unsubscribe(NServiceBusTransport.Wrap(messageType)); }
     catch (Exception ex) { throw new ServiceBusMessageException(messageType, ex); }
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Publishes the specified messages.
 /// </summary>
 /// <param name="messages">The messages.</param>
 public override void Publish(params object[] messages)
 {
     if (messages == null || messages.Length == 0 || messages[0] == null)
     {
         throw new ArgumentNullException("messages");
     }
     try { Bus.Publish(NServiceBusTransport.Wrap(messages)); }
     catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); }
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Replies the specified messages.
 /// </summary>
 /// <param name="messages">The messages.</param>
 public override void Reply(params object[] messages)
 {
     if (messages == null || messages.Length == 0 || messages[0] == null)
     {
         throw new ArgumentNullException("messages", "Please include at least one message.");
     }
     try { Bus.Reply(NServiceBusTransport.Wrap(messages)); }
     catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); }
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Sends the specified endpoint.
 /// </summary>
 /// <param name="endpoint">The endpoint.</param>
 /// <param name="messages">The messages.</param>
 /// <returns></returns>
 public override IServiceBusCallback Send(IServiceBusEndpoint endpoint, params object[] messages)
 {
     if (messages == null || messages.Length == 0 || messages[0] == null)
     {
         throw new ArgumentNullException("messages", "Please include at least one message.");
     }
     try
     {
         if (endpoint == null)
         {
             Bus.Send(NServiceBusTransport.Wrap(messages));
         }
         else if (endpoint != ServiceBus.SelfEndpoint)
         {
             Bus.Send(NServiceBusTransport.Cast(endpoint), NServiceBusTransport.Wrap(messages));
         }
         else
         {
             Bus.SendLocal(NServiceBusTransport.Wrap(messages));
         }
     }
     catch (Exception ex) { throw new ServiceBusMessageException(messages[0].GetType(), ex); }
     return(null);
 }