Esempio n. 1
0
        public void CopyMgaAndRunImporter(string tbName)
        {
            //proj.Save(proj.ProjectConnStr + asmName + ".mga", true);
            File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), (proj.ProjectConnStr + tbName + ".mga").Substring("MGA=".Length), true);

            MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject"));

            proj2.OpenEx(proj.ProjectConnStr + tbName + ".mga", "CyPhyML", null);
            proj2.BeginTransactionInNewTerr();
            try
            {
                MgaFCO oldTestBench = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + tbName + "|kind=TestBench");
                Assert.NotNull(oldTestBench);
                oldTestBench.DestroyObject();
                CyPhyML.TestBenchType testBench;
                using (StreamReader streamReader = new StreamReader(Path.Combine(AtmPath, tbName + ".atm")))
                {
                    avm.TestBench avmTestBench = OpenMETA.Interchange.AvmXmlSerializer.Deserialize <avm.TestBench>(streamReader);
                    testBench = CyPhy2TestBenchInterchange.TestBenchInterchange2CyPhy.Convert(avmTestBench, proj2);
                }
            }
            finally
            {
                proj2.CommitTransaction();
                if (Debugger.IsAttached)
                {
                    proj2.Save(null, true);
                }
                proj2.Close(true);
            }
        }
Esempio n. 2
0
        public void CopyMgaAndRunDesignImporter(string asmName)
        {
            //proj.Save(proj.ProjectConnStr + asmName + ".mga", true);
            File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), (proj.ProjectConnStr + asmName + ".mga").Substring("MGA=".Length), true);

            MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject"));

            proj2.OpenEx(proj.ProjectConnStr + asmName + ".mga", "CyPhyML", null);
            proj2.BeginTransactionInNewTerr();
            try
            {
                MgaFCO componentAssembly = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + asmName);
                Assert.NotNull(componentAssembly);
                componentAssembly.DestroyObject();
                var        importer = new CyPhyDesignImporter.AVMDesignImporter(null, proj2);
                avm.Design design;
                using (StreamReader streamReader = new StreamReader(Path.Combine(AdmPath, asmName + ".adm")))
                    design = CyPhyDesignImporter.CyPhyDesignImporterInterpreter.DeserializeAvmDesignXml(streamReader);
                var ret = (ISIS.GME.Dsml.CyPhyML.Interfaces.DesignEntity)importer.ImportDesign(design,
                                                                                               "ComponentAssemblies" == FolderName ? CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_CAS : CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_DS);
            }
            finally
            {
                proj2.CommitTransaction();
                if (Debugger.IsAttached)
                {
                    proj2.Save(null, true);
                }
                proj2.Close(true);
            }
        }
Esempio n. 3
0
        protected string CopyMgaAndRunDesignImporter(string asmName, Action <ISIS.GME.Dsml.CyPhyML.Interfaces.ComponentAssembly> caTest)
        {
            string testrunDir = Path.Combine(Path.GetDirectoryName(proj.ProjectConnStr.Substring("MGA=".Length)), "testrun");

            try
            {
                Directory.Delete(testrunDir, true);
            }
            catch (DirectoryNotFoundException)
            {
            }
            Directory.CreateDirectory(testrunDir);
            string importMgaPath = Path.Combine(testrunDir, Path.GetFileNameWithoutExtension(proj.ProjectConnStr.Substring("MGA=".Length)) + asmName + ".mga");

            //proj.Save(proj.ProjectConnStr + asmName + ".mga", true);
            File.Copy(proj.ProjectConnStr.Substring("MGA=".Length), importMgaPath, true);

            MgaProject proj2 = (MgaProject)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaProject"));

            proj2.OpenEx("MGA=" + importMgaPath, "CyPhyML", null);
            proj2.BeginTransactionInNewTerr();
            try
            {
                MgaFCO componentAssembly = (MgaFCO)proj2.RootFolder.GetObjectByPathDisp("/@" + FolderName + "/@" + asmName);
                Assert.NotNull(componentAssembly);
                componentAssembly.DestroyObject();
                var        importer = new CyPhyDesignImporter.AVMDesignImporter(null, proj2);
                avm.Design design;
                var        adpPath = Path.Combine(fixture.AdmPath, asmName + ("ComponentAssemblies" == FolderName ? ".adp" : ".adm"));
                var        ret     = importer.ImportFile(adpPath,
                                                         "ComponentAssemblies" == FolderName ? CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_CAS : CyPhyDesignImporter.AVMDesignImporter.DesignImportMode.CREATE_DS);
                if (caTest != null)
                {
                    caTest((ISIS.GME.Dsml.CyPhyML.Interfaces.ComponentAssembly)ret);
                }
            }
            finally
            {
                proj2.CommitTransaction();
                if (Debugger.IsAttached)
                {
                    proj2.Save(null, true);
                }
                proj2.Close(true);
            }
            return(importMgaPath);
        }
