Esempio n. 1
0
        /// <summary>
        /// Requests that the message should not be delivered before the specified time.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <param name="at">The time when this message should be made available.</param>
        public static void DoNotDeliverBefore(this SendOptions options, DateTimeOffset at)
        {
            Guard.AgainstNull(nameof(options), options);

            if (options.GetExtensions().TryGetDeliveryConstraint(out DelayDeliveryWith _))
            {
                throw new InvalidOperationException($"The options are already configured for delayed delivery by the '{nameof(DelayDeliveryWith)}' API.");
            }

            options.GetExtensions().AddDeliveryConstraint(new DoNotDeliverBefore(at.UtcDateTime));
        }
Esempio n. 2
0
        /// <summary>
        /// Delays the delivery of the message with the specified delay.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <param name="delay">The requested delay.</param>
        public static void DelayDeliveryWith(this SendOptions options, TimeSpan delay)
        {
            Guard.AgainstNull(nameof(options), options);
            Guard.AgainstNegative(nameof(delay), delay);

            if (options.GetExtensions().TryGetDeliveryConstraint(out DoNotDeliverBefore _))
            {
                throw new InvalidOperationException($"The options are already configured for delayed delivery by the '{nameof(DoNotDeliverBefore)}' API.");
            }

            options.GetExtensions().AddDeliveryConstraint(new DelayDeliveryWith(delay));
        }
        /// <summary>
        /// Delays the delivery of the message with the specified delay.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <param name="delay">The requested delay.</param>
        public static void DelayDeliveryWith(this SendOptions options, TimeSpan delay)
        {
            Guard.AgainstNull(nameof(options), options);
            Guard.AgainstNegative(nameof(delay), delay);

            options.GetExtensions().AddDeliveryConstraint(new DelayDeliveryWith(delay));
        }
        /// <summary>
        /// Returns the delivery date configured by using <see cref="DoNotDeliverBefore" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="DateTimeOffset" /> or <c>null</c>.</returns>
        public static DateTimeOffset?GetDeliveryDate(this SendOptions options)
        {
            DoNotDeliverBefore deliveryDate;

            options.GetExtensions().TryGetDeliveryConstraint(out deliveryDate);

            return(deliveryDate?.At);
        }
        /// <summary>
        /// Returns the configured delivery delay by using <see cref="DelayDeliveryWith" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="TimeSpan" /> or <c>null</c>.</returns>
        public static TimeSpan?GetDeliveryDelay(this SendOptions options)
        {
            DelayDeliveryWith delay;

            options.GetExtensions().TryGetDeliveryConstraint(out delay);

            return(delay?.Delay);
        }
        /// <summary>
        /// Returns the delivery date configured by using <see cref="DoNotDeliverBefore" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="DateTimeOffset" /> or <c>null</c>.</returns>
        public static DateTimeOffset?GetDeliveryDate(this SendOptions options)
        {
            Guard.AgainstNull(nameof(options), options);
            DoNotDeliverBefore deliveryDate;

            options.GetExtensions().TryGetDeliveryConstraint(out deliveryDate);

            return(deliveryDate?.At);
        }
        /// <summary>
        /// Returns the configured delivery delay by using <see cref="DelayDeliveryWith" />.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <returns>The configured <see cref="TimeSpan" /> or <c>null</c>.</returns>
        public static TimeSpan?GetDeliveryDelay(this SendOptions options)
        {
            Guard.AgainstNull(nameof(options), options);
            DelayDeliveryWith delay;

            options.GetExtensions().TryGetDeliveryConstraint(out delay);

            return(delay?.Delay);
        }
Esempio n. 8
0
        /// <summary>
        /// Instructs NServiceBus to send a given message to remote site(s).
        /// </summary>
        public static void SendToSites(this SendOptions options, params string[] sites)
        {
            if (sites.Length == 0)
            {
                throw new Exception("When sending to sites at least one site name has to be specified.");
            }
            var state = options.GetExtensions().GetOrCreate <RouteToSitesBehavior.State>();

            state.Sites = sites;
        }
Esempio n. 9
0
        /// <summary>
        /// Enables the use of custom SqlTransaction instances for send operations. The same transaction can be used in more than one send operation.
        /// </summary>
        /// <param name="options">The <see cref="SendOptions" /> to extend.</param>
        /// <param name="transaction">SqlTransaction instance that will be used by any operations performed by the transport.</param>
        public static void UseCustomSqlTransaction(this SendOptions options, SqlTransaction transaction)
        {
            // When dispatching, the TransportTransaction is overwritten.
            // The only way for a custom transaction to work is by using immediate dispatch and messages should only appear when the user commits the custom transaction.
            // Which is exactly what will happen after NServiceBus dispatches this message immediately.
            options.RequireImmediateDispatch();

            var transportTransaction = new TransportTransaction();

            transportTransaction.Set(SettingsKeys.IsUserProvidedTransactionKey, true);
            transportTransaction.Set(SettingsKeys.TransportTransactionSqlConnectionKey, transaction.Connection);
            transportTransaction.Set(SettingsKeys.TransportTransactionSqlTransactionKey, transaction);
            options.GetExtensions().Set(transportTransaction);
        }
Esempio n. 10
0
        /// <summary>
        /// Enables the use of custom SqlConnection for send operations.
        /// </summary>
        /// <param name="options">The <see cref="SendOptions" /> to extend.</param>
        /// <param name="connection">SqlConnection instance that will be used by any operations performed by the transport.</param>
        public static void UseCustomSqlConnection(this SendOptions options, SqlConnection connection)
        {
            if (connection == null)
            {
                throw new ArgumentException(nameof(connection));
            }

            options.RequireImmediateDispatch();

            var transportTransaction = new TransportTransaction();

            transportTransaction.Set(SettingsKeys.IsUserProvidedTransactionKey, true);
            transportTransaction.Set(SettingsKeys.TransportTransactionSqlConnectionKey, connection);

            options.GetExtensions().Set(transportTransaction);
        }
        /// <summary>
        /// Requests that the message should not be delivered before the specified time.
        /// </summary>
        /// <param name="options">The options being extended.</param>
        /// <param name="at">The time when this message should be made available.</param>
        public static void DoNotDeliverBefore(this SendOptions options, DateTimeOffset at)
        {
            Guard.AgainstNull(nameof(options), options);

            options.GetExtensions().AddDeliveryConstraint(new DoNotDeliverBefore(at.UtcDateTime));
        }
Esempio n. 12
0
 /// <summary>
 /// Route the message through the Gateway to the specified sites.
 /// </summary>
 public static void RouteToSites(this SendOptions options, params string[] siteKeys)
 {
     options.SetHeader(Headers.DestinationSites, string.Join(",", siteKeys));
     options.GetExtensions().Set(new RouteThroughGateway());
     options.RouteToThisEndpoint();
 }