Пример #1
0
        public void addElementToDiagram(MDDiagramObject mdDiagramObject, TSF_EA.Diagram eaDiagram)
        {
            //get the EA element represented by this MDDiagramObject
            string getEAElementSQL = @"select o.Object_ID from (t_object o
						inner join t_objectproperties tv on (tv.Object_ID = o.Object_ID
															and tv.Property = 'md_guid'))
						where tv.Value = '"                         + mdDiagramObject.mdID + "'";
            var    eaElement       = this.model.getElementWrappersByQuery(getEAElementSQL).FirstOrDefault();

            if (eaElement != null)
            {
                //first check if the elemnt is already on the diagram
                if (!eaDiagram.contains(eaElement))
                {
                    //for each of the elements on the diagram create the diagramobject with the appropriate link to the elemment and geometry.
                    var newDiagramObject = eaDiagram.addToDiagram(eaElement, mdDiagramObject.x, mdDiagramObject.y, mdDiagramObject.bottom, mdDiagramObject.right);
                    //if the diagramObject is an ActivityPartition then we need to set its orientation to vertical
                    if (mdDiagramObject.umlType.StartsWith("Swimlane"))
                    {
                        newDiagramObject.setOrientation(true);
                        newDiagramObject.save();
                    }
                }
                if (mdDiagramObject.umlType == "CombinedFragment" &&
                    mdDiagramObject.ownedSplits.Any())
                {
                    //set the partitions
                    setPartitionSizes(eaElement, mdDiagramObject);
                }
            }
        }
Пример #2
0
        //correct the lines
        void correctLines(TSF_EA.Diagram eaDiagram)
        {
            //first do the line styles
            foreach (var diagramLink in eaDiagram.diagramLinkWrappers)
            {
                TSF_EA.LinkStyle linkStyle = getDefaultStyle(diagramLink);
                diagramLink.setStyle(linkStyle);
                diagramLink.save();
            }
            //then remove all the weights
            string removeWeightsSQL = @"update t_connector set PDATA3 = null
									where Connector_ID in (
									select c.Connector_ID from (t_connector c
									inner join t_object o on o.Object_ID = c.Start_Object_ID)
									where c.PDATA3 = '1'
									and o.Package_ID in ("                                     + packageTreeIDString + "))";

            this.model.executeSQL(removeWeightsSQL);
        }
        public bool ValidateChecks(ucEAValidator uc, List <Check> selectedchecks, TSF_EA.Element scopeElement, TSF_EA.Diagram EA_diagram)
        {
            // Clear the log
            this.clearEAOutput();

            // Check if the Enterprise Architect repository type is allowed
            if (!(this.settings.AllowedRepositoryTypes.Contains(this.model.repositoryType)))
            {
                MessageBox.Show($"Connectiontype of EA project not allowed: {this.model.repositoryType.ToString()}"
                                + $"{Environment.NewLine}Please connect to an EA project of an allowed repository type");
                this.addLineToEAOutput("Connectiontype of EA project not allowed: ", this.model.repositoryType.ToString());
                return(false);
            }
            this.addLineToEAOutput("Connected to: ", this.model.repositoryType.ToString());

            // Check if any checks are selected
            int numberOfChecks = selectedchecks.Count();

            uc.InitProgressbar(numberOfChecks);
            // Check if the Enterprise Architect connection is sql
            this.addLineToEAOutput("Number of checks to validate: ", numberOfChecks.ToString());
            if (numberOfChecks > 0)
            {
                // Clear list of validations
                this.validations.Clear();

                // Perform the selected checks and return the validation-results
                this.addLineToEAOutput("START of Validations...", "");

                //get the ID's of the scope package tree
                var scopePackage = scopeElement as TSF_EA.Package;
                if (scopePackage != null)
                {
                    this.scopePackageIDs = scopePackage.packageTreeIDString;
                }
                else
                {
                    //make sure it won't hurt if used in a query anyway
                    this.scopePackageIDs = "0";
                }
                //reset status for all checks
                this.checks.ToList().ForEach(x => x.resetStatus());
                // Validate all selected checks
                foreach (var check in selectedchecks)
                {
                    this.addLineToEAOutput("Validating check: ", check.CheckDescription);
                    this.validations.AddRange(check.Validate(scopeElement, EA_diagram, this.settings.excludeArchivedPackages, this.scopePackageIDs));
                    uc.refreshCheck(check);
                    uc.IncrementProgressbar();
                }

                this.addLineToEAOutput("END of Validations.", "");
                this.addLineToEAOutput("Show list with validation results.", "");
            }

            // If one (or more) check gave an ERROR, then notify the user about it
            return(selectedchecks.Any(x => x.Status == CheckStatus.Error));
        }