Esempio n. 4
0
        public void merge(MgaFCO currentObject, string filename) {

            _currentMgaProject = currentObject.Project;

            MgaProject mgaProject = GetProject(filename, currentObject.Project.MetaName);

            if (mgaProject == null)
                return;
            try
            {

                _projectFilename = filename;

                MgaGateway mgaGateway = new MgaGateway(mgaProject);

                mgaGateway.PerformInTransaction(delegate
                {

                    // "DO" LOOP IS ONLY TO ALLOW "break" TO TERMINATE THIS INTERPRETER
                    do
                    {

                        int origPrefs = _currentMgaProject.Preferences;
                        // Magic word allows us to remove ConnPoints
                        _currentMgaProject.Preferences = origPrefs | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS;

                        try
                        {
                            // GET FCO TO BE MERGED FROM OTHER MGA FILE
                            IMgaFCO otherCurrentObject = mgaProject.get_ObjectByPath(currentObject.AbsPath) as IMgaFCO;
                            if (otherCurrentObject == null)
                            {
                                gmeConsole.Error.WriteLine("Could not perform merge:  could not find object of path \"" + currentObject.AbsPath + "\" in file \"" + filename + "\"");
                                _exitStatus |= Errors.PathError;
                                break;
                            }

                            recordConnections(otherCurrentObject);

                            // GET PARENT (IN CURRENT MODEL) OF THE FCO TO BE MERGED INTO THE CURRENT MODEL
                            MgaObject currentParentMGAObject = null;
                            GME.MGA.Meta.objtype_enum currentParentObjTypeEnum;
                            currentObject.GetParent(out currentParentMGAObject, out currentParentObjTypeEnum);


                            // THE ROOT OF THE MERGED FCO
                            IMgaFCO newCurrentObject = null;

                            IMgaFCO otherArchetype = otherCurrentObject.ArcheType;
                            if (otherArchetype != null)
                            {

                                MgaFCO newArchetype = mgaProject.get_ObjectByPath(otherArchetype.AbsPath) as MgaFCO;
                                if (newArchetype == null)
                                {
                                    gmeConsole.Error.WriteLine("Could not find object of path \"" + otherArchetype.AbsPath + "\" (archetype of \"" + otherCurrentObject.AbsPath + "\" in file \"" + filename + "\") in current model.");
                                    _exitStatus |= Errors.PathError;
                                    break;
                                }

                                if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_FOLDER)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaFolder).DeriveRootObject(newArchetype, otherCurrentObject.IsInstance);
                                }
                                else if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaModel).DeriveChildObject(newArchetype, otherCurrentObject.MetaRole, otherCurrentObject.IsInstance);
                                }
                                else
                                {
                                    gmeConsole.Error.WriteLine("Unable to merge \"" + otherCurrentObject.AbsPath + "\" of file \"" + filename + "\":  prospective parent neither a folder nor a model.");
                                    _exitStatus |= Errors.GMEError;
                                    break;
                                }

                                attributesAndRegistryCopy(newCurrentObject, otherCurrentObject);
                                connectionCopy();

                            }
                            else
                            {

                                if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_FOLDER)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaFolder).CreateRootObject(currentObject.Meta);
                                }
                                else if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaModel).CreateChildObject(currentObject.MetaRole);
                                }
                                else
                                {
                                    gmeConsole.Error.WriteLine("Unable to merge \"" + otherCurrentObject.AbsPath + "\" of file \"" + filename + "\":  prospective parent neither a folder nor a model.");
                                    _exitStatus |= Errors.GMEError;
                                    break;
                                }

                                subTreeCopy(newCurrentObject, otherCurrentObject);
                                instanceCopy();
                                attributesAndRegistryCopy(newCurrentObject, otherCurrentObject);
                                referenceCopy();
                                connectionCopy();
                                //referenceConnectionCopy();
                            }
                        }
                        finally
                        {
                            _currentMgaProject.Preferences = origPrefs;
                        }


                    } while (false);

                }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false);

                currentObject.DestroyObject();
            }
            finally
            {
                mgaProject.Close(true);
            }
        }
