Exemple #1
0
        public CyPhyGUIs.IInterpreterResult RunInterpreterMainAndReturnResult(string outputdirname, string testBenchPath, CyPhy2Schematic.CyPhy2Schematic_Settings config = null)
        {
            if (Directory.Exists(outputdirname))
            {
                foreach (string filename in Directory.GetFiles(outputdirname, "*", SearchOption.AllDirectories))
                {
                    File.Delete(Path.Combine(outputdirname, filename));
                }
            }
            Directory.CreateDirectory(outputdirname);
            Assert.True(Directory.Exists(outputdirname), "Output directory wasn't created for some reason.");

            CyPhyGUIs.IInterpreterResult result = null;
            project.PerformInTransaction(delegate
            {
                MgaFCO testObj = null;
                testObj        = project.ObjectByPath[testBenchPath] as MgaFCO;
                Assert.NotNull(testObj);

                var interpreter = new CyPhy2Schematic.CyPhy2SchematicInterpreter();
                interpreter.Initialize(project);

                var mainParameters = new CyPhyGUIs.InterpreterMainParameters()
                {
                    config = (config == null) ? new CyPhy2Schematic.CyPhy2Schematic_Settings()
                    {
                        Verbose = false
                    }
                                              : config,
                    Project          = project,
                    CurrentFCO       = testObj,
                    SelectedFCOs     = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")),
                    StartModeParam   = 128,
                    ConsoleMessages  = false,
                    ProjectDirectory = project.GetRootDirectoryPath(),
                    OutputDirectory  = outputdirname
                };

                result = interpreter.Main(mainParameters);
                interpreter.DisposeLogger();
            }, abort: true);

            return(result);
        }
        public void MSD_dymola_cfg871()
        {
            Assert.True(File.Exists(mgaFile), "Failed to generate the mga.");
            CyPhyGUIs.IInterpreterResult result = null;
            try
            {
                result = CyPhy2ModelicaRunner.Run("MSD_dymola_cfg871", mgaFile,
                                                  "/@TestBenches|kind=Testing|relpos=0/@PCC_NaN|kind=Testing|relpos=0/@MSD_dymola_cfg871|kind=TestBench|relpos=0");
            }
            catch (META.InterpreterException ex)
            {
                Console.WriteLine(ex.Message);
                Assert.NotNull(result);
            }

            Assert.NotNull(result);
            Assert.True(result.Success, "Interpreter return with result.Success as false!");
            var runCommand = result.RunCommand.Split(new char[] { ' ' }).FirstOrDefault();

            Assert.True(File.Exists(Path.Combine(Path.GetDirectoryName(mgaFile), "MSD_dymola_cfg871", runCommand)),
                        string.Format("RunCommand file : {0}, does not exist.", runCommand));
        }
        public void PCC_MSD_om_CA()
        {
            Assert.True(File.Exists(mgaFile), "Failed to generate the mga.");
            CyPhyGUIs.IInterpreterResult result = null;
            try
            {
                result = CyPhyPETRunner.Run("PCC_MSD_om_CA", mgaFile,
                                            "/@TestBenches|kind=Testing|relpos=0/@SingleConfig|kind=Testing|relpos=0/@PCC_CA|kind=ParametricExplorationFolder|relpos=0/@PCC_MSD_om_CA|kind=ParametricExploration|relpos=0");
            }
            catch (META.InterpreterException ex)
            {
                Console.WriteLine(ex.Message);
                Assert.NotNull(result);
            }

            Assert.NotNull(result);
            Assert.True(result.Success, "Interpreter return with result.Success as false!");
            var runCommand = result.RunCommand.Split(new char[] { ' ' }).FirstOrDefault();

            Assert.True(File.Exists(Path.Combine(Path.GetDirectoryName(mgaFile), "PCC_MSD_om_CA", runCommand)),
                        string.Format("RunCommand file : {0}, does not exist.", runCommand));
        }
Exemple #4
0
        public static Tuple <CyPhyGUIs.InterpreterMainParameters, CyPhyGUIs.IInterpreterResult> RunReturnFull(string outputdirname, string projectPath, string absPath,
                                                                                                              CyPhyGUIs.SmartLogger logger = null, Action <MgaProject> preProcess = null)
        {
            var mainParameters = new CyPhyGUIs.InterpreterMainParameters();

            CyPhyGUIs.IInterpreterResult results = null;
            Assert.True(File.Exists(projectPath), "Project file does not exist.");
            string ProjectConnStr = "MGA=" + projectPath;

            //Type CyPhyPETInterpreter = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyPET");
            //Type MainParametersType = Type.GetTypeFromProgID("ISIS.CyPhyML.InterpreterConfiguration");

            MgaProject project = new MgaProject();

            project.OpenEx(ProjectConnStr, "CyPhyML", null);
            try
            {
                if (preProcess != null)
                {
                    preProcess(project);
                }
                var terr    = project.BeginTransactionInNewTerr();
                var testObj = project.ObjectByPath[absPath] as MgaFCO;
                Assert.True(testObj != null, String.Format("Could not find FCO by path '{0}'", absPath));
                mainParameters.OriginalCurrentFCOName = testObj.Name;
                project.AbortTransaction();

                string OutputDir = Path.Combine(Path.GetDirectoryName(projectPath), outputdirname);
                OutputDir = Path.GetFullPath(OutputDir);
                if (Directory.Exists(OutputDir))
                {
                    CyPhyGUIs.CyPhyDirectory.EnsureEmptyDirectory(OutputDir);
                }
                Directory.CreateDirectory(OutputDir);

                //dynamic interpreter = Activator.CreateInstance(CyPhyPETInterpreter);
                var interpreter = new CyPhyPET.CyPhyPETInterpreter();
                interpreter.Initialize(project);

                //dynamic mainParameters = Activator.CreateInstance(MainParametersType);
                mainParameters.Project          = project;
                mainParameters.CurrentFCO       = testObj;
                mainParameters.SelectedFCOs     = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                mainParameters.StartModeParam   = 128;
                mainParameters.ConsoleMessages  = false;
                mainParameters.ProjectDirectory = Path.GetDirectoryName(projectPath);
                mainParameters.OutputDirectory  = OutputDir;

                //dynamic results = interpreter.Main(mainParameters);
                interpreter.Logger = logger;
                results            = interpreter.MainThrows(mainParameters);

                Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length)));

                if (results.Success == false)
                {
                    Test.DeleteDirectory(OutputDir);
                }
            }
            finally
            {
                project.Close(true);
            }

            return(new Tuple <CyPhyGUIs.InterpreterMainParameters, CyPhyGUIs.IInterpreterResult>(mainParameters, results));
        }