public IMgaFCO ImportDesignToComponentAssembly(IMgaProject project, string filename)
        {
            var importer = new AVMDesignImporter(null, project);
            var result   = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CAS);

            return((IMgaFCO)result.Impl);
        }
        /*
         * returns: ComponentAssembly if the design contains no design space concepts
         */
        public IMgaFCO ImportDesignToDesignSpaceIfApplicable(IMgaProject project, string filename)
        {
            var importer = new AVMDesignImporter(null, project);
            var result   = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);

            return((IMgaFCO)result.Impl);
        }
        public IMgaFCO ImportDesign(IMgaProject project, string filename)
        {
            var importer = new AVMDesignImporter(null, project);
            var result   = importer.ImportFile(filename);

            return((IMgaFCO)result.Impl);
        }
Exemple #4
0
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            string[]     fileNames = null;
            DialogResult dr;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.CheckFileExists  = true;
                ofd.Multiselect      = true;
                ofd.Filter           = "AVM design files and packages (*.adm;*.adp)|*.adm;*.adp|All files (*.*)|*.*";
                ofd.RestoreDirectory = true;
                if (project.ProjectConnStr.StartsWith("MGA=", true, System.Globalization.CultureInfo.InvariantCulture))
                {
                    ofd.InitialDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));
                }

                dr = ofd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    fileNames = ofd.FileNames;
                }
            }
            if (dr == DialogResult.OK)
            {
                Model[] result = null;
                var     addons = project.AddOnComponents.Cast <IMgaComponentEx>();
                foreach (var addon in addons)
                {
                    if (addon.ComponentName.ToLowerInvariant() == "CyPhyAddOn".ToLowerInvariant())
                    {
                        // keep the InstanceGUID on imported Component instances
                        addon.ComponentParameter["DontAssignGuidsOnNextTransaction".ToLowerInvariant()] = true;
                    }
                }
                MgaGateway.PerformInTransaction(delegate
                {
                    var importer = new AVMDesignImporter(GMEConsole, project);
                    result       = importer.ImportFiles(fileNames, mode: AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);
                }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false);

                if (result.Length > 0 && GMEConsole.gme != null)
                {
                    GMEConsole.gme.ShowFCO((MgaFCO)result[0].Impl);
                }
                return;
            }
            else
            {
                GMEConsole.Warning.WriteLine("Design Importer canceled");
                return;
            }
        }
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            string[]     fileNames = null;
            DialogResult dr;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.CheckFileExists  = true;
                ofd.DefaultExt       = "design.adm";
                ofd.Multiselect      = true;
                ofd.Filter           = "AVM design files (*.adm)|*.adm|All files (*.*)|*.*";
                ofd.RestoreDirectory = true;
                if (project.ProjectConnStr.StartsWith("MGA=", true, System.Globalization.CultureInfo.InvariantCulture))
                {
                    ofd.InitialDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));
                }

                dr = ofd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    fileNames = ofd.FileNames;
                }
            }
            if (dr == DialogResult.OK)
            {
                Model[] result = null;
                MgaGateway.PerformInTransaction(delegate
                {
                    var importer = new AVMDesignImporter(GMEConsole, project);
                    result       = importer.ImportFiles(fileNames, mode: AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);
                }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false);

                if (result.Length > 0 && GMEConsole.gme != null)
                {
                    GMEConsole.gme.ShowFCO((MgaFCO)result[0].Impl);
                }
                return;
            }
            else
            {
                GMEConsole.Warning.WriteLine("Design Importer canceled");
                return;
            }
        }
        public void DesignPackageImport()
        {
            // Clean the test directory
            var pathTest = Path.Combine(META.VersionInfo.MetaPath,
                                        "test",
                                        "InterchangeTest",
                                        "DesignInterchangeTest",
                                        "ImportTestUnits",
                                        "Package");
            foreach (var path in Directory.EnumerateDirectories(pathTest))
            {
                Directory.Delete(path, true);
            }
            foreach (var path in Directory.EnumerateFiles(pathTest, "*.*"))
            {
                if (!path.Contains("NestedFolders.adp"))
                {
                    File.Delete(path);
                }
            }

            // Create a test project
            var proj = new MgaProject();
            proj.Create("MGA=" + Path.Combine(pathTest,"testmodel.mga"), "CyPhyML");

            try
            {
                String pathCA = null;
                proj.PerformInTransaction(() =>
                {
                    // Instantiate the importer and import the package
                    var importer = new AVMDesignImporter(GMEConsole.CreateFromProject(proj), proj);

                    var mdlCA = importer.ImportFile(Path.Combine(pathTest, "NestedFolders.adp"), AVMDesignImporter.DesignImportMode.CREATE_CAS);
                    var ca = CyPhyClasses.ComponentAssembly.Cast(mdlCA.Impl);
                    pathCA = ca.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE);
                });

                // Check the design's backend folder for all files except for the ADM.
                var filesExpected = new List<String> 
                { 
                    "testObject.txt",
                    "dir1/testObject.txt",
                    "dir1/dir1a/testObject.txt",
                    "dir2/testObject.txt"
                };
                var filesInDir = Directory.GetFiles(pathCA, "*.*", SearchOption.AllDirectories);

                Assert.Equal(filesExpected.Count(), filesInDir.Count());
                foreach (var file in filesExpected)
                {
                    String fullPath = Path.Combine(pathCA, file);
                    Assert.True(File.Exists(fullPath));
                }
            }
            finally
            {
                proj.Save();
                proj.Close();
            }
        }
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            string[] fileNames = null;
            DialogResult dr;
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.CheckFileExists = true;
                ofd.DefaultExt = "design.adm";
                ofd.Multiselect = true;
                ofd.Filter = "AVM design files (*.adm)|*.adm|All files (*.*)|*.*";
                ofd.RestoreDirectory = true;
                if (project.ProjectConnStr.StartsWith("MGA=", true, System.Globalization.CultureInfo.InvariantCulture))
                {
                    ofd.InitialDirectory = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));
                }

                dr = ofd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    fileNames = ofd.FileNames;
                }
            }
            if (dr == DialogResult.OK)
            {
                Model[] result = null;
                MgaGateway.PerformInTransaction(delegate
                {
                    var importer = new AVMDesignImporter(GMEConsole, project);
                    result  = importer.ImportFiles(fileNames, mode: AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);
                }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false);

                if (result.Length > 0 && GMEConsole.gme != null)
                {
                    GMEConsole.gme.ShowFCO((MgaFCO)result[0].Impl);
                }
                return;
            }
            else
            {
                GMEConsole.Warning.WriteLine("Design Importer canceled");
                return;
            }
        }
 /*
  * returns: ComponentAssembly if the design contains no design space concepts
  */
 public IMgaFCO ImportDesignToDesignSpaceIfApplicable(IMgaProject project, string filename)
 {
     var importer = new AVMDesignImporter(null, project);
     var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);
     return (IMgaFCO)result.Impl;
 }
 public IMgaFCO ImportDesignToComponentAssembly(IMgaProject project, string filename)
 {
     var importer = new AVMDesignImporter(null, project);
     var result = importer.ImportFile(filename, AVMDesignImporter.DesignImportMode.CREATE_CAS);
     return (IMgaFCO)result.Impl;
 }
 public IMgaFCO ImportDesign(IMgaProject project, string filename)
 {
     var importer = new AVMDesignImporter(null, project);
     var result = importer.ImportFile(filename);
     return (IMgaFCO)result.Impl;
 }
        public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
        {
            string[] fileNames = null;
            DialogResult dr;
            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.CheckFileExists = true;
                ofd.Multiselect = true;
                ofd.Filter = "AVM design files and packages (*.adm;*.adp)|*.adm;*.adp|All files (*.*)|*.*";

                dr = ofd.ShowDialog();
                if (dr == DialogResult.OK)
                {
                    fileNames = ofd.FileNames;
                }
            }
            if (dr == DialogResult.OK)
            {
                Model[] result = null;
                MgaGateway.PerformInTransaction(delegate
                {
                    var importer = new AVMDesignImporter(GMEConsole, project);
                    result  = importer.ImportFiles(fileNames, mode: AVMDesignImporter.DesignImportMode.CREATE_CA_IF_NO_DS_CONCEPTS);
                }, transactiontype_enum.TRANSACTION_NON_NESTED);

                if (result.Length > 0 && GMEConsole.gme != null)
                {
                    GMEConsole.gme.ShowFCO((MgaFCO)result[0].Impl);
                }
                return;
            }
            else
            {
                GMEConsole.Warning.WriteLine("Design Importer canceled");
                return;
            }
        }