public Dictionary<string, List<Rule>> parseRules() { Dictionary<string, List<Rule>> eventWatchers = new Dictionary<string, List<Rule>>(); string addInPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/sthAddin/rules"; string[] files = Directory.GetFiles(addInPath, "*.rule"); foreach (string file in files) { try { string content = File.ReadAllText(file); JObject obj = (JObject)JsonConvert.DeserializeObject(content); Rule rule = new Rule(); rule.name = obj["name"].ToString(); rule.elementType = obj["element"]["type"].ToString(); rule.elementStereotype = obj["element"]["stereotype"].ToString(); rule.attributeType = obj["attribute"]["type"].ToString(); rule.attributeStereotype = obj["element"]["stereotype"].ToString(); rule.contentDefectMsg = obj["content"]["defectMsg"].ToString(); rule.contentValid = obj["content"]["valid"].ToString(); rule.contentCorrect = obj["content"]["correct"].ToString(); if (obj["content"]["cond"] != null) { rule.contentCond = obj["content"]["cond"].ToString(); } if (!eventWatchers.ContainsKey(rule.elementType)) { eventWatchers.Add(rule.elementType, new List<Rule>()); } eventWatchers[rule.elementType].Add(rule); } catch (Exception ex) { } } return eventWatchers; }
public void handleContextItemChange(EA.Repository repository, string GUID, ObjectType ot) { try { switch (ot) { case ObjectType.otElement: this.currentItem = repository.GetElementByGuid(GUID); if (currentItem.Type == "Class") { currentAttributes = new Dictionary<string, EA.Attribute>(); foreach (EA.Attribute attr in currentItem.Attributes) { currentAttributes.Add(attr.AttributeGUID, attr); } } if (currentItem.Type == "UseCase") { // CONSTRAINTS currentConstraintsList = new List<ConstraintWrapper>(); foreach (EA.Constraint constraint in currentItem.Constraints) { currentConstraintsList.Add(new ConstraintWrapper(constraint)); } // SCENARIOS currentScenarioList = new List<ScenarioWrapper>(); currentScenarioStepList = new Dictionary<string, List<EA.ScenarioStep>>(); foreach (EA.Scenario scenario in currentItem.Scenarios) { currentScenarioList.Add(new ScenarioWrapper(scenario)); if (!currentScenarioStepList.ContainsKey(scenario.ScenarioGUID)) { currentScenarioStepList.Add(scenario.ScenarioGUID, new List<ScenarioStep>()); } foreach (ScenarioStep step in scenario.Steps) { currentScenarioStepList[scenario.ScenarioGUID].Add(step); } } } this.currentConnector = null; this.currentDiagram = null; changed = false; currentAuthor = repository.GetElementByGuid(GUID).Author; break; case ObjectType.otPackage: this.currentItem = repository.GetElementByGuid(GUID); this.currentConnector = null; this.currentDiagram = null; changed = false; currentAuthor = repository.GetElementByGuid(GUID).Author; break; case ObjectType.otConnector: this.currentConnector = repository.GetConnectorByGuid(GUID); this.currentItem = null; this.currentDiagram = null; changed = false; break; case ObjectType.otDiagram: this.currentDiagram = (EA.Diagram)repository.GetDiagramByGuid(GUID); this.currentConnector = null; this.currentItem = null; changed = false; currentAuthor = ((EA.Diagram)repository.GetDiagramByGuid(GUID)).Author; currentParent = currentDiagram.ParentID.ToString(); currentExtensionPoints = new Dictionary<string, string>(); currentDiagramObjectPositions = new Dictionary<int, string>(); foreach (EA.DiagramObject diagramObject in currentDiagram.DiagramObjects) { try { EA.Collection col = repository.GetElementSet("" + diagramObject.ElementID, 1); EA.Element element = (EA.Element)col.GetAt(0); if (element.Type == "UseCase") { currentExtensionPoints.Add(element.ElementGUID, element.ExtensionPoints); } } catch (Exception ex) { } string coordinates = ""; coordinates += "l=" + diagramObject.left + ";"; coordinates += "r=" + diagramObject.right + ";"; coordinates += "t=" + diagramObject.top + ";"; coordinates += "b=" + diagramObject.bottom + ";"; currentDiagramObjectPositions.Add(diagramObject.ElementID, coordinates); } break; default: return; } } catch (NullReferenceException nEx) { } catch (Exception ex) { } }
public void handleUseCaseChanges(string GUID, EA.Element changedElement) { if (changedElement.Type != "UseCase") { return; } // CONSTRAINTS EA.Collection changedConstraints = changedElement.Constraints; List<ConstraintWrapper> changedConstraintsList = new List<ConstraintWrapper>(); foreach (EA.Constraint constraint in changedConstraints) { changedConstraintsList.Add(new ConstraintWrapper(constraint)); } if (!((changedConstraintsList.Count == currentConstraintsList.Count) && !changedConstraintsList.Except(currentConstraintsList).Any())) { List<ConstraintWrapper> createdConstraints = changedConstraintsList.Except(currentConstraintsList).ToList(); List<ConstraintWrapper> removedConstraints = currentConstraintsList.Except(changedConstraintsList).ToList(); foreach (ConstraintWrapper constraintWrapper in removedConstraints) { PropertyChange propertyChange = new PropertyChange(); propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; propertyChange.itemGUID = GUID; propertyChange.elementType = itemTypes.getElementType(GUID); propertyChange.propertyType = 11; propertyChange.propertyBody = constraintWrapper.constraint.Name; propertyChange.oldPropertyBody = constraintWrapper.constraint.Type; propertyChange.elementDeleted = 1; changeService.saveChange(propertyChange); } foreach (ConstraintWrapper constraintWrapper in createdConstraints) { PropertyChange propertyChange = new PropertyChange(); propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; propertyChange.itemGUID = GUID; propertyChange.elementType = itemTypes.getElementType(GUID); propertyChange.propertyType = 10; propertyChange.propertyBody = constraintWrapper.constraint.Name + ",notes:=" + constraintWrapper.constraint.Notes; propertyChange.oldPropertyBody = constraintWrapper.constraint.Type; changeService.saveChange(propertyChange); } } // SCENARIO EA.Collection changedScenarios = changedElement.Scenarios; List<ScenarioWrapper> changedScenariosList = new List<ScenarioWrapper>(); foreach (EA.Scenario scenario in changedScenarios) { changedScenariosList.Add(new ScenarioWrapper(scenario)); } Dictionary<string, ScenarioWrapper> changedDict = new Dictionary<string, ScenarioWrapper>(); foreach (ScenarioWrapper wrapper in changedScenariosList) { if (!changedDict.ContainsKey(wrapper.getGUID())) { changedDict.Add(wrapper.getGUID(), wrapper); } } Dictionary<string, ScenarioWrapper> currentDict = new Dictionary<string, ScenarioWrapper>(); foreach (ScenarioWrapper wrapper in currentScenarioList) { if (!currentDict.ContainsKey(wrapper.getGUID())) { currentDict.Add(wrapper.getGUID(), wrapper); } } if (!((changedScenariosList.Count == currentScenarioList.Count) && !changedScenariosList.Except(currentScenarioList).Any())) { // scenario delete foreach (KeyValuePair<string, ScenarioWrapper> scenario in currentDict) { if (!changedDict.ContainsKey(scenario.Key)) { EA.Scenario eaScenario = scenario.Value.scenario; StepChange scenarioChange = new StepChange(); scenarioChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; scenarioChange.itemGUID = GUID; scenarioChange.elementType = itemTypes.getElementType(GUID); scenarioChange.status = 0; scenarioChange.scenarioGUID = eaScenario.ScenarioGUID; changeService.saveChange(scenarioChange); } } // scenario add foreach (KeyValuePair<string, ScenarioWrapper> scenario in changedDict) { if (!currentDict.ContainsKey(scenario.Key)) { // pridaj scenar EA.Scenario eaScenario = scenario.Value.scenario; StepChange scenarioChange = new StepChange(); scenarioChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; scenarioChange.itemGUID = GUID; scenarioChange.elementType = itemTypes.getElementType(GUID); scenarioChange.name = eaScenario.Name; scenarioChange.stepType = eaScenario.Type; scenarioChange.status = 1; scenarioChange.scenarioGUID = eaScenario.ScenarioGUID; scenarioChange.state = eaScenario.XMLContent; changeService.saveChange(scenarioChange); } else { try { // zisti zmeny v scenari EA.Scenario eaChangedScenario = scenario.Value.scenario; EA.Scenario eaCurrentScenario = currentDict[scenario.Key].scenario; bool wasChanged = false; StepChange changedScenario = new StepChange(); changedScenario.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; changedScenario.itemGUID = GUID; changedScenario.elementType = itemTypes.getElementType(GUID); changedScenario.status = 2; changedScenario.scenarioGUID = eaChangedScenario.ScenarioGUID; changedScenario.name = eaChangedScenario.Name; changedScenario.stepType = eaChangedScenario.Type; changedScenario.state = eaChangedScenario.XMLContent; if (eaChangedScenario.Name != eaCurrentScenario.Name) { wasChanged = true; changedScenario.name = eaChangedScenario.Name; } if (eaChangedScenario.Type != eaCurrentScenario.Type) { wasChanged = true; changedScenario.stepType = eaChangedScenario.Type; } if (eaChangedScenario.XMLContent != eaCurrentScenario.XMLContent) { wasChanged = true; changedScenario.state = eaChangedScenario.XMLContent; } if (wasChanged) { changeService.saveChange(changedScenario); } } catch (Exception ex) { } } } } // EXTENSION POINTS if (!currentItem.ExtensionPoints.Equals(changedElement.ExtensionPoints)) { PropertyChange propertyChange = new PropertyChange(); propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID; propertyChange.itemGUID = GUID; propertyChange.elementType = itemTypes.getElementType(GUID); propertyChange.propertyType = 13; propertyChange.propertyBody = changedElement.ExtensionPoints; propertyChange.oldPropertyBody = currentItem.ExtensionPoints; changeService.saveChange(propertyChange); } }