private static void ImportTest(String p_test, String p_xme, out String p_mga) { try { String xmeName = Path.GetFileName(p_xme); Assert.True(File.Exists(p_xme), String.Format("{0} is missing", xmeName)); p_mga = p_xme.Replace(".xme", "_test.mga"); MgaUtils.ImportXME(p_xme, p_mga); // Assert that MGA file exists, and is relatively new String mgaName = Path.GetFileName(p_mga); Assert.True(File.Exists(p_mga), String.Format("{0} does not exist. It probably didn't import successfully.", mgaName)); DateTime dt_mgaLastWrite = File.GetLastWriteTime(p_mga); var threshold = DateTime.Now.AddSeconds(-10.0); Assert.True(dt_mgaLastWrite > threshold, String.Format("{0} is older than 10 seconds. It probably didn't import successfully, and this is an old copy.", mgaName)); // Delete temp file File.Delete(p_mga); } catch (Exception exc) { throw exc; } }
private void unpackXme(string xmeFilename) { if (!File.Exists(xmeFilename)) { return; } var mgaFilename = Path.ChangeExtension(xmeFilename, "mga"); MgaUtils.ImportXME(xmeFilename, mgaFilename); }
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(); } }