/// <summary>Return the index of next job to run or -1 if nothing to run.</summary> /// <returns>Job to run or null if no more jobs to run</returns> public IRunnable GetNextJobToRun() { // First time through there. Get a list of things to run. if (simulationEnumerator == null) { // Find runnable objects that aren't simulations e.g. ExcelInput toolsToRun = Apsim.FindAll(simulations, typeof(IRunnable)).Cast <IRunnable>().ToList(); // Send event telling all models that we're about to begin running. Events events = new Events(simulations); events.Publish("BeginRun", null); Runner.SimulationEnumerator enumerator = new Runner.SimulationEnumerator(modelSelectedByUser, SimulationNamesToRun); simulationEnumerator = enumerator; NumSimulationNamesBeingRun = enumerator.NumSimulationsBeingRun; } // Are there any runnable things? if (toolsToRun.Count > 0) { var toolToRun = toolsToRun[0]; toolsToRun.RemoveAt(0); return(toolToRun); } // If we didn't find anything to run then return null to tell job runner to exit. if (simulationEnumerator.MoveNext()) { return(new RunSimulation(simulations, simulationEnumerator.Current)); } else { return(null); } }
/// <summary>Return the index of next job to run or -1 if nothing to run.</summary> /// <returns>Job to run or null if no more jobs to run</returns> public IRunnable GetNextJobToRun() { // First time through there. Get a list of things to run. if (simulationEnumerator == null) { // Send event telling all models that we're about to begin running. Events events = new Events(simulations); events.Publish("BeginRun", null); Runner.SimulationEnumerator enumerator = new Runner.SimulationEnumerator(modelSelectedByUser); simulationEnumerator = enumerator; SimulationNamesBeingRun = enumerator.SimulationNamesBeingRun; // Send event telling all models that we're about to begin running. events.Publish("RunCommencing", new object[] { AllSimulationNames, SimulationNamesBeingRun }); } // If we didn't find anything to run then return null to tell job runner to exit. if (simulationEnumerator.MoveNext()) { return(new RunSimulation(simulations, simulationEnumerator.Current, false)); } else { return(null); } }
/// <summary>Return the index of next job to run or -1 if nothing to run.</summary> /// <returns>Job to run or null if no more jobs to run</returns> public IRunnable GetNextJobToRun() { // First time through there. Get a list of things to run. if (simulationEnumerator == null) { // Send event telling all models that we're about to begin running. Events events = new Events(simulations); events.Publish("BeginRun", null); Runner.SimulationEnumerator enumerator = new Runner.SimulationEnumerator(modelSelectedByUser); simulationEnumerator = enumerator; SimulationNamesBeingRun = enumerator.SimulationNamesBeingRun; // Send event telling all models that we're about to begin running. Dictionary <string, string> simAndFolderNames = new Dictionary <string, string>(); foreach (ISimulationGenerator simulation in Apsim.ChildrenRecursively(simulations, typeof(ISimulationGenerator)).Cast <ISimulationGenerator>()) { string folderName = Apsim.Parent(simulation as IModel, typeof(Folder)).Name; foreach (string simulationName in simulation.GetSimulationNames()) { if (simAndFolderNames.ContainsKey(simulationName)) { throw new Exception(string.Format("Duplicate simulation names found: {0} in simulation {1}", simulationName, (simulation as IModel).Name)); } simAndFolderNames.Add(simulationName, folderName); } } events.Publish("RunCommencing", new object[] { simAndFolderNames, SimulationNamesBeingRun }); } // If we didn't find anything to run then return null to tell job runner to exit. if (simulationEnumerator.MoveNext()) { return(new RunSimulation(simulations, simulationEnumerator.Current, false)); } else { return(null); } }