예제 #1
0
        public void ImportOldITARStatement_ITARDistributionD()
        {
            // There should be both an ITAR element and a DistributionD element
            var acmPath = Path.Combine(testPath, "DistD.oldstyle.acm");

            IMgaFCO fco = null;

            proj.PerformInTransaction(delegate
            {
                var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                importer.Initialize(fixture.proj);

                fco = importer.ImportFiles(fixture.proj, fixture.proj.GetRootDirectoryPath(), new[] { acmPath }, doNotReplaceAll: true)[1];
                importer.DisposeLogger();
            });

            proj.PerformInTransaction(delegate
            {
                var comp = CyPhyClasses.Component.Cast(fco);

                var itarCollection = comp.Children.ITARCollection;
                Assert.True(itarCollection.Count() == 1);

                var itar = itarCollection.First();
                Assert.True(itar.Attributes.RestrictionLevel == CyPhyClasses.ITAR.AttributesClass.RestrictionLevel_enum.ITAR);

                var distStatementCollection = comp.Children.DoDDistributionStatementCollection;
                Assert.True(distStatementCollection.Count() == 1);

                var distStatement = distStatementCollection.First();
                Assert.True(distStatement.Attributes.DoDDistributionStatementEnum == CyPhyClasses.DoDDistributionStatement.AttributesClass.DoDDistributionStatementEnum_enum.StatementD);
            });
        }
예제 #2
0
        public void ZipIsMissingACM()
        {
            var zipPath = Path.Combine(testPath, "TestModel_noACM.zip");

            var mgaProject = Common.GetProject(mgaPath);

            Assert.False(mgaProject == null, "Could not load MGA project.");

            var mgaGateway = new MgaGateway(mgaProject);

            mgaGateway.PerformInTransaction(delegate
            {
                var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                importer.Initialize(mgaProject);

                try
                {
                    var result = importer.ImportFile(mgaProject, testPath, zipPath);
                }
                finally
                {
                    importer.DisposeLogger();
                }
            });
        }
예제 #3
0
        public void ImportZIP()
        {
            var zipPath = Path.Combine(testPath, "TestModel.zip");

            // Import the ZIP file.
            // Check that we run without exception, have a manifest file,
            // have a folder for the component, and have 2 files in there.

            // Delete manifest and any subfolders
            File.Delete(manifestFilePath);
            if (Directory.Exists(Path.Combine(testPath, "components")))
            {
                Directory.Delete(Path.Combine(testPath, "components"), true);
            }

            var mgaProject = Common.GetProject(mgaPath);

            Assert.True(mgaProject != null, "Could not load MGA project.");

            bool resultIsNull = false;
            var  mgaGateway   = new MgaGateway(mgaProject);

            mgaGateway.PerformInTransaction(delegate
            {
                var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                importer.Initialize(mgaProject);

                try
                {
                    var result = importer.ImportFile(mgaProject, testPath, zipPath);
                    if (result == null)
                    {
                        resultIsNull = true;
                    }
                }
                finally
                {
                    importer.DisposeLogger();
                }
            });
            Assert.False(resultIsNull, "Exception occurred during import.");
            Assert.False(File.Exists(manifestFilePath), "Manifest erroneously generated");
        }
예제 #4
0
        public void ImportCADZIP_Spring_Tungsten()
        {
            var zipPath = Path.Combine(testPath, "Spring_Tungsten.zip");

            // Import the ZIP file.
            // Check that we run without exception, have a manifest file,
            // have a folder for the component, and have 2 files in there.

            // Delete manifest and any subfolders
            File.Delete(manifestFilePath);
            if (Directory.Exists(Path.Combine(testPath, "components")))
            {
                Directory.Delete(Path.Combine(testPath, "components"), true);
            }

            var mgaProject = Common.GetProject(mgaPath);

            Assert.True(mgaProject != null, "Could not load MGA project.");

            var mgaGateway = new MgaGateway(mgaProject);

            mgaGateway.PerformInTransaction(delegate
            {
                var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                importer.Initialize(mgaProject);

                try
                {
                    var result   = importer.ImportFile(mgaProject, testPath, zipPath);
                    var tungsten = result.ChildObjects.Cast <IMgaFCO>().Where(x => x.Meta.Name == "Resource" && x.Name == "TUNGSTEN_SPRING.PRT").FirstOrDefault();
                    Assert.Equal("CAD\\TUNGSTEN_SPRING.PRT", tungsten.StrAttrByName["Path"]);
                }
                finally
                {
                    importer.DisposeLogger();
                }
            });
        }
