< Summary

Information
Class: Morpho25.IO.SimulationBatch
Assembly: Morpho25
File(s): D:\a\Morpho\Morpho\project\Morpho\Morpho25\IO\SimulationBatch.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 35
Coverable lines: 35
Total lines: 69
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
RunSimulation(...)100%10%
GetBatchFile(...)0%20%

File(s)

D:\a\Morpho\Morpho\project\Morpho\Morpho25\IO\SimulationBatch.cs

#LineLine coverage
 1using Morpho25.Management;
 2using System;
 3using System.Diagnostics;
 4using System.IO;
 5
 6namespace 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)
 019        {
 20            try
 021            {
 022                Process.Start(GetBatchFile(simx));
 023            }
 024            catch (System.IO.DirectoryNotFoundException)
 025            {
 026                throw new Exception("Batch file not found. " +
 027                    "If problem persist, run simulation using ENVI-Met GUI.");
 28            }
 029        }
 30
 31        private static string GetBatchFile(Simx simx)
 032        {
 33            string envimet;
 034            string root = Path.GetPathRoot(
 035                Environment.GetFolderPath(
 036                    Environment.SpecialFolder.ApplicationData));
 37
 038            if (simx.MainSettings.Inx.Workspace.EnvimetFolder == null)
 039                envimet = Path.Combine(root,
 040                    Workspace.DEFAULT_FOLDER + "\\win64");
 41            else
 042                envimet = Path.Combine(simx.MainSettings
 043                    .Inx.Workspace.EnvimetFolder, "win64");
 44
 045            string project = simx.MainSettings.Inx.Workspace.ProjectName;
 046            string simulationName = simx.MainSettings.Name + ".simx";
 47
 048            string path = Path.Combine(simx.MainSettings
 049                .Inx.Workspace.ProjectFolder, simulationName + ".bat");
 050            string unit = Path.GetPathRoot(envimet);
 051            unit = Path.GetPathRoot(envimet).Remove(unit.Length - 1);
 52
 053            string batch = $"@echo off\n" +
 054            $"cd {unit}\n" +
 055            $"cd {envimet}\n" +
 056            $"if errorlevel 1 goto :failed\n" +
 057            $"\"{envimet}\\envicore_console.exe\" \"{simx.MainSettings.Inx.Workspace.WorkspaceFolder}\" \"{project}\" \"
 058            $": failed\n" +
 059            $"echo If Envimet is not in default unit 'C:\' connect installation folder.\n" +
 060            $"pause\n";
 61
 62            //string[] contentOfBatch = { String.Format(batch, unit, envimet, project, simulationName) };
 63
 064            File.WriteAllText(path, batch);
 65
 066            return path;
 067        }
 68    }
 69}