private void CreateMappingsForLocalDateTimeConverter() { var converter = new LocalDateTimeConverter(); CreateMap <LocalDateTime, DateTime>().ConvertUsing(converter); CreateMap <LocalDateTime?, DateTime?>().ConvertUsing(converter); CreateMap <DateTime, LocalDateTime>().ConvertUsing(converter); CreateMap <DateTime?, LocalDateTime?>().ConvertUsing(converter); }
/// <summary> /// Converts the instance into a local date time /// </summary> /// <param name="dateTime">The current instance of the date time</param> /// <param name="timeZone">The time zone to convert to</param> /// <returns>The same date time but expressed in local time</returns> public static DateTime?ToLocal(this DateTime?dateTime, string timeZone = null) { if (dateTime == null) { return(null); } IDateTimeConverter converter = new LocalDateTimeConverter(timeZone); return(converter.Convert((DateTime)dateTime)); }
public static IEdmModel GetEdmModel() { var builder = new ODataConventionModelBuilder(); var customer = builder.EntitySet <Customer>("Customers").EntityType; var type = builder.AddEntityType(typeof(Customer)); IList <PropertyInfo> removedProperties = new List <PropertyInfo>(); foreach (var propertyInfo in typeof(Customer).GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)) { if (propertyInfo.PropertyType == typeof(DateTime) || propertyInfo.PropertyType == typeof(DateTime?)) // add more codes to process collection { type.RemoveProperty(propertyInfo); removedProperties.Add(propertyInfo); } } // customer.Ignore(c => c.ReleaseDate); EdmModel model = builder.GetEdmModel() as EdmModel; EdmEntityType customerType = model.SchemaElements.OfType <IEdmEntityType>().First(c => c.Name == "Customer") as EdmEntityType; var localDateTime = model.FindType("Org.OData.Core.V1.LocalDateTime") as IEdmTypeDefinition; var localDateTimeNullableRef = new EdmTypeDefinitionReference(localDateTime, true); var localDateTimenonNullableRef = new EdmTypeDefinitionReference(localDateTime, false); foreach (var propertyInfo in removedProperties) { EdmProperty edmProperty = null; if (propertyInfo.PropertyType == typeof(DateTime)) { edmProperty = customerType.AddStructuralProperty(propertyInfo.Name, localDateTimenonNullableRef); } else if (propertyInfo.PropertyType == typeof(DateTime?)) { edmProperty = customerType.AddStructuralProperty(propertyInfo.Name, localDateTimeNullableRef); } if (edmProperty != null) { model.SetAnnotationValue(edmProperty, new ClrPropertyInfoAnnotation(propertyInfo)); } } LocalDateTimeConverter converter = new LocalDateTimeConverter(); model.SetPrimitiveValueConverter(localDateTimeNullableRef, converter); model.SetPrimitiveValueConverter(localDateTimenonNullableRef, converter); return(model); }
public void LocalDateTimeConverter_ConvertToLocalTime_DateTime_UseCustomTimezone_Success() { const string inputValue = "2016-12-31 15:00"; string outputValue = ""; const string timeZone = "Europe/Brussels"; IDateTimeConverter converter = new LocalDateTimeConverter(timeZone); const string exactFormat = "yyyy-MM-dd HH:mm"; if (DateTime.TryParseExact(inputValue, exactFormat, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime output)) { DateTime convertedDate = converter.Convert(DateTime.SpecifyKind(output, DateTimeKind.Utc)); outputValue = convertedDate.ToString(exactFormat); } Assert.True(outputValue == "2016-12-31 16:00"); }
private void PART_ScCompactView_IsLoaded(object sender, RoutedEventArgs e) { PART_ScCompactView.Children.Clear(); PART_ScCompactView.ColumnDefinitions.Clear(); // Prepare Grid 40x40 & add data double actualWidth = PART_ScCompactView.ActualWidth; int nbGrid = (int)actualWidth / 52; #if DEBUG logger.Debug($"SuccessStory - SuccessStoryAchievementsCompact - actualWidth: {actualWidth} - nbGrid: {nbGrid} - AchievementsList: {AchievementsList.Count}"); #endif if (nbGrid > 0) { for (int i = 0; i < nbGrid; i++) { ColumnDefinition gridCol = new ColumnDefinition(); gridCol.Width = new GridLength(1, GridUnitType.Star); PART_ScCompactView.ColumnDefinitions.Add(gridCol); if (i < AchievementsList.Count) { if (i < nbGrid - 1) { Image gridImage = new Image(); gridImage.Stretch = Stretch.UniformToFill; gridImage.Width = 48; gridImage.Height = 48; gridImage.ToolTip = AchievementsList[i].Name; gridImage.SetValue(Grid.ColumnProperty, i); if (_withUnlocked) { var converter = new LocalDateTimeConverter(); converter.Convert(AchievementsList[i].DateUnlock, null, null, null); gridImage.ToolTip += " (" + converter.Convert(AchievementsList[i].DateUnlock, null, null, null) + ")"; } if (AchievementsList[i].IsGray) { var tmpImg = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute)); gridImage.Source = ImageTools.ConvertBitmapImage(tmpImg, ImageColor.Gray); ImageBrush imgB = new ImageBrush { ImageSource = new BitmapImage(new Uri(AchievementsList[i].IconImage, UriKind.Absolute)) }; gridImage.OpacityMask = imgB; } else { gridImage.Source = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute)); } DropShadowEffect myDropShadowEffect = new DropShadowEffect(); myDropShadowEffect.ShadowDepth = 0; myDropShadowEffect.BlurRadius = 30; SetColorConverter setColorConverter = new SetColorConverter(); var color = setColorConverter.Convert(AchievementsList[i].Percent, null, null, CultureInfo.CurrentCulture); if (color != null) { myDropShadowEffect.Color = (Color)color; } if (_EnableRaretyIndicator) { gridImage.Effect = myDropShadowEffect; } PART_ScCompactView.Children.Add(gridImage); } else { Label lb = new Label(); lb.FontSize = 16; lb.Content = $"+{AchievementsList.Count - i}"; lb.VerticalAlignment = VerticalAlignment.Center; lb.HorizontalAlignment = HorizontalAlignment.Center; lb.SetValue(Grid.ColumnProperty, i); PART_ScCompactView.Children.Add(lb); #if DEBUG logger.Debug($"SuccessStory - SuccessStoryAchievementsCompact - AchievementsList.Count: {AchievementsList.Count} - nbGrid: {nbGrid} - i: {i}"); #endif } } } } else { } }
private void PART_ScCompactView_IsLoaded(object sender, RoutedEventArgs e) { if (sender != null) { IntegrationUI.SetControlSize((FrameworkElement)sender); } if (double.IsNaN(PART_ScCompactView.ActualHeight) || PART_ScCompactView.ActualHeight == 0) { return; } PART_ScCompactView.Children.Clear(); PART_ScCompactView.ColumnDefinitions.Clear(); // Prepare Grid 40x40 & add data double actualHeight = PART_ScCompactView.ActualHeight; int nbRow = (int)actualHeight / 52; #if DEBUG logger.Debug($"SuccessStory [Ignored] - SuccessStoryAchievementsCompact - ActualHeight: {actualHeight} - nbGrid: {nbRow} - AchievementsList: {AchievementsList.Count}"); #endif if (nbRow > 0) { for (int i = 0; i < nbRow; i++) { RowDefinition gridRow = new RowDefinition(); gridRow.Height = new GridLength(1, GridUnitType.Star); PART_ScCompactView.RowDefinitions.Add(gridRow); if (i < AchievementsList.Count) { if (i < nbRow - 1) { Image gridImage = new Image(); gridImage.Stretch = Stretch.UniformToFill; gridImage.Width = 48; gridImage.Height = 48; gridImage.ToolTip = AchievementsList[i].Name; gridImage.SetValue(Grid.RowProperty, i); if (_withUnlocked) { var converter = new LocalDateTimeConverter(); gridImage.ToolTip = AchievementsList[i].NameWithDateUnlock; } if (AchievementsList[i].IsGray) { if (AchievementsList[i].Icon.IsNullOrEmpty() || AchievementsList[i].IconImage.IsNullOrEmpty()) { logger.Warn($"SuccessStory - Empty image"); } else { var tmpImg = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute)); gridImage.Source = ImageTools.ConvertBitmapImage(tmpImg, ImageColor.Gray); ImageBrush imgB = new ImageBrush { ImageSource = new BitmapImage(new Uri(AchievementsList[i].IconImage, UriKind.Absolute)) }; gridImage.OpacityMask = imgB; } } else { if (AchievementsList[i].Icon.IsNullOrEmpty()) { logger.Warn($"SuccessStory - Empty image"); } else { gridImage.Source = new BitmapImage(new Uri(AchievementsList[i].Icon, UriKind.Absolute)); } } DropShadowEffect myDropShadowEffect = new DropShadowEffect(); myDropShadowEffect.ShadowDepth = 0; myDropShadowEffect.BlurRadius = 15; SetColorConverter setColorConverter = new SetColorConverter(); var color = setColorConverter.Convert(AchievementsList[i].Percent, null, null, CultureInfo.CurrentCulture); if (color != null) { myDropShadowEffect.Color = (Color)color; } if (PluginDatabase.PluginSettings.EnableRaretyIndicator) { gridImage.Effect = myDropShadowEffect; } PART_ScCompactView.Children.Add(gridImage); } else { Label lb = new Label(); lb.FontSize = 16; lb.Content = $"+{AchievementsList.Count - i}"; lb.VerticalAlignment = VerticalAlignment.Center; lb.HorizontalAlignment = HorizontalAlignment.Center; lb.SetValue(Grid.RowProperty, i); PART_ScCompactView.Children.Add(lb); } } } } else { } }
/// <summary> /// Converts the instance into a local date time /// </summary> /// <param name="dateTime">The current instance of the date time</param> /// <param name="timeZone">The time zone to convert to</param> /// <returns>The same date time but expressed in local time</returns> public static DateTime ToLocal(this DateTime dateTime, string timeZone = null) { IDateTimeConverter converter = new LocalDateTimeConverter(timeZone); return(converter.Convert(dateTime)); }