Esempio n. 5
0
        public void merge(MgaFCO currentObject, string filename)
        {
            _currentMgaProject = currentObject.Project;

            MgaProject mgaProject = GetProject(filename, currentObject.Project.MetaName);

            if (mgaProject == null)
            {
                return;
            }
            try
            {
                _projectFilename = filename;

                MgaGateway mgaGateway = new MgaGateway(mgaProject);

                mgaGateway.PerformInTransaction(delegate
                {
                    // "DO" LOOP IS ONLY TO ALLOW "break" TO TERMINATE THIS INTERPRETER
                    do
                    {
                        int origPrefs = _currentMgaProject.Preferences;
                        // Magic word allows us to remove ConnPoints
                        _currentMgaProject.Preferences = origPrefs | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS;

                        try
                        {
                            // GET FCO TO BE MERGED FROM OTHER MGA FILE
                            IMgaFCO otherCurrentObject = mgaProject.get_ObjectByPath(currentObject.AbsPath) as IMgaFCO;
                            if (otherCurrentObject == null)
                            {
                                gmeConsole.Error.WriteLine("Could not perform merge:  could not find object of path \"" + currentObject.AbsPath + "\" in file \"" + filename + "\"");
                                _exitStatus |= Errors.PathError;
                                break;
                            }

                            recordConnections(otherCurrentObject);

                            // GET PARENT (IN CURRENT MODEL) OF THE FCO TO BE MERGED INTO THE CURRENT MODEL
                            MgaObject currentParentMGAObject = null;
                            GME.MGA.Meta.objtype_enum currentParentObjTypeEnum;
                            currentObject.GetParent(out currentParentMGAObject, out currentParentObjTypeEnum);


                            // THE ROOT OF THE MERGED FCO
                            IMgaFCO newCurrentObject = null;

                            IMgaFCO otherArchetype = otherCurrentObject.ArcheType;
                            if (otherArchetype != null)
                            {
                                MgaFCO newArchetype = mgaProject.get_ObjectByPath(otherArchetype.AbsPath) as MgaFCO;
                                if (newArchetype == null)
                                {
                                    gmeConsole.Error.WriteLine("Could not find object of path \"" + otherArchetype.AbsPath + "\" (archetype of \"" + otherCurrentObject.AbsPath + "\" in file \"" + filename + "\") in current model.");
                                    _exitStatus |= Errors.PathError;
                                    break;
                                }

                                if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_FOLDER)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaFolder).DeriveRootObject(newArchetype, otherCurrentObject.IsInstance);
                                }
                                else if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaModel).DeriveChildObject(newArchetype, otherCurrentObject.MetaRole, otherCurrentObject.IsInstance);
                                }
                                else
                                {
                                    gmeConsole.Error.WriteLine("Unable to merge \"" + otherCurrentObject.AbsPath + "\" of file \"" + filename + "\":  prospective parent neither a folder nor a model.");
                                    _exitStatus |= Errors.GMEError;
                                    break;
                                }

                                attributesAndRegistryCopy(newCurrentObject, otherCurrentObject);
                                connectionCopy();
                            }
                            else
                            {
                                if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_FOLDER)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaFolder).CreateRootObject(currentObject.Meta);
                                }
                                else if (currentParentObjTypeEnum == GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL)
                                {
                                    newCurrentObject = (currentParentMGAObject as MgaModel).CreateChildObject(currentObject.MetaRole);
                                }
                                else
                                {
                                    gmeConsole.Error.WriteLine("Unable to merge \"" + otherCurrentObject.AbsPath + "\" of file \"" + filename + "\":  prospective parent neither a folder nor a model.");
                                    _exitStatus |= Errors.GMEError;
                                    break;
                                }

                                subTreeCopy(newCurrentObject, otherCurrentObject);
                                instanceCopy();
                                attributesAndRegistryCopy(newCurrentObject, otherCurrentObject);
                                referenceCopy();
                                connectionCopy();
                                //referenceConnectionCopy();
                            }
                        }
                        finally
                        {
                            _currentMgaProject.Preferences = origPrefs;
                        }
                    } while (false);
                }, transactiontype_enum.TRANSACTION_NON_NESTED, abort: false);

                currentObject.DestroyObject();
            }
            finally
            {
                mgaProject.Close(true);
            }
        }