| | 1 | | using Morpho25.Management; |
| | 2 | | using System; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using System.Diagnostics; |
| | 5 | | using System.Linq; |
| | 6 | | using System.Text; |
| | 7 | | using System.Threading.Tasks; |
| | 8 | |
|
| | 9 | | namespace Morpho25.IO |
| | 10 | | { |
| | 11 | | /// <summary> |
| | 12 | | /// Climate file batch class. |
| | 13 | | /// </summary> |
| | 14 | | class FoxBatch |
| | 15 | | { |
| | 16 | | /// <summary> |
| | 17 | | /// Generate a climate file from a EPW file. |
| | 18 | | /// </summary> |
| | 19 | | /// <param name="epw">EPW file to use.</param> |
| | 20 | | /// <param name="workspace">Workspace.</param> |
| | 21 | | /// <returns></returns> |
| | 22 | | public static string GetFoxFile(string epw, |
| | 23 | | Workspace workspace) |
| 0 | 24 | | { |
| | 25 | | string envimet; |
| 0 | 26 | | string root = System.IO.Path.GetPathRoot(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData |
| | 27 | |
|
| 0 | 28 | | if (workspace.EnvimetFolder == null) |
| 0 | 29 | | envimet = System.IO.Path.Combine(root, Workspace.DEFAULT_FOLDER + "\\win64"); |
| | 30 | | else |
| 0 | 31 | | envimet = System.IO.Path.Combine(workspace.EnvimetFolder, "win64"); |
| | 32 | |
|
| 0 | 33 | | string foxName = System.IO.Path.GetFileNameWithoutExtension(epw) + ".fox"; |
| 0 | 34 | | string target = System.IO.Path.Combine(workspace.ProjectFolder, foxName); |
| | 35 | |
|
| 0 | 36 | | string path = System.IO.Path.Combine(workspace.ProjectFolder, workspace.ModelName + "FOX.bat"); |
| | 37 | |
|
| 0 | 38 | | string batch = "@echo I'm writing FOX file...\n" + |
| 0 | 39 | | "@echo off\n" + |
| 0 | 40 | | "cd {0}\n" + |
| 0 | 41 | | "if errorlevel 1 goto :failed\n" + |
| 0 | 42 | | "foxmanager.exe {1} {2}\n" + |
| 0 | 43 | | ": failed\n" + |
| 0 | 44 | | "echo If Envimet is not in default unit 'C:\' connect installation folder.\n" + |
| 0 | 45 | | "pause\n"; |
| | 46 | |
|
| 0 | 47 | | string[] contentOfBatch = { String.Format(batch, envimet, epw, target) }; |
| | 48 | |
|
| 0 | 49 | | System.IO.File.WriteAllLines(path, contentOfBatch); |
| | 50 | |
|
| 0 | 51 | | if (!System.IO.File.Exists(target)) |
| 0 | 52 | | RunBat(path); |
| | 53 | |
|
| 0 | 54 | | return foxName; |
| 0 | 55 | | } |
| | 56 | |
|
| | 57 | | private static void RunBat(string path) |
| 0 | 58 | | { |
| 0 | 59 | | Process process = new Process(); |
| 0 | 60 | | process.StartInfo.FileName = path; |
| 0 | 61 | | process.Start(); |
| 0 | 62 | | } |
| | 63 | | } |
| | 64 | | } |