public override void doRuleQuickFix(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository, int i, string errorMessage) { if (i == 0) { List <SQLConnector> toDelte = new List <SQLConnector>(); List <SQLElement> baseClasses = EAUtil.getBaseClasses(eaElement); if (baseClasses.Count > 1) { foreach (SQLConnector con in eaElement.Connectors) { if (con.Type != Main.EAGeneralizationConType) { toDelte.Add(con); } } } else { foreach (SQLConnector con in eaElement.Connectors) { if (con.Type == Main.EAAssociationType) { bool valid = true; SQLConnectorEnd rightEnd = null; SQLConnectorEnd wrongEnd = null; if (con.ClientID == eaElement.ElementID) { wrongEnd = con.ClientEnd; rightEnd = con.SupplierEnd; } else if (con.SupplierID == eaElement.ElementID) { wrongEnd = con.SupplierEnd; rightEnd = con.ClientEnd; } valid &= wrongEnd.Role == ""; valid &= !wrongEnd.IsNavigable; valid &= (rightEnd.Role == "source" || rightEnd.Role == "target"); valid &= rightEnd.IsNavigable; valid &= rightEnd.Cardinality == "1"; if (!valid) { toDelte.Add(con); } } } } foreach (EA.Connector toDeleteCon in toDelte) { EAUtil.deleteConnector(toDeleteCon, repository.GetOriginalRepository()); } } }
private void buttonOk_Click(object sender, EventArgs e) { List <String> constraintEntries = new List <string>(); foreach (CSPInstanceEntry entry in constraintInstance.createdEntries) { constraintEntries.Add(entry.ToString()); } //save existing connectors List <SQLConnector> existingConnectors = new List <SQLConnector>(); foreach (SQLConnector actCon in constraintElement.Connectors) { existingConnectors.Add(actCon); } Dictionary <SQLElement, EA.DiagramObject> elementsToDiagramObjects = new Dictionary <SQLElement, EA.DiagramObject>(); List <SQLConnector> validConnectors = new List <SQLConnector>(); EA.Diagram currentDiagram = repository.GetCurrentDiagram(); if (currentDiagram != null) { repository.SaveDiagram(currentDiagram.DiagramID); foreach (EA.DiagramObject diagObject in currentDiagram.DiagramObjects) { SQLElement currentElement = repository.GetElementByID(diagObject.ElementID); elementsToDiagramObjects.Add(currentElement, diagObject); } //check for all constrant entries foreach (String consString in constraintEntries) { MatchCollection matches = Regex.Matches(consString, @"[a-z0-9_]+\.[a-z0-9_]+", RegexOptions.IgnoreCase); foreach (Match match in matches) { Boolean connectionAlreadyExisting = false; String[] values = match.Value.Split('.'); String objectName = values[0]; String attributeName = values[1]; //if connection already existing connectionAlreadyExisting = checkForConnectionExistence(existingConnectors, validConnectors, objectName, attributeName); //otherwise create new connection to object for current constraint entry if (!connectionAlreadyExisting) { EA.Connector newConnection = createNewConnection(elementsToDiagramObjects, currentDiagram, objectName, attributeName); if (newConnection != null) { validConnectors.Add(repository.GetConnectorByID(newConnection.ConnectorID)); } } } } //find all invalid connectors List <SQLConnector> consToDelete = new List <SQLConnector>(); constraintElement.Connectors.Refresh(); foreach (SQLConnector con in constraintElement.Connectors) { Boolean conValid = false; foreach (SQLConnector validCon in validConnectors) { if (con.ConnectorID == validCon.ConnectorID) { conValid = true; } } if (!conValid) { consToDelete.Add(con); } } //delete all invalid connectors foreach (SQLConnector toDelete in consToDelete) { EAUtil.deleteConnector(toDelete.getRealConnector(), repository.GetOriginalRepository()); } repository.ReloadDiagram(currentDiagram.DiagramID); } constraintInstance.saveTreeToEATaggedValue(true); Close(); }