private static async Task <bool> SendToSignalR(IAsyncCollector <SignalRMessage> signalRMessages, ILogger log, DateTimeOffset readAtUtc, double temperature, Weather weather) { try { await signalRMessages.AddAsync( new SignalRMessage { Target = "notifyCurrentWeatherUpdated", Arguments = new object[] { new { city = City, timestampWest = DateTimeOffsetHelper.ConvertToWest(readAtUtc), temperature, weatherId = weather.id, weatherDescription = weather.description, weatherIcon = weather.icon } } }); return(true); } catch (Exception e) { log.LogError(e, "Error when sending current weather to signalr"); return(false); } }
public Task Handle(TestCommand message, IMessageHandlerContext context) { testContext.CommandHandled = true; testContext.TimeSent = DateTimeOffsetHelper.ToDateTimeOffset(context.MessageHeaders[Headers.TimeSent]); testContext.MessageId = context.MessageId; return(Task.FromResult(0)); }
public static void SetExceptionHeaders(Dictionary <string, string> headers, Exception e) { headers["NServiceBus.ExceptionInfo.ExceptionType"] = e.GetType().FullName; if (e.InnerException != null) { headers["NServiceBus.ExceptionInfo.InnerExceptionType"] = e.InnerException.GetType().FullName; } headers["NServiceBus.ExceptionInfo.HelpLink"] = e.HelpLink; headers["NServiceBus.ExceptionInfo.Message"] = e.GetMessage().Truncate(16384); headers["NServiceBus.ExceptionInfo.Source"] = e.Source; headers["NServiceBus.ExceptionInfo.StackTrace"] = e.ToString(); headers["NServiceBus.TimeOfFailure"] = DateTimeOffsetHelper.ToWireFormattedString(DateTimeOffset.UtcNow); // ReSharper disable once ConditionIsAlwaysTrueOrFalse if (e.Data == null) // ReSharper disable HeuristicUnreachableCode { return; } // ReSharper restore HeuristicUnreachableCode foreach (DictionaryEntry entry in e.Data) { if (entry.Value == null) { continue; } headers["NServiceBus.ExceptionInfo.Data." + entry.Key] = entry.Value.ToString(); } }
public async Task Should_honor_stored_delivery_constraints() { var messageId = "id"; var options = new Dictionary <string, string>(); var deliverTime = DateTimeOffset.UtcNow.AddDays(1); var maxTime = TimeSpan.FromDays(1); options["Destination"] = "test"; options["DeliverAt"] = DateTimeOffsetHelper.ToWireFormattedString(deliverTime); options["DelayDeliveryFor"] = TimeSpan.FromSeconds(10).ToString(); options["TimeToBeReceived"] = maxTime.ToString(); fakeOutbox.ExistingMessage = new OutboxMessage(messageId, new[] { new NServiceBus.Outbox.TransportOperation("x", options, new byte[0], new Dictionary <string, string>()) }); var context = CreateContext(fakeBatchPipeline, messageId); await Invoke(context); Assert.True(fakeBatchPipeline.TransportOperations.First().DeliveryConstraints.TryGet(out DelayDeliveryWith delayDeliveryWith)); Assert.AreEqual(TimeSpan.FromSeconds(10), delayDeliveryWith.Delay); Assert.True(fakeBatchPipeline.TransportOperations.First().DeliveryConstraints.TryGet(out DoNotDeliverBefore doNotDeliverBefore)); Assert.AreEqual(deliverTime.ToString(), doNotDeliverBefore.At.ToString()); Assert.True(fakeBatchPipeline.TransportOperations.First().DeliveryConstraints.TryGet(out DiscardIfNotReceivedBefore discard)); Assert.AreEqual(maxTime, discard.MaxTime); Assert.Null(fakeOutbox.StoredMessage); }
public async Task SetAsync_Test() { const string key = "Key"; await using (var serviceProvider = await this.CreateServiceProviderAsync()) { serviceProvider.SetTime(await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000)); var sqliteCache = (SqliteCache)serviceProvider.GetRequiredService <IDistributedCache>(); await sqliteCache.SetAsync(key, Array.Empty <byte>()); await using (var sqliteCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <SqliteCacheContext> >().CreateDbContext()) { Assert.AreEqual(1, await sqliteCacheContext.Cache.CountAsync()); var cacheEntry = await sqliteCacheContext.Cache.FindAsync(key); Assert.IsNull(cacheEntry.AbsoluteExpiration); Assert.AreEqual(await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000, minute: 20), cacheEntry.ExpiresAtTime); Assert.AreEqual(key, cacheEntry.Id); Assert.AreEqual(Convert.ToInt64(TimeSpan.FromMinutes(20).TotalSeconds), cacheEntry.SlidingExpirationInSeconds); Assert.IsTrue(Array.Empty <byte>().SequenceEqual(cacheEntry.Value)); } } }
public async Task Set_Test() { var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); await using (var serviceProvider = await this.CreateServiceProviderAsync(now)) { var sqlServerCacheOptions = serviceProvider.GetRequiredService <IOptions <SqlServerCacheOptions> >().Value; Assert.AreEqual(TimeSpan.FromMinutes(20), sqlServerCacheOptions.DefaultSlidingExpiration); Assert.IsNull(sqlServerCacheOptions.ExpiredItemsDeletionInterval); var sqlServerCache = (SqlServerCache)serviceProvider.GetRequiredService <IDistributedCache>(); // ReSharper disable MethodHasAsyncOverload sqlServerCache.Set("1", Array.Empty <byte>(), new DistributedCacheEntryOptions()); // ReSharper restore MethodHasAsyncOverload using (var scope = serviceProvider.CreateScope()) { var sqlServerCacheContext = scope.ServiceProvider.GetRequiredService <SqlServerCacheContext>(); Assert.AreEqual(1, await sqlServerCacheContext.Cache.CountAsync()); var cacheEntry = await sqlServerCacheContext.Cache.FindAsync("1"); Assert.IsNotNull(cacheEntry); Assert.IsNull(cacheEntry.AbsoluteExpiration); Assert.AreEqual(now.Add(sqlServerCacheOptions.DefaultSlidingExpiration), cacheEntry.ExpiresAtTime); Assert.AreEqual("1", cacheEntry.Id); Assert.AreEqual((uint)sqlServerCacheOptions.DefaultSlidingExpiration.TotalSeconds, cacheEntry.SlidingExpirationInSeconds); Assert.IsTrue(Array.Empty <byte>().SequenceEqual(cacheEntry.Value)); } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var jsonValue = serializer.Deserialize <JValue>(reader); switch (jsonValue.Type) { case JTokenType.Integer: var dto = DateTimeOffsetHelper.FromUnixTimeSeconds(jsonValue.Value <long>()); if (objectType == DateTimeOffsetType || (objectType.IsNullable() && Nullable.GetUnderlyingType(objectType) == DateTimeOffsetType)) { return(dto); } return(dto.LocalDateTime); case JTokenType.Date: if (objectType == DateTimeOffsetType || (objectType.IsNullable() && Nullable.GetUnderlyingType(objectType) == DateTimeOffsetType)) { return(jsonValue.Value <DateTimeOffset>()); } return(jsonValue.Value <DateTime>()); case JTokenType.Null: if (objectType.IsNullable()) { return(null); } throw new JsonSerializationException($"Can't deserialize null value to non-nullable type"); default: throw new JsonSerializationException($"Unexpected token {jsonValue.Type} when parsing a date."); } }
internal static SagaChangeInitiator BuildSagaChangeInitiatorMessage(IReadOnlyDictionary <string, string> headers, string messageId, string messageType) { headers.TryGetValue(Headers.OriginatingMachine, out var originatingMachine); headers.TryGetValue(Headers.OriginatingEndpoint, out var originatingEndpoint); var timeSent = headers.TryGetValue(Headers.TimeSent, out var timeSentHeaderValue) ? DateTimeOffsetHelper.ToDateTimeOffset(timeSentHeaderValue) : DateTimeOffset.MinValue; var intent = headers.TryGetValue(Headers.MessageIntent, out var messageIntent) ? messageIntent : "Send"; // Just in case the received message is from an early version that does not have intent, should be a rare occasion. var isTimeoutMessage = headers.TryGetValue(Headers.IsSagaTimeoutMessage, out var isTimeout) && isTimeout.ToLowerInvariant() == "true"; return(new SagaChangeInitiator { IsSagaTimeoutMessage = isTimeoutMessage, InitiatingMessageId = messageId, OriginatingMachine = originatingMachine, OriginatingEndpoint = originatingEndpoint, MessageType = messageType, TimeSent = timeSent.UtcDateTime, Intent = intent }); }
public async Task Should_update_retry_headers_when_present() { var delayedRetryExecutor = CreateExecutor(); var originalHeadersTimestamp = DateTimeOffsetHelper.ToWireFormattedString(new DateTime(2012, 12, 12, 0, 0, 0, DateTimeKind.Utc)); var incomingMessage = CreateMessage(new Dictionary <string, string> { { Headers.DelayedRetries, "2" }, { Headers.DelayedRetriesTimestamp, originalHeadersTimestamp } }); var now = DateTime.UtcNow; await delayedRetryExecutor.Retry(incomingMessage, TimeSpan.Zero, new TransportTransaction(), default); var outgoingMessageHeaders = dispatcher.UnicastTransportOperations.Single().Message.Headers; Assert.AreEqual("3", outgoingMessageHeaders[Headers.DelayedRetries]); Assert.AreEqual("2", incomingMessage.Headers[Headers.DelayedRetries]); var utcDateTime = DateTimeOffsetHelper.ToDateTimeOffset(outgoingMessageHeaders[Headers.DelayedRetriesTimestamp]); // the serialization removes precision which may lead to now being greater than the deserialized header value var adjustedNow = DateTimeOffsetHelper.ToDateTimeOffset(DateTimeOffsetHelper.ToWireFormattedString(now)); Assert.That(utcDateTime, Is.GreaterThanOrEqualTo(adjustedNow)); Assert.AreEqual(originalHeadersTimestamp, incomingMessage.Headers[Headers.DelayedRetriesTimestamp]); }
public async Task GetAsync_Test() { const string key = "Key"; await using (var serviceProvider = await this.CreateServiceProviderAsync()) { var sqliteCache = (SqliteCache)serviceProvider.GetRequiredService <IDistributedCache>(); var value = await sqliteCache.GetAsync(key); Assert.IsNull(value); await sqliteCache.SetAsync(key, Array.Empty <byte>()); value = await sqliteCache.GetAsync(key); Assert.IsNotNull(value); var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); serviceProvider.SetTime(now); await sqliteCache.SetAsync(key, Array.Empty <byte>(), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(1) }); serviceProvider.SetTime(now.AddSeconds(2)); value = await sqliteCache.GetAsync(key); Assert.IsNull(value); } }
public async Task Message_should_not_be_processed() { var tcs = new Lazy <CancellationTokenSource>(() => new CancellationTokenSource(TimeSpan.FromSeconds(5))); var context = await Scenario.Define <Context>() .WithEndpoint <SomeEndpoint>(endpoint => endpoint .CustomConfig(e => { var transportConfig = (MsmqTransport)e.ConfigureTransport(); transportConfig.IgnoreIncomingTimeToBeReceivedHeaders = false; }) .When(async(session, ctx) => { var sendOptions = new SendOptions(); sendOptions.RouteToThisEndpoint(); sendOptions.SetHeader(Headers.TimeSent, DateTimeOffsetHelper.ToWireFormattedString(DateTime.UtcNow.AddSeconds(-10))); sendOptions.SetHeader(Headers.TimeToBeReceived, TimeSpan.FromSeconds(5).ToString()); await session.Send(new SomeMessage(), sendOptions); ctx.WasSent = true; }) ) .Done(c => tcs.Value.IsCancellationRequested) // wait at least 5 seconds to give the endpoint time to process any message .Run(); Assert.IsTrue(context.WasSent, "Message was sent"); Assert.IsFalse(context.WasReceived, "Message was processed"); }
public async Task Should_contain_processing_stats_headers() { var now = DateTimeOffset.UtcNow; var context = await Scenario.Define <Context>() .WithEndpoint <EndpointWithAuditOn>(b => b.When(session => session.SendLocal(new MessageToBeAudited())).DoNotFailOnErrorMessages()) .WithEndpoint <EndpointThatHandlesAuditMessages>() .WithEndpoint <EndpointThatHandlesErrorMessages>() .Done(c => c.IsMessageHandledByTheAuditEndpoint && c.IsMessageHandledByTheFaultEndpoint) .Run(); var processingStarted = DateTimeOffsetHelper.ToDateTimeOffset(context.Headers[Headers.ProcessingStarted]); var processingEnded = DateTimeOffsetHelper.ToDateTimeOffset(context.Headers[Headers.ProcessingEnded]); var timeSent = DateTimeOffsetHelper.ToDateTimeOffset(context.Headers[Headers.TimeSent]); var timeSentWhenFailedMessageWasSentToTheErrorQueue = DateTimeOffsetHelper.ToDateTimeOffset(context.FaultHeaders[Headers.TimeSent]); Assert.That(processingStarted, Is.EqualTo(now).Within(TimeSpan.FromSeconds(30)), nameof(processingStarted)); Assert.That(processingEnded, Is.EqualTo(now).Within(TimeSpan.FromSeconds(30)), nameof(processingEnded)); Assert.That(timeSent, Is.EqualTo(now).Within(TimeSpan.FromSeconds(30)), nameof(timeSent)); Assert.That(timeSentWhenFailedMessageWasSentToTheErrorQueue, Is.EqualTo(now).Within(TimeSpan.FromSeconds(30)), nameof(timeSentWhenFailedMessageWasSentToTheErrorQueue)); Assert.That(timeSent, Is.LessThanOrEqualTo(processingEnded), nameof(processingEnded)); Assert.That(timeSent, Is.LessThanOrEqualTo(timeSentWhenFailedMessageWasSentToTheErrorQueue), nameof(timeSentWhenFailedMessageWasSentToTheErrorQueue)); Assert.That(timeSentWhenFailedMessageWasSentToTheErrorQueue, Is.EqualTo(context.TimeSentOnTheFailingMessageWhenItWasHandled), nameof(timeSentWhenFailedMessageWasSentToTheErrorQueue)); Assert.That(processingStarted, Is.LessThanOrEqualTo(processingEnded), nameof(processingStarted)); Assert.IsTrue(context.IsMessageHandledByTheFaultEndpoint, nameof(context.IsMessageHandledByTheFaultEndpoint)); }
public async Task Get_Test() { const string key = "Key"; await using (var serviceProvider = await this.CreateServiceProviderAsync()) { // ReSharper disable MethodHasAsyncOverload var dateTimeOffsetContextCache = (DateTimeOffsetCacheMock)serviceProvider.GetRequiredService <IDistributedCache>(); var value = dateTimeOffsetContextCache.Get(key); Assert.IsNull(value); dateTimeOffsetContextCache.Set(key, Array.Empty <byte>()); value = dateTimeOffsetContextCache.Get(key); Assert.IsNotNull(value); var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); serviceProvider.SetTime(now); dateTimeOffsetContextCache.Set(key, Array.Empty <byte>(), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(1) }); serviceProvider.SetTime(now.AddSeconds(2)); value = dateTimeOffsetContextCache.Get(key); Assert.IsNull(value); // ReSharper restore MethodHasAsyncOverload } }
public async Task Refresh_Test() { const string key = "Key"; await using (var serviceProvider = await this.CreateServiceProviderAsync()) { var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); serviceProvider.SetTime(now); var dateTimeOffsetContextCache = (DateTimeOffsetCacheMock)serviceProvider.GetRequiredService <IDistributedCache>(); // ReSharper disable All dateTimeOffsetContextCache.Set(key, Array.Empty <byte>(), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(1) }); using (var dateTimeOffsetCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <DateTimeOffsetCacheContext> >().CreateDbContext()) { var cacheEntry = dateTimeOffsetCacheContext.Cache.Find(key); Assert.AreEqual(now.AddSeconds(1), cacheEntry.ExpiresAtTime); } serviceProvider.SetTime(now.AddSeconds(1)); dateTimeOffsetContextCache.Refresh(key); using (var dateTimeOffsetCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <DateTimeOffsetCacheContext> >().CreateDbContext()) { var cacheEntry = dateTimeOffsetCacheContext.Cache.Find(key); Assert.AreEqual(now.AddSeconds(2), cacheEntry.ExpiresAtTime); } // ReSharper restore All } }
public async Task RemoveExpiredCacheEntriesAsync_Test() { var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); await using (var serviceProvider = await this.CreateServiceProviderAsync()) { // Prepare await using (var sqliteCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <SqliteCacheContext> >().CreateDbContext()) { for (var i = 0; i < 10; i++) { sqliteCacheContext.Cache.Add(new CacheEntry <DateTime> { ExpiresAtTime = now.AddYears(i).UtcDateTime, Id = i.ToString(CultureInfo.InvariantCulture), Value = new byte[i] }); } Assert.AreEqual(10, await sqliteCacheContext.SaveChangesAsync()); } now = now.AddYears(4).AddMonths(6); serviceProvider.SetTime(now); var sqliteCache = (SqliteCache)serviceProvider.GetRequiredService <IDistributedCache>(); Assert.AreEqual(5, await sqliteCache.RemoveExpiredCacheEntriesAsync()); await using (var sqliteCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <SqliteCacheContext> >().CreateDbContext()) { Assert.AreEqual(5, await sqliteCacheContext.Cache.CountAsync()); Assert.AreEqual(5, await sqliteCacheContext.Cache.CountAsync(cacheEntry => cacheEntry.ExpiresAtTime > now.UtcDateTime)); } } }
internal static DateTimeOffset ReadInternal(DataInput input) { var nanos = input.ReadLong(); var offset = TimeSpan.FromTicks(input.ReadLong()); return(DateTimeOffsetHelper.TimeFromNanos(nanos, offset)); }
public static DateTimeOffset GetWithMaximumMonth(this DateTimeOffset dateTime, TimeZoneInfo timeZone = null) { var daysInMonth = Calendar.GetDaysInMonth(dateTime.Year, 12); if (dateTime.Day < daysInMonth) { daysInMonth = dateTime.Day; } if (timeZone == null) { return(new DateTimeOffset( dateTime.Year, 12, daysInMonth, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, dateTime.Offset)); } return(DateTimeOffsetHelper.CreateDateTime( dateTime.Year, 12, daysInMonth, dateTime.Hour, dateTime.Minute, dateTime.Second, dateTime.Millisecond, timeZone)); }
public async Task Message_should_be_processed_when_ignoringTTBRHeaders() { var context = await Scenario.Define <Context>() .WithEndpoint <SomeEndpoint>(endpoint => endpoint .CustomConfig(e => { var transportConfig = (MsmqTransport)e.ConfigureTransport(); transportConfig.IgnoreIncomingTimeToBeReceivedHeaders = true; }) .When(async(session, ctx) => { var sendOptions = new SendOptions(); sendOptions.RouteToThisEndpoint(); sendOptions.SetHeader(Headers.TimeSent, DateTimeOffsetHelper.ToWireFormattedString(DateTime.UtcNow.AddSeconds(-10))); sendOptions.SetHeader(Headers.TimeToBeReceived, TimeSpan.FromSeconds(5).ToString()); await session.Send(new SomeMessage(), sendOptions); ctx.WasSent = true; }) ) .Run(TimeSpan.FromSeconds(5)); Assert.IsTrue(context.WasSent, "Message was sent"); Assert.IsTrue(context.WasReceived, "Message was not processed"); }
public async Task RefreshAsync_Test() { const string key = "Key"; await using (var serviceProvider = await this.CreateServiceProviderAsync()) { var now = await DateTimeOffsetHelper.CreateDateTimeOffsetAsync(2000); serviceProvider.SetTime(now); var sqliteCache = (SqliteCache)serviceProvider.GetRequiredService <IDistributedCache>(); await sqliteCache.SetAsync(key, Array.Empty <byte>(), new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromSeconds(1) }); await using (var sqliteCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <SqliteCacheContext> >().CreateDbContext()) { var cacheEntry = await sqliteCacheContext.Cache.FindAsync(key); Assert.AreEqual(now.UtcDateTime.AddSeconds(1), cacheEntry.ExpiresAtTime); } serviceProvider.SetTime(now.AddSeconds(1)); await sqliteCache.RefreshAsync(key); await using (var sqliteCacheContext = serviceProvider.GetRequiredService <IDbContextFactory <SqliteCacheContext> >().CreateDbContext()) { var cacheEntry = await sqliteCacheContext.Cache.FindAsync(key); Assert.AreEqual(now.UtcDateTime.AddSeconds(2), cacheEntry.ExpiresAtTime); } } }
private void AddInternal(Module module, String deploymentId) { var now = DateTimeOffsetHelper.Now(_timeZone); var desc = new DeploymentInformation( deploymentId, module, now, now, new DeploymentInformationItem[0], DeploymentState.UNDEPLOYED); _deploymentStateService.AddUpdateDeployment(desc); }
public DeploymentResult Deploy(Module module, DeploymentOptions options) { using (_iLock.Acquire()) { var deploymentId = _deploymentStateService.NextDeploymentId; return(DeployInternal(module, options, deploymentId, DateTimeOffsetHelper.Now(_timeZone))); } }
public void When_converting_string_with_invalid_characters_should_throw() { var dateString = "201j-08-16 10:06:20:123456 Z"; var exception = Assert.Throws <FormatException>(() => DateTimeOffsetHelper.ToDateTimeOffset(dateString)); Assert.AreEqual(exception.Message, "String was not recognized as a valid DateTime."); }
public Task Handle(MessageThatFails message, IMessageHandlerContext context) { testContext.TimeSentOnTheFailingMessageWhenItWasHandled = DateTimeOffsetHelper.ToDateTimeOffset(context.MessageHeaders[Headers.TimeSent]); testContext.FaultHeaders = context.MessageHeaders.ToDictionary(x => x.Key, x => x.Value); testContext.IsMessageHandledByTheFaultEndpoint = true; return(Task.FromResult(0)); }
public void When_roundtripping_constructed_date_should_be_equal() { var date = new DateTimeOffset(2016, 8, 29, 16, 37, 25, 75, TimeSpan.Zero); var dateString = DateTimeOffsetHelper.ToWireFormattedString(date); var result = DateTimeOffsetHelper.ToDateTimeOffset(dateString); Assert.AreEqual(date, result); }
internal static void WriteInternal( DateTimeOffset @object, DataOutput output) { var nanos = DateTimeOffsetHelper.UtcNanos(@object); var offset = @object.Offset.Ticks; output.WriteLong(nanos); output.WriteLong(offset); }
public static TemperatureHumidityApiModel ToApiModel(this TemperatureHumidityReading businessModel) { return(new TemperatureHumidityApiModel { SensorId = businessModel.SensorId, TimestampWest = DateTimeOffsetHelper.ConvertToWest(businessModel.TimestampUtc), Temperature = businessModel.Temperature, Humidity = businessModel.Humidity }); }
public void Parse_ValueIsValidDateTime_ReturnsParsedValue(Tuple <string, DateTimeOffset> testPair) { var testValue = testPair.Item1; var result = DateTimeOffsetHelper.Parse(testValue); var expectedResult = testPair.Item2; Assert.That(result, Is.EqualTo(expectedResult)); }
static bool TryGetTimeSent(Dictionary <string, string> headers, out DateTimeOffset timeSent) { if (headers.TryGetValue(Headers.TimeSent, out var timeSentString)) { timeSent = DateTimeOffsetHelper.ToDateTimeOffset(timeSentString); return(true); } timeSent = DateTimeOffset.MinValue; return(false); }
public static bool TryGetTimeSent(this ReceivePipelineCompleted completed, out DateTimeOffset timeSent) { var headers = completed.ProcessedMessage.Headers; if (headers.TryGetValue(Headers.TimeSent, out var timeSentString)) { timeSent = DateTimeOffsetHelper.ToDateTimeOffset(timeSentString); return(true); } timeSent = DateTimeOffset.MinValue; return(false); }
/// <summary> /// Check if this is a valid date. /// </summary> /// <param name="day"></param> /// <param name="month"></param> /// <param name="year"></param> /// <returns></returns> private static bool CheckDayValidInMonth(TimeZoneInfo timeZone, int day, int month, int year) { try { DateTimeOffsetHelper.CreateDateTime(year, month, day, 0, 0, 0, 0, timeZone); return(true); } catch (ArgumentException) { return(false); } }