Example #1
0
 /// <summary>
 /// constructor where we set the menuheader and menuOptions
 /// </summary>
 public BPAddIn()
     : base()
 {
     this.menuHeader = menuName;
     this.menuOptions = new string[] { menuSynchronization, menuJoining, menuStartNewProject, menuEndJoining, menuSynchronizationWindow, menuDbTest, menuLoginWindow, menuRegistrationWindow, menuUpdate };
     this.dict = new Dictionary();
 }
Example #2
0
 public RuleService()
 {
     RuleParser parser = new RuleParser();
     eventWatchers = parser.parseRules();
     this.defectReportService = new DefectReportService();
     this.defectReportDispatcherThread = new Thread(new ThreadStart(this.defectReportService.startActivityDispatcher));
     this.defectReportDispatcherThread.Start();
 }
Example #3
0
        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 handleChange(EA.Repository repository, string GUID, EA.ObjectType ot)
        {
            // check extension pointy
            if (ot == ObjectType.otDiagram)
            {
                try
                {
                    EA.Diagram changedDiagram = (EA.Diagram)model.getWrappedModel().GetDiagramByGuid(GUID);
                    foreach (EA.DiagramObject diagramObject in changedDiagram.DiagramObjects)
                    {
                        string coordinates = "";
                        coordinates += "l=" + diagramObject.left + ";";
                        coordinates += "r=" + diagramObject.right + ";";
                        coordinates += "t=" + diagramObject.top + ";";
                        coordinates += "b=" + diagramObject.bottom + ";";

                        if (currentDiagramObjectPositions[diagramObject.ElementID] != coordinates)
                        {
                            EA.Element element = model.getWrappedModel().GetElementByID(diagramObject.ElementID);

                            PropertyChange propertyChange = new PropertyChange();
                            propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                            propertyChange.itemGUID = element.ElementGUID;
                            propertyChange.elementType = itemTypes.getElementType(element.ElementGUID);
                            propertyChange.propertyType = 405;
                            propertyChange.propertyBody = coordinates;
                            propertyChange.oldPropertyBody = GUID;

                            changeService.saveChange(propertyChange);

                            currentDiagramObjectPositions[diagramObject.ElementID] = coordinates;
                        }
                    }
                }
                catch (Exception ex) { }

                try
                {
                    EA.Diagram changedDiagram = (EA.Diagram)model.getWrappedModel().GetDiagramByGuid(GUID);
                    if (changedDiagram.Type == "Use Case")
                    {
                        Dictionary<string, string> updatedExtensionPoints = new Dictionary<string, string>();

                        foreach (EA.DiagramObject diagramObjects in changedDiagram.DiagramObjects)
                        {
                            EA.Element element = (EA.Element)repository.GetElementByID(diagramObjects.ElementID);
                            if (element.Type == "UseCase")
                            {
                                if (!currentExtensionPoints.ContainsKey(element.ElementGUID))
                                {
                                    PropertyChange propertyChange = new PropertyChange();
                                    propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                                    propertyChange.itemGUID = element.ElementGUID;
                                    propertyChange.elementType = itemTypes.getElementType(element.ElementGUID);
                                    propertyChange.propertyType = 13;
                                    propertyChange.propertyBody = element.ExtensionPoints;
                                    propertyChange.oldPropertyBody = "";

                                    changeService.saveChange(propertyChange);
                                    updatedExtensionPoints.Add(element.ElementGUID, element.ExtensionPoints);
                                    currentExtensionPoints.Add(element.ElementGUID, element.ExtensionPoints);
                                }
                                else if (currentExtensionPoints[element.ElementGUID] != element.ExtensionPoints)
                                {
                                    PropertyChange propertyChange = new PropertyChange();
                                    propertyChange.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                                    propertyChange.itemGUID = element.ElementGUID;
                                    propertyChange.elementType = itemTypes.getElementType(element.ElementGUID);
                                    propertyChange.propertyType = 13;
                                    propertyChange.propertyBody = element.ExtensionPoints;
                                    propertyChange.oldPropertyBody = currentExtensionPoints[element.ElementGUID];

                                    changeService.saveChange(propertyChange);
                                    updatedExtensionPoints.Add(element.ElementGUID, element.ExtensionPoints);
                                    currentExtensionPoints[element.ElementGUID] = element.ExtensionPoints;
                                }
                            }
                        }
                    }
                }
                catch (Exception ex) { }

            }

            if (GUID != null && changed == false && currentItem != null)
            {
                try
                {
                    handleAttributeChange(GUID);
                    handleElementChange(GUID);
                }
                catch (NullReferenceException ex2) { }
                catch (Exception ex) { }
            }

            if (GUID != null && changed == false && currentDiagram != null)
            {
                try
                {
                    handleDiagramChange(GUID);
                }
                catch (NullReferenceException ex2) { }
                catch (Exception ex) { }
            }

            if (GUID != null && changed == false && currentConnector != null)
            {
                try
                {
                    handleConnectorChange(GUID);
                }
                catch (NullReferenceException ex2) { }
                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);
            }
        }
