public void CheckConfiguration() { FixEmptyContainers(); SpecFlow.CheckConfiguration(); Traceability.CheckConfiguration(); }
private MgaFCO ClonePort(MgaModel parent, MgaFCO oldPort) { Logger.WriteDebug("ClonePort: {0}", oldPort.AbsPath); GME.MGA.Meta.MgaMetaRole role = null; foreach (GME.MGA.Meta.MgaMetaRole roleItem in (parent.Meta as GME.MGA.Meta.MgaMetaModel).Roles) { if (roleItem.Kind.MetaRef == oldPort.MetaBase.MetaRef) { role = roleItem; break; } } var newPortFCO = parent.CopyFCODisp(oldPort, role); String lastGood = oldPort.ID; String iter = null; while (Traceability.TryGetMappedObject(lastGood, out iter) && lastGood != iter) { lastGood = iter; } Traceability.AddItem(newPortFCO.ID, lastGood); return(newPortFCO); }
public override int GetHashCode() { unchecked { var hashCode = (ConfigurationBaseFolder != null ? ConfigurationBaseFolder.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (SpecFlow != null ? SpecFlow.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (Traceability != null ? Traceability.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (int)ProcessorArchitecture; hashCode = (hashCode * 397) ^ DebugConnector.GetHashCode(); hashCode = (hashCode * 397) ^ (DefaultFeatureLanguage != null ? DefaultFeatureLanguage.GetHashCode() : 0); hashCode = (hashCode * 397) ^ (ConfiguredBindingCulture != null ? ConfiguredBindingCulture.GetHashCode() : 0); return(hashCode); } }
private void CheckAssembly(CyPhy.ComponentAssembly cyphyasm) { foreach (CyPhy.ComponentRef cref in cyphyasm.Children.ComponentRefCollection) { if (cref.AllReferred == null) { string originalId = null; if (Traceability != null && Traceability.TryGetMappedObject(cref.ID, out originalId)) { throw new Exception("Null ComponentRef <a href=\"mga:" + originalId + "\">[" + cref.Path + "]</a>."); } throw new Exception("Null ComponentRef [" + cref.Path + "]."); } else { throw new Exception("Model not fully elaborated, contains ComponentRef [" + cref.Path + "]"); } } }
private void button6_Click(object sender, EventArgs e) { var dupa = new Traceability(new ConnectionStringModel(_sqlIp, _db, _sqlUser, _sqlPass)); if (!dupa.IsConnection()) { return; } try { var tb = new DataTable(); tb.Load(dupa.Ask_SN("Junior", "750", "26111047", "26111047062173033700", new[] { "1", "abc" })); // tb.Load(dupa.Ask_SN("Junior", "750", "26111047", "26111047062173033700", new[] {"" })); var foo = tb.Rows[0][0].ToString(); MessageBox.Show(foo); } catch (Exception exception) { MessageBox.Show(exception.ToString()); throw; } }
private void button5_Click(object sender, EventArgs e) { //EXEC [dbo].[ASK_SN] @LINE = N'JUNIOR', @OP = 750, @PN = N'26111047', @SN = N'26111047062173033700' var dupa = new Traceability(new ConnectionStringModel(_sqlIp, _db, _sqlUser, _sqlPass)); if (!dupa.IsConnection()) { return; } try { var tb = new DataTable(); tb.Load(dupa.Ask_SN("Junior", "750", "26111047", "26111047062173033700")); var foo = tb.Rows[0][0].ToString(); MessageBox.Show(foo); } catch (Exception exception) { MessageBox.Show(exception.ToString()); throw; } }
// What do we have to do here now? // Well, if this connector has instances, we need to add port maps for those things too. // Then those connectors need to be visited to connections can be adjusted. private void VisitConnector(MgaModel connector) { #region Check arguments if (connector == null) { throw new ArgumentNullException("connector"); } if (connector.MetaBase.MetaRef != MetaRef["Connector"]) { throw new ArgumentException("Input parameter was not a connector.", "connector"); } if (ConnectorsProcessed.Contains(connector)) { return; } #endregion Logger.WriteDebug("VisitConnector: {0}", connector.AbsPath); ConnectorToStandalonePortMap.Add(connector, new List <PortWrapper>()); var parent = connector.ParentModel; Boolean connectorIsArchetype = (connector.ArcheType == null); Boolean parentIsArchetype = (parent.ArcheType == null); if (parentIsArchetype) { Logger.WriteDebug("VisitConnector: Processing with parent as Archetype"); if (connectorIsArchetype) { Logger.WriteDebug("VisitConnector: Processing connector as Archetype"); } else { Logger.WriteDebug("VisitConnector: Processing connector as Derived"); Logger.WriteDebug("VisitConnector: Setting connector's local attributes and detaching"); SetAttributesLocally(connector as MgaFCO); connector.DetachFromArcheType(); } // I'm an archetype. // Go through each supported port, clone it, and create a wrapper. // Add it to traceability. // Redirect connections to constituent ports. foreach (MgaFCO port in connector.ChildFCOs) { if (false == SupportedPortTypesMeta.Contains(port.MetaBase.MetaRef)) { Logger.WriteDebug("VisitConnector: Skipping unsupported port {0}", port.AbsPath); continue; } var newPort = ClonePort(parent, port); newPort.Name = String.Format("{0}__{1}", connector.Name, port.Name); var wrapper = new PortWrapper() { SourceConnector = connector, SourcePortRole = port.Name, SourcePort = port, StandalonePort = newPort }; ConnectorToStandalonePortMap[connector].Add(wrapper); // See if the derived guy is itself in the Traceability. String lastGood = port.ID; String iter = null; while (Traceability.TryGetMappedObject(lastGood, out iter) && lastGood != iter) { lastGood = iter; } Traceability.AddItem(newPort.ID, lastGood); } RedirectConnectionsToConstituentPorts(connector); } else { Logger.WriteDebug("VisitConnector: Processing as Derived"); var connectorArchetype = connector.ArcheType as MgaModel; // I'm derived. What we need to do is go through each // port, and create a new wrapper for each one. foreach (MgaFCO derivedPort in connector.ChildFCOs) { if (false == SupportedPortTypesMeta.Contains(derivedPort.MetaBase.MetaRef)) { Logger.WriteDebug("VisitConnector: Skipping unsupported derived port {0}", derivedPort.AbsPath); continue; } // Find the wrapper for these guys var orgWrapper = ConnectorToStandalonePortMap[connectorArchetype] .FirstOrDefault(w => w.SourceConnector == connectorArchetype && w.SourcePort == derivedPort.ArcheType); if (orgWrapper == null) { Logger.WriteDebug("VisitConnector: orgWrapper is null for {0}", derivedPort.AbsPath); throw new ArgumentNullException("orgWrapper is null for " + derivedPort.AbsPath); } // Now guess at the standalone port. MgaFCO standalonePort = null; foreach (MgaFCO brokenOutPort in parent.ChildFCOs) { if (brokenOutPort.ArcheType != null && brokenOutPort.ArcheType == orgWrapper.StandalonePort) { standalonePort = brokenOutPort; break; } } if (standalonePort == null) { Logger.WriteDebug("VisitConnector: standalonePort is null for {0}", derivedPort.AbsPath); throw new ArgumentNullException("standalonePort is null for " + derivedPort.AbsPath); } var wrapper = new PortWrapper() { SourceConnector = connector, SourcePortRole = derivedPort.Name, SourcePort = derivedPort, StandalonePort = standalonePort }; ConnectorToStandalonePortMap[connector].Add(wrapper); // See if the derived guy is itself in the Traceability. String lastGood = derivedPort.ID; String iter = null; while (Traceability.TryGetMappedObject(lastGood, out iter) && lastGood != iter) { lastGood = iter; } Traceability.AddItem(standalonePort.ID, lastGood); } } foreach (MgaModel derivedConnector in connector.DerivedObjects) { Logger.WriteDebug("VisitConnector: Visiting derived connector {0}", derivedConnector.AbsPath); VisitConnector(derivedConnector); } ConnectorsProcessed.Add(connector); }
/// <summary> /// Utility function to switch a reference to a model copy or instance. Reference should be deleted after this call. /// </summary> /// <remarks>In case copy is requested and the target element is a derived type (i.e. subtype or instance) inheritance chain will be cut. To make further elaboration possible.</remarks> /// <param name="parentModel">Parent model of the reference</param> /// <param name="reference">Reference to switch to a model</param> /// <param name="createInstance">If true creates an instance otherwise makes a copy of the target object. See remarks.</param> /// <returns>Model which was created instead of the reference.</returns> protected MgaModel SwitchReferenceToModel(MgaModel parentModel, MgaReference reference, bool createInstance) { this.LogDebug("Switching reference to model", reference); if (reference.Referred == null) { // failed to elaborate this.Logger.WriteFailed("Reference is null. {0} {1} [{2}]", reference.ID, reference.Name, reference.MetaBase.Name); return(null); } var referred = reference.Referred; // FIXME: this could fail, e.g. if componentref refers to a test component and we are in a CA GME.MGA.Meta.MgaMetaRole role = null; foreach (GME.MGA.Meta.MgaMetaRole roleItem in (parentModel.Meta as GME.MGA.Meta.MgaMetaModel) .Roles) { if (roleItem.Kind.MetaRef == referred.MetaBase.MetaRef) { role = roleItem; break; } } if (role == null) { throw new ElaboratorException(string.Format("Role was not found for {0} [{1}] in {2} [{3}]", referred.Name, referred.MetaBase.Name, parentModel.Name, parentModel.MetaBase.Name)); } MgaFCO copiedObj = null; Func <MgaFCO, MgaFCO, MgaFCO> getOriginalChildObject = null; if (createInstance) { this.LogDebug("Creating instance from", referred); MgaFCO originalReferred = null; if (UnrollConnectors) { originalReferred = referred; MgaFCO referredCopy; if (ComponentCopyMap.TryGetValue(referred, out referredCopy)) { } else { // FIXME update traceability referredCopy = referred.ParentFolder.CopyFCODisp(referred); ComponentCopyMap[referred] = referredCopy; } referred = referredCopy; } copiedObj = parentModel.DeriveChildObject(referred, role, true); Func <IMgaFCO, int> getRelID = (fco) => { if (fco.DerivedFrom != null && fco.IsPrimaryDerived == false) { // workaround GME bug fixed 2/27/2017 const int RELID_BASE_MAX = 0x07FFFFFF; // Mga.idl return((~RELID_BASE_MAX & fco.RelID) | (RELID_BASE_MAX & fco.DerivedFrom.RelID)); } return(fco.RelID); }; Func <MgaFCO, string> getFCORelIds = fco => { string ret = "/#" + getRelID(fco); MgaModel parent = fco.ParentModel; while (parent != null) { ret = "/#" + getRelID(parent) + ret; parent = parent.ParentModel; } return(ret); }; getOriginalChildObject = new Func <MgaFCO, MgaFCO, MgaFCO>((parent, copied) => { if (UnrollConnectors == false) { return(copied.DerivedFrom); } string relPath = getFCORelIds(copied.DerivedFrom).Substring(getFCORelIds(referred).Length); var ret = (MgaFCO)originalReferred.GetObjectByPathDisp(relPath); if (ret == null) { ret = originalReferred; // GME bug workaround continued foreach (var relID in relPath.Substring(2).Split(new[] { "/#" }, StringSplitOptions.None)) { ret = ret.ChildObjects.Cast <MgaFCO>().Where(f => getRelID(f).ToString() == relID).First(); } if (ret == null) { throw new ArgumentNullException(); } } return(ret); }); var guid = reference.StrAttrByName[AttributeNameInstanceGuid]; if (string.IsNullOrWhiteSpace(guid)) { reference.set_StrAttrByName(AttributeNameInstanceGuid, reference.GetGuidDisp()); guid = reference.StrAttrByName[AttributeNameInstanceGuid]; this.LogDebug("InstanceGUID was empty for reference, assigned new : " + guid, reference); } // parent model should contain the concatenated InstanceGUID string guidConcat = parentModel.RegistryValue[RegistryNameInstanceGuidChain] + guid; copiedObj.RegistryValue[RegistryNameInstanceGuidChain] = guidConcat; copiedObj.RegistryValue[RegistryNameOriginalReferredID] = reference.Referred.ID; this.LogDebug(string.Format("Overwriting InstanceGUID to {0}", guidConcat), referred); copiedObj.StrAttrByName[AttributeNameInstanceGuid] = guidConcat; copiedObj.RegistryValue[RegistryNameGmeIDChain] = parentModel.RegistryValue[RegistryNameGmeIDChain] + "," + reference.ID + "," + referred.ID; } else { this.LogDebug("Creating copy from", referred); copiedObj = parentModel.CopyFCODisp(referred, role); if (copiedObj.ArcheType != null) { // instance or subtype this.LogDebug("Cutting inheritance for copied object", copiedObj); copiedObj.DetachFromArcheType(); } getOriginalChildObject = new Func <MgaFCO, MgaFCO, MgaFCO>((parent, copied) => { // only chance to find objects are based on relids, which might not be unique return(parent.ChildObjectByRelID[copied.RelID] as MgaFCO); }); copiedObj.RegistryValue[RegistryNameGmeIDChain] = parentModel.RegistryValue[RegistryNameGmeIDChain] + "," + reference.ID + "," + referred.ID; if (reference.MetaBase.MetaRef == this.Factory.ComponentRefMeta) { var guid = reference.StrAttrByName[AttributeNameInstanceGuid]; copiedObj.RegistryValue[RegistryNameInstanceGuidChain] = parentModel.RegistryValue[RegistryNameInstanceGuidChain] + guid; copiedObj.RegistryValue[RegistryNameOriginalReferredID] = reference.Referred.ID; // push current instance GUID down to all component assembly elements MgaFilter filter = copiedObj.Project.CreateFilter(); filter.ObjType = GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL.ToString(); // filter.Kind = "ComponentAssembly"; foreach (MgaFCO obj in (copiedObj as MgaModel).GetDescendantFCOs(filter)) { if (obj.MetaBase.MetaRef == this.Factory.ComponentAssemblyMeta) { obj.RegistryValue[RegistryNameInstanceGuidChain] = copiedObj.RegistryValue[RegistryNameInstanceGuidChain]; obj.RegistryValue[RegistryNameGmeIDChain] = copiedObj.RegistryValue[RegistryNameGmeIDChain]; } } } } copiedObj.Name = reference.Name; if (reference.Meta.MetaRef == this.Factory.ComponentRefMeta && copiedObj.Meta.MetaRef == this.Factory.ComponentAssemblyMeta) { // TODO what should happen here // var managedGuid = reference.StrAttrByName["ManagedGUID"]; ComponentRef does not have ManagedGUID var managedGuid = reference.StrAttrByName["InstanceGUID"]; if (string.IsNullOrEmpty(managedGuid) == false) { // copiedObj.StrAttrByName["ManagedGUID"] = managedGuid; } } foreach (MgaPart part in reference.Parts) { int x; int y; string icon; part.GetGmeAttrs(out icon, out x, out y); try { copiedObj.Part[part.MetaAspect].SetGmeAttrs(icon, x, y); } catch (System.Runtime.InteropServices.COMException) { // It's okay. This means that Reference is visible in this aspect, but copiedObj isn't } } // add / update to traceability string baseId = null; if (this.Traceability.TryGetValue(reference.ID, out baseId)) { //// if it is already in the traceability it is a temporary object. //// we need our final object in the mapping this.Traceability.Remove(reference.ID); this.Traceability.Add(copiedObj.ID, baseId); } else { this.Traceability.Add(copiedObj.ID, referred.ID); } // safe connection information for switching connections later. Dictionary <MgaFCO, MgaFCO> original2Copied = new Dictionary <MgaFCO, MgaFCO>(); original2Copied.Add(referred, copiedObj); MgaFCOs objects = null; if (createInstance) { objects = (copiedObj as MgaModel).GetDescendantFCOs(copiedObj.Project.CreateFilter()); } else { objects = (copiedObj as MgaModel).ChildFCOs; } foreach (MgaFCO copied in objects) { if (copied == copiedObj) { continue; } var original = getOriginalChildObject(referred, copied); original2Copied.Add(original, copied); if (this.Traceability.TryGetValue(original.ID, out baseId)) { // if it is already in the traceability it is a temporary object. // we need our final object in the mapping this.Traceability.Remove(original.ID); this.Traceability.Add(copied.ID, baseId); } else { this.Traceability.Add(copied.ID, original.ID); } if (!createInstance && copied.ObjType == GME.MGA.Meta.objtype_enum.OBJTYPE_MODEL) { this.AddRecursivelyTraceability(copied, original); } } // switch connections to refport children foreach (MgaConnPoint connPoint in reference.UsedByConns) { var connection = connPoint.Owner as IMgaSimpleConnection; if (connPoint.ConnRole == "src" && connection.SrcReferences.Count > 0 && connection.SrcReferences[1] == reference) { // what if this is instance var newEndPoint = original2Copied[connection.Src]; if (newEndPoint == null) { throw new Exception("null connection endpoint"); } // create an empty array for the connection references MgaFCOs emptyArray = (MgaFCOs)Activator.CreateInstance(Elaborator.MgaFCOsType); connection.SetSrc(emptyArray, newEndPoint); } if (connPoint.ConnRole == "dst" && connection.DstReferences.Count > 0 && connection.DstReferences[1] == reference) { // what if this is instance var newEndPoint = original2Copied[connection.Dst]; if (newEndPoint == null) { throw new Exception("null connection endpoint"); } // create an empty array for the connection references MgaFCOs emptyArray = (MgaFCOs)Activator.CreateInstance(Elaborator.MgaFCOsType); connection.SetDst(emptyArray, newEndPoint); } } // switch connections to original reference object itself foreach (MgaConnPoint connPoint in reference.PartOfConns) { var connection = connPoint.Owner as IMgaSimpleConnection; if (connPoint.ConnRole == "src") { // create an empty array for the connection references MgaFCOs emptyArray = (MgaFCOs)Activator.CreateInstance(Elaborator.MgaFCOsType); try { connection.SetSrc(emptyArray, copiedObj); } catch (COMException ex) { if (ex.Message.Contains("Illegal connection") && ex.Message.Contains("meta violation")) { var refID = reference.ID; while (Traceability.ContainsKey(refID)) { refID = Traceability[refID]; } Logger.WriteWarning("<a href=\"mga:{0}\">{1}</a>'s referred type ({2}) isn't a legal SRC target for {3} connections. Skipping re-creation of this connection.", refID, reference.Name, reference.Referred.MetaBase.Name, connection.MetaBase.Name); } else { throw ex; } } } else if (connPoint.ConnRole == "dst") { // create an empty array for the connection references MgaFCOs emptyArray = (MgaFCOs)Activator.CreateInstance(Elaborator.MgaFCOsType); try { connection.SetDst(emptyArray, copiedObj); } catch (COMException ex) { if (ex.Message.Contains("Illegal connection") && ex.Message.Contains("meta violation")) { var refID = reference.ID; while (Traceability.ContainsKey(refID)) { refID = Traceability[refID]; } Logger.WriteWarning("<a href=\"mga:{0}\">{1}</a>'s referred type ({2}) isn't a legal DST target for {3} connections. Skipping re-creation of this connection.", refID, reference.Name, reference.Referred.MetaBase.Name, connection.MetaBase.Name); } else { throw ex; } } } } return(copiedObj as MgaModel); }