public static void Run(IEnumerable <Tuple <string, string> > files) { Shared.OpenErrorLog(); Simulations simulations = new Simulations(null); IAT iat; Folder folder = null; foreach (var file in files) { // Cancel the conversion if (Shared.Worker.CancellationPending) { Shared.CloseErrorLog(); return; } // Read in the IAT try { iat = new IAT(file.Item1); } catch (ConversionException) { Shared.WriteError(new ErrorData() { FileName = Path.GetFileName(file.Item1), FileType = "IAT", Message = "The file could not be read", Sheet = "-", Table = "-", Severity = "High" }); continue; } if (GroupSims && GroupSheets) { folder = new Folder(simulations) { Name = iat.Name } } ; if (file.Item2 != "All") { iat.SetSheet(file.Item2); AttachParameterSheet(simulations, iat); // Update the Progress bar Shared.Worker?.ReportProgress(0); } else { // Find all the parameter sheets in the IAT foreach (Sheet sheet in iat.Book.Workbook.Sheets) { // Cancel the conversion if (Shared.Worker.CancellationPending) { Shared.CloseErrorLog(); return; } // Ensure a parameter sheet is selected string name = sheet.Name.ToString(); if (!name.ToLower().Contains("param")) { continue; } iat.SetSheet(name); if (GroupSims && GroupSheets) { AttachParameterSheet(folder, iat); } else { AttachParameterSheet(simulations, iat); } iat.ClearTables(); // Update the Progress bar Shared.Worker?.ReportProgress(0); } } if (!GroupSims) { Shared.WriteApsimX(simulations, iat.Name); simulations = new Simulations(null); } else if (GroupSheets) { simulations.Add(folder); } iat.Dispose(); GC.WaitForPendingFinalizers(); } if (GroupSims) { Shared.WriteApsimX(simulations, "Simulations"); } Shared.CloseErrorLog(); }
// Creates a node structure from the IAT, using the set Sheet private static void AttachParameterSheet(Node node, IAT iat) { node.Source = iat; Simulation simulation = new Simulation(node) { Name = iat.ParameterSheet.Name }; node.Children.Add(simulation); iat.ClearTables(); }