public static bool RunElaborator(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; if (testObj == null) { throw new ApplicationException(absPath + " not found in " + project.ProjectConnStr); } project.AbortTransaction(); MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); result = elaborator.RunInTransaction(project, testObj, fcos, 128); } finally { project.Close(true); } return result; }
public static void RunFormulaEvaluate(string projectPath, string absPath, bool automation) { Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); Type tFormulaEval = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyFormulaEvaluator"); var formulaEval = Activator.CreateInstance(tFormulaEval) as GME.MGA.IMgaComponentEx; formulaEval.ComponentParameter["automation"] = automation ? "true" : "false"; formulaEval.ComponentParameter["console_messages"] = "on"; formulaEval.ComponentParameter["expanded"] = "true"; //formulaEval.Initialize(project); formulaEval.InvokeEx(project, testObj, fcos, 16); } finally { project.Close(true); } }
public void InvokeExShouldNotThrowIfCurrentObjNull() { Assert.True(File.Exists(this.mgaFile), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(this.mgaFile); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath["/@TestBenches|kind=Testing|relpos=0/@DesignSpace|kind=Testing|relpos=0/@Dynamics|kind=Testing|relpos=0/@MSD_om_DS|kind=TestBench|relpos=0"] as MgaFCO; project.AbortTransaction(); MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); IMgaComponentEx interpreter = GetInterpreterByProgID(ProgID); Assert.DoesNotThrow(() => { interpreter.Initialize(project); }); Assert.DoesNotThrow(() => { interpreter.InvokeEx(project, null, fcos, 128); }); } finally { project.Close(true); } }
public void CopyMgaAndRunImporter(string tbName) { //proj.Save(proj.ProjectConnStr + asmName + ".mga", true); File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), (proj.ProjectConnStr + tbName + ".mga").Substring("MGA=".Length), true); MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject")); proj2.OpenEx(proj.ProjectConnStr + tbName + ".mga", "CyPhyML", null); proj2.BeginTransactionInNewTerr(); try { MgaFCO oldTestBench = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + tbName + "|kind=TestBench"); Assert.NotNull(oldTestBench); oldTestBench.DestroyObject(); CyPhyML.TestBenchType testBench; using (StreamReader streamReader = new StreamReader(Path.Combine(AtmPath, tbName + ".atm"))) { avm.TestBench avmTestBench = OpenMETA.Interchange.AvmXmlSerializer.Deserialize <avm.TestBench>(streamReader); testBench = CyPhy2TestBenchInterchange.TestBenchInterchange2CyPhy.Convert(avmTestBench, proj2); } } finally { proj2.CommitTransaction(); if (Debugger.IsAttached) { proj2.Save(null, true); } proj2.Close(true); } }
//public List<IMgaFCO> InsertComponents( // IMgaFCO designContainer, // IMgaFCO componentRef, // List<IMgaFCO> components, // List<KeyValuePair<IMgaFCO, string>> messages) /// <summary> /// Calls CLM_LIght without showing any GUI. /// </summary> /// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param> /// <param name="projectPath">name of mga-file</param> /// <param name="absPath">Folder-path to test-bench</param> /// <returns>Boolean - True -> interpreter call was successful</returns> public static bool Run( string projectPath, string absPathDesignContainer, List <string> absPathComponentsToAdd) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + projectPath; //Type CLM_light_interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CLM_light"); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { //dynamic interpreter = Activator.CreateInstance(CLM_light_interpreter); var interpreter = new CLM_light.CLM_lightInterpreter(); interpreter.Initialize(project); var terr = project.BeginTransactionInNewTerr(); var designContainer = project.ObjectByPath[absPathDesignContainer] as MgaFCO; List <IMgaFCO> componentsToAdd = new List <IMgaFCO>(); var defaultComponentRef = designContainer.ChildObjects.Cast <MgaFCO>().FirstOrDefault(x => x.Meta.Name == "ComponentRef"); var compRefCountBeforeInsert = designContainer.ChildObjects.Cast <MgaFCO>().Count(x => x.Meta.Name == "ComponentRef"); Assert.False(defaultComponentRef == null, string.Format("Design Container has no Component References: {0}", absPathDesignContainer)); foreach (string path in absPathComponentsToAdd) { var component = project.ObjectByPath[path] as MgaFCO; Assert.False(component == null, string.Format("Component was not found in the project: {0}", path)); componentsToAdd.Add(component); } List <KeyValuePair <IMgaFCO, string> > messages = new List <KeyValuePair <IMgaFCO, string> >(); if (interpreter.CheckForValidContext(designContainer)) { List <IMgaFCO> results = interpreter.InsertComponents(designContainer, defaultComponentRef, componentsToAdd, messages); var compRefCountAfterInsert = designContainer.ChildObjects.Cast <MgaFCO>().Count(x => x.Meta.Name == "ComponentRef"); result = compRefCountBeforeInsert + absPathComponentsToAdd.Count == compRefCountAfterInsert; project.AbortTransaction(); Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length))); } } finally { project.Close(true); } return(result); }
public void LibraryAttach() { var mgaReference = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.EnableAutoAddOns(true); project.OpenEx(mgaReference, "CyPhyML", null); try { Assert.Contains("MGA.Addon.CyPhyDecoratorAddon", project.AddOnComponents.Cast <IMgaComponentEx>().Select(addon => addon.ComponentProgID)); MgaFolder lib; project.BeginTransactionInNewTerr(); try { project.RootFolder.AttachLibrary(project.ProjectConnStr, out lib); } finally { project.CommitTransaction(); } } finally { project.Close(true); } Assert.True(File.Exists(mgaReference.Substring("MGA=".Length))); }
public void CopyMgaAndRunDesignImporter(string asmName) { //proj.Save(proj.ProjectConnStr + asmName + ".mga", true); File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), (proj.ProjectConnStr + asmName + ".mga").Substring("MGA=".Length), true); MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject")); proj2.OpenEx(proj.ProjectConnStr + asmName + ".mga", "CyPhyML", null); proj2.BeginTransactionInNewTerr(); try { MgaFCO componentAssembly = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + asmName); Assert.NotNull(componentAssembly); componentAssembly.DestroyObject(); var importer = new CyPhyDesignImporter.AVMDesignImporter(null, proj2); avm.Design design; using (StreamReader streamReader = new StreamReader(Path.Combine(AdmPath, asmName + ".adm"))) design = CyPhyDesignImporter.CyPhyDesignImporterInterpreter.DeserializeAvmDesignXml(streamReader); var ret = (ISIS.GME.Dsml.CyPhyML.Interfaces.DesignEntity)importer.ImportDesign(design, "ComponentAssemblies" == FolderName ? CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_CAS : CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_DS); } finally { proj2.CommitTransaction(); if (Debugger.IsAttached) { proj2.Save(null, true); } proj2.Close(true); } }
public static bool RunElaborator(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; if (testObj == null) { throw new ApplicationException(absPath + " not found in " + project.ProjectConnStr); } project.AbortTransaction(); MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter(); result = elaborator.RunInTransaction(project, testObj, fcos, 128); } finally { project.Close(true); } return(result); }
// This tests that the interpreters would not fail on null object public void CAD_CurrentObjectNull() { var XmePath = Path.GetFullPath(@"..\..\..\..\models\CADTeam\MSD_CAD.xme"); UnpackXmes(XmePath); var mgaFile = XmePath.Replace(".xme", ".mga"); string ProjectConnStr = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var PrepIFABInt = new CyPhyPrepareIFab.CyPhyPrepareIFabInterpreter(); var CADAnalysisInt = new CyPhyCADAnalysis.CyPhyCADAnalysisInterpreter(); var CyPhy2CAD = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter(); PrepIFABInt.Initialize(project); CADAnalysisInt.Initialize(project); CyPhy2CAD.Initialize(project); Assert.DoesNotThrow(() => PrepIFABInt.InvokeEx(project, null, null, 16)); Assert.DoesNotThrow(() => CyPhy2CAD.InvokeEx(project, null, null, 16)); Assert.DoesNotThrow(() => CADAnalysisInt.InvokeEx(project, null, null, 16)); } finally { project.Close(true); } }
public static bool RunContextCheck(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context result = masterInterpreter.TryCheckContext(testObj as MgaModel, out contextCheckerResults); } } finally { project.Close(true); } return(result); }
public static bool GetConfigurations(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(testObj as MgaModel); }; Assert.DoesNotThrow(d); } } finally { project.Close(true); } return(result); }
public void ShouldThrowExceptions() { // null context Assert.Throws <ArgumentNullException>(() => { AnalysisModelProcessor.GetAnalysisModelProcessor(null); }); Assert.True(File.Exists(this.mgaFile), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(this.mgaFile); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var componentAssembly = project.RootFolder.GetDescendantFCOs(project.CreateFilter()).OfType <MgaModel>().FirstOrDefault(x => x.MetaBase.Name == "ComponentAssembly"); Assert.True(componentAssembly != null, string.Format("{0} project must contain one component assembly.", Path.GetFullPath(this.mgaFile))); // invalid context Assert.Throws <AnalysisModelContextNotSupportedException>(() => { AnalysisModelProcessor.GetAnalysisModelProcessor(componentAssembly); }); } finally { project.AbortTransaction(); project.Close(true); } }
public static bool GetConfigurations(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { IMgaFCOs configurations = null; Assert.ThrowsDelegate d = () => { configurations = masterInterpreter.GetConfigurations(testObj as MgaModel); }; Assert.DoesNotThrow(d); } } finally { project.Close(true); } return result; }
public static bool RunContextCheck(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null; // check context result = masterInterpreter.TryCheckContext(testObj as MgaModel, out contextCheckerResults); } } finally { project.Close(true); } return result; }
private MgaProject GetProject(String filename, String metaName) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { gmeConsole.Out.Write("Opening {0} ... ", filename); result.OpenEx("MGA=" + filename, metaName, null); } else { gmeConsole.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, metaName); } gmeConsole.Out.WriteLine("Done."); } else { gmeConsole.Error.WriteLine("{0} file must be an mga project.", filename); _exitStatus |= Errors.FileError; } } else { gmeConsole.Error.WriteLine("Please specify an Mga project."); _exitStatus |= Errors.FileError; } return(result); }
/// <summary> /// Calls CyPhy2Modelica using early bindings /// </summary> /// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param> /// <param name="projectPath">name of mga-file</param> /// <param name="absPath">Folder-path to test-bench</param> /// <returns>Boolean - True -> interpreter call was successful</returns> public static bool RunMain(string outputdirname, string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + projectPath; //Type CyPhy2Modelica_v2Interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CyPhy2Modelica_v2"); //Type MainParametersType = Type.GetTypeFromProgID("ISIS.CyPhyML.InterpreterConfiguration"); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); string OutputDir = Path.Combine(Path.GetDirectoryName(projectPath), outputdirname); if (Directory.Exists(OutputDir)) { Test.DeleteDirectory(OutputDir); } Directory.CreateDirectory(OutputDir); //dynamic interpreter = Activator.CreateInstance(CyPhy2Modelica_v2Interpreter); var interpreter = new CyPhy2Modelica_v2.CyPhy2Modelica_v2Interpreter(); interpreter.Initialize(project); //dynamic mainParameters = Activator.CreateInstance(MainParametersType); var mainParameters = new CyPhyGUIs.InterpreterMainParameters(); 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); var results = interpreter.Main(mainParameters); Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length))); result = results.Success; if (result == false) { Test.DeleteDirectory(OutputDir); } } finally { project.Close(true); } return(result); }
/// <summary> /// Calls CyPhy2Modelica using early bindings /// </summary> /// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param> /// <param name="projectPath">name of mga-file</param> /// <param name="absPath">Folder-path to test-bench</param> /// <returns>Boolean - True -> interpreter call was successful</returns> public static bool Run(string outputdirname, string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + projectPath; //Type CyPhy2Modelica_v2Interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CyPhy2Modelica_v2"); //Type MainParametersType = Type.GetTypeFromProgID("ISIS.CyPhyML.InterpreterConfiguration"); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); string OutputDir = Path.Combine(Path.GetDirectoryName(projectPath), outputdirname); if (Directory.Exists(OutputDir)) { Test.DeleteDirectory(OutputDir); } Directory.CreateDirectory(OutputDir); //dynamic interpreter = Activator.CreateInstance(CyPhy2Modelica_v2Interpreter); var interpreter = new CyPhy2Modelica_v2.CyPhy2Modelica_v2Interpreter(); interpreter.Initialize(project); //dynamic mainParameters = Activator.CreateInstance(MainParametersType); var mainParameters = new CyPhyGUIs.InterpreterMainParameters(); 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); var results = interpreter.MainThrows(mainParameters); Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length))); result = results.Success; if (result == false) { Test.DeleteDirectory(OutputDir); } } finally { project.Close(true); } return result; }
public void OpenProject(string mgaFile) { if (project != null) { project.Close(true); } project = new MgaProjectClass(); project.OpenEx("MGA=" + mgaFile, "CyPhyML", null); }
public void ProjectMgaOpen() { var mgaReference = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.OpenEx(mgaReference, "CyPhyML", null); project.Close(true); Assert.True(File.Exists(mgaReference.Substring("MGA=".Length))); }
public void ProjectMgaOpen() { var mgaReference = "MGA=" + this.mgaFile; MgaProject project = new MgaProject(); project.OpenEx(mgaReference, "CyPhyML", null); MgaHelper.CheckParadigmVersionUpgrade(project); project.Close(true); Assert.True(File.Exists(mgaReference.Substring("MGA=".Length))); }
public bool Execute() { Exception excep = null; bool success = false; Thread t = new Thread(() => { try { MgaProject project = new MgaProject(); project.OpenEx("MGA=" + InputFile, "MetaGME", null); try { string rootName; project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED); try { rootName = project.RootFolder.Name; } finally { project.AbortTransaction(); } if (Path.GetFileNameWithoutExtension(InputFile) != rootName) { // TODO: warn } IMgaComponentEx metaInterpreter = (IMgaComponentEx)Activator.CreateInstance(Type.GetTypeFromProgID("MGA.Interpreter.MetaInterpreter")); metaInterpreter.InvokeEx(project, null, null, (int)component_startmode_enum.GME_SILENT_MODE); success = File.ReadAllText(Path.Combine(Path.GetDirectoryName(InputFile), rootName + ".xmp.log")).Contains("Successfully generated"); } finally { project.Close(); } } catch (Exception e) { excep = e; } } ); t.SetApartmentState(ApartmentState.STA); t.Start(); t.Join(); if (excep != null) { throw new Exception("Error running MetaInterpreter", excep); } return(success); }
public void CreatedObjectWithDefaultNamesShouldNotHaveSpaces() { var mgaReference = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.EnableAutoAddOns(true); project.OpenEx(mgaReference, "CyPhyML", null); List <IMgaObject> createdObjects = new List <IMgaObject>(); try { var terr = project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED); // turn off CyPhySignalBlocksAddOn var addons = project.AddOnComponents.Cast <IMgaComponentEx>().Where(x => x.ComponentName == "CyPhySignalBlocksAddOnAddon"); foreach (var addon in addons) { try { addon.Enable(false); } catch (Exception ex) { // if one fails keep trying the other ones. } } // Use default names empty suffix createdObjects = this.CreateObjectHierarchy(project, ""); project.CommitTransaction(); project.BeginTransaction(terr, transactiontype_enum.TRANSACTION_NON_NESTED); // check renames foreach (var obj in createdObjects) { // this will fail on the first one // FIXME: should we collect everything and print a detailed message about failures? Assert.False(obj.Name.Contains(' '), string.Format("Name contains space, but it should not contain any spaces. {0} [{1}]", obj.Name, obj.MetaBase.DisplayedName)); } project.AbortTransaction(); } finally { project.Close(false); } Assert.True(File.Exists(mgaReference.Substring("MGA=".Length))); }
public static CyPhyMasterInterpreter.MasterInterpreterResult RunMasterInterpreterAndReturnResults( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false, [System.Runtime.CompilerServices.CallerMemberName] string functionName = "") { Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); MgaFCO testObj; MgaFCO configObj; try { testObj = project.ObjectByPath[absPath] as MgaFCO; configObj = project.ObjectByPath[configPath] as MgaFCO; } finally { project.AbortTransaction(); } using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; if (String.IsNullOrWhiteSpace(functionName) == false) { masterInterpreter.ResultsSubdirectoryName = functionName; var resultsDirPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(projectPath)), "results", masterInterpreter.ResultsSubdirectoryName); if (Directory.Exists(resultsDirPath)) { Directory.Delete(resultsDirPath, true); } } var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); Assert.True(miResults.Length == 1, "MasterInterpreter.RunInTransactionOnOneConfig should always return one result."); return(miResults[0]); } } finally { project.Close(true); } }
protected string CopyMgaAndRunDesignImporter(string asmName, Action <ISIS.GME.Dsml.CyPhyML.Interfaces.ComponentAssembly> caTest) { string testrunDir = Path.Combine(Path.GetDirectoryName(proj.ProjectConnStr.Substring("MGA=".Length)), "testrun"); try { Directory.Delete(testrunDir, true); } catch (DirectoryNotFoundException) { } Directory.CreateDirectory(testrunDir); string importMgaPath = Path.Combine(testrunDir, Path.GetFileNameWithoutExtension(proj.ProjectConnStr.Substring("MGA=".Length)) + asmName + ".mga"); //proj.Save(proj.ProjectConnStr + asmName + ".mga", true); File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), importMgaPath, true); MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject")); proj2.OpenEx("MGA=" + importMgaPath, "CyPhyML", null); proj2.BeginTransactionInNewTerr(); try { MgaFCO componentAssembly = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + asmName); Assert.NotNull(componentAssembly); componentAssembly.DestroyObject(); var importer = new CyPhyDesignImporter.AVMDesignImporter(null, proj2); avm.Design design; var adpPath = Path.Combine(fixture.AdmPath, asmName + ("ComponentAssemblies" == FolderName ? ".adp" : ".adm")); var ret = importer.ImportFile(adpPath, "ComponentAssemblies" == FolderName ? CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_CAS : CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_DS); if (caTest != null) { caTest((ISIS.GME.Dsml.CyPhyML.Interfaces.ComponentAssembly)ret); } } finally { proj2.CommitTransaction(); if (Debugger.IsAttached) { proj2.Save(null, true); } proj2.Close(true); } return(importMgaPath); }
public void TestExcelImport() { var excelType = Type.GetTypeFromProgID("Excel.Application"); if (excelType == null) { Console.Out.WriteLine("Skipping " + GetCurrentMethod() + " because Excel is not installed"); return; } MgaProject project = new MgaProject(); project.OpenEx("MGA=" + this.mgaFile, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var excel = (IMgaModel)project.ObjectByPath["/@Testing/@ParametricExploration/@TestExcel/@ExcelWrapper"]; foreach (var fco in excel.ChildFCOs.Cast <IMgaFCO>().ToList()) { fco.DestroyObject(); } var excelDS = ISIS.GME.Dsml.CyPhyML.Classes.ExcelWrapper.Cast(excel); string mgaDir = Path.GetDirectoryName(Path.GetFullPath(excel.Project.ProjectConnStr.Substring("MGA=".Length))); CyPhyPET.CyPhyPETInterpreter.CreateParametersAndMetricsForExcel(excelDS, Path.Combine(mgaDir, excelDS.Attributes.ExcelFilename)); Dictionary <string, ISIS.GME.Dsml.CyPhyML.Interfaces.Parameter> params_ = excelDS.Children.ParameterCollection.ToDictionary(p => p.Name, p => p); Assert.Contains("x", params_.Keys); Assert.Contains("b", params_.Keys); Assert.Contains("s", params_.Keys); Assert.Equal("12", params_["x"].Attributes.Value); Dictionary <string, ISIS.GME.Dsml.CyPhyML.Interfaces.Metric> metrics = excelDS.Children.MetricCollection.ToDictionary(m => m.Name, m => m); Assert.Contains("y", metrics.Keys); Assert.Contains("bout", metrics.Keys); Assert.Contains("sout", metrics.Keys); } finally { project.AbortTransaction(); project.Close(); } }
public static CyPhyMasterInterpreter.MasterInterpreterResult RunMasterInterpreterAndReturnResults( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false) { Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); MgaFCO testObj; MgaFCO configObj; try { testObj = project.ObjectByPath[absPath] as MgaFCO; configObj = project.ObjectByPath[configPath] as MgaFCO; } finally { project.AbortTransaction(); } using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); Assert.True(miResults.Length == 1, "MasterInterpreter.RunInTransactionOnOneConfig should always return one result."); return(miResults[0]); } } finally { project.Close(true); } }
public void CyPhyMultiJobRun_CurrentObjectNull() { Assert.True(File.Exists(mgaFile), "Failed to generate the mga."); string ProjectConnStr = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var interpreter = new CyPhyMultiJobRun.CyPhyMultiJobRunInterpreter(); interpreter.Initialize(project); Assert.DoesNotThrow(() => interpreter.InvokeEx(project, null, null, 16)); } finally { project.Close(true); } }
public static bool AnalysisModelSupported(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null; project.BeginTransactionInNewTerr(); try { Assert.ThrowsDelegate d = () => { analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(testObj as MgaModel); }; Assert.DoesNotThrow(d); Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", testObj.Name, testObj.Meta.Name)); } finally { project.AbortTransaction(); } } finally { project.Close(true); } return(result); }
public void NullObjectAndInteractiveMode() { MgaProject project = null; MgaFCO currentObj = null; MgaFCOs fcos = null; MgaObject obj = null; MgaObjects objs = null; IMgaComponentEx interpreter = GetInterpreterByProgID(ProgID); Assert.Throws <ArgumentNullException>(() => { interpreter.Initialize(project); }); Assert.Throws <NotImplementedException>(() => { interpreter.ObjectsInvokeEx(project, obj, objs, 128); }); Assert.Throws <ArgumentNullException>(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); Assert.True(File.Exists(this.mgaFile), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(this.mgaFile); project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { // project is set, but fcos are not Assert.DoesNotThrow(() => { interpreter.Initialize(project); }); Assert.Throws <ArgumentNullException>(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); // fcos are set fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); Assert.DoesNotThrow(() => { interpreter.InvokeEx(project, currentObj, fcos, 128); }); Assert.True(interpreter.InteractiveMode == false, "Interactive is not set correctly. (128) silent mode"); Assert.DoesNotThrow(() => { interpreter.InvokeEx(project, currentObj, fcos, 16); }); Assert.True(interpreter.InteractiveMode == true, "Interactive is not set correctly. (16)"); } finally { project.Close(true); } }
public void ComponentLibraryManagerAddonRelativeProjectPathURI() { var mgaReference = "MGA=" + mgaFile; MgaProject project = new MgaProject(); project.EnableAutoAddOns(true); project.OpenEx(mgaReference, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED); // turn off CyPhySignalBlocksAddOn var addons = project.AddOnComponents.Cast <IMgaComponentEx>().Where(x => x.ComponentName == "CyPhySignalBlocksAddOnAddon"); foreach (var addon in addons) { try { addon.Enable(false); } catch (Exception ex) { // if one fails keep trying the other ones. } } var components = project.RootFolder.CreateFolder(project.RootMeta.RootFolder.LegalChildFolderByName["Components"]); components.Name = "ComponentLibraryManagerAddonProjectPathURITest"; var component = components.CreateRootObject(project.RootMeta.RootFolder.DefinedFCOByName["Component", false]); component.Name = "ComponentLibraryManagerAddonProjectPathURITest"; project.CommitTransaction(); } finally { project.Close(false); } }
public void TestInitArguments() { MgaProject project = new MgaProject(); project.OpenEx("MGA=" + mgaFile, "CyPhyML", null); try { project.BeginTransactionInNewTerr(); try { string petExperimentPath = "/@Testing/@ParametricExploration/@TestAnalysis"; string assemblyDir = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath); string pyFile = Path.Combine(assemblyDir, "..\\..\\..\\..\\models\\PET_simple_proof-of-concept\\sample_analysis.py"); MgaModel model = (MgaModel)project.ObjectByPath[petExperimentPath]; var params_ = CyPhyPET.CyPhyPETInterpreter.GetPythonComponentInitializerParameters(pyFile, (MgaFCO)model); Assert.Equal(new string[] { "self", "config1", "config2", "opt1", "opt2" }, params_.args); Assert.Equal(new string[] { "self", "config1", "config2" }, params_.requiredArgs); Assert.Equal(new object[] { null, 0.0 }, params_.defaults); var analysisBlock = ISIS.GME.Dsml.CyPhyML.Classes.AnalysisBlock.Cast(model.ObjectByPath["/@AnalysisBlock"]); CyPhyPET.CyPhyPETInterpreter.EditConfigurationParameters(params_, analysisBlock, showGui: false); var kwargs = CyPhyPET.CyPhyPETInterpreter.GetConfigurationParameters(analysisBlock); CyPhyPET.CyPhyPETInterpreter.GetParamsAndUnknownsForPythonOpenMDAO(pyFile, analysisBlock, kwargs); } finally { project.AbortTransaction(); } } finally { project.Close(true); } }
public void Test_CyPhyPET_unit_matcher() { var project = new MgaProject(); project.OpenEx("MGA=" + this.mgaFile, "CyPhyML", null); try { project.BeginTransactionInNewTerr(); try { var wrapper = project.RootFolder.ObjectByPath["/@Testing/@ParametricExploration/@TestPython/@PythonWrapper"]; var pythonBlock = ISIS.GME.Dsml.CyPhyML.Classes.PythonWrapper.Cast(wrapper); var binDir = Path.GetDirectoryName(System.Reflection.Assembly.GetAssembly(typeof(Workflow_PET_Test)).CodeBase.Substring("file:///".Length)); var path = Path.GetFullPath(binDir + "/../../paraboloid.py"); var pet = CyPhyPET.CyPhyPETInterpreter.GetParamsAndUnknownsForPythonOpenMDAO(path, pythonBlock); // "{\"unknowns\": {\"f_xy\": {\"units\": \"m**3\", \"gme_unit_id\": \"id-0065-00000179\", \"shape\": 1, \"val\": 0.0, \"size\": 1}}, \"params\": {\"x\": {\"units\": \"m\", \"gme_unit_id\": \"id-0066-00000014\", \"shape\": 1, \"val\": 0.0, \"size\": 1}, \"y\": {\"units\": \"m**3\", \"gme_unit_id\": \"id-0065-00000179\", \"shape\": 1, \"val\": 0.0, \"size\": 1}}}" var unknowns = pet["unknowns"]; var params_ = pet["params"]; var x = params_["x"]; var y = params_["y"]; var f_xy = unknowns["f_xy"]; Assert.Equal("Meter", project.GetFCOByID((string)x["gme_unit_id"]).Name); Assert.Equal("Cubic Meter", project.GetFCOByID((string)y["gme_unit_id"]).Name); Assert.Equal("Cubic Meter", project.GetFCOByID((string)f_xy["gme_unit_id"]).Name); } finally { project.CommitTransaction(); } } finally { project.Close(abort: true); } }
private MgaProject GetProject(String filename, String metaName) { MgaProject result = null; if (filename != null && filename != "") { if (Path.GetExtension(filename) == ".mga") { result = new MgaProject(); if (System.IO.File.Exists(filename)) { gmeConsole.Out.Write("Opening {0} ... ", filename); result.OpenEx("MGA=" + filename, metaName, null); } else { gmeConsole.Out.Write("Creating {0} ... ", filename); result.Create("MGA=" + filename, metaName); } gmeConsole.Out.WriteLine("Done."); } else { gmeConsole.Error.WriteLine("{0} file must be an mga project.", filename); _exitStatus |= Errors.FileError; } } else { gmeConsole.Error.WriteLine("Please specify an Mga project."); _exitStatus |= Errors.FileError; } return result; }
//public List<IMgaFCO> InsertComponents( // IMgaFCO designContainer, // IMgaFCO componentRef, // List<IMgaFCO> components, // List<KeyValuePair<IMgaFCO, string>> messages) /// <summary> /// Calls CLM_LIght without showing any GUI. /// </summary> /// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param> /// <param name="projectPath">name of mga-file</param> /// <param name="absPath">Folder-path to test-bench</param> /// <returns>Boolean - True -> interpreter call was successful</returns> public static bool Run( string projectPath, string absPathDesignContainer, List<string> absPathComponentsToAdd) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + projectPath; //Type CLM_light_interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CLM_light"); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { //dynamic interpreter = Activator.CreateInstance(CLM_light_interpreter); var interpreter = new CLM_light.CLM_lightInterpreter(); interpreter.Initialize(project); var terr = project.BeginTransactionInNewTerr(); var designContainer = project.ObjectByPath[absPathDesignContainer] as MgaFCO; List<IMgaFCO> componentsToAdd = new List<IMgaFCO>(); var defaultComponentRef = designContainer.ChildObjects.Cast<MgaFCO>().FirstOrDefault(x => x.Meta.Name == "ComponentRef"); var compRefCountBeforeInsert = designContainer.ChildObjects.Cast<MgaFCO>().Count(x => x.Meta.Name == "ComponentRef"); Assert.False(defaultComponentRef == null, string.Format("Design Container has no Component References: {0}", absPathDesignContainer)); foreach (string path in absPathComponentsToAdd) { var component = project.ObjectByPath[path] as MgaFCO; Assert.False(component == null, string.Format("Component was not found in the project: {0}", path)); componentsToAdd.Add(component); } List<KeyValuePair<IMgaFCO, string>> messages = new List<KeyValuePair<IMgaFCO, string>>(); if (interpreter.CheckForValidContext(designContainer)) { List<IMgaFCO> results = interpreter.InsertComponents(designContainer, defaultComponentRef, componentsToAdd, messages); var compRefCountAfterInsert = designContainer.ChildObjects.Cast<MgaFCO>().Count(x => x.Meta.Name == "ComponentRef"); result = compRefCountBeforeInsert + absPathComponentsToAdd.Count == compRefCountAfterInsert; project.AbortTransaction(); Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length))); } } finally { project.Close(true); } return result; }
public static bool RunMasterInterpreter( string projectPath, string absPath, string configPath, bool postToJobManager = false, bool keepTempModels = false) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; var configObj = project.ObjectByPath[configPath] as MgaFCO; project.AbortTransaction(); using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project)) { masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug; var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels); result = miResults.Any(x => x.Success == false) ? false: true; } } finally { project.Close(true); } return result; }
public static bool AnalysisModelSupported(string projectPath, string absPath) { bool result = false; Assert.True(File.Exists(projectPath), "Project file does not exist."); string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath); MgaProject project = new MgaProject(); project.OpenEx(ProjectConnStr, "CyPhyML", null); try { var terr = project.BeginTransactionInNewTerr(); var testObj = project.ObjectByPath[absPath] as MgaFCO; project.AbortTransaction(); CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null; project.BeginTransactionInNewTerr(); try { Assert.ThrowsDelegate d = () => { analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(testObj as MgaModel); }; Assert.DoesNotThrow(d); Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", testObj.Name, testObj.Meta.Name)); } finally { project.AbortTransaction(); } } finally { project.Close(true); } return result; }
protected void RunCyPhyMLSync(System.Action <MgaProject, CyPhyMetaLink.CyPhyMetaLinkAddon, CyPhyMetaLink.CyPhyMetalinkInterpreter> testAction) { try { if (debugMetalinkStartup) { metalink.WaitForExit(); string stderr = metalink.StandardError.ReadToEnd(); string stdout = metalink.StandardOutput.ReadToEnd(); } Exception exception = null; AutoResetEvent workEvent = new AutoResetEvent(false); Thread work = new Thread(new ThreadStart(delegate { try { // Import XME file to create an MGA String xmeFullPath = Path.Combine(TestModelDir, testXMEFilename); String mgaFullPath = TestModelDir + testInputFilename; MgaUtils.ImportXME(xmeFullPath, mgaFullPath); Assert.True(File.Exists(mgaFullPath), "MGA file not found. XME import may have failed."); MgaProject project = new MgaProject(); project.EnableAutoAddOns(true); project.OpenEx("MGA=" + mgaFullPath, "", true); CyPhyMetaLink.CyPhyMetaLinkAddon propagate = null; try { Assert.Contains("MGA.Addon.CyPhyMLPropagate", project.AddOnComponents.Cast <IMgaComponentEx>().Select(x => x.ComponentProgID)); propagate = (CyPhyMetaLink.CyPhyMetaLinkAddon)project.AddOnComponents.Cast <IMgaComponent>().Where(comp => comp is CyPhyMetaLink.CyPhyMetaLinkAddon).FirstOrDefault(); CyPhyMetaLink.CyPhyMetalinkInterpreter interpreter = new CyPhyMetaLink.CyPhyMetalinkInterpreter(); propagate.TestMode = true; propagate.TestMode_NoAutomaticCreoStart = true; propagate.TestMode_CreoJobObject = JobObjectPinvoke.CreateKillOnCloseJob(); interpreter.GMEConsole = GME.CSharp.GMEConsole.CreateFromProject(project); interpreter.MgaGateway = new MgaGateway(project); var task = Task.Run(async() => await interpreter.ConnectToMetaLinkBridge(project, 128)); task.Wait(); propagate.bridgeClient.SocketQueue.EditMessageReceived += msg => addonMessagesQueue.Add(msg); testAction(project, propagate, interpreter); } finally { if (propagate != null) { JobObjectPinvoke.CloseHandle(propagate.TestMode_CreoJobObject); propagate.TestMode_CreoJobObject = IntPtr.Zero; } project.Save(project.ProjectConnStr + "_posttest.mga", true); project.Close(true); } } catch (Exception e) { exception = e; KillMetaLink(); } finally { workEvent.Set(); } })); work.SetApartmentState(ApartmentState.STA); work.Start(); ManualResetEvent metalinkEvent = new ManualResetEvent(true); metalinkEvent.SafeWaitHandle = new SafeWaitHandle(metalink.Handle, false); int handle = WaitHandle.WaitAny(new WaitHandle[] { metalinkEvent, workEvent }); if (exception != null) { throw new Exception("Test failed", exception); } if (handle == 0) { work.Abort(); throw new Exception("metalink exited"); } } finally { KillMetaLink(); lock (metalinkLogStream) metalinkLogStream.Dispose(); } }
protected void RunCyPhyMLSync(System.Action<MgaProject, CyPhyMetaLink.CyPhyMetaLinkAddon, CyPhyMetaLink.CyPhyMetalinkInterpreter> testAction) { try { if (debugMetalinkStartup) { metalink.WaitForExit(); string stderr = metalink.StandardError.ReadToEnd(); string stdout = metalink.StandardOutput.ReadToEnd(); } Exception exception = null; AutoResetEvent workEvent = new AutoResetEvent(false); Thread work = new Thread(new ThreadStart(delegate { try { // Import XME file to create an MGA String xmeFullPath = Path.Combine(TestModelDir, testXMEFilename); String mgaFullPath = TestModelDir + testInputFilename; MgaUtils.ImportXME(xmeFullPath, mgaFullPath); Assert.True(File.Exists(mgaFullPath), "MGA file not found. XME import may have failed."); MgaProject project = new MgaProject(); project.EnableAutoAddOns(true); project.OpenEx("MGA=" + mgaFullPath, "", true); try { Assert.Contains("MGA.Addon.CyPhyMLPropagate", project.AddOnComponents.Cast<IMgaComponentEx>().Select(x => x.ComponentProgID)); CyPhyMetaLink.CyPhyMetaLinkAddon propagate = (CyPhyMetaLink.CyPhyMetaLinkAddon)project.AddOnComponents.Cast<IMgaComponent>().Where(comp => comp is CyPhyMetaLink.CyPhyMetaLinkAddon).FirstOrDefault(); CyPhyMetaLink.CyPhyMetalinkInterpreter interpreter = new CyPhyMetaLink.CyPhyMetalinkInterpreter(); propagate.TestMode = true; interpreter.GMEConsole = GME.CSharp.GMEConsole.CreateFromProject(project); interpreter.MgaGateway = new MgaGateway(project); interpreter.ConnectToMetaLinkBridge(project, 128); propagate.bridgeClient.SocketQueue.EditMessageReceived += msg => addonMessagesQueue.Add(msg); testAction(project, propagate, interpreter); } finally { project.Save(project.ProjectConnStr + "_posttest.mga", true); project.Close(true); } } catch (Exception e) { exception = e; KillMetaLink(); } finally { workEvent.Set(); } })); work.SetApartmentState(ApartmentState.STA); work.Start(); ManualResetEvent metalinkEvent = new ManualResetEvent(true); metalinkEvent.SafeWaitHandle = new SafeWaitHandle(metalink.Handle, false); int handle = WaitHandle.WaitAny(new WaitHandle[] { metalinkEvent, workEvent }); if (exception != null) { throw new Exception("Test failed", exception); } if (handle == 0) { work.Abort(); throw new Exception("metalink exited"); } } finally { KillMetaLink(); lock (metalinkLogStream) metalinkLogStream.Dispose(); } }
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)); }