/// <summary> /// Load a subset of current presets. Is only called once. /// </summary> /// <returns>A subset of the current presets.</returns> private static BuildingPresets InitSubsetFromPresetsFile() { var loader = new BuildingPresetsLoader(); string basePath = AppDomain.CurrentDomain.BaseDirectory; var buildingPresets = loader.Load(Path.Combine(basePath, CoreConstants.PresetsFiles.BuildingPresetsFile)); var buildings_1404 = buildingPresets.Buildings.Where(x => x.Header.StartsWith("(A4")).OrderByDescending(x => x.GetOrderParameter()).Take(10).ToList(); var buildings_2070 = buildingPresets.Buildings.Where(x => x.Header.StartsWith("(A5")).OrderByDescending(x => x.GetOrderParameter()).Take(10).ToList(); var buildings_2205 = buildingPresets.Buildings.Where(x => x.Header.StartsWith("(A6")).OrderByDescending(x => x.GetOrderParameter()).Take(10).ToList(); var buildings_1800 = buildingPresets.Buildings.Where(x => x.Header.StartsWith("(A7")).OrderByDescending(x => x.GetOrderParameter()).Take(10).ToList(); var filteredBuildings = new List <BuildingInfo>(); filteredBuildings.AddRange(buildings_1404); filteredBuildings.AddRange(buildings_2070); filteredBuildings.AddRange(buildings_2205); filteredBuildings.AddRange(buildings_1800); var presets = new BuildingPresets { Version = buildingPresets.Version, Buildings = filteredBuildings }; return(presets); }
private async Task GenerateTemplate(object param) { try { IsBusy = true; StatusMessage = string.Empty; var buildingPresetsTask = Task.Run(() => { //load building presets BuildingPresets localBuildingPresets = null; try { var loader = new BuildingPresetsLoader(); localBuildingPresets = loader.Load(PresetsVM.SelectedFile); if (localBuildingPresets == null || localBuildingPresets.Buildings == null) { throw new ArgumentException(); } } catch (Exception ex) { var message = $"Error parsing {nameof(BuildingPresets)}."; logger.Error(ex, message); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Maybe wrong selected file?"; return(null); } PresetsVersion = localBuildingPresets.Version; return(localBuildingPresets); }); var wikiBuildingInfoPresetsTask = Task.Run(() => { //load wiki buildng info WikiBuildingInfoPresets localWikiBuildingInfoPresets = null; try { var loader = new WikiBuildingInfoPresetsLoader(); localWikiBuildingInfoPresets = loader.Load(WikiBuildingsInfoVM.SelectedFile); } catch (Exception ex) { var message = $"Error parsing {nameof(WikiBuildingInfoPresets)}."; logger.Error(ex, message); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Maybe wrong selected file?"; return(null); } WikiBuildingInfoPresetsVersion = localWikiBuildingInfoPresets.Version.ToString(); return(localWikiBuildingInfoPresets); }); var layoutTask = Task.Run(() => { //load layout List <AnnoObject> localLayout = null; try { ILayoutLoader loader = new LayoutLoader(); localLayout = loader.LoadLayout(LayoutVM.SelectedFile); } catch (Exception ex) { var message = "Error parsing layout file."; logger.Error(ex, message); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Maybe wrong selected file?"; return(null); } LayoutName = Path.GetFileName(LayoutVM.SelectedFile); return(localLayout); }); await Task.WhenAll(buildingPresetsTask, wikiBuildingInfoPresetsTask, layoutTask); var buildingPresets = buildingPresetsTask.Result; var wikiBuildingInfoPresets = wikiBuildingInfoPresetsTask.Result; var layout = layoutTask.Result; if (buildingPresets == null || wikiBuildingInfoPresets == null || layout == null) { return; } var layoutNameForTemplate = Path.GetFileNameWithoutExtension(LayoutVM.SelectedFile).Replace("_", " "); await Task.Run(() => { var exporter = new FandomExporter(); Template = exporter.StartExport(layoutNameForTemplate, layout, buildingPresets, wikiBuildingInfoPresets, true); }); StatusMessage = "Template successfully generated."; } catch (Exception ex) { var message = "Error generating template."; logger.Error(ex, message); MessageBox.Show(message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); StatusMessage = $"{message} -> Details in log file."; } finally { IsBusy = false; } }
private ColorPresetsHelper() { _colorPresetsLoader = new ColorPresetsLoader(); _buildingPresetsLoader = new BuildingPresetsLoader(); }