public InterpreterFixtureBaseClass() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(path_XME, out mgaConnectionString); path_MGA = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(path_MGA)), String.Format("{0} not found. Model import may have failed.", path_MGA)); foreach (string dirname in new string[] { Path.Combine(path_Test, "output"), Path.Combine(path_Test, "results") }) { if (Directory.Exists(dirname)) { foreach (string filename in Directory.GetFiles(dirname, "*", SearchOption.AllDirectories)) { File.Delete(Path.Combine(dirname, filename)); } } } proj = new MgaProject(); bool ro_mode; proj.Open("MGA=" + Path.GetFullPath(path_MGA), out ro_mode); proj.EnableAutoAddOns(true); // Ensure "~/Documents/eagle" exists var pathDocEagle = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "eagle"); Directory.CreateDirectory(pathDocEagle); }
public ValueFlowTestFixture() { String connectionString; GME.MGA.MgaUtils.ImportXMEForTest(path_XME, out connectionString); Boolean ro_mode; Project = new MgaProject(); Project.Open(connectionString, out ro_mode); Project.EnableAutoAddOns(true); MgaFilter filter = Project.CreateFilter(); filter.Kind = "Component"; filter.Name = "ValueFlow"; var mgaGateway = new MgaGateway(Project); mgaGateway.PerformInTransaction(delegate { ValueFlow = Project.AllFCOs(filter) .Cast <MgaFCO>() .Select(x => CyPhyC.Component.Cast(x)) .First(); RunFormulaEvaluator(ValueFlow.Impl as MgaFCO); }, transactiontype_enum.TRANSACTION_GENERAL, abort: false); }
public OrganizeByCategoryFixture() { #region Set up test model and folder if (!Directory.Exists(PathTest)) { Directory.CreateDirectory(PathTest); } if (File.Exists(PathTestXME)) { File.Delete(PathTestXME); } File.Copy(PathOriginalXME, PathTestXME); #endregion String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(PathTestXME, out mgaConnectionString); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter(); importer.Initialize(proj); }
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 static void ImportXME(string xmePath, string mgaPath, bool enableAutoAddons = false) { MgaParser parser = new MgaParser(); string paradigm; string paradigmVersion; object paradigmGuid; string basename; string version; parser.GetXMLInfo(xmePath, out paradigm, out paradigmVersion, out paradigmGuid, out basename, out version); parser = new MgaParser(); MgaProject project = new MgaProject(); MgaResolver resolver = new MgaResolver(); resolver.IsInteractive = false; dynamic dynParser = parser; dynParser.Resolver = resolver; project.Create("MGA=" + Path.GetFullPath(mgaPath), paradigm); if (enableAutoAddons) { project.EnableAutoAddOns(true); } try { parser.ParseProject(project, xmePath); project.Save(); } finally { project.Close(); } }
public static void ImportXME(string xmePath, string mgaPath, bool enableAutoAddons=false) { MgaParser parser = new MgaParser(); string paradigm; string paradigmVersion; object paradigmGuid; string basename; string version; parser.GetXMLInfo(xmePath, out paradigm, out paradigmVersion, out paradigmGuid, out basename, out version); parser = new MgaParser(); MgaProject project = new MgaProject(); MgaResolver resolver = new MgaResolver(); resolver.IsInteractive = false; dynamic dynParser = parser; dynParser.Resolver = resolver; project.Create("MGA=" + Path.GetFullPath(mgaPath), paradigm); if (enableAutoAddons) { project.EnableAutoAddOns(true); } try { parser.ParseProject(project, xmePath); project.Save(); } finally { project.Close(); } }
public ExporterFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(pathXME, out mgaConnectionString); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
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 DesignImporterTestFixtureBase() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(Path.Combine(PathTest, pathXME), out mgaConnectionString); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
public ExporterFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(pathXME, out mgaConnectionString); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
public GMEProjectFixtureBase() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(xmePath, out mgaConnectionString); var mgaPath = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(mgaPath)), String.Format("{0} not found. Model import may have failed.", mgaPath)); proj = new MgaProject(); bool ro_mode; proj.Open("MGA=" + Path.GetFullPath(mgaPath), out ro_mode); proj.EnableAutoAddOns(true); }
public ExportZipFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(path_XME, out mgaConnectionString); path_MGA = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(path_MGA)), String.Format("{0} not found. Model import may have failed.", path_MGA)); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
public FormulaEvaluatorFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(FormulaEvaluator.xmePath, out mgaConnectionString); mgaPath = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(mgaPath)), String.Format("{0} not found. Model import may have failed.", mgaPath)); proj = new MgaProject(); bool ro_mode; proj.Open("MGA=" + Path.GetFullPath(mgaPath), out ro_mode); proj.EnableAutoAddOns(true); }
public InterpreterFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(path_XME, out mgaConnectionString); var path_MGA = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(path_MGA)), String.Format("{0} not found. Model import may have failed.", path_MGA)); if (Directory.Exists(Path.Combine(path_Test, "output"))) { Directory.Delete(Path.Combine(path_Test, "output"), true); } proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
public DesignPackageFixture() { // Delete files from past runs var adm = Directory.EnumerateFiles(PathTest, "*.adm", SearchOption.AllDirectories); var adp = Directory.EnumerateFiles(PathTest, "*.adp", SearchOption.AllDirectories); foreach (var file in adm.Union(adp)) { File.Delete(file); } String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(pathXME, out mgaConnectionString); proj = new MgaProject(); bool ro_mode; proj.Open(mgaConnectionString, out ro_mode); proj.EnableAutoAddOns(true); }
public TestFixture() { String mgaConnectionString; // n.b. another test uses Schematic_test.mga, so use a different name GME.MGA.MgaUtils.ImportXMEForTest(path_XME, Path.Combine(Path.GetDirectoryName(path_XME), Path.GetFileNameWithoutExtension(path_XME) + "_CyPhy2CADPCB_test.mga"), out mgaConnectionString); path_MGA = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(path_MGA)), String.Format("{0} not found. Model import may have failed.", path_MGA)); if (Directory.Exists(Path.Combine(path_Test, "output"))) { Directory.Delete(Path.Combine(path_Test, "output"), true); } if (Directory.Exists(Path.Combine(path_Test, "results"))) { Directory.Delete(Path.Combine(path_Test, "results"), true); } proj = new MgaProject(); bool ro_mode; proj.Open("MGA=" + Path.GetFullPath(path_MGA), out ro_mode); proj.EnableAutoAddOns(true); // Ensure "~/Documents/eagle" exists var pathDocEagle = Path.Combine(Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%"), "Documents", "eagle"); if (!Directory.Exists(pathDocEagle)) { Directory.CreateDirectory(pathDocEagle); } }
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 VFTestFixture() { String mgaConnectionString; GME.MGA.MgaUtils.ImportXMEForTest(xmePath, out mgaConnectionString); var mgaPath = mgaConnectionString.Substring("MGA=".Length); Assert.True(File.Exists(Path.GetFullPath(mgaPath)), String.Format("{0} not found. Model import may have failed.", mgaPath)); // Copy the python scripts referenced in the Python Math Block System.IO.Directory.CreateDirectory("scripts"); File.Copy(Path.Combine("..", "..", "..", "..", "scripts", "optimizeContainer.py"), Path.Combine("scripts", "optimizeContainer.py"), true); //Overwrite = true proj = new MgaProject(); bool ro_mode; proj.Open("MGA=" + Path.GetFullPath(mgaPath), out ro_mode); proj.EnableAutoAddOns(true); }
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(); } }
//[Fact] public void DesignSpaceWithRefs() { var fullTestPath = Path.Combine(_exportModelDirectory, "DesignSpaceWithRefs"); var xmeFilePath = Path.Combine(fullTestPath, "DesignSpaceWithRefs.xme"); var pathExportedDesign = Path.Combine(fullTestPath, "DesignSpace.adm"); // delete design file if it already exists if (File.Exists(pathExportedDesign)) { File.Delete(pathExportedDesign); } String connectionString; GME.MGA.MgaUtils.ImportXMEForTest(xmeFilePath, out connectionString); var proj = new MgaProject(); bool ro_mode; proj.Open(connectionString, out ro_mode); proj.EnableAutoAddOns(true); try { var designExporter = new CyPhyDesignExporter.CyPhyDesignExporterInterpreter(); designExporter.Initialize(proj); var mgaGateway = new MgaGateway(proj); MgaFCO currentFCO = null; mgaGateway.PerformInTransaction(delegate { currentFCO = proj.get_ObjectByPath("/@DesignSpaces|kind=DesignSpace|relpos=0/@DesignSpace|kind=DesignContainer|relpos=0") as MgaFCO; Assert.NotNull(currentFCO); }); var parameters = new CyPhyGUIs.InterpreterMainParameters() { CurrentFCO = currentFCO, Project = proj, OutputDirectory = fullTestPath }; var result = designExporter.Main(parameters); var design = avm.Design.LoadFromFile(pathExportedDesign); /// Add assert statements to check structure var root = design.RootContainer; Assert.NotNull(root); Assert.Equal(1, root.Container1.Count(c => c.Name == "AltContainer")); var AltContainer = root.Container1.First(c => c.Name == "AltContainer"); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_5")); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_6")); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_7")); Assert.Equal(1, root.Container1.Count(c => c.Name == "DesignContainer")); var DesignContainer = root.Container1.First(c => c.Name == "DesignContainer"); Assert.Equal(1, DesignContainer.ComponentInstance.Count(ci => ci.Name == "CompA3")); Assert.Equal(1, DesignContainer.Container1.Count(c => c.Name == "Assembly1")); var Assembly1 = DesignContainer.Container1.First(c => c.Name == "Assembly1"); Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA1")); Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA2")); Assert.Equal(1, root.Container1.Count(c => c.Name == "ReusableContainer")); var ReusableContainer = root.Container1.First(c => c.Name == "ReusableContainer"); Assert.Equal(1, ReusableContainer.Container1.Count(c => c.Name == "Assembly4")); var Assembly4 = ReusableContainer.Container1.First(c => c.Name == "Assembly4"); Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA1")); Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA2")); Assert.Equal(1, ReusableContainer.ComponentInstance.Count(ci => ci.Name == "CompA4")); Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA")); Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA")); } finally { proj.Close(); } }
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(); } }
private static void ConvertAllSchematicsToCyPhy(string path) { var schematics = ConvertAllDevices(path); // Create MGA project on the spot. var proj = new MgaProject(); String connectionString = String.Format("MGA={0}", Path.GetTempFileName()); proj.Create(connectionString, "CyPhyML"); proj.EnableAutoAddOns(true); var mgaGateway = new MgaGateway(proj); var module = new CyPhyComponentAuthoring.Modules.EDAModelImport(); Dictionary <String, String> d_failures = new Dictionary <string, string>(); mgaGateway.PerformInTransaction(delegate { var rf = CyPhyClasses.RootFolder.GetRootFolder(proj); var cf = CyPhyClasses.Components.Create(rf); foreach (var t in schematics) { var identifier = t.Item1; var schematic = t.Item2; CyPhy.Component component = CyPhyClasses.Component.Create(cf); component.Name = identifier; module.SetCurrentDesignElement(component); module.CurrentObj = component.Impl as MgaFCO; try { var cyphySchematicModel = module.BuildCyPhyEDAModel(schematic, component); Assert.Equal(component.Children.SchematicModelCollection.Count(), 1); } catch (Exception e) { d_failures[identifier] = e.ToString(); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); proj.Save(); proj.Close(); if (d_failures.Any()) { String msg = String.Format("Failures in converting {0} component(s):" + Environment.NewLine, d_failures.Count); foreach (var kvp in d_failures) { msg += String.Format("{0}: {1}" + Environment.NewLine + Environment.NewLine, kvp.Key, kvp.Value); } Assert.True(false, msg); } }
//[Fact] public void DesignSpaceWithRefs() { var fullTestPath = Path.Combine(_exportModelDirectory, "DesignSpaceWithRefs"); var xmeFilePath = Path.Combine(fullTestPath, "DesignSpaceWithRefs.xme"); var pathExportedDesign = Path.Combine(fullTestPath, "DesignSpace.adm"); // delete design file if it already exists if (File.Exists(pathExportedDesign)) { File.Delete(pathExportedDesign); } String connectionString; GME.MGA.MgaUtils.ImportXMEForTest(xmeFilePath, out connectionString); var proj = new MgaProject(); bool ro_mode; proj.Open(connectionString, out ro_mode); proj.EnableAutoAddOns(true); try { var designExporter = new CyPhyDesignExporter.CyPhyDesignExporterInterpreter(); designExporter.Initialize(proj); var mgaGateway = new MgaGateway(proj); MgaFCO currentFCO = null; mgaGateway.PerformInTransaction(delegate { currentFCO = proj.get_ObjectByPath("/@DesignSpaces|kind=DesignSpace|relpos=0/@DesignSpace|kind=DesignContainer|relpos=0") as MgaFCO; Assert.NotNull(currentFCO); }); var parameters = new CyPhyGUIs.InterpreterMainParameters() { CurrentFCO = currentFCO, Project = proj, OutputDirectory = fullTestPath }; var result = designExporter.Main(parameters); var design = avm.Design.LoadFromFile(pathExportedDesign); /// Add assert statements to check structure var root = design.RootContainer; Assert.NotNull(root); Assert.Equal(1, root.Container1.Count(c => c.Name == "AltContainer")); var AltContainer = root.Container1.First(c => c.Name == "AltContainer"); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_5")); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_6")); Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_7")); Assert.Equal(1, root.Container1.Count(c => c.Name == "DesignContainer")); var DesignContainer = root.Container1.First(c => c.Name == "DesignContainer"); Assert.Equal(1, DesignContainer.ComponentInstance.Count(ci => ci.Name == "CompA3")); Assert.Equal(1, DesignContainer.Container1.Count(c => c.Name == "Assembly1")); var Assembly1 = DesignContainer.Container1.First(c => c.Name == "Assembly1"); Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA1")); Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA2")); Assert.Equal(1, root.Container1.Count(c => c.Name == "ReusableContainer")); var ReusableContainer = root.Container1.First(c => c.Name == "ReusableContainer"); Assert.Equal(1, ReusableContainer.Container1.Count(c => c.Name == "Assembly4")); var Assembly4 = ReusableContainer.Container1.First(c => c.Name == "Assembly4"); Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA1")); Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA2")); Assert.Equal(1, ReusableContainer.ComponentInstance.Count(ci => ci.Name == "CompA4")); Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA")); Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA")); } finally { proj.Close(); } }
private static void ConvertAllSchematicsToCyPhy(string path) { var schematics = ConvertAllDevices(path); // Create MGA project on the spot. var proj = new MgaProject(); String connectionString = String.Format("MGA={0}", Path.GetTempFileName()); proj.Create(connectionString, "CyPhyML"); proj.EnableAutoAddOns(true); var mgaGateway = new MgaGateway(proj); proj.CreateTerritoryWithoutSink(out mgaGateway.territory); var module = new CyPhyComponentAuthoring.Modules .EDAModelImport() { CurrentProj = proj }; Dictionary<String, String> d_failures = new Dictionary<string, string>(); mgaGateway.PerformInTransaction(delegate { var rf = CyPhyClasses.RootFolder.GetRootFolder(proj); var cf = CyPhyClasses.Components.Create(rf); foreach (var t in schematics) { var identifier = t.Item1; var schematic = t.Item2; CyPhy.Component component = CyPhyClasses.Component.Create(cf); component.Name = identifier; module.SetCurrentComp(component); try { var cyphySchematicModel = module.BuildCyPhyEDAModel(schematic, component); Assert.Equal(component.Children.SchematicModelCollection.Count(), 1); } catch (Exception e) { d_failures[identifier] = e.ToString(); } } }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: true); proj.Save(); proj.Close(); if (d_failures.Any()) { String msg = String.Format("Failures in converting {0} component(s):" + Environment.NewLine, d_failures.Count); foreach (var kvp in d_failures) { msg += String.Format("{0}: {1}" + Environment.NewLine + Environment.NewLine, kvp.Key, kvp.Value); } Assert.True(false, msg); } }