ToUtcDateTime() public static method

Converts a wire formatted string from ToWireFormattedString to a UTC DateTime.
public static ToUtcDateTime ( string wireFormattedString ) : System.DateTime
wireFormattedString string
return System.DateTime
        public async Task Invoke(MessageContext context)
        {
            var sagaId = Guid.Empty;

            string sagaIdString;

            if (context.Headers.TryGetValue(Headers.SagaId, out sagaIdString))
            {
                sagaId = Guid.Parse(sagaIdString);
            }

            if (context.Headers.ContainsKey(TimeoutManagerHeaders.ClearTimeouts))
            {
                if (sagaId == Guid.Empty)
                {
                    throw new InvalidOperationException("Invalid saga id specified, clear timeouts is only supported for saga instances");
                }

                await persister.RemoveTimeoutBy(sagaId, context.Context).ConfigureAwait(false);
            }
            else
            {
                string expire;
                if (!context.Headers.TryGetValue(TimeoutManagerHeaders.Expire, out expire))
                {
                    throw new InvalidOperationException("Non timeout message arrived at the timeout manager, id:" + context.MessageId);
                }

                var destination = GetReplyToAddress(context);

                string routeExpiredTimeoutTo;
                if (context.Headers.TryGetValue(TimeoutManagerHeaders.RouteExpiredTimeoutTo, out routeExpiredTimeoutTo))
                {
                    destination = routeExpiredTimeoutTo;
                }

                var data = new TimeoutData
                {
                    Destination          = destination,
                    SagaId               = sagaId,
                    State                = context.Body,
                    Time                 = DateTimeExtensions.ToUtcDateTime(expire),
                    Headers              = context.Headers,
                    OwningTimeoutManager = owningTimeoutManager
                };

                if (data.Time.AddSeconds(-1) <= DateTime.UtcNow)
                {
                    var outgoingMessage    = new OutgoingMessage(context.MessageId, data.Headers, data.State);
                    var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(data.Destination));
                    await dispatcher.Dispatch(new TransportOperations(transportOperation), context.TransportTransaction, context.Context).ConfigureAwait(false);

                    return;
                }

                await persister.Add(data, context.Context).ConfigureAwait(false);

                poller.NewTimeoutRegistered(data.Time);
            }
        }
        static List <DeliveryConstraint> DeserializeConstraints(Dictionary <string, string> options)
        {
            var constraints = new List <DeliveryConstraint>(4);

            if (options.ContainsKey("NonDurable"))
            {
                constraints.Add(new NonDurableDelivery());
            }

            if (options.TryGetValue("DeliverAt", out var deliverAt))
            {
                constraints.Add(new DoNotDeliverBefore(DateTimeExtensions.ToUtcDateTime(deliverAt)));
            }

            if (options.TryGetValue("DelayDeliveryFor", out var delay))
            {
                constraints.Add(new DelayDeliveryWith(TimeSpan.Parse(delay)));
            }

            if (options.TryGetValue("TimeToBeReceived", out var ttbr))
            {
                constraints.Add(new DiscardIfNotReceivedBefore(TimeSpan.Parse(ttbr)));
            }
            return(constraints);
        }
Example #3
0
        static bool HasReachedMaxTime(IncomingMessage message)
        {
            string timestampHeader;

            if (!message.Headers.TryGetValue(Headers.DelayedRetriesTimestamp, out timestampHeader))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(timestampHeader))
            {
                return(false);
            }

            try
            {
                var handledAt = DateTimeExtensions.ToUtcDateTime(timestampHeader);

                var now = DateTime.UtcNow;
                if (now > handledAt.AddDays(1))
                {
                    return(true);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            // this code won't usually throw but in case a user has decided to hack a message/headers and for some bizarre reason
            // they changed the date and that parse fails, we want to make sure that doesn't prevent the message from being
            // forwarded to the error queue.
            catch (Exception)
            {
            }

            return(false);
        }
Example #4
0
        public async Task Invoke(IIncomingPhysicalMessageContext context, Func <IIncomingPhysicalMessageContext, Task> next)
        {
            var state = new State();

            string timeSentString;
            var    headers = context.Message.Headers;

            if (headers.TryGetValue(Headers.TimeSent, out timeSentString))
            {
                state.TimeSent = DateTimeExtensions.ToUtcDateTime(timeSentString);
            }

            state.ProcessingStarted = DateTime.UtcNow;
            context.Extensions.Set(state);
            var stopwatch = Stopwatch.StartNew();

            try
            {
                await next(context).ConfigureAwait(false);
            }
            finally
            {
                stopwatch.Stop();
                state.ProcessingEnded = state.ProcessingStarted + stopwatch.Elapsed;
            }
        }
Example #5
0
        public void Invoke(IncomingContext context, Action next)
        {
            string timeSentString;
            var    headers = context.PhysicalMessage.Headers;

            if (headers.TryGetValue(Headers.TimeSent, out timeSentString))
            {
                context.Set("IncomingMessage.TimeSent", DateTimeExtensions.ToUtcDateTime(timeSentString));
            }

            context.Set("IncomingMessage.ProcessingStarted", DateTime.UtcNow);

            try
            {
                next();
            }
            finally
            {
                context.Set("IncomingMessage.ProcessingEnded", DateTime.UtcNow);
            }
        }