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(); }
public static void Run(IEnumerable <string> files) { Shared.OpenErrorLog(); Simulations simulations = new Simulations(null); foreach (string file in files) { // Read in the IAT IAT iat = new IAT(file); Folder folder = new Folder(simulations) { Name = iat.Name }; // Find all the parameter sheets in the IAT List <string> sheets = new List <string>(); foreach (Sheet sheet in iat.Book.Workbook.Sheets) { // Ensure a parameter sheet is selected string name = sheet.Name.ToString(); if (!name.ToLower().Contains("param")) { continue; } iat.SetSheet(name); } // Files will already be written if groupSims is false if (!GroupSims) { continue; } // Collect all the IAT files in the same .apsimx file if (GroupSheets) { simulations.Children.Add(folder); } // Only gather parameter sets into the same .apsimx file else { Shared.WriteApsimX(simulations, iat.Name); simulations = new Simulations(null); } } if (GroupSheets) { Shared.WriteApsimX(simulations, "Simulations"); } Shared.CloseErrorLog(); }
/// <summary> /// Looks through an IAT for the given name and attempts to load data into the object /// </summary> /// <param name="name">Name of the table to search for</param> /// <param name="iat">IAT to search through</param> public SubTable(string name, IAT iat) { this.iat = iat; Name = name; // Check the table exists if (!FindTable()) { throw new Exception($"'{name}' table not found, invalid dataset"); } // Attenot to find the rows and columns of the table LoadRows(); LoadCols(); // Attempt to load table data once rows/columns are found LoadExtra(); LoadData(); }