/// <summary> /// Create a job for each simulation in the specified .con file. /// </summary> private void CreateJobsFromCON(string FileName, string[] SimulationPaths, ref List <IJob> jobs) { // Run ConToSim first. string ConToSimExe = Path.Combine(Configuration.ApsimBinDirectory(), "ConToSim.exe"); Process ConToSim = Utility.RunProcess(ConToSimExe, StringManip.DQuote(FileName), Path.GetDirectoryName(FileName)); Utility.CheckProcessExitedProperly(ConToSim); // If no paths were specified then get a list of all paths. if (SimulationPaths == null || SimulationPaths.Length == 0) { List <String> AllPaths = new List <String> (); AllPaths = ConFile.GetSimsInConFile(FileName); SimulationPaths = AllPaths.ToArray(); } // Create a series of jobs for each simulation in the .con file. foreach (string SimulationPath in SimulationPaths) { string SimFileName = Path.Combine(Path.GetDirectoryName(FileName), Path.GetFileNameWithoutExtension(FileName) + "." + SimulationPath + ".sim"); Job J = CreateJob(SimFileName, SimFileName.Replace(".sim", ".sum")); jobs.Add(J); J = CleanupJob(SimFileName, J.Name); jobs.Add(J); } }
private void AddDirectory(string DirectoryName) { // Recursively add a directory of simulations to the run queue. foreach (string FileName in Directory.GetFiles(DirectoryName)) { string Extension = Path.GetExtension(FileName).ToLower(); if (Extension == ".con") { foreach (string SimulationName in ConFile.GetSimsInConFile(FileName)) { _JobRunner.Add(new RunConJob(FileName, SimulationName, _JobRunner)); } } else if (Extension == ".apsim") { _JobRunner.Add(new RunEntireApsimFileJob(FileName, _JobRunner)); } } foreach (string ChildDirectoryName in Directory.GetDirectories(DirectoryName)) { if (ChildDirectoryName != ".svn") { AddDirectory(ChildDirectoryName); } } }
private void AddFile(string FileName, bool JustDoIt) { List <string> SimulationsToRun = null; if (Directory.Exists(FileName)) { _JobRunner.Add(new RunApsimDirectory(FileName, _JobRunner)); return; } else if (Path.GetExtension(FileName).ToLower() == ".con") { SimulationsToRun = ConFile.GetSimsInConFile(FileName); } else if (Path.GetExtension(FileName).ToLower() == ".apsim") { SimulationsToRun = ApsimFile.ApsimFile.GetSimsInApsimFile(FileName); } else if (Path.GetExtension(FileName).ToLower() == ".txt") { StreamReader In = new StreamReader(FileName); string Line = In.ReadLine(); while (Line != "" && Line != null) { AddFile(Line, JustDoIt); // recursion Line = In.ReadLine(); } In.Close(); } else { throw new Exception("Unknown simulation file type: " + FileName); } // Display a selection form if there are more than 1 simulations and this isn't an AutoRun if (SimulationsToRun != null && SimulationsToRun.Count > 1 && !JustDoIt) { SelectionForm Form = new SelectionForm(SimulationsToRun); if (Form.ShowDialog() == DialogResult.OK) { SimulationsToRun = Form.Selections; } else { return; } } if (SimulationsToRun != null) { foreach (string SimulationName in SimulationsToRun) { if (Path.GetExtension(FileName).ToLower() == ".con") { _JobRunner.Add(new RunConJob(FileName, SimulationName, _JobRunner)); } else if (Path.GetExtension(FileName).ToLower() == ".apsim") { _JobRunner.Add(new RunApsimFileJob(FileName, SimulationName, _JobRunner)); } } } else if (Path.GetExtension(FileName).ToLower() != ".txt") { _JobRunner.Add(new RunEntireApsimFileJob(FileName, _JobRunner)); } }