예제 #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 ImportOldITARStatement_ITAR()
        {
            // There should be only an ITAR object, with attribute set to ITAR
            var acmPath = Path.Combine(testPath, "ITAR.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];
            });

            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);

                Assert.False(comp.Children.DoDDistributionStatementCollection.Any());
            });
        }
예제 #3
0
        public static List <MgaFCO> ImportComponentZips(MgaProject mgaProject, List <string> zipPaths)
        {
            IMgaFCOs importedComponentFcos;

            try
            {
                CyPhyComponentImporter.CyPhyComponentImporterInterpreter importer =
                    new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();

                importer.Initialize(mgaProject);

                importedComponentFcos =
                    importer.ImportFiles(mgaProject, Path.GetDirectoryName(mgaProject.ProjectConnStr.Substring("MGA=".Length)), zipPaths.ToArray());
            }
            catch (Exception)
            {
                throw new VFDownloadFailedException();
            }

            return(importedComponentFcos.OfType <MgaFCO>().ToList());
        }
예제 #4
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];
            });

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

                Assert.False(comp.Children.ITARCollection.Any());
                Assert.False(comp.Children.DoDDistributionStatementCollection.Any());
            });
        }
예제 #5
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);
                        bExceptionOccurred = importer.Errors.Count > 0;
                    });

                    mgaProject.Save();

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

                    if (bExceptionOccurred)
                    {
                        return -1;
                    }
                }
            }
            finally
            {
                mgaProject.Close(true);
            }
            return 0;
        }
예제 #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);
        }
예제 #7
0
파일: Clm.cs 프로젝트: neemask/meta-core
        public static List<MgaFCO> ImportComponentZips(MgaProject mgaProject, List<string> zipPaths)
        {
            IMgaFCOs importedComponentFcos;

            try
            {
                CyPhyComponentImporter.CyPhyComponentImporterInterpreter importer =
                    new CyPhyComponentImporter.CyPhyComponentImporterInterpreter();

                importer.Initialize(mgaProject);

                importedComponentFcos =
                    importer.ImportFiles(mgaProject, Path.GetDirectoryName(mgaProject.ProjectConnStr.Substring("MGA=".Length)), zipPaths.ToArray());
            }
            catch (Exception)
            {
                throw new VFDownloadFailedException();
            }

            return importedComponentFcos.OfType<MgaFCO>().ToList();
        }