Пример #4
0
        public bool ValidateChecks(ucEAValidator uc, List <Check> selectedchecks, TSF_EA.Element EA_element, TSF_EA.Diagram EA_diagram)
        {
            // Clear the log
            clearEAOutput();

            // Check if the Enterprise Architect connection is sql
            var repositoryType = this._model.repositoryType.ToString();

            if (!(this.settings.AllowedRepositoryTypes.Contains(repositoryType)))
            {
                MessageBox.Show("Connectiontype of EA project not allowed: " + repositoryType + Environment.NewLine + "Please connect to another EA project.");
                addLineToEAOutput("Connectiontype of EA project not allowed: ", repositoryType);
                return(false);
            }
            addLineToEAOutput("Connected to: ", _model.repositoryType.ToString());

            // Check if any checks are selected
            int numberOfChecks = selectedchecks.Count();

            uc.InitProgressbar(numberOfChecks);
            // Check if the Enterprise Architect connection is sql
            addLineToEAOutput("Number of checks to validate: ", numberOfChecks.ToString());
            if (numberOfChecks > 0)
            {
                // Clear list of validations
                validations.Clear();

                // Perform the selected checks and return the validation-results
                addLineToEAOutput("START of Validations...", "");

                // Validate all selected checks
                foreach (var check in selectedchecks)
                {
                    addLineToEAOutput("Validating check: ", check.CheckDescription);

                    validations.AddRange(check.Validate(this, EA_element, EA_diagram, uc.getExcludeArchivedPackagesState()));
                    var obj = checks.FirstOrDefault(x => x.CheckId == check.CheckId);
                    if (obj != null)
                    {
                        obj.SetStatus(check.Status);
                    }

                    uc.IncrementProgressbar();
                }

                addLineToEAOutput("END of Validations.", "");
                addLineToEAOutput("Show list with validation results.", "");
            }

            // If one (or more) check gave an ERROR, then notify the user about it
            var objWithError = checks.FirstOrDefault(x => x.Status == "ERROR");

            if (objWithError != null)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
        /// <summary>
        /// method moves diagram object of element in diagram
        /// </summary>
        /// <param name="Repository">EA repository</param>
        /// <param name="elementGUID">GUID of element which diagram object that should be moved belongs to</param>
        /// <param name="diagramGUID">GUID of diagram</param>
        /// <param name="coordinates">new coordinates of diagram object that should be moved</param>
        public void moveElementInDiagram(EA.Repository Repository, string elementGUID, string diagramGUID, string coordinates)
        {
            EA.Element element = (EA.Element)Repository.GetElementByGuid(elementGUID);
            EA.Diagram diagram = (EA.Diagram)Repository.GetDiagramByGuid(diagramGUID);

            int left, right, top, bottom, pocet = 0;

            Wrapper.Diagram diagramWrapper = new Wrapper.Diagram(model, diagram);
            Wrapper.ElementWrapper elWrapper = new Wrapper.ElementWrapper(model, element);
            EA.DiagramObject diagramObject = diagramWrapper.getdiagramObjectForElement(elWrapper);

            string[] coordinate;
            string str;
            string[] parts = coordinates.Split(';');

            str = parts[0];
            coordinate = str.Split('=');
            diagramObject.left = Convert.ToInt32(coordinate[1]);
            left = Convert.ToInt32(coordinate[1]);

            str = parts[1];
            coordinate = str.Split('=');
            diagramObject.right = Convert.ToInt32(coordinate[1]);
            right = Convert.ToInt32(coordinate[1]);

            str = parts[2];
            coordinate = str.Split('=');
            diagramObject.top = Convert.ToInt32(coordinate[1]);
            top = Convert.ToInt32(coordinate[1]);

            str = parts[3];
            coordinate = str.Split('=');
            diagramObject.bottom = Convert.ToInt32(coordinate[1]);
            bottom = Convert.ToInt32(coordinate[1]);

            for (short i = 0; i < diagram.DiagramObjects.Count; i++)
            {
                EA.DiagramObject diagramObj = (EA.DiagramObject)diagram.DiagramObjects.GetAt(i);
                EA.Element el = (EA.Element)Repository.GetElementByID(diagramObj.ElementID);
                if (diagramObj.left >= left && diagramObj.right <= right && diagramObj.top <= top && diagramObj.bottom >= bottom)
                {
                    if (diagramObj.ElementID != diagramObject.ElementID)
                    {
                        pocet++;
                    }
                }
            }

            diagramObject.Sequence = 1 + pocet;
            diagramObject.Update();

            for (short i = 0; i < diagram.DiagramObjects.Count; i++)
            {
                EA.DiagramObject diagramObj = (EA.DiagramObject)diagram.DiagramObjects.GetAt(i);
                EA.Element el = (EA.Element)Repository.GetElementByID(diagramObj.ElementID);
                if (diagramObj.left <= left && diagramObj.right >= right && diagramObj.top >= top && diagramObj.bottom <= bottom)
                {
                    if (diagramObj.ElementID != diagramObject.ElementID)
                    {
                        diagramObj.Sequence += 1;
                        diagramObj.Update();
                    }
                }
            }

            int parentID = diagram.ParentID;
            EA.Package package = (EA.Package)Repository.GetPackageByID(diagram.PackageID);
            if (parentID == 0)
            {
                BPAddIn.synchronizationWindow.addToList("Change of coordinates of element '" + element.Name + "' in diagram '" +
                    diagram.Name + "' (Location of diagram: package '" + package.Name + "')");
            }
            else {
                EA.Element parent = (EA.Element)Repository.GetElementByID(parentID);
                BPAddIn.synchronizationWindow.addToList("Change of coordinates of element '" + element.Name + "' in diagram '" +
                    diagram.Name + "' (Location of diagram: element '" + parent.Name + "' in package '" + package.Name + "')");
            }

            diagram.DiagramObjects.Refresh();
        }
Пример #6
0
        public void handleDiagramObjectCreation(Repository repository, int elementID, int diagramID, string DUID)
        {
            try
            {
                changed = false;

                EA.Element el = repository.GetElementByID(elementID);
                EA.Diagram diag = repository.GetDiagramByID(diagramID);

                Wrapper.Diagram diagram = new Wrapper.Diagram(model, diag);
                Wrapper.ElementWrapper elWrapper = new Wrapper.ElementWrapper(model, el);

                DiagramObject cur = diagram.getdiagramObjectForElement(elWrapper);
                string coordinates = "";
                coordinates += "l=" + cur.left + ";";
                coordinates += "r=" + cur.right + ";";
                coordinates += "t=" + cur.top + ";";
                coordinates += "b=" + cur.bottom + ";";
                currentDiagramObjectPositions.Add(cur.ElementID, coordinates);

                ItemCreation itemCreation = new ItemCreation();
                itemCreation.modelGUID = model.getWrappedModel().GetPackageByID(1).PackageGUID;
                itemCreation.itemGUID = el.ElementGUID;
                itemCreation.diagramGUID = diag.DiagramGUID;
                itemCreation.elementType = 700;
                itemCreation.coordinates = "";

                for (short i = 0; i < diag.DiagramObjects.Count; i++)
                {
                    EA.DiagramObject diagramObject = (EA.DiagramObject)diag.DiagramObjects.GetAt(i);
                    if (diagramObject.ElementID == el.ElementID)
                    {
                        coordinates = "";
                        coordinates += "l=" + diagramObject.left + ";";
                        coordinates += "r=" + diagramObject.right + ";";
                        coordinates += "t=" + diagramObject.top + ";";
                        coordinates += "b=" + diagramObject.bottom + ";";
                        itemCreation.coordinates = coordinates;
                        break;
                    }
                }

                changeService.saveChange(itemCreation);
            }
            catch (Exception ex) { }
        }
Пример #7
0
        private string getElementGuids(EAValidatorController controller, TSF_EA.Element EA_element, TSF_EA.Diagram EA_diagram, bool excludeArchivedPackages)
        {
            var qryToFindElements     = this.QueryToFindElements;
            int numberOfElementsFound = 0;

            // Check EA_element => Change / Release / Package / ...  and add to query
            if (EA_element != null)
            {
                if (!(String.IsNullOrEmpty(EA_element.guid)))
                {
                    string filterType;
                    string whereclause = string.Empty;
                    if (EA_element is TSF_EA.Package)
                    {
                        filterType = "Package";
                        this.QueryToFindElementsFilters.TryGetValue(filterType, out whereclause);
                        if (string.IsNullOrEmpty(whereclause))
                        {
                            this.SetStatus("ERROR");
                            return("");
                        }
                        else
                        {
                            // Replace Branch with package-guids of branch
                            if (whereclause.Contains(controller.settings.PackageBranch))
                            {
                                whereclause = whereclause.Replace(controller.settings.PackageBranch, getBranchPackageIDsByGuid(EA_element.guid));
                            }
                            else
                            {
                                // Replace Search Term with Element guid
                                whereclause = whereclause.Replace(controller.settings.SearchTermInQueryToFindElements, EA_element.guid);
                            }
                        }
                    }
                    else
                    {
                        filterType = EA_element.stereotypeNames.FirstOrDefault();
                        this.QueryToFindElementsFilters.TryGetValue(filterType, out whereclause);
                        if (string.IsNullOrEmpty(whereclause))
                        {
                            this.SetStatus("ERROR");
                            return("");
                        }
                        else
                        {
                            // Replace Search Term with Element guid
                            whereclause = whereclause.Replace(controller.settings.SearchTermInQueryToFindElements, EA_element.guid);
                        }
                    }
                    qryToFindElements = qryToFindElements + whereclause;
                }
            }

            // Check EA_diagram => Use Case diagram (= Functional Design) and add to query
            if (EA_diagram != null)
            {
                if (!(String.IsNullOrEmpty(EA_diagram.diagramGUID)))
                {
                    string filterType;
                    string whereclause = string.Empty;
                    filterType = "FunctionalDesign";
                    this.QueryToFindElementsFilters.TryGetValue(filterType, out whereclause);
                    if (string.IsNullOrEmpty(whereclause))
                    {
                        this.SetStatus("ERROR");
                        return("");
                    }
                    else
                    {
                        // Replace Search Term with diagram guid
                        whereclause = whereclause.Replace(controller.settings.SearchTermInQueryToFindElements, EA_diagram.diagramGUID);
                    }
                    qryToFindElements = qryToFindElements + whereclause;
                }
            }

            if (excludeArchivedPackages)
            {
                qryToFindElements = qryToFindElements + " " + controller.settings.QueryExcludeArchivedPackages;
            }

            var foundelementguids = "";

            try
            {
                // Execute the query using EA
                var elementsFound = this.model.SQLQuery(qryToFindElements);

                // Parse xml document with elements found and count number of elements found
                foreach (XmlNode node in elementsFound.SelectNodes("//Row"))
                {
                    numberOfElementsFound += 1;
                    foreach (XmlNode subNode in node.ChildNodes)
                    {
                        if (subNode.Name == "ItemGuid")
                        {
                            foundelementguids += ",'" + subNode.InnerText + "'";
                        }
                    }
                }
                this.NumberOfElementsFound = numberOfElementsFound.ToString();
            }
            catch (Exception ex)
            {
                //MessageBox.Show("Error in query: " + qryToFindElements);
                this.SetStatus("ERROR");
            }
            return(foundelementguids);
        }
Пример #8
0
        public List <Validation> Validate(EAValidatorController controller, TSF_EA.Element EA_element, TSF_EA.Diagram EA_diagram, bool excludeArchivedPackages)
        {
            var validations = new List <Validation>();

            // Default status to Passed
            this.SetStatus("Passed");
            this.NumberOfElementsFound     = "";
            this.NumberOfValidationResults = "";

            // Search elements that need to be checked depending on filters and give back their guids.
            var foundelementguids = getElementGuids(controller, EA_element, EA_diagram, excludeArchivedPackages);

            if (this.Status == "ERROR")
            {
                controller.addLineToEAOutput("- Error while searching elements.", "");
                return(validations);
            }

            if (foundelementguids.Length > 0)
            {
                controller.addLineToEAOutput("- Elements found: ", this.NumberOfElementsFound);

                foundelementguids = foundelementguids.Substring(1);   // remove first ","
                // Perform the checks for the elements found (based on their guids)
                validations = CheckFoundElements(controller, foundelementguids);
                if (this.Status == "ERROR")
                {
                    controller.addLineToEAOutput("- Error while validating found elements.", "");
                }
                controller.addLineToEAOutput("- Validation results found: ", this.NumberOfValidationResults);
            }
            else
            {
                this.NumberOfValidationResults = "0";
                controller.addLineToEAOutput("- No elements found.", "");
            }
            return(validations);
        }
Пример #9
0
        /// <summary>
        /// creates a diagram based on the given EA.Diagram object
        /// </summary>
        /// <param name="diagramToWrap">the EA.Diagram object to wrap</param>
        /// <returns>a diagram wrapping the given EA.Diagram object</returns>
        public override UML.Diagrams.Diagram createDiagram(object diagramToWrap)
        {
            Diagram newDiagram = null;

            global::EA.Diagram eaDiagramToWrap = diagramToWrap as global::EA.Diagram;
            if (eaDiagramToWrap != null)
            {
                switch (eaDiagramToWrap.Type)
                {
                case "Sequence":
                    newDiagram = new SequenceDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Collaboration":
                    newDiagram = new CommunicationDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Activity":
                    newDiagram = new ActivityDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Logical":
                    newDiagram = new ClassDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Component":
                    newDiagram = new ComponentDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "CompositeStructure":
                    newDiagram = new CompositeStructureDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Deployment":
                    newDiagram = new DeploymentDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "InteractionOverview":
                    newDiagram = new InteractionOverviewDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Object":
                    newDiagram = new ObjectDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Package":
                    newDiagram = new PackageDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Statechart":
                    newDiagram = new StateMachineDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Timing":
                    newDiagram = new TimingDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                case "Use Case":
                    newDiagram = new UseCaseDiagram(this.model as Model, eaDiagramToWrap);
                    break;

                // TODO add creation of profile diagram
                default:
                    newDiagram = new Diagram(this.model as Model, eaDiagramToWrap);
                    break;
                }
            }
            return(newDiagram);
        }
 public DiagramObjectWrapper(Model model, ElementWrapper element,
                             Diagram diagram)
     : this(model, diagram.getdiagramObjectForElement(element))
 {
 }