public void Execute(GlobalProgress progress, CancellationToken ct) { try { var path = Project.OutputsDirectory; //var outputscsv=GenerateOutputCSV(); // var SQLite=new HowLeakySQLiteOutput(SQLiteFilename,outputscsv); foreach (var sim in Simulations) { if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } if (!sim.OutputExists()) { var inputs = sim.GenerateInputs(); if (inputs != null) { HLEngine.Execute(inputs, (outputs) => { //SQLite.UpdateDataTable(sim,outputs); Project.CheckZeroArrays(sim.GenerateOutputName(), outputs); switch (OutputType) { case HowLeakyOutputType.DailyBin: HowLeakyBinOutput.WriteOutputs(path, sim, outputs); break; case HowLeakyOutputType.DailyCsv: HowLeakyCsvOutput.WriteDailyOutputs(path, sim, outputs); break; case HowLeakyOutputType.MonthlyCsv: HowLeakyCsvOutput.WriteMonthlyOutputs(path, sim, outputs); break; case HowLeakyOutputType.YearlyCsv: HowLeakyCsvOutput.WriteYearlyOutputs(path, sim, outputs); break; case HowLeakyOutputType.DailyAndMonthlyCsv: HowLeakyCsvOutput.WriteDailyOutputs(path, sim, outputs); HowLeakyCsvOutput.WriteMonthlyOutputs(path, sim, outputs); break; } sim.Reset(); }, (exception) => { Project.AddErrorOutput(exception.ToString()); }); } else { foreach (var error in sim.Errors) { Project.AddErrorOutput(error); } } } progress.Increment(); } ////SQLite.WriteToTable(); } catch (Exception ex) { Project.AddErrorOutput(ex.ToString()); } finally { //if(SQLite!=null) //{ // SQLite.CloseConnection(); //} } }
public void Execute(ProjectHLK project, CancellationTokenSource tokenSource, int cores, int?targetindex, HowLeakyOutputType outputType, GlobalProgress progress = null) { try { if (progress == null) { Progress = new GlobalProgress(project.Simulations.Count); } else { Progress = progress; } CancellationToken ct = tokenSource.Token; var simdict = project.GroupedSimulations; ct.ThrowIfCancellationRequested(); Progress.Max = targetindex == null?project.Simulations.Count:1; project.PrepareReferenceCounts(); if (project.GroupedSimulations.Count() > 1)//cores) { Parallel.ForEach(simdict.ToList(), new ParallelOptions() { MaxDegreeOfParallelism = cores }, simkeypair => { var worker = new SimulationThread(project, simkeypair, outputType); if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } worker.Execute(Progress, ct); Debug.WriteLine(""); }); } else { var climatedatasets = project.DataFiles.ToList(); foreach (var datafile in climatedatasets) { datafile.OpenFull(); } var simulations = targetindex == null?project.Simulations:new List <Simulation>() { project.Simulations.FirstOrDefault(x => x.Index == (int)targetindex) }; Parallel.ForEach(simulations, new ParallelOptions() { MaxDegreeOfParallelism = cores }, sim => { var worker = new SimulationThread(project, new List <Simulation>() { sim }, outputType); if (ct.IsCancellationRequested) { ct.ThrowIfCancellationRequested(); } worker.Execute(Progress, ct); }); } } catch (Exception ex) { throw ErrorLogger.CreateException(ex); } }