public override void Up() { try { LogProvider.Log.Info("Preparing migration #14"); defaultLayouts = GetDefaultLayouts(); var oldLayouts = LoadOldLayouts(Path.Combine(StringFormatter.GetAppDataFolderPath(), "Layouts.xml")); if (oldLayouts == null) { return; } while (oldLayouts.Layouts.Count > 0) { var currentLayout = oldLayouts.Layouts[0]; var tableDescription = hashTable.FirstOrDefault(h => h.Hash == currentLayout.LayoutId); if (tableDescription == null) { oldLayouts.Layouts.RemoveAt(0); continue; } var grouppedLayouts = oldLayouts.Layouts.Where( l => GetTableDescription(l.LayoutId).TableType == tableDescription?.TableType && l.HudStats.Any() && HudObjectsComparer.AreEquals( l.HudBumperStickerTypes, currentLayout.HudBumperStickerTypes) && HudObjectsComparer.AreEquals(l.HudPlayerTypes, currentLayout.HudPlayerTypes) && HudObjectsComparer.AreEquals(l.HudStats, currentLayout.HudStats)).ToList(); foreach (var hudViewType in Enum.GetValues(typeof(HudViewType)).OfType <HudViewType>()) { var newLayout = GetHudLayoutInfo(grouppedLayouts, hudViewType); if (newLayout == null) { continue; } if (!newLayout.IsDefault) { var i = 1; string hudTypeName = string.Empty; if (hudViewType != HudViewType.Plain) { hudTypeName = $" {hudViewType}"; } string tableTypeName = string.Empty; if (!newLayout.Name.Contains(CommonResourceManager.Instance.GetEnumResource(tableDescription.TableType))) { tableTypeName = $" {CommonResourceManager.Instance.GetEnumResource(tableDescription.TableType)}"; } var layoutName = $"{newLayout.Name}{tableTypeName}{hudTypeName}"; while (hudLayoutsService.HudLayoutMappings.Mappings.Any(f => f.Name == layoutName)) { layoutName = $"{newLayout.Name}{tableTypeName}{hudTypeName} {i}"; i++; } newLayout.Name = layoutName; } else { var def = defaultLayouts.FirstOrDefault(l => l.Name == newLayout.Name); if (def != null) { defaultLayouts[defaultLayouts.IndexOf(def)] = newLayout; } } var layoutFileName = Save(newLayout); foreach (var selected in grouppedLayouts) { var table = hashTable.FirstOrDefault(h => h.Hash == selected.LayoutId); if (table == null) { continue; } var mapping = new HudLayoutMapping { FileName = Path.GetFileName(layoutFileName), GameType = table.GameType, TableType = table.TableType, PokerSite = table.PokerSite, IsDefault = false, IsSelected = selected.IsDefault, Name = newLayout.Name, HudViewType = newLayout.HudViewType }; if (mapping.IsSelected && hudLayoutsService.HudLayoutMappings.Mappings.Any( m => m.IsSelected && m.PokerSite == table.PokerSite && m.TableType == table.TableType && m.GameType == table.GameType)) { mapping.IsSelected = false; } hudLayoutsService.HudLayoutMappings.Mappings.Add(mapping); } } oldLayouts.Layouts.RemoveAll( l => GetTableDescription(l.LayoutId).TableType == tableDescription.TableType && HudObjectsComparer.AreEquals(l.HudBumperStickerTypes, currentLayout.HudBumperStickerTypes) && HudObjectsComparer.AreEquals(l.HudPlayerTypes, currentLayout.HudPlayerTypes) && HudObjectsComparer.AreEquals(l.HudStats, currentLayout.HudStats)); } hudLayoutsService.SaveLayoutMappings(); LogProvider.Log.Info("Migration #14 executed."); } catch (Exception e) { LogProvider.Log.Error(this, $"Migration #14 failed.", e); } }