// RECORD ALL CONNECTIONS AND ALL OBJECTS THAT HAVE CONNECTIONS public void recordConnections(IMgaFCO otherCurrentObject) { if (otherCurrentObject.PartOfConns.Count != 0) { _hasConnectionList.Add(otherCurrentObject); } if (otherCurrentObject is IMgaReference) { IMgaReference otherReference = (IMgaReference)otherCurrentObject; if (otherReference.UsedByConns.Count > 0) { _hasConnectionList.Add(otherReference); } } if (otherCurrentObject.ObjType != GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL) { return; } foreach (MgaObject otherChildMgaObject in otherCurrentObject.ChildObjects) { if (otherChildMgaObject.MetaBase.ObjType == GME.MGA.Meta.objtype_enum.OBJTYPE_CONNECTION) { _iMgaConnectionSet.Add(otherChildMgaObject as IMgaConnection); continue; } recordConnections(otherChildMgaObject as IMgaFCO); } }
private static IMgaFCOs GetRefChain(IMgaReference reference) { IMgaFCOs ret = (IMgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs")); ret.Append(reference as MgaFCO); while (true) { if (reference.Referred == null) { break; } if (reference.Referred.ObjType == GME.MGA.Meta.objtype_enum.OBJTYPE_REFERENCE) { reference = reference.Referred as IMgaReference; ret.Append(reference as MgaFCO); } else { break; } } return(ret); }
public void SwitchReference(IMgaFCO to, IMgaReference @ref) { Switcher.MoveReferenceWithRefportConnections(to, @ref, PrintLine); }
/** * First we disconnect all connections to refports, then move the reference, then reconnect */ public static void MoveReferenceWithRefportConnections(IMgaFCO fco2, IMgaReference origref, WriteLineF WriteLine) { Queue <IMgaReference> references = new Queue <IMgaReference>(); references.Enqueue(origref); IMgaFCO targetModel = fco2; while (targetModel is IMgaReference) { targetModel = ((IMgaReference)targetModel).Referred; } MgaFCOs fco2ChildFCOs = ((IMgaModel)targetModel).ChildFCOs; Dictionary <string, IMgaFCO> newRefeChildren = GetNameMap(fco2ChildFCOs, x => { }); // TODO: warn, but only for refport-connected children //GMEConsole.Warning.WriteLine("Warning: " + fco2.Name + " has multiple children named " + x)); int origPrefs = fco2.Project.Preferences; // Magic word allows us to remove ConnPoints fco2.Project.Preferences = origPrefs | (int)GME.MGA.preference_flags.MGAPREF_IGNORECONNCHECKS | (int)GME.MGA.preference_flags.MGAPREF_FREEINSTANCEREFS; try { MgaConnection conn = null; var ReconnectList = MakeList(new { ConnRole = "src", Ref = origref, Port = fco2, Conn = conn }); while (references.Count != 0) { IMgaReference refe = references.Dequeue(); foreach (IMgaConnPoint connPoint in refe.UsedByConns) { if (connPoint.References[1] != refe) { continue; } IMgaFCO fco2Port; if (newRefeChildren.TryGetValue(connPoint.Target.Name, out fco2Port)) { if (fco2Port == null) { // fco2Port == null => multiple children with the same name // Try matching based on Kind too fco2Port = fco2ChildFCOs.Cast <IMgaFCO>().Where(x => x.Name == connPoint.Target.Name && x.Meta.MetaRef == connPoint.Target.Meta.MetaRef).FirstOrDefault(); } if (fco2Port != null) { ReconnectList.Add(new { ConnRole = connPoint.ConnRole, Ref = refe, Port = fco2Port, Conn = connPoint.Owner }); connPoint.Remove(); } } else { WriteLine((x, y) => "Can't find corresponding port for " + x + " in " + y, connPoint.Target, fco2); connPoint.Owner.DestroyObject(); } } foreach (IMgaReference x in refe.ReferencedBy.Cast <IMgaReference>()) { if (x.ID == origref.ID) { throw new Exception("Circular reference chain starting with " + origref.AbsPath); } references.Enqueue(x); } } origref.Referred = (MgaFCO)fco2; foreach (var reconnect in ReconnectList) { if (reconnect.ConnRole == "src") { (reconnect.Conn as IMgaSimpleConnection).SetSrc((MgaFCOs)GetRefChain(reconnect.Ref), (MgaFCO)reconnect.Port); } else { (reconnect.Conn as IMgaSimpleConnection).SetDst((MgaFCOs)GetRefChain(reconnect.Ref), (MgaFCO)reconnect.Port); } } } finally { fco2.Project.Preferences = origPrefs; } }
private void UpdateSublibrary(IMgaObject fco1Objec, IMgaObject fco2Objec) { // fco2Object may be null if (fco1Objec is IMgaFCO) // references only refer to FCOs { IMgaFCO fco1 = (IMgaFCO)fco1Objec; IMgaFCO fco2 = fco2Objec as IMgaFCO; foreach (IMgaFCO fco in fco1.ReferencedBy) { if (fco.IsInstance) { continue; // instance references will be updated by their archetype } // Don't update references in the old library bool fcoInLib1Objects = false; foreach (IMgaObject lib1Root in this.lib1Objects) { // FIXME: Contains(this.fco1Object) doesn't work if (new ParentChain(fco).Contains(lib1Root, new MgaObjectEqualityComparor <IMgaObject>())) { fcoInLib1Objects = true; } } if (fcoInLib1Objects) { continue; } IMgaReference refe = (IMgaReference)fco; if (fco2 != null) { if (refe.UsedByConns.Count != 0) { if (refe.DerivedFrom == null) { try { MoveReferenceWithRefportConnections(fco2, refe, WriteLine); } catch (Exception e) { if (GMEConsole != null) { GMEConsole.Error.WriteLine("Could not set reference " + GetLink(refe, refe.Name)); } throw new Exception("Could not set reference " + getPath(refe) + " (" + refe.ID + ")", e); } } } else { try { bool setRef; if (refe.DerivedFrom == null) { setRef = true; } else { short compareToBase; refe.CompareToBase(out compareToBase); setRef = compareToBase != 0; } if (setRef) { // FIXME: can this fail; should we handle it somehow? refe.Referred = (GME.MGA.MgaFCO)fco2; } } catch (Exception e) { if (GMEConsole != null) { GMEConsole.Error.WriteLine("Could not set reference " + GetLink(refe, refe.Name)); } throw new Exception("Could not set reference " + getPath(refe) + " (" + refe.ID + ")", e); } } } else { WriteLine((x, y) => "Couldn't update " + x + ": " + y + " has no counterpart", refe, fco1); } } } List <IMgaObject> fco1Children = getChildren(fco1Objec); List <IMgaObject> fco2Children = getChildren(fco2Objec); Dictionary <string, ObjectPair> dict = new Dictionary <string, ObjectPair>(); foreach (IMgaObject o in fco1Children) { dict.GetValueOrDefault(o.Name + "xxx ;xxx" + o.MetaBase.Name).o1 = o; } foreach (IMgaObject o in fco2Children) { dict.GetValueOrDefault(o.Name + "xxx ;xxx" + o.MetaBase.Name).o2 = o; } foreach (KeyValuePair <string, ObjectPair> entry in dict) { if (entry.Value.o1 != null) { UpdateSublibrary(entry.Value.o1, entry.Value.o2); } } }
public ReferenceInfo(IMgaReference otherReference, IMgaReference newReference) { _otherReference = otherReference; _newReference = newReference; }
public static IMgaFCO FindTestInjectionTarget( CyPhy.TopLevelSystemUnderTest originalSut, IMgaReference originalTip, CyPhy.TopLevelSystemUnderTest targetSut) { if (originalSut == null) { throw new ArgumentNullException("originalSut"); } if (originalTip == null) { throw new ArgumentNullException("originalTip"); } if (targetSut == null) { throw new ArgumentNullException("targetSut"); } // target that the reference has to be redirected IMgaFCO targetTipByBuilt = null; IMgaFCO targetTipByAbsPath = null; // get tip reference // relative path var relativePath = string.Empty; // ASSUME original SUT is a design container if (originalSut.Referred.DesignContainer == null && targetSut.Referred.ComponentAssembly == null) { throw new NotImplementedException(); } var sutDesignContainer = originalSut.Referred.DesignContainer; var sutComponentAssemblyTarget = targetSut.Referred.ComponentAssembly; // TOOD: Double check this cast CyPhy.DesignEntity originalDesignEntity = null; if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name) { originalDesignEntity = CyPhyClasses.DesignContainer.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.Component).Name) { originalDesignEntity = CyPhyClasses.Component.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentRef).Name) { originalDesignEntity = CyPhyClasses.ComponentRef.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentAssembly).Name) { originalDesignEntity = CyPhyClasses.ComponentAssembly.Cast(originalTip.Referred); } List <CyPhy.DesignEntity> possibleDesignEntities = new List <CyPhy.DesignEntity>(); possibleDesignEntities.Add(originalDesignEntity); // TODO: abspath for component assemblies / Component assembly refs too. Call function recursively if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name) { var designContainer = CyPhyClasses.DesignContainer.Cast(originalTip.Referred); if (designContainer.Attributes.ContainerType == CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound) { // there could be a referece to the compound container // BUG: no tracking of compound containers attempt to get it by AbsPath // this implementation will work as long as // names are unqiue to Compound containes // structure as follows // // == PASS == // | Compound // +-- Compound // | // +-- Compound // // == FAIL 1 == Have no idea how to get the path correctly // | Compound // +-- Alternative // | // +-- Compound // // == FAIL 2 == Have no idea how to get the path correctly // | Compound // +-- Optional // | // +-- Compound // TODO: would be nice to use a regexp or something like that Func <string, string> shortenAbsPath = new Func <string, string>((absPath) => { // Example: // input: /@NewTesting|kind=Testing|relpos=0/@FEA_CompoundTIP_DS|kind=CADTestBench|relpos=0/@DesignContainer|kind=TopLevelSystemUnderTest|relpos=0 // output: /@NewTesting/@FEA_CompoundTIP_DS/@DesignContainer return(string.Join("/", absPath.Split('/').Select(x => string.Join("", x.TakeWhile(y => y != '|'))))); }); var sutPath = shortenAbsPath(originalSut.AllReferred.Impl.AbsPath); var originalTipPath = shortenAbsPath(originalTip.Referred.AbsPath); relativePath = originalTipPath.Substring(sutPath.Length); // TODO: meta base name [kind] can be different if there are no unique path to the object. targetTipByAbsPath = (targetSut.AllReferred.Impl as MgaModel).get_ObjectByPath(relativePath) as MgaFCO; } else { // while optional and alternative containers are not tracked, get all ComponentAssembly, Component, ComponentRef recursively. possibleDesignEntities.AddRange(ExpandInnerOptionalAndAlternativesRecursively(designContainer)); } } Exception ex = null; foreach (var designEntity in possibleDesignEntities) { // Look for a DesignEntityRef, within a CWC, that points to this element in the Design Space. foreach (CyPhy.DesignEntityRef designEntityRef in designEntity.ReferencedBy.DesignEntityRef) { var cwc = CyPhyClasses.CWC.Cast(designEntityRef.ParentContainer.Impl); bool hasMatchingCARoot = false; var caRefs = cwc.DstConnections.Config2CACollection.Select(x => x.DstEnds.ComponentAssemblyRef); foreach (var caRef in caRefs) { if (caRef.AllReferred != null) { if ((caRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID) { hasMatchingCARoot = true; break; } } } if (hasMatchingCARoot == false) { // do not log any messages since they irrelevant. continue; } // TODO: log if design is dirty. // get design entity ref where the refered object is the test injection point reference // // Multiple configuration (1, 2, 3, ...) can have the same design entity refs // // design entity ref ----> DesignSpace element // ^ // | // original test injection --------- // verify root fco do match if ((designEntityRef.Impl as MgaFCO).RootFCO != (sutDesignContainer.Impl as MgaFCO).RootFCO) { // in case user accidentally moves these object in the tree string message = string.Format("Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } // user may have leftovers from running CAExporter then deleting the CA var builts = designEntityRef.DstConnections.BuiltCollection.Where(x => x.DstEnds.BuiltDesignEntityRef.AllReferred != null); var builtConnections = builts.Count(); if (builtConnections == 0) { // no built connection -> not good string message = string.Format("No 'built' connection. Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } if (builtConnections > 1) { // more than one built connection -> not good string message = string.Format("There are more than one 'built' connections traceability is ambiguous. Model has to be fixed first. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } // Get the Built connection and then the BuildDesignEntityRef. // The BuildDesignEntityRef will point to our source object within a Component Assembly / configuration. foreach (CyPhy.Built built in builts) { var builtDesignEntityRef = built.DstEnds.BuiltDesignEntityRef; if ((builtDesignEntityRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID) { // verify that the component is inside the target design // TODO: how this would work if it points to a component in a CA which is referred in the design??? targetTipByBuilt = builtDesignEntityRef.AllReferred.Impl as MgaFCO; } } } } if (targetTipByBuilt != null) { // prefer by built return(targetTipByBuilt); } else if (targetTipByAbsPath != null) { // fallback to by abs path return(targetTipByAbsPath); } else if (ex != null) { // not found throw ex; } else { return(null); } }
public static IMgaFCO FindTestInjectionTarget( CyPhy.TopLevelSystemUnderTest originalSut, IMgaReference originalTip, CyPhy.TopLevelSystemUnderTest targetSut) { if (originalSut == null) { throw new ArgumentNullException("originalSut"); } if (originalTip == null) { throw new ArgumentNullException("originalTip"); } if (targetSut == null) { throw new ArgumentNullException("targetSut"); } // target that the reference has to be redirected IMgaFCO targetTipByBuilt = null; IMgaFCO targetTipByAbsPath = null; // get tip reference // relative path var relativePath = string.Empty; // ASSUME original SUT is a design container if (originalSut.Referred.DesignContainer == null && targetSut.Referred.ComponentAssembly == null) { throw new NotImplementedException(); } var sutDesignContainer = originalSut.Referred.DesignContainer; var sutComponentAssemblyTarget = targetSut.Referred.ComponentAssembly; // TOOD: Double check this cast CyPhy.DesignEntity originalDesignEntity = null; if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name) { originalDesignEntity = CyPhyClasses.DesignContainer.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.Component).Name) { originalDesignEntity = CyPhyClasses.Component.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentRef).Name) { originalDesignEntity = CyPhyClasses.ComponentRef.Cast(originalTip.Referred); } else if (originalTip.Referred.Meta.Name == typeof(CyPhy.ComponentAssembly).Name) { originalDesignEntity = CyPhyClasses.ComponentAssembly.Cast(originalTip.Referred); } List<CyPhy.DesignEntity> possibleDesignEntities = new List<CyPhy.DesignEntity>(); possibleDesignEntities.Add(originalDesignEntity); // TODO: abspath for component assemblies / Component assembly refs too. Call function recursively if (originalTip.Referred.Meta.Name == typeof(CyPhy.DesignContainer).Name) { var designContainer = CyPhyClasses.DesignContainer.Cast(originalTip.Referred); if (designContainer.Attributes.ContainerType == CyPhyClasses.DesignContainer.AttributesClass.ContainerType_enum.Compound) { // there could be a referece to the compound container // BUG: no tracking of compound containers attempt to get it by AbsPath // this implementation will work as long as // names are unqiue to Compound containes // structure as follows // // == PASS == // | Compound // +-- Compound // | // +-- Compound // // == FAIL 1 == Have no idea how to get the path correctly // | Compound // +-- Alternative // | // +-- Compound // // == FAIL 2 == Have no idea how to get the path correctly // | Compound // +-- Optional // | // +-- Compound // TODO: would be nice to use a regexp or something like that Func<string, string> shortenAbsPath = new Func<string, string>((absPath) => { // Example: // input: /@NewTesting|kind=Testing|relpos=0/@FEA_CompoundTIP_DS|kind=CADTestBench|relpos=0/@DesignContainer|kind=TopLevelSystemUnderTest|relpos=0 // output: /@NewTesting/@FEA_CompoundTIP_DS/@DesignContainer return string.Join("/", absPath.Split('/').Select(x => string.Join("", x.TakeWhile(y => y != '|')))); }); var sutPath = shortenAbsPath(originalSut.AllReferred.Impl.AbsPath); var originalTipPath = shortenAbsPath(originalTip.Referred.AbsPath); relativePath = originalTipPath.Substring(sutPath.Length); // TODO: meta base name [kind] can be different if there are no unique path to the object. targetTipByAbsPath = (targetSut.AllReferred.Impl as MgaModel).get_ObjectByPath(relativePath) as MgaFCO; } else { // while optional and alternative containers are not tracked, get all ComponentAssembly, Component, ComponentRef recursively. possibleDesignEntities.AddRange(ExpandInnerOptionalAndAlternativesRecursively(designContainer)); } } Exception ex = null; foreach (var designEntity in possibleDesignEntities) { // Look for a DesignEntityRef, within a CWC, that points to this element in the Design Space. foreach (CyPhy.DesignEntityRef designEntityRef in designEntity.ReferencedBy.DesignEntityRef) { var cwc = CyPhyClasses.CWC.Cast(designEntityRef.ParentContainer.Impl); bool hasMatchingCARoot = false; var caRefs = cwc.DstConnections.Config2CACollection.Select(x => x.DstEnds.ComponentAssemblyRef); foreach (var caRef in caRefs) { if (caRef.AllReferred != null) { if ((caRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID) { hasMatchingCARoot = true; break; } } } if (hasMatchingCARoot == false) { // do not log any messages since they irrelevant. continue; } // TODO: log if design is dirty. // get design entity ref where the refered object is the test injection point reference // // Multiple configuration (1, 2, 3, ...) can have the same design entity refs // // design entity ref ----> DesignSpace element // ^ // | // original test injection --------- // verify root fco do match if ((designEntityRef.Impl as MgaFCO).RootFCO != (sutDesignContainer.Impl as MgaFCO).RootFCO) { // in case user accidentally moves these object in the tree string message = string.Format("Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } var builtConnections = designEntityRef.DstConnections.BuiltCollection.Count(); if (builtConnections == 0) { // no built connection -> not good string message = string.Format("No 'built' connection. Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } if (builtConnections > 1) { // more than one built connection -> not good string message = string.Format("There are more than one 'built' connections traceability is ambiguous. Model has to be fixed first. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } // Get the Built connection and then the BuildDesignEntityRef. // The BuildDesignEntityRef will point to our source object within a Component Assembly / configuration. foreach (CyPhy.Built built in designEntityRef.DstConnections.BuiltCollection) { var builtDesignEntityRef = built.DstEnds.BuiltDesignEntityRef; if (builtDesignEntityRef.AllReferred == null) { // in case user clears the reference string message = string.Format("Model does not contain traceablity information between the generated configurations and the design space. {0} will not be found in the original design space. Please try to export the configurations again using CAExporter or run the design space exploration tool.", originalTip.Meta.Name); ex = new AnalysisModelTipNotFoundException(message); continue; } if ((builtDesignEntityRef.AllReferred.Impl as MgaFCO).RootFCO.ID == (sutComponentAssemblyTarget.Impl as MgaFCO).RootFCO.ID) { // verify that the component is inside the target design // TODO: how this would work if it points to a component in a CA which is referred in the design??? targetTipByBuilt = builtDesignEntityRef.AllReferred.Impl as MgaFCO; } } } } if (targetTipByBuilt != null) { // prefer by built return targetTipByBuilt; } else if (targetTipByAbsPath != null) { // fallback to by abs path return targetTipByAbsPath; } else if (ex != null) { // not found throw ex; } else { return null; } }
public List <IMgaFCO> InsertComponents( IMgaFCO designContainer, IMgaFCO componentRef, List <IMgaFCO> components, List <KeyValuePair <IMgaFCO, string> > messages) { Contract.Requires(designContainer as IMgaModel != null); Contract.Requires(componentRef as IMgaReference != null); Contract.Requires((componentRef as IMgaReference).Referred != null); Contract.Requires(components != null); List <IMgaFCO> result = new List <IMgaFCO>(); IMgaModel container = designContainer as IMgaModel; IMgaReference compRef = componentRef as IMgaReference; var childComps = container. ChildFCOs. Cast <IMgaFCO>(). Where(x => x.MetaBase.Name == "ComponentRef"). Cast <IMgaReference>(). Select(x => x.Referred). ToList(); // get all connections which has the componentRef as an endpoint var childConnections = container. ChildFCOs. Cast <IMgaFCO>(). Where(x => x is IMgaSimpleConnection). Cast <IMgaSimpleConnection>(). ToList(); // ith new component int iNewComponent = 0; foreach (var compToCreate in components) { if (childComps.Contains(compToCreate)) { // If the component already exists this function will not create it again // skip messages.Add(new KeyValuePair <IMgaFCO, string>(compToCreate, "Component already exists.")); continue; } // create reference var newRef = container.CreateReference(componentRef.MetaRole, compToCreate as MgaFCO); newRef.Name = compToCreate.Name; //////// //VehicleForge.VFSession session = null; //VFComponentExchange results = session.SendGetRequest<VFComponentExchange>(""); //VFComponentExchange resultjson = Newtonsoft.Json.JsonConvert.DeserializeObject<VFComponentExchange>(""); //////// result.Add(newRef); bool compatible = true; // create connections foreach (var connectionToCreate in childConnections) { if (SafeMgaObjectCompare(connectionToCreate.SrcReferences.Cast <IMgaFCO>().FirstOrDefault(), compRef) || SafeMgaObjectCompare(connectionToCreate.DstReferences.Cast <IMgaFCO>().FirstOrDefault(), compRef)) { try { var connRole = connectionToCreate.MetaRole; var connSrc = connectionToCreate.Src; var connDst = connectionToCreate.Dst; var connSrcReference = connectionToCreate.SrcReferences.Cast <MgaFCO>().FirstOrDefault(); var connDstReference = connectionToCreate.DstReferences.Cast <MgaFCO>().FirstOrDefault(); // overwrite the new endpoints if (SafeMgaObjectCompare(connectionToCreate.SrcReferences.Cast <IMgaFCO>().FirstOrDefault(), compRef)) { connSrcReference = newRef; // Check for objects with same name and same type var srcCandidates = compToCreate.ChildObjects.OfType <MgaFCO>().Where(x => x.Name == connSrc.Name && x.Meta.Name == connSrc.Meta.Name); MgaFCO srcCandidate = srcCandidates.FirstOrDefault(); if (srcCandidates.Count() > 1) { messages.Add(new KeyValuePair <IMgaFCO, string>( compToCreate, "Not Inserted. It has more than one matching object named: " + connSrc.Name)); compatible = false; } if (srcCandidate == null) { messages.Add(new KeyValuePair <IMgaFCO, string>( compToCreate, "Not Inserted. It does not have a port with name: " + connSrc.Name)); compatible = false; } connSrc = srcCandidate; } if (SafeMgaObjectCompare(connectionToCreate.DstReferences.Cast <IMgaFCO>().FirstOrDefault(), compRef)) { connDstReference = newRef; //var dstCandidate = compToCreate.ObjectByPath[connDst.Name] as MgaFCO; var dstCandidates = compToCreate.ChildObjects.OfType <MgaFCO>().Where(x => x.Name == connDst.Name && x.Meta.Name == connDst.Meta.Name); MgaFCO dstCandidate = dstCandidates.FirstOrDefault(); if (dstCandidates.Count() > 1) { messages.Add(new KeyValuePair <IMgaFCO, string>( compToCreate, "Not Inserted. It has more than one matching object named: " + connDst.Name)); compatible = false; } if (dstCandidate == null) { messages.Add(new KeyValuePair <IMgaFCO, string>( compToCreate, "Not Inserted. It does not have port with name: " + connDst.Name)); compatible = false; } connDst = dstCandidate; } // check end points if (connSrc != null && connDst != null) { var newConnection = container.CreateSimpleConnDisp( connRole, connSrc, connDst, connSrcReference, connDstReference); } } catch (Exception ex) { System.Diagnostics.Trace.TraceError(ex.ToString()); System.Diagnostics.Trace.TraceError("Probably some ports do not match."); compatible = false; } } } if (compatible) { iNewComponent = iNewComponent + 1; foreach (IMgaPart part in newRef.Parts) { int x = 0; int y = 0; string icon; componentRef.PartByMetaPart[part.Meta].GetGmeAttrs(out icon, out x, out y); part.SetGmeAttrs(icon, x, y + 80 * iNewComponent); } } else { //messages.Add(new KeyValuePair<IMgaFCO, string>(compToCreate, "Component was skipped: " + compToCreate.Name)); result.Remove(newRef); newRef.DestroyObject(); } } foreach (var item in messages) { GMEConsole.Error.WriteLine("{0}: {1}", item.Key.ToMgaHyperLink(), item.Value); } GMEConsole.Info.WriteLine("{0} components were inserted. Detailed list as follows:", result.Count); foreach (var item in result) { GMEConsole.Info.WriteLine("- {0}", item.ToMgaHyperLink()); } return(result); }