Esempio n. 1
0
        void referenceConnectionCopy()
        {
            foreach (IMgaConnection otherIMgaConnection in _iMgaConnectionSet)
            {
                IMgaModel otherIMgaConnectionParent = otherIMgaConnection.ParentModel;

                IMgaModel newIMgaConnectionParent = getCorrespondingIMgaFCO(otherIMgaConnectionParent) as IMgaModel;
                if (newIMgaConnectionParent == null)
                {
                    Dictionary <string, IMgaFCO> nameTargetMap = new Dictionary <string, IMgaFCO>();
                    foreach (IMgaConnPoint otherIMgaConnPoint in otherIMgaConnection.ConnPoints)
                    {
                        nameTargetMap[otherIMgaConnPoint.ConnRole] = otherIMgaConnPoint.Target;
                    }
                    gmeConsole.Error.Write("Could not make connection between ");
                    bool first = true;
                    foreach (string key in nameTargetMap.Keys)
                    {
                        if (first)
                        {
                            first = false;
                        }
                        else
                        {
                            gmeConsole.Error.Write(", ");
                        }
                        gmeConsole.Error.Write("\"" + key + "\"=\"" + nameTargetMap[key].AbsPath + "\"");
                    }

                    gmeConsole.Error.Write(" in main model:  Could not access parent (path: \"" + otherIMgaConnectionParent.AbsPath + "\")");
                    _exitStatus |= Errors.PathError;
                    continue;
                }

                IMgaConnection newIMgaConnection = newIMgaConnectionParent.CreateChildObject(otherIMgaConnection.MetaRole) as IMgaConnection;
                foreach (IMgaConnPoint otherIMgaConnPointToCopy in otherIMgaConnection.ConnPoints)
                {
                    IMgaFCO otherTarget = otherIMgaConnPointToCopy.Target;
                    MgaFCO  newTarget   = getCorrespondingIMgaFCO(otherTarget) as MgaFCO;

                    if (newTarget == null)
                    {
                        gmeConsole.Error.WriteLine("Could not find connection target of path \"" + otherTarget.AbsPath + "\" and role \"" + otherIMgaConnPointToCopy.ConnRole + "\" for connection of path \"" + newIMgaConnection.AbsPath + "\"");
                        newIMgaConnection.DestroyObject();
                        newIMgaConnection = null;
                        _exitStatus      |= Errors.PathError;
                        break;
                    }

                    MgaFCOs newMgaFCOs     = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                    bool    referenceError = false;
                    foreach (IMgaFCO otherReferenceIMgaFCO in otherIMgaConnPointToCopy.References)
                    {
                        IMgaFCO newReferenceIMgaFCO = getCorrespondingIMgaFCO(otherReferenceIMgaFCO);
                        if (newReferenceIMgaFCO == null)
                        {
                            gmeConsole.Error.WriteLine("Could not make connection reference \"" + otherReferenceIMgaFCO.AbsPath + "\" for connection \"" + newIMgaConnection.AbsPath + "\", role \"" + otherIMgaConnPointToCopy.ConnRole + "\".");
                            newIMgaConnection.DestroyObject();
                            newIMgaConnection = null;
                            referenceError    = true;
                            _exitStatus      |= Errors.PathError;
                            break;
                        }
                        newMgaFCOs.Append(newReferenceIMgaFCO as MgaFCO);
                    }
                    if (referenceError)
                    {
                        break;
                    }

                    MgaConnPoint newMgaConnPoint = null;
                    newIMgaConnection.AddConnPoint(otherIMgaConnPointToCopy.ConnRole, 1, newTarget, newMgaFCOs, out newMgaConnPoint);
                }
                if (newIMgaConnection != null)
                {
                    attributesAndRegistryCopy(newIMgaConnection, otherIMgaConnection);
                }
            }
        }
Esempio n. 2
0
        public void connectionCopy()
        {
            HashSet <IMgaConnection> otherIMgaConnectionSet = new HashSet <IMgaConnection>();

            foreach (IMgaFCO otherIMgaFCO in _hasConnectionList)
            {
                IEnumerable <IMgaConnPoint> otherIMgaConnPoints = otherIMgaFCO.PartOfConns.Cast <IMgaConnPoint>();
                if (otherIMgaFCO is IMgaReference)
                {
                    otherIMgaConnPoints = otherIMgaConnPoints.Concat(((IMgaReference)otherIMgaFCO).UsedByConns
                                                                     .Cast <IMgaConnPoint>().Where(cp => cp.References[1] == otherIMgaFCO));
                }

                IMgaFCO newIMgaFCO = getCorrespondingIMgaFCO(otherIMgaFCO);
                if (newIMgaFCO == null)
                {
                    gmeConsole.Error.WriteLine("Could not make any connections to \"" + otherIMgaFCO.AbsPath + "\" in main model during merge:  FCO not found.");
                    _exitStatus |= Errors.PathError;
                    continue;
                }

                // AT THIS POINT, NO CONNECTIONS SHOULD EXIST EXCEPT FOR CONNECTIONS THAT ARE INSTANCE/SUBTYPES
                foreach (IMgaConnPoint otherIMgaConnPoint in otherIMgaConnPoints)
                {
                    if (otherIMgaConnPoint.References.Count > 0)
                    {
                        if (!_fcoMap.ContainsKey(otherIMgaConnPoint.References[1]))
                        {
                            continue;
                        }
                    }
                    // GET ACTUAL CONNECTION
                    IMgaConnection otherIMgaConnection = otherIMgaConnPoint.Owner;

                    // ANY CONNECTIONS THAT ARE INSTANCES/SUBTYPES IN THE "OTHER" MODEL (I.E. ORIGINAL MODEL IN THE OTHER FILE)
                    // MUST BE INSTANCES/SUBTYPES IN "NEW" MODEL.  I.E. THEY ALREADY EXIST IN THE "NEW" MODEL, SO SKIP
                    if (otherIMgaConnection.ArcheType != null)
                    {
                        continue;
                    }

                    // IF CONNECTION ALREADY PROCESSED, SKIP
                    if (otherIMgaConnectionSet.Contains(otherIMgaConnection))
                    {
                        continue;
                    }
                    otherIMgaConnectionSet.Add(otherIMgaConnection);
                    _iMgaConnectionSet.Remove(otherIMgaConnection);

                    IMgaModel otherIMgaConnectionParent = otherIMgaConnection.ParentModel;

                    IMgaModel newIMgaConnectionParent = getCorrespondingIMgaFCO(otherIMgaConnectionParent) as IMgaModel;
                    if (newIMgaConnectionParent == null)
                    {
                        gmeConsole.Error.WriteLine("Could not make connection to \"" + otherIMgaFCO.AbsPath + "\" in main model:  Could not access parent (path: \"" + otherIMgaConnectionParent.AbsPath + "\").");
                        _exitStatus |= Errors.PathError;
                        continue;
                    }

                    IMgaConnection newIMgaConnection = newIMgaConnectionParent.CreateChildObject(otherIMgaConnection.MetaRole) as IMgaConnection;
                    foreach (IMgaConnPoint otherIMgaConnPointToCopy in otherIMgaConnection.ConnPoints)
                    {
                        IMgaFCO otherTarget = otherIMgaConnPointToCopy.Target;
                        MgaFCO  newTarget   = getCorrespondingIMgaFCO(otherTarget) as MgaFCO;

                        if (newTarget == null)
                        {
                            gmeConsole.Error.WriteLine("Could not find connection target of path \"" + otherTarget.AbsPath + "\" and role \"" + otherIMgaConnPointToCopy.ConnRole + "\" for connection of path \"" + newIMgaConnection.AbsPath + "\"");
                            newIMgaConnection.DestroyObject();
                            newIMgaConnection = null;
                            _exitStatus      |= Errors.PathError;
                            break;
                        }

                        MgaFCOs newMgaFCOs     = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
                        bool    referenceError = false;
                        foreach (IMgaFCO otherReferenceIMgaFCO in otherIMgaConnPointToCopy.References)
                        {
                            IMgaFCO newReferenceIMgaFCO = getCorrespondingIMgaFCO(otherReferenceIMgaFCO);
                            if (newReferenceIMgaFCO == null)
                            {
                                gmeConsole.Error.WriteLine("Could not make connection reference \"" + otherReferenceIMgaFCO.AbsPath + "\" for connection \"" + newIMgaConnection.AbsPath + "\", role \"" + otherIMgaConnPointToCopy.ConnRole + "\".");
                                newIMgaConnection.DestroyObject();
                                newIMgaConnection = null;
                                referenceError    = true;
                                _exitStatus      |= Errors.PathError;
                                break;
                            }
                            newMgaFCOs.Append(newReferenceIMgaFCO as MgaFCO);
                        }
                        if (referenceError)
                        {
                            break;
                        }

                        MgaConnPoint newMgaConnPoint = null;
                        newIMgaConnection.AddConnPoint(otherIMgaConnPointToCopy.ConnRole, 1, newTarget, newMgaFCOs, out newMgaConnPoint);
                    }
                    if (newIMgaConnection != null)
                    {
                        attributesAndRegistryCopy(newIMgaConnection, otherIMgaConnection);
                    }
                }
            }
        }