예제 #5
0
        public void ImportOldITARStatement_NotITAR()
        {
            var acmPath = Path.Combine(testPath, "NotITAR.oldstyle.acm");

            IMgaFCO fco = null;

            proj.PerformInTransaction(delegate
            {
                var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                importer.Initialize(fixture.proj);

                fco = importer.ImportFiles(fixture.proj, fixture.proj.GetRootDirectoryPath(), new[] { acmPath }, doNotReplaceAll: true)[1];
                importer.DisposeLogger();
            });

            proj.PerformInTransaction(delegate
            {
                var comp = CyPhyClasses.Component.Cast(fco);

                Assert.False(comp.Children.ITARCollection.Any());
                Assert.False(comp.Children.DoDDistributionStatementCollection.Any());
            });
        }
예제 #6
0
        public static int Main(String[] args)
        {
            if (args.Length < 2 || args.Length > 4)
            {
                usage();
                return(1);
            }
            MgaProject    mgaProject;
            List <String> lp_FilesToImport         = new List <string>();
            string        avmFilePath              = "";
            string        mgaProjectPath           = "";
            string        componentReplacementPath = "";

            bool rOptionUsed = false;
            bool pOptionUsed = false;

            for (int ix = 0; ix < args.Length; ++ix)
            {
                if (args[ix].ToLower() == "-r")
                {
                    if (pOptionUsed)
                    {
                        usage();
                        return(1);
                    }
                    rOptionUsed = true;

                    if (++ix >= args.Length)
                    {
                        usage();
                        return(1);
                    }

                    if (avmFilePath != null && avmFilePath != "")
                    {
                        if (mgaProjectPath != null && mgaProjectPath != "")
                        {
                            usage();
                            return(1);
                        }
                        mgaProjectPath = avmFilePath;
                        avmFilePath    = "";
                        lp_FilesToImport.Clear();
                    }

                    String sImportDirectory = args[ix];

                    String   startingDirectory = Path.GetFullPath(sImportDirectory);
                    string[] xmlFiles          = Directory.GetFiles(startingDirectory, "*.acm", SearchOption.AllDirectories);

                    foreach (String p_XMLFile in xmlFiles)
                    {
                        lp_FilesToImport.Add(Path.GetFullPath(p_XMLFile));
                    }
                }
                else if (args[ix].ToLower() == "-p")
                {
                    if (rOptionUsed)
                    {
                        usage();
                        return(1);
                    }
                    pOptionUsed = true;

                    if (++ix >= args.Length)
                    {
                        usage();
                        return(1);
                    }
                    componentReplacementPath = args[ix];
                }
                else if (lp_FilesToImport.Count == 0 && avmFilePath == "")
                {
                    avmFilePath = args[ix];
                    try
                    {
                        lp_FilesToImport.Add(Path.GetFullPath(avmFilePath));
                    }
                    catch (System.ArgumentException ex)
                    {
                        Console.Out.WriteLine(ex.Message);
                        Console.Out.WriteLine(avmFilePath);
                        throw ex;
                    }
                }
                else
                {
                    if (mgaProjectPath != null && mgaProjectPath != "")
                    {
                        usage();
                        return(1);
                    }
                    mgaProjectPath = args[ix];
                }
            }


            mgaProject = GetProject(mgaProjectPath);
            try
            {
                bool bExceptionOccurred = false;
                if (mgaProject != null)
                {
                    MgaGateway mgaGateway = new MgaGateway(mgaProject);

                    mgaGateway.PerformInTransaction(delegate
                    {
                        string libroot = Path.GetDirectoryName(Path.GetFullPath(mgaProjectPath));

                        CyPhyML.RootFolder cyPhyMLRootFolder = ISIS.GME.Common.Utils.CreateObject <CyPhyMLClasses.RootFolder>(mgaProject.RootFolder as MgaObject);

                        #region Attach QUDT library if needed
                        IMgaFolder oldQudt = mgaProject.RootFolder.ChildFolders.Cast <IMgaFolder>().Where(x => x.LibraryName != "" && (x.Name.ToLower().Contains("qudt"))).FirstOrDefault();
                        string mgaQudtPath = Meta_Path + "\\meta\\CyPhyMLQudt.mga";

                        bool needAttach = false;
                        if (oldQudt == null)
                        {
                            needAttach = true;
                        }
                        else
                        {
                            long loldModTime;
                            DateTime oldModTime = long.TryParse(oldQudt.RegistryValue["modtime"], out loldModTime) ? DateTime.FromFileTimeUtc(loldModTime) : DateTime.MinValue;
                            needAttach          = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).CompareTo(oldModTime) > 0;
                            if (!needAttach)
                            {
                                Console.Error.WriteLine("QUDT is up-to-date: embedded library modified " + oldModTime.ToString() + ", CyPhyMLQudt.mga modified " + System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).ToString());
                            }
                        }

                        if (needAttach)
                        {
                            Console.Error.WriteLine("Attaching library " + mgaQudtPath);
                            ISIS.GME.Common.Interfaces.RootFolder newQudt = ISIS.GME.Common.Classes.RootFolder.GetRootFolder(mgaProject).AttachLibrary("MGA=" + mgaQudtPath);
                            DateTime modtime = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath);
                            ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).RegistryValue["modtime"] =
                                modtime.ToFileTimeUtc().ToString();

                            if (oldQudt != null)
                            {
                                ReferenceSwitcher.Switcher sw = new ReferenceSwitcher.Switcher(oldQudt, newQudt.Impl, null);
                                sw.UpdateSublibrary();
                                oldQudt.DestroyObject();
                            }
                            ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).LibraryName = "UnitLibrary QUDT";
                            Console.Error.WriteLine((oldQudt == null ? "Attached " : "Refreshed") + " Qudt library.");
                        }
                        #endregion

                        var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                        importer.Initialize(cyPhyMLRootFolder.Impl.Project);
                        importer.ImportFiles(cyPhyMLRootFolder.Impl.Project, libroot, lp_FilesToImport.ToArray(), true);
                        importer.DisposeLogger();
                        bExceptionOccurred = importer.Errors.Count > 0;
                    }, abort: false);

                    mgaProject.Save();

                    if (bExceptionOccurred)
                    {
                        return(-1);
                    }
                }
            }
            finally
            {
                mgaProject.Close(true);
            }
            return(0);
        }
        public static int Main( String[] args ) {

            if( args.Length < 2 || args.Length > 4 ) usage();

            MgaProject mgaProject;
            List<String> lp_FilesToImport = new List<string>();
            string avmFilePath = "";
            string mgaProjectPath = "";
            string componentReplacementPath = "";

            bool rOptionUsed = false;
            bool pOptionUsed = false;

            for( int ix = 0 ; ix < args.Length ; ++ix ) {

                if( args[ ix ].ToLower() == "-r" ) {

                    if( pOptionUsed ) usage();
                    rOptionUsed = true;

                    if ( ++ix >= args.Length ) usage();

                    if( avmFilePath != null && avmFilePath != "" ) {
                        if( mgaProjectPath != null && mgaProjectPath != "" ) usage();
                        mgaProjectPath = avmFilePath;
                        avmFilePath = "";
                        lp_FilesToImport.Clear();
                    }

                    String sImportDirectory = args[ ix ];

                    String startingDirectory = Path.GetFullPath( sImportDirectory );
                    string[] xmlFiles = Directory.GetFiles( startingDirectory, "*.acm", SearchOption.AllDirectories );

                    foreach( String p_XMLFile in xmlFiles ) {
                        lp_FilesToImport.Add( Path.GetFullPath( p_XMLFile ) );
                    }

                } else if( args[ ix ].ToLower() == "-p" ) {

                    if( rOptionUsed ) usage();
                    pOptionUsed = true;

                    if ( ++ix >= args.Length ) usage();
                    componentReplacementPath = args[ ix ];

                } else if ( lp_FilesToImport.Count == 0 && avmFilePath == "" ) {

                    avmFilePath = args[ ix ];
                    try
                    {
                        lp_FilesToImport.Add(Path.GetFullPath(avmFilePath));
                    }
                    catch (System.ArgumentException ex)
                    {
                        Console.Out.WriteLine(ex.Message);
                        Console.Out.WriteLine(avmFilePath);
                        throw ex;
                    }

                } else {

                    if( mgaProjectPath != null && mgaProjectPath != "" ) usage();
                    mgaProjectPath = args[ ix ];
                }

            }


            mgaProject = GetProject( mgaProjectPath );
            try
            {
                bool bExceptionOccurred = false;
                if (mgaProject != null)
                {
                    MgaGateway mgaGateway = new MgaGateway(mgaProject);

                    mgaProject.CreateTerritoryWithoutSink(out mgaGateway.territory);
                    mgaGateway.PerformInTransaction(delegate
                    {

                        string libroot = Path.GetDirectoryName(Path.GetFullPath(mgaProjectPath));

                        CyPhyML.RootFolder cyPhyMLRootFolder = ISIS.GME.Common.Utils.CreateObject<CyPhyMLClasses.RootFolder>(mgaProject.RootFolder as MgaObject);

                        #region Attach QUDT library if needed
                        IMgaFolder oldQudt = mgaProject.RootFolder.ChildFolders.Cast<IMgaFolder>().Where(x => x.LibraryName != "" && (x.Name.ToLower().Contains("qudt"))).FirstOrDefault();
                        string mgaQudtPath = Meta_Path + "\\meta\\CyPhyMLQudt.mga";

                        bool needAttach = false;
                        if (oldQudt == null)
                        {

                            needAttach = true;

                        }
                        else
                        {

                            long loldModTime;
                            DateTime oldModTime = long.TryParse(oldQudt.RegistryValue["modtime"], out loldModTime) ? DateTime.FromFileTimeUtc(loldModTime) : DateTime.MinValue;
                            needAttach = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).CompareTo(oldModTime) > 0;
                            if (!needAttach)
                            {
                                Console.Error.WriteLine("QUDT is up-to-date: embedded library modified " + oldModTime.ToString() + ", CyPhyMLQudt.mga modified " + System.IO.File.GetLastWriteTimeUtc(mgaQudtPath).ToString());
                            }
                        }

                        if (needAttach)
                        {

                            Console.Error.WriteLine("Attaching library " + mgaQudtPath);
                            ISIS.GME.Common.Interfaces.RootFolder newQudt = ISIS.GME.Common.Classes.RootFolder.GetRootFolder(mgaProject).AttachLibrary("MGA=" + mgaQudtPath);
                            DateTime modtime = System.IO.File.GetLastWriteTimeUtc(mgaQudtPath);
                            ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).RegistryValue["modtime"] =
                                    modtime.ToFileTimeUtc().ToString();

                            if (oldQudt != null)
                            {
                                ReferenceSwitcher.Switcher sw = new ReferenceSwitcher.Switcher(oldQudt, newQudt.Impl, null);
                                sw.UpdateSublibrary();
                                oldQudt.DestroyObject();
                            }
                            ((newQudt as ISIS.GME.Common.Classes.RootFolder).Impl as GME.MGA.IMgaFolder).LibraryName = "UnitLibrary QUDT";
                            Console.Error.WriteLine((oldQudt == null ? "Attached " : "Refreshed") + " Qudt library.");
                        }
                        #endregion

                        var importer = new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();
                        importer.Initialize(cyPhyMLRootFolder.Impl.Project);
                        importer.ImportFiles(cyPhyMLRootFolder.Impl.Project, libroot, lp_FilesToImport.ToArray(), true);
                        importer.DisposeLogger();
                        bExceptionOccurred = importer.Errors.Count > 0;
                    });

                    mgaProject.Save();

                    if (mgaGateway.territory != null)
                    {
                        mgaGateway.territory.Destroy();
                    }

                    if (bExceptionOccurred)
                    {
                        return -1;
                    }
                }
            }
            finally
            {
                mgaProject.Close(true);
            }
            return 0;
        }