/// <summary> /// Return true if duplications were found. /// </summary> /// <returns></returns> private bool DuplicatesFound() { List <IModel> allSims = Apsim.ChildrenRecursively(simulations, typeof(Simulation)); List <string> allSimNames = allSims.Select(s => s.Name).ToList(); var duplicates = allSimNames .GroupBy(i => i) .Where(g => g.Count() > 1) .Select(g => g.Key); if (duplicates.ToList().Count > 0) { string errorMessage = "Duplicate simulation names found " + StringUtilities.BuildString(duplicates.ToArray(), ", "); explorerPresenter.ShowMessage(errorMessage, Models.DataStore.ErrorLevel.Error); return(true); } return(false); }
/// <summary> /// Perform the command /// </summary> public void Do(CommandHistory CommandHistory) { IsRunning = true; if (!DuplicatesFound()) { stopwatch.Start(); if (modelClicked is Simulations) { simulations.SimulationToRun = null; // signal that we want to run all simulations. numSimulationsToRun = Simulations.FindAllSimulationsToRun(simulations).Length; } else { simulations.SimulationToRun = modelClicked; numSimulationsToRun = Simulations.FindAllSimulationsToRun(modelClicked).Length; } if (explorerPresenter != null) { explorerPresenter.ShowMessage(modelClicked.Name + " running (" + numSimulationsToRun + ")", Models.DataStore.ErrorLevel.Information); } if (numSimulationsToRun > 1) { timer = new Timer(); timer.Interval = 1000; timer.Tick += OnTimerTick; } jobManager.AddJob(simulations); jobManager.AllJobsCompleted += OnComplete; jobManager.Start(waitUntilFinished: false); if (numSimulationsToRun > 1) { timer.Start(); } } }
/// <summary> /// Perform the command /// </summary> public void Do(CommandHistory CommandHistory) { IsRunning = true; if (ExplorerPresenter != null) { ExplorerPresenter.ShowMessage(ModelClicked.Name + " running...", Models.DataStore.ErrorLevel.Information); } Timer.Start(); if (ModelClicked is Simulations) { Simulations.SimulationToRun = null; // signal that we want to run all simulations. } else { Simulations.SimulationToRun = ModelClicked; } JobManager.AddJob(Simulations); JobManager.AllJobsCompleted += OnComplete; JobManager.Start(waitUntilFinished: false); }