internal TimeZoneInfo ToTimeZoneInfo() { if (this.daylightTime.HasTransitionTime && this.standardTime.HasTransitionTime) { AdjustmentRule adjustmentRule = AdjustmentRule.CreateAdjustmentRule( DateTime.MinValue.Date, DateTime.MaxValue.Date, -this.daylightTime.Delta, this.daylightTime.ToTransitionTime(), this.standardTime.ToTransitionTime()); return(TimeZoneExtensions.CreateCustomTimeZone( Guid.NewGuid().ToString(), -this.bias, "Custom time zone", "Standard time", "Daylight time", new AdjustmentRule[] { adjustmentRule })); } else { // Create no DST time zone return(TimeZoneExtensions.CreateCustomTimeZone( Guid.NewGuid().ToString(), -this.bias, "Custom time zone", "Standard time")); } }
public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func <TState, Exception, string> formatter) { try { var messageLogEntity = new MessageLogEntity { Id = Guid.NewGuid(), Timestamp = TimeZoneExtensions.GetCurrentTime(), TypeId = _logLevelMapper.Map(logLevel), Message = $"{formatter(state, exception)}", Exception = exception?.ToString(), InnerException = exception?.InnerException?.ToString(), StackTrace = exception?.StackTrace, Source = exception?.Source, CreatedOn = TimeZoneExtensions.GetCurrentTime(), CreatedBy = _createdBy }; Task.Run(() => { _tableStorageRepository.InsertAsync(messageLogEntity); }).Wait(); } catch (Exception e) { Console.WriteLine(e); // do nothing } }
/// <summary> /// Will always go through here /// </summary> /// <param name="view"></param> /// <param name="user"></param> /// <returns></returns> public async Task <bool> UpdateSummonerInfoAsync(SummonerInfoView view, UserEntity user) { try { view.RemoveEmptyViewsForDb(); var readEntity = await _summonerInfoRepository.ReadOneByUserIdAsync(user.Id); if (readEntity == null) { return(await CreateSummonerInfoAsync(view, user)); } var summonerInfo = _summonerMapper.Map(view); summonerInfo.Id = readEntity.Id; summonerInfo.UserId = readEntity.UserId; summonerInfo.IsValidPlayer = readEntity.IsValidPlayer; summonerInfo.UpdatedOn = TimeZoneExtensions.GetCurrentTime(); var altAccountTask = UpdateAlternateAccountsAsync(summonerInfo.Id, view.AlternateAccounts); var updateSummonerInfoTask = _summonerInfoRepository.UpdateAsync(new List <SummonerInfoEntity> { summonerInfo }); return(await altAccountTask && await updateSummonerInfoTask); } catch (SummonerInfoException) { throw; } catch (Exception e) { var message = $"Error updating summoner info for: {user.Email}"; _logger.LogError(e, message); throw new Exception(message, e); } }
/// <summary> /// Converts this time zone definition into a TimeZoneInfo structure. /// </summary> /// <param name="service">The service.</param> /// <returns>A TimeZoneInfo representing the same time zone as this definition.</returns> internal TimeZoneInfo ToTimeZoneInfo(ExchangeService service) { this.Validate(); TimeZoneInfo result; // Retrieve the base offset to UTC, standard and daylight display names from // the last transition group, which is the one that currently applies given that // transitions are ordered chronologically. TimeZoneTransitionGroup.CustomTimeZoneCreateParams creationParams = this.transitions[this.transitions.Count - 1].TargetGroup.GetCustomTimeZoneCreationParams(); List <AdjustmentRule> adjustmentRules = new List <AdjustmentRule>(); DateTime startDate = DateTime.MinValue; DateTime endDate; DateTime effectiveEndDate; for (int i = 0; i < this.transitions.Count; i++) { if (i < this.transitions.Count - 1) { endDate = (this.transitions[i + 1] as AbsoluteDateTransition).DateTime; effectiveEndDate = endDate.AddDays(-1); } else { endDate = DateTime.MaxValue; effectiveEndDate = endDate; } // OM:1648848 Due to bad timezone data from clients the // startDate may not always come before the effectiveEndDate if (startDate < effectiveEndDate) { AdjustmentRule adjustmentRule = this.transitions[i].TargetGroup.CreateAdjustmentRule(startDate, effectiveEndDate); if (adjustmentRule != null) { adjustmentRules.Add(adjustmentRule); } startDate = endDate; } else { service.TraceMessage( TraceFlags.EwsTimeZones, string.Format( "The startDate '{0}' is not before the effectiveEndDate '{1}'. Will skip creating adjustment rule.", startDate, effectiveEndDate)); } } if (adjustmentRules.Count == 0) { // If there are no adjustment rule, the time zone does not support Daylight // saving time. result = TimeZoneExtensions.CreateCustomTimeZone( this.Id, creationParams.BaseOffsetToUtc, this.Name, creationParams.StandardDisplayName); } else { result = TimeZoneExtensions.CreateCustomTimeZone( this.Id, creationParams.BaseOffsetToUtc, this.Name, creationParams.StandardDisplayName, creationParams.DaylightDisplayName, adjustmentRules.ToArray()); } return(result); }