| | 1 | | using Morpho25.Management; |
| | 2 | | using System; |
| | 3 | | using System.Diagnostics; |
| | 4 | | using System.IO; |
| | 5 | |
|
| | 6 | | namespace Morpho25.IO |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Simulation batch class. |
| | 10 | | /// </summary> |
| | 11 | | public class SimulationBatch |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Run envimet simulation. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="simx">Simulation definition.</param> |
| | 17 | | /// <exception cref="Exception"></exception> |
| | 18 | | public static void RunSimulation(Simx simx) |
| 0 | 19 | | { |
| | 20 | | try |
| 0 | 21 | | { |
| 0 | 22 | | Process.Start(GetBatchFile(simx)); |
| 0 | 23 | | } |
| 0 | 24 | | catch (System.IO.DirectoryNotFoundException) |
| 0 | 25 | | { |
| 0 | 26 | | throw new Exception("Batch file not found. " + |
| 0 | 27 | | "If problem persist, run simulation using ENVI-Met GUI."); |
| | 28 | | } |
| 0 | 29 | | } |
| | 30 | |
|
| | 31 | | private static string GetBatchFile(Simx simx) |
| 0 | 32 | | { |
| | 33 | | string envimet; |
| 0 | 34 | | string root = Path.GetPathRoot( |
| 0 | 35 | | Environment.GetFolderPath( |
| 0 | 36 | | Environment.SpecialFolder.ApplicationData)); |
| | 37 | |
|
| 0 | 38 | | if (simx.MainSettings.Inx.Workspace.EnvimetFolder == null) |
| 0 | 39 | | envimet = Path.Combine(root, |
| 0 | 40 | | Workspace.DEFAULT_FOLDER + "\\win64"); |
| | 41 | | else |
| 0 | 42 | | envimet = Path.Combine(simx.MainSettings |
| 0 | 43 | | .Inx.Workspace.EnvimetFolder, "win64"); |
| | 44 | |
|
| 0 | 45 | | string project = simx.MainSettings.Inx.Workspace.ProjectName; |
| 0 | 46 | | string simulationName = simx.MainSettings.Name + ".simx"; |
| | 47 | |
|
| 0 | 48 | | string path = Path.Combine(simx.MainSettings |
| 0 | 49 | | .Inx.Workspace.ProjectFolder, simulationName + ".bat"); |
| 0 | 50 | | string unit = Path.GetPathRoot(envimet); |
| 0 | 51 | | unit = Path.GetPathRoot(envimet).Remove(unit.Length - 1); |
| | 52 | |
|
| 0 | 53 | | string batch = $"@echo off\n" + |
| 0 | 54 | | $"cd {unit}\n" + |
| 0 | 55 | | $"cd {envimet}\n" + |
| 0 | 56 | | $"if errorlevel 1 goto :failed\n" + |
| 0 | 57 | | $"\"{envimet}\\envicore_console.exe\" \"{simx.MainSettings.Inx.Workspace.WorkspaceFolder}\" \"{project}\" \" |
| 0 | 58 | | $": failed\n" + |
| 0 | 59 | | $"echo If Envimet is not in default unit 'C:\' connect installation folder.\n" + |
| 0 | 60 | | $"pause\n"; |
| | 61 | |
|
| | 62 | | //string[] contentOfBatch = { String.Format(batch, unit, envimet, project, simulationName) }; |
| | 63 | |
|
| 0 | 64 | | File.WriteAllText(path, batch); |
| | 65 | |
|
| 0 | 66 | | return path; |
| 0 | 67 | | } |
| | 68 | | } |
| | 69 | | } |