Ejemplo n.º 1
0
        static int Main(string[] args) {

            if (args.Length < 2) usage();

            MgaProject mainMgaProject = GetProject( args[0] );

            if( mainMgaProject == null ) {
                Environment.Exit( 2 );
            }

            int retval = 0;
            MgaGateway mgaGateway = new MgaGateway(mainMgaProject);

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

                for (int ix = 1; ix < args.Length; ++ix) {
                    string[] mergeInfo = args[ix].Split(new string[] { ".mga/" }, 2, StringSplitOptions.None);

                    string filename = mergeInfo[0] + ".mga";
                    string path = "/" + mergeInfo[1];

                    MgaFCO currentObject = mainMgaProject.get_ObjectByPath(path) as MgaFCO;
                    if (currentObject == null) {
                        Console.Error.WriteLine("Error: could not find object of path \"" + path + "\" in model of file \"" + args[0] + "\", cannot merge file \"" + filename + "\"");
                        retval |= (int)SubTreeMerge.SubTreeMerge.Errors.PathError;
                        continue;
                    }

                    SubTreeMerge.SubTreeMerge subTreeMerge = new SubTreeMerge.SubTreeMerge();
                    subTreeMerge.gmeConsole = new SubTreeMerge.FlexConsole( SubTreeMerge.FlexConsole.ConsoleType.CONSOLE );

                    subTreeMerge.merge(currentObject, filename);
                    retval = (int)subTreeMerge.exitStatus;
                }

            });

            mainMgaProject.Save();

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

            return retval;
        }
Ejemplo n.º 2
0
        static int Main(string[] args)
        {
            if (args.Length < 2)
            {
                usage();
                return(1);
            }

            MgaProject mainMgaProject = GetProject(args[0]);

            if (mainMgaProject == null)
            {
                return(2);
            }

            int        retval     = 0;
            MgaGateway mgaGateway = new MgaGateway(mainMgaProject);

            mgaGateway.PerformInTransaction(delegate {
                for (int ix = 1; ix < args.Length; ++ix)
                {
                    string[] mergeInfo = args[ix].Split(new string[] { ".mga/" }, 2, StringSplitOptions.None);

                    string filename = mergeInfo[0] + ".mga";
                    string path     = "/" + mergeInfo[1];

                    MgaFCO currentObject = mainMgaProject.get_ObjectByPath(path) as MgaFCO;
                    if (currentObject == null)
                    {
                        Console.Error.WriteLine("Error: could not find object of path \"" + path + "\" in model of file \"" + args[0] + "\", cannot merge file \"" + filename + "\"");
                        retval |= (int)SubTreeMerge.SubTreeMerge.Errors.PathError;
                        continue;
                    }

                    SubTreeMerge.SubTreeMerge subTreeMerge = new SubTreeMerge.SubTreeMerge();
                    subTreeMerge.gmeConsole = new SubTreeMerge.FlexConsole(SubTreeMerge.FlexConsole.ConsoleType.CONSOLE);

                    subTreeMerge.merge(currentObject, filename);
                    retval = (int)subTreeMerge.exitStatus;
                }
            }, abort: false);

            mainMgaProject.Save();

            return(retval);
        }
Ejemplo n.º 3
0
        void TestSubTreeMergeModel()
        {
            string mgaFileCopy = mgaFile + "copy.mga";

            File.Copy(mgaFile, mgaFile + "copy.mga", true);
            MgaProject project = new MgaProject();

            project.OpenEx("MGA=" + this.mgaFile, "CyPhyML", null);
            try
            {
                project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
                try
                {
                    string mergeMeModelPath       = "/@ComponentAssemblies/@MergeMe";
                    MgaFCO mergeMe                = (MgaFCO)project.ObjectByPath[mergeMeModelPath];
                    int    startingDescendantFCOs = ((MgaModel)mergeMe).GetDescendantFCOs(mergeMe.Project.CreateFilter()).Count;

                    var fcos = ((MgaModel)mergeMe).GetDescendantFCOs(project.CreateFilter()).Cast <MgaFCO>().Select(
                        x => x.AbsPath).ToList();

                    foreach (MgaObject obj in mergeMe.ChildObjects)
                    {
                        if (obj.MetaBase.Name != "Connector" && obj.MetaBase.Name != "Axis" && /* keep these, since they have refport connections*/
                            obj.Status == (int)objectstatus_enum.OBJECT_EXISTS /* connections may be deleted when their endpoints are */)
                        {
                            obj.DestroyObject();
                        }
                    }

                    var subTreeMerge = new SubTreeMerge.SubTreeMerge();
                    subTreeMerge.merge(mergeMe, mgaFileCopy);
                    Assert.Equal(SubTreeMerge.SubTreeMerge.Errors.NoError, subTreeMerge.exitStatus);
                    MgaFCO newMergeMe = (MgaFCO)project.ObjectByPath[mergeMeModelPath];

                    Assert.Equal(newMergeMe.ID, ((MgaReference)project.ObjectByPath["/@ComponentAssemblies/@AsmWithRef/@MergeMe"]).Referred.ID);
                    Assert.Equal(newMergeMe.ID, ((MgaReference)project.ObjectByPath["/@Testing/@TestBench/@MergeMe"]).Referred.ID);
                    Assert.Equal(2, ((MgaReference)project.ObjectByPath["/@ComponentAssemblies/@AsmWithRef/@MergeMe"]).UsedByConns.Count);
                    Assert.Equal(2, ((MgaReference)project.ObjectByPath["/@Testing/@TestBench/@MergeMe"]).UsedByConns.Count);
                    //Debugging:
                    //var fcos2 = ((MgaModel)newMergeMe).GetDescendantFCOs(project.CreateFilter()).Cast<MgaFCO>().Select(x => x.AbsPath)
                    //    .Where(x => fcos.Contains(x) == false);
                    //HashSet<string> originalObjects = new HashSet<string>();
                    //foreach (string abspath in fcos)
                    //    originalObjects.Add(abspath);
                    //foreach (string abspath in ((MgaModel)newMergeMe).GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>().Select(x => x.AbsPath))
                    //    originalObjects.Remove(abspath);
                    // Console.Out.WriteLine(string.Join("\n", originalObjects));
                    Assert.Equal(startingDescendantFCOs, ((MgaModel)newMergeMe).GetDescendantFCOs(project.CreateFilter()).Count);
                }
                finally
                {
                    project.CommitTransaction();
                }
            }
            finally
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    project.Save(project.ProjectConnStr + "_testoutput.mga", true);
                }
                project.Close(true);
            }
        }