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); } } }
public static T CreateObject <T>( ISIS.GME.Common.Interfaces.Container parent, string roleStr = null) where T : ISIS.GME.Common.Classes.Base, new() { Contract.Requires(parent != null); T result = new T(); string Kind = typeof(T).Name; if (parent.Impl is IMgaModel) { IMgaModel model = parent.Impl as IMgaModel; MgaMetaRole role = null; if (string.IsNullOrEmpty(roleStr)) { try { // try to use user defined role role = (model.MetaBase as IMgaMetaModel).RoleByName[Kind]; } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Role was not found in the container."); sb.AppendLine("Paradigm violation."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } else { try { // try to use user defined role role = (model.MetaBase as IMgaMetaModel).RoleByName[roleStr]; } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("Role was not found in the container."); sb.AppendLine("Paradigm violation."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } try { MgaFCO fco = model.CreateChildObject(role); result.Impl = fco as IMgaObject; return(result); } catch (Exception ex) { StringBuilder sb = new StringBuilder(); sb.AppendLine("New element could not be created."); sb.AppendFormat("Container type: {0} Requested role: {1}", parent.Kind, result.GetType().Name); throw new Exception(sb.ToString(), ex); } } else if (parent.Impl is MgaFolder) { if (string.IsNullOrEmpty(roleStr)) { MgaFolder folder = parent.Impl as MgaFolder; foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders) { if (item.Name == Kind) { MgaFolder f = folder.CreateFolder(item); result.Impl = f as IMgaObject; return(result); } } if (result.Impl == null) { foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects) { if (item.Name == Kind) { IMgaFCO fco = folder.CreateRootObject(item); result.Impl = fco as IMgaObject; return(result); } } } } else { MgaFolder folder = parent.Impl as MgaFolder; foreach (MgaMetaFolder item in folder.MetaFolder.LegalChildFolders) { if (item.Name == roleStr) { MgaFolder f = folder.CreateFolder(item); result.Impl = f as IMgaObject; return(result); } } if (result.Impl == null) { foreach (MgaMetaFCO item in folder.MetaFolder.LegalRootObjects) { if (item.Name == roleStr) { IMgaFCO fco = folder.CreateRootObject(item); result.Impl = fco as IMgaObject; return(result); } } } } } return(null); }
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); } } } }