Example #7
0
        public string activate(object element, Model model)
        {
            string elStereotype = "";

            if (!(element is EA.Diagram))
            {
                elStereotype = getStringAttributeValue(element, "Stereotype");
            }

            if (elementStereotype == "-" && elStereotype != "")
            {
                return "";
            }
            else if (elementStereotype != elStereotype && elementStereotype != "*")
            {
                return "";
            }

            string[] validCall = contentValid.Split('.');

            if (contentValid.IndexOf('=') != -1)
            {
                validCall = contentValid.Split('=');
            }

            Word word = null;
            Dictionary dict = null;

            for (int i = 0; i < validCall.Length; i++)
            {
                try
                {
                    string value = "";
                    if (validCall[i] == "dict")
                    {
                        dict = new Dictionary();
                        if (validCall[i + 1].StartsWith("getWord"))
                        {
                            value = getStringAttributeValue(element, validCall[i + 1].Split('(', ')')[1]);
                            word = dict.getWord(value.Split(' '));
                        }
                        i++;
                        continue;
                    }

                    if (word != null)
                    {
                        if (validCall[i].StartsWith("isNoun"))
                        {
                            return dict.isNoun(word.word.Split(' ')) ? "" : createDescription(element, getStringAttributeValue(element, attributeType));
                        }
                    }

                    if (validCall[i] == "getName")
                    {
                        if (contentCond != null)
                        {
                            string[] condCall = contentCond.Split('&');
                            bool rslt = true;
                            for (int j = 0; j < condCall.Length; j++)
                            {
                                if (condCall[j].StartsWith("Connector"))
                                {
                                    string expr = condCall[j].Split('.')[1];
                                    if (expr.StartsWith("getSrcType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "src", ownerType);
                                    }
                                    else if (expr.StartsWith("getTargetType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "target", ownerType);
                                    }
                                }
                            }

                            if (!rslt)
                            {
                                return "";
                            }
                        }

                        if (String.IsNullOrEmpty(getStringAttributeValue(element, "Name")))
                        {
                            if (element is EA.Connector)
                            {
                                return createDescription(element, getConnectorOwnerName(element, model, "src"), getConnectorOwnerName(element, model, "target"));
                            }
                            else
                            {
                                return createDescription(element);
                            }
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i] == "getCardinalities")
                    {
                        if (contentCond != null)
                        {
                            string[] condCall = contentCond.Split('&');
                            bool rslt = true;
                            for (int j = 0; j < condCall.Length; j++)
                            {
                                if (condCall[j].StartsWith("Connector"))
                                {
                                    string expr = condCall[j].Split('.')[1];
                                    if (expr.StartsWith("getSrcType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "src", ownerType);
                                    }
                                    else if (expr.StartsWith("getTargetType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "target", ownerType);
                                    }
                                }
                            }

                            if (!rslt)
                            {
                                return "";
                            }
                        }

                        object objectClient = getAttributeValue(element, "ClientEnd");
                        string cardinalityClient = getStringAttributeValue(objectClient, "Cardinality");

                        object objectSupplier = getAttributeValue(element, "SupplierEnd");
                        string cardinalitySupplier = getStringAttributeValue(objectSupplier, "Cardinality");

                        if (String.IsNullOrEmpty(cardinalityClient) || String.IsNullOrEmpty(cardinalitySupplier))
                        {
                            return createDescription(element, getConnectorOwnerName(element, model, "src"), getConnectorOwnerName(element, model, "target"));
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i] == "getExtensionPointsCount")
                    {
                        int extensionPointsCount = getStringAttributeValue(element, attributeType).Count(c => c == ',');
                        int rightSide = 0;

                        if (!String.IsNullOrEmpty(getStringAttributeValue(element, attributeType)) && !getStringAttributeValue(element, attributeType).EndsWith(","))
                        {
                            extensionPointsCount++;
                        }

                        if (validCall[i + 1].StartsWith("Connector"))
                        {
                            string expr = validCall[i + 1].Split('.')[1];

                            if (expr.StartsWith("getStereotypeCount"))
                            {
                                string stereotype = expr.Split('(', ')')[1];

                                foreach (EA.Connector con in (EA.Collection)getAttributeValue(element, "Connectors"))
                                {
                                    if (stereotype == con.Stereotype)
                                    {
                                        rightSide++;
                                    }
                                }
                            }
                        }

                        if (contentValid.IndexOf('=') != -1)
                        {
                            if (extensionPointsCount < rightSide)
                            {
                                return createDescription(element, getStringAttributeValue(element, "Name"));
                            }
                            else
                            {
                                return "";
                            }
                        }
                    }

                    if (validCall[i] == "getTransitionGuard")
                    {
                        if (contentCond != null)
                        {
                            string[] condCall = contentCond.Split('&');
                            bool rslt = true;
                            for (int j = 0; j < condCall.Length; j++)
                            {
                                if (condCall[j].StartsWith("Connector"))
                                {
                                    string expr = condCall[j].Split('.')[1];
                                    if (expr.StartsWith("getSrcType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "src", ownerType);
                                    }
                                    else if (expr.StartsWith("getTargetType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "target", ownerType);
                                    }
                                }
                            }

                            if (!rslt)
                            {
                                return "";
                            }
                        }

                        if (String.IsNullOrEmpty(getStringAttributeValue(element, attributeType)))
                        {
                            return createDescription(element, getConnectorOwnerName(element, model, "target"));
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i].StartsWith("getSrcControlFlows"))
                    {
                        if (contentCond != null)
                        {
                            string[] condCall = contentCond.Split('&');
                            bool rslt = true;
                            for (int j = 0; j < condCall.Length; j++)
                            {
                                if (condCall[j].StartsWith("Connector"))
                                {
                                    string expr = condCall[j].Split('.')[1];
                                    if (expr.StartsWith("getSrcType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "src", ownerType);
                                    }
                                    else if (expr.StartsWith("getTargetType"))
                                    {
                                        string ownerType = expr.Split('(', ')')[1];
                                        rslt &= checkConnectorOwnerType(element, model, "target", ownerType);
                                    }
                                }

                                if (condCall[j].StartsWith("Element"))
                                {
                                    string expr = condCall[j].Split('.')[1];

                                    if (expr.StartsWith("getType"))
                                    {
                                        string elType = expr.Split('(', ')')[1];
                                        rslt &= getStringAttributeValue(element, "Type") == elType;
                                    }
                                }
                            }

                            if (!rslt)
                            {
                                return "";
                            }
                        }

                        int numControlFlows = Convert.ToInt32(validCall[i].Split('(', ')')[1]);
                        EA.Element connectorOwner = (EA.Element)getConnectorOwner(element, model, "src");
                        EA.Collection collection = (EA.Collection)getAttributeValue(connectorOwner, "Connectors");

                        int numOutgoing = 0;

                        foreach (EA.Connector con in collection)
                        {
                            if (con.ClientID == connectorOwner.ElementID)
                            {
                                numOutgoing++;
                            }
                        }

                        if (numControlFlows < numOutgoing)
                        {
                            return createDescription(element, getStringAttributeValue(getConnectorOwner(element, model, "src"), "Name"));
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i] == "checkInitialNode")
                    {
                        bool rslt = false;

                        EA.Diagram diagram = model.getWrappedModel().GetCurrentDiagram();

                        foreach (EA.DiagramObject diagramObject in diagram.DiagramObjects)
                        {
                            EA.Element el = model.getWrappedModel().GetElementByID(diagramObject.ElementID);
                            if (el.Type == "StateNode" && el.Subtype == 100)
                            {
                                rslt = true;
                            }
                        }

                        if (!rslt)
                        {
                            return createDescription(element, getStringAttributeValue(diagram, "Name"));
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i] == "checkFinalNode")
                    {
                        bool rslt = false;

                        EA.Diagram diagram = model.getWrappedModel().GetCurrentDiagram();

                        foreach (EA.DiagramObject diagramObject in diagram.DiagramObjects)
                        {
                            EA.Element el = model.getWrappedModel().GetElementByID(diagramObject.ElementID);
                            if (el.Type == "StateNode" && el.Subtype == 101)
                            {
                                rslt = true;
                            }
                        }

                        if (!rslt)
                        {
                            return createDescription(element, getStringAttributeValue(diagram, "Name"));
                        }
                        else
                        {
                            return "";
                        }
                    }

                    if (validCall[i] == "checkIncludeInScenario")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");

                        if (contentCond.StartsWith("Scenario"))
                        {
                            string expr = contentCond.Split('.')[1];

                            if (expr == "hasAny")
                            {
                                if (scenarios.Count == 0)
                                {
                                    return "";
                                }
                            }
                        }

                        if (scenarios.Count > 0)
                        {
                            EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                            XElement xElement = XElement.Parse(scenario.XMLContent);

                            try
                            {
                                EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                                foreach (EA.Connector con in connectors)
                                {
                                    if (con.Stereotype == "include" && con.ClientID == Convert.ToInt32(getAttributeValue(element, "ElementID")))
                                    {
                                        string targetName = getConnectorOwnerName(con, model, "target");

                                        IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                                      where ((string)el.Attribute("name")).ToLowerInvariant().Contains(targetName.ToLowerInvariant())
                                                                      select el;

                                        try
                                        {
                                            if (!steps.Any())
                                            {
                                                return createDescription(element, getStringAttributeValue(element, "Name"), targetName);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            return createDescription(element, getStringAttributeValue(element, "Name"), targetName);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) { };
                        }
                    }

                    if (validCall[i] == "checkExtendInScenario")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");

                        if (contentCond.StartsWith("Scenario"))
                        {
                            string expr = contentCond.Split('.')[1];

                            if (expr == "hasAny")
                            {
                                if (scenarios.Count == 0)
                                {
                                    return "";
                                }
                            }
                        }

                        if (scenarios.Count > 0)
                        {
                            EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                            XElement xElement = XElement.Parse(scenario.XMLContent);

                            try
                            {
                                EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                                foreach (EA.Connector con in connectors)
                                {
                                    if (con.Stereotype == "extend" && con.SupplierID == Convert.ToInt32(getAttributeValue(element, "ElementID")))
                                    {
                                        string targetName = getConnectorOwnerName(con, model, "src");

                                        IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                                      where ((string)el.Attribute("name")).ToLowerInvariant().Contains(targetName.ToLowerInvariant())
                                                                      select el;

                                        try
                                        {
                                            if (!steps.Any())
                                            {
                                                return createDescription(element, getStringAttributeValue(element, "Name"), targetName);
                                            }
                                        }
                                        catch (Exception ex)
                                        {
                                            return createDescription(element, getStringAttributeValue(element, "Name"), targetName);
                                        }
                                    }
                                }
                            }
                            catch (Exception ex) { };
                        }
                    }

                    if (validCall[i] == "checkIncludeDependency")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");

                        if (contentCond.StartsWith("Scenario"))
                        {
                            string expr = contentCond.Split('.')[1];

                            if (expr == "hasAny")
                            {
                                if (scenarios.Count == 0)
                                {
                                    return "";
                                }
                            }
                        }

                        if (scenarios.Count > 0)
                        {
                            EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                            XElement xElement = XElement.Parse(scenario.XMLContent);

                            IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                          where ((string)el.Attribute("name")).ToLowerInvariant().Contains("<include>")
                                                          select el;

                            try
                            {
                                EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                                bool rslt = false;

                                foreach (XElement e in steps)
                                {
                                    string name = (string)e.Attribute("name");

                                    if (findElementInCurDiagramtByName(model, name.Substring(name.IndexOf("UC"))) == null)
                                    {
                                        continue;
                                    }

                                    foreach (EA.Connector con in connectors)
                                    {
                                        if (con.Stereotype == "include" && con.ClientID == Convert.ToInt32(getAttributeValue(element, "ElementID")))
                                        {
                                            string targetName = getConnectorOwnerName(con, model, "target");

                                            rslt |= targetName == name.Substring(name.IndexOf("UC"));
                                        }
                                    }

                                    if (!rslt)
                                    {
                                        return createDescription(element, getStringAttributeValue(element, "Name"), name.Substring(name.IndexOf("UC")));
                                    }
                                }
                            }
                            catch (Exception ex) { };
                        }
                    }
                }
                catch (Exception ex) { }
            }

            return "";
        }
Example #8
0
        /// <summary>
        /// Correct detected defect based on value in contentCorrect attribute
        /// </summary>
        /// <param name="element">Defected element</param>
        /// <param name="model">Wrapper EA.Repository object</param>
        /// <returns>true if correction was successful, else false</returns>
        public bool correct(object element, Model model)
        {
            string[] correctCall = contentCorrect.Split('@');

            for (int i = 0; i < correctCall.Length; i++)
            {
                try
                {
                    if (correctCall[i].StartsWith("setName"))
                    {
                        string[] nameExpression = correctCall[i].Split('(', ')')[1].Split('.');
                        for (int j = 0; j < nameExpression.Length; j++)
                        {
                            if (nameExpression[j] == "dict")
                            {
                                Dictionary dict = new Dictionary();
                                if (nameExpression[j + 1].StartsWith("getBaseNoun"))
                                {
                                    string attributeName = correctCall[i].Split('(', ')')[2];
                                    string value = getStringAttributeValue(element, attributeName);
                                    string word = dict.getBaseNoun(value);

                                    if (word == "")
                                    {
                                        return false;
                                    }

                                    setStringAttributeValue(element, attributeName, word);
                                    try
                                    {
                                        model.adviseChange((new ElementWrapper(model, (EA.Element)element)));
                                        RuleService.active.Remove(getStringAttributeValue(element, "GUID"));
                                    }
                                    catch (Exception ex) { }

                                    return true;
                                }
                            }
                            else
                            {
                                setStringAttributeValue(element, attributeType, nameExpression[j]);
                                try
                                {
                                    if (element is EA.Connector)
                                    {
                                        model.adviseChange(new ConnectorWrapper(model, (EA.Connector)element));
                                    }
                                    else
                                    {
                                        model.adviseChange(new ElementWrapper(model, (EA.Element)element));
                                    }
                                }
                                catch (Exception ex) { }

                                return true;
                            }
                        }
                    }

                    if (correctCall[i].StartsWith("setCardinalities"))
                    {
                        string nameExpression = correctCall[i].Split('(', ')')[1];

                        object objectClient = getAttributeValue(element, "ClientEnd");
                        string cardinalityClient = getStringAttributeValue(objectClient, "Cardinality");

                        object objectSupplier = getAttributeValue(element, "SupplierEnd");
                        string cardinalitySupplier = getStringAttributeValue(objectSupplier, "Cardinality");

                        if (String.IsNullOrEmpty(cardinalityClient))
                        {
                            setStringAttributeValue(objectClient, "Cardinality", nameExpression);
                        }

                        if (String.IsNullOrEmpty(cardinalitySupplier))
                        {
                            setStringAttributeValue(objectSupplier, "Cardinality", nameExpression);
                        }

                        try
                        {
                            model.adviseChange(new ConnectorWrapper(model, (EA.Connector)element));
                        }
                        catch (Exception ex) { }
                    }

                    if (correctCall[i].StartsWith("setExtensionPointsCount"))
                    {
                        string nameExpression = correctCall[i].Split('(', ')')[1];
                        if (nameExpression.StartsWith("Connector"))
                        {
                            string expr = nameExpression.Split('.')[1];
                            if (expr == "getStereotypeCount")
                            {
                                string stereotype = correctCall[i].Split('(', ')')[2];
                                int stereotypeCount = 0;

                                foreach (EA.Connector con in (EA.Collection)getAttributeValue(element, "Connectors"))
                                {
                                    if (stereotype == con.Stereotype)
                                    {
                                        stereotypeCount++;
                                    }
                                }

                                string extensionPoints = getStringAttributeValue(element, attributeType);
                                int num = Math.Abs(extensionPoints.Count(c => c == ',') - stereotypeCount);
                                if (num > 1) num--;

                                for (int k = 0; k < num; k++)
                                {
                                    extensionPoints += "," + k + 1 + " extension point,";
                                }

                                setStringAttributeValue(element, attributeType, extensionPoints);

                                try
                                {
                                    model.adviseChange((new ElementWrapper(model, (EA.Element)element)));
                                    RuleService.active.Remove(getStringAttributeValue(element, "GUID"));
                                }
                                catch (Exception ex) { }

                                return true;
                            }
                        }
                    }

                    if (correctCall[i].StartsWith("setTransitionGuard"))
                    {
                        string nameExpression = correctCall[i].Split('(', ')')[1];

                        setStringAttributeValue(element, attributeType, nameExpression);

                        try
                        {
                            model.adviseChange(new ConnectorWrapper(model, (EA.Connector)element));
                        }
                        catch (Exception ex) { }
                    }

                    if (correctCall[i] == "createDecisionNode")
                    {
                        object owner = getConnectorOwner(element, model, "src");
                        object target = getConnectorOwner(element, model, "target");

                        EA.Collection collection = (EA.Collection)getAttributeValue(owner, "Connectors");
                        EA.Collection elements = model.getWrappedModel().GetPackageByID(Convert.ToInt32(getStringAttributeValue(owner, "PackageID"))).Elements;
                        EA.Collection connectors = model.getWrappedModel().GetPackageByID(Convert.ToInt32(getStringAttributeValue(owner, "PackageID"))).Connectors;

                        EA.Element decisionNode = (EA.Element)elements.AddNew("", "Decision");
                        decisionNode.Update();
                        elements.Refresh();

                        EA.Diagram diagram = model.getWrappedModel().GetCurrentDiagram();
                        EA.DiagramObject ownerDO = new Diagram(model, diagram).getdiagramObjectForElement(new ElementWrapper(model, (EA.Element)owner));

                        int l = ownerDO.left;
                        int b = ownerDO.bottom;
                        string coordinates = "l=" + (l + 20) + "r=" + (l + 60) + "t=" + (b - 50) + "b=" + (b - 90) + ";";

                        EA.DiagramObject displayElement = (EA.DiagramObject)diagram.DiagramObjects.AddNew(coordinates, "");

                        displayElement.ElementID = decisionNode.ElementID;
                        displayElement.Sequence = 1;
                        displayElement.Update();
                        diagram.DiagramObjects.Refresh();
                        diagram.Update();

                        EA.Connector connector = (EA.Connector)connectors.AddNew("", "ControlFlow");
                        connectors.Refresh();

                        connector.ClientID = Convert.ToInt32(getStringAttributeValue(owner, "ElementID"));
                        connector.SupplierID = decisionNode.ElementID;
                        connector.Update();

                        foreach (EA.Connector con in (EA.Collection)getAttributeValue(owner, "Connectors"))
                        {
                            if (con.ClientID == ((EA.Element)owner).ElementID)
                            {
                                con.ClientID = decisionNode.ElementID;
                                con.TransitionGuard = "guard";
                                con.Update();
                            }
                        }

                        model.refreshDiagram(new Diagram(model, diagram));

                        return true;
                    }

                    if (correctCall[i] == "createInitialNode")
                    {
                        EA.Diagram diagram = model.getWrappedModel().GetCurrentDiagram();
                        EA.Collection elements = model.getWrappedModel().GetPackageByID(Convert.ToInt32(getStringAttributeValue(diagram, "PackageID"))).Elements;

                        EA.Element initialNode = (EA.Element)elements.AddNew("", "StateNode");
                        initialNode.Subtype = 100;
                        initialNode.Name = "pociatocny uzol";
                        initialNode.Update();
                        elements.Refresh();

                        EA.DiagramObject displayElement = (EA.DiagramObject)diagram.DiagramObjects.AddNew("l=0;r=0;t=0;b=0;", "");
                        displayElement.ElementID = initialNode.ElementID;
                        displayElement.Sequence = 1;
                        displayElement.Update();
                        diagram.DiagramObjects.Refresh();
                        diagram.Update();

                        model.refreshDiagram(new Diagram(model, diagram));

                        return true;
                    }

                    if (correctCall[i] == "createFinalNode")
                    {
                        EA.Diagram diagram = model.getWrappedModel().GetCurrentDiagram();
                        EA.Collection elements = model.getWrappedModel().GetPackageByID(Convert.ToInt32(getStringAttributeValue(diagram, "PackageID"))).Elements;

                        EA.Element initialNode = (EA.Element)elements.AddNew("", "StateNode");
                        initialNode.Subtype = 101;
                        initialNode.Name = "koncovy uzol";
                        initialNode.Update();
                        elements.Refresh();

                        EA.DiagramObject displayElement = (EA.DiagramObject)diagram.DiagramObjects.AddNew("l=0;r=0;t=0;b=0;", "");
                        displayElement.ElementID = initialNode.ElementID;
                        displayElement.Sequence = 1;
                        displayElement.Update();
                        diagram.DiagramObjects.Refresh();
                        diagram.Update();

                        model.refreshDiagram(new Diagram(model, diagram));

                        return true;
                    }

                    if (correctCall[i] == "addIncludeToScenario")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");
                        EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                        XElement xElement = XElement.Parse(scenario.XMLContent);

                        try
                        {
                            EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                            IEnumerable<XElement> max = from el in xElement.Elements("step") select el;
                            int maxLevel = max.Max(x => Convert.ToInt32((string)x.Attribute("level")));

                            foreach (EA.Connector con in connectors)
                            {
                                if (con.Stereotype == "include")
                                {
                                    string targetName = getConnectorOwnerName(con, model, "target");

                                    IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                                  where ((string)el.Attribute("name")).Contains(targetName)
                                                                  select el;
                                    try
                                    {
                                        steps.First();
                                    }
                                    catch (Exception ex)
                                    {
                                        xElement.Add(new XElement("step", new XAttribute("name", "<include> " + targetName), new XAttribute("guid", "{" + Guid.NewGuid().ToString().ToUpper() + "}"),
                                            new XAttribute("level", maxLevel + 1), new XAttribute("uses", ""), new XAttribute("useslist", ""), new XAttribute("result", ""), new XAttribute("state", ""),
                                            new XAttribute("trigger", "0"), new XAttribute("link", "")));

                                        scenario.XMLContent = xElement.ToString();
                                        scenario.Update();

                                        model.adviseChange(new ElementWrapper(model, (EA.Element)element));

                                        return true;
                                    }
                                }
                            }
                        }
                        catch (Exception ex) { }
                    }

                    if (correctCall[i] == "addExtendToScenario")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");
                        EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                        XElement xElement = XElement.Parse(scenario.XMLContent);

                        try
                        {
                            EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                            IEnumerable<XElement> max = from el in xElement.Elements("step") select el;
                            int maxLevel = max.Max(x => Convert.ToInt32((string)x.Attribute("level")));

                            foreach (EA.Connector con in connectors)
                            {
                                if (con.Stereotype == "extend")
                                {
                                    string sourceName = getConnectorOwnerName(con, model, "src");

                                    IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                                  where ((string)el.Attribute("name")).Contains(sourceName)
                                                                  select el;
                                    try
                                    {
                                        steps.First();
                                    }
                                    catch (Exception ex)
                                    {
                                        xElement.Add(new XElement("step", new XAttribute("name", "<extend> " + sourceName), new XAttribute("guid", "{" + Guid.NewGuid().ToString().ToUpper() + "}"),
                                            new XAttribute("level", maxLevel + 1), new XAttribute("uses", ""), new XAttribute("useslist", ""), new XAttribute("result", ""), new XAttribute("state", ""),
                                            new XAttribute("trigger", "0"), new XAttribute("link", "")));

                                        scenario.XMLContent = xElement.ToString();
                                        scenario.Update();

                                        model.adviseChange(new ElementWrapper(model, (EA.Element)element));

                                        return true;
                                    }
                                }
                            }
                        }
                        catch (Exception ex) { }
                    }

                    if (correctCall[i] == "addIncludeDependency")
                    {
                        EA.Collection scenarios = (EA.Collection)getAttributeValue(element, "Scenarios");
                        EA.Scenario scenario = (EA.Scenario)scenarios.GetAt(0);
                        XElement xElement = XElement.Parse(scenario.XMLContent);

                        IEnumerable<XElement> steps = from el in xElement.Elements("step")
                                                      where ((string)el.Attribute("name")).ToLowerInvariant().Contains("<include>")
                                                      select el;

                        try
                        {
                            EA.Collection connectors = (EA.Collection)getAttributeValue(element, "Connectors");
                            bool rslt = false;

                            foreach (XElement e in steps)
                            {
                                string name = (string)e.Attribute("name");

                                if (findElementInCurDiagramtByName(model, name.Substring(name.IndexOf("UC"))) == null)
                                {
                                    continue;
                                }

                                foreach (EA.Connector con in connectors)
                                {
                                    if (con.Stereotype == "include" && con.ClientID == Convert.ToInt32(getAttributeValue(element, "ElementID")))
                                    {
                                        string targetName = getConnectorOwnerName(con, model, "target");

                                        rslt |= targetName == name.Substring(name.IndexOf("UC"));
                                    }
                                }

                                if (!rslt)
                                {
                                    EA.Element el = findElementInCurDiagramtByName(model, name.Substring(name.IndexOf("UC")));
                                    EA.Collection connectorsPcg = model.getWrappedModel().GetPackageByID(Convert.ToInt32(getStringAttributeValue(element, "PackageID"))).Connectors;

                                    EA.Connector connector = (EA.Connector)connectors.AddNew("", "Dependency");
                                    connector.Stereotype = "include";
                                    connector.ClientID = Convert.ToInt32(getStringAttributeValue(element, "ElementID"));
                                    connector.SupplierID = el.ElementID;
                                    connector.Update();
                                    connectors.Refresh();

                                    model.refreshDiagram(new Diagram(model, model.getWrappedModel().GetCurrentDiagram()));
                                    return true;
                                }
                            }
                        }
                        catch (Exception ex) { };
                    }
                }
                catch (Exception ex) { }
            }

            return false;
        }