Example #1
0
        public MappingSet getMappingSet(TSF_EA.Element sourceElement)
        {
            var sourceRoot = sourceElement as TSF_EA.ElementWrapper;

            //if an attribute was selected then we select the parent element as root
            if (sourceRoot == null)
            {
                sourceRoot = sourceElement?.owner as TSF_EA.ElementWrapper;
            }
            var mappingSet = getEmptyMappingSet(sourceRoot);

            //actually load the mappingset
            if (mappingSet != null)
            {
                //log progress
                this.clearOutput();
                //log progress
                var startTime = DateTime.Now;
                EAOutputLogger.log($"Start loading mapping for {sourceRoot.name}", sourceRoot.id);
                //Load the mappings
                mappingSet.loadMappings(sourceRoot);
                //mappingSet.loadAllMappings();
                //log progress
                var endTime        = DateTime.Now;
                var processingTime = (endTime - startTime).TotalSeconds;
                EAOutputLogger.log($"Finished loading mapping for {sourceRoot.name} in {processingTime.ToString("N0")} seconds", sourceRoot.id);
            }
            //return
            return(mappingSet);
        }
        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));
        }
        /// <summary>
        /// copies only the tagged values necesarry
        /// </summary>
        /// <param name="source">the source element</param>
        /// <param name="target">the target element</param>
        public void copyTaggedValues(TSF_EA.Element source, TSF_EA.Element target)
        {
            //build a dictionary of tagged value pairs
            var matchedPairs = new Dictionary <TSF_EA.TaggedValue, TSF_EA.TaggedValue>();
            //get a copy of the list of target tagged values
            var targetTaggedValues = target.taggedValues.OfType <TSF_EA.TaggedValue>().ToList();

            //copy tagged values
            foreach (TSF_EA.TaggedValue sourceTaggedValue in source.taggedValues)
            {
                //if it's a tagged value to be synchronized then add it to the list and skip the rest
                if (this.settings.synchronizedTaggedValues.Contains(sourceTaggedValue.name))
                {
                    this.taggedValuesToSynchronize.Add(new Tuple <TSF_EA.TaggedValue, TSF_EA.Element>(sourceTaggedValue, target));
                    continue;
                }
                bool updateTaggedValue = true;
                var  targetTaggedValue = this.popTargetTaggedValue(targetTaggedValues, sourceTaggedValue);
                if (this.settings.ignoredTaggedValues.Contains(sourceTaggedValue.name) ||
                    sourceTaggedValue.name.Equals(this.settings.customPositionTag, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (targetTaggedValue != null &&
                        targetTaggedValue.eaStringValue != string.Empty)
                    {
                        //don't update any of the tagged values of the ignoredTaggeValues if the value is already filled in.
                        updateTaggedValue = false;
                    }
                }
                if (updateTaggedValue)
                {
                    if (targetTaggedValue != null)
                    {
                        //check if neededs to be updated
                        if (targetTaggedValue.eaStringValue != sourceTaggedValue.eaStringValue ||
                            targetTaggedValue.comment != sourceTaggedValue.comment)
                        {
                            targetTaggedValue.eaStringValue = sourceTaggedValue.eaStringValue;
                            targetTaggedValue.comment       = sourceTaggedValue.comment;
                            targetTaggedValue.save();
                        }
                    }
                    else
                    {
                        //create new tagged value
                        target.addTaggedValue(sourceTaggedValue.name, sourceTaggedValue.eaStringValue, sourceTaggedValue.comment, true);
                    }
                }
            }
            //remove the tagged values to be synchronized from the target element
            var taggedValuesToDelete = target.taggedValues.Where(x => this.settings.synchronizedTaggedValues.Contains(x.name)).ToList();

            foreach (var targetTag in taggedValuesToDelete)
            {
                targetTag.delete();
            }
        }
        TSF_EA.Element findTarget(TSF_EA.Element sourceElement)
        {
            var trace = sourceElement.getRelationships <UML.Classes.Dependencies.Abstraction>().FirstOrDefault(x => x.stereotypes.Any(y => y.name.Equals("trace", StringComparison.InvariantCultureIgnoreCase)) &&
                                                                                                               (x.target is UML.Classes.Kernel.Package || x.target is UML.Classes.Kernel.Class));

            if (trace != null)
            {
                return(trace.target as TSF_EA.Element);
            }
            //if nothing found then return null
            return(null);
        }
        /// <summary>
        /// copies only the tagged values necesarry
        /// </summary>
        /// <param name="source">the source element</param>
        /// <param name="target">the target element</param>
        public void copyTaggedValues(TSF_EA.Element source, TSF_EA.Element target)
        {
            //build a dictionary of tagged value pairs
            var matchedPairs = new Dictionary <TSF_EA.TaggedValue, TSF_EA.TaggedValue>();
            //get a copy of the list of target tagged values
            var targetTaggedValues = target.taggedValues.OfType <TSF_EA.TaggedValue>().ToList();

            //copy tagged values
            foreach (TSF_EA.TaggedValue sourceTaggedValue in source.taggedValues)
            {
                bool updateTaggedValue = true;
                var  targetTaggedValue = this.popTargetTaggedValue(targetTaggedValues, sourceTaggedValue);
                if (this.settings.ignoredTaggedValues.Contains(sourceTaggedValue.name) ||
                    sourceTaggedValue.name.Equals(this.settings.customPositionTag, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (targetTaggedValue != null &&
                        targetTaggedValue.eaStringValue != string.Empty)
                    {
                        //don't update any of the tagged values of the ignoredTaggeValues if the value is already filled in.
                        updateTaggedValue = false;
                    }
                }
                if (updateTaggedValue)
                {
                    if (targetTaggedValue != null)
                    {
                        //check if neededs to be updated
                        if (targetTaggedValue.eaStringValue != sourceTaggedValue.eaStringValue ||
                            targetTaggedValue.comment != sourceTaggedValue.comment)
                        {
                            targetTaggedValue.eaStringValue = sourceTaggedValue.eaStringValue;
                            targetTaggedValue.comment       = sourceTaggedValue.comment;
                            targetTaggedValue.save();
                        }
                    }
                    else
                    {
                        //create new tagged value
                        target.addTaggedValue(sourceTaggedValue.name, sourceTaggedValue.eaStringValue, sourceTaggedValue.comment, true);
                    }
                }
            }
        }
Example #6
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);
        }
Example #7
0
        public static DB_EA.Database getDatabase(TSF_EA.Element element)
        {
            //first get the database based on the attribute
            var databasePackage = element.getAllOwners().OfType <Package>().FirstOrDefault(x => x.stereotypeNames.Any(y => y.ToLower() == "database"));

            //no database found, return empty
            if (databasePackage == null)
            {
                return(null);
            }
            string databaseType = databasePackage.taggedValues.FirstOrDefault(x => x.name.ToLower() == "dbms")?.tagValue.ToString();

            //no database type found. We cannot create the database
            if (string.IsNullOrEmpty(databaseType))
            {
                return(null);
            }
            //create the factory and database
            // TODO: add caching?
            var dbFactory = getFactory(databaseType, element.EAModel, new StrategyFactory());

            return(dbFactory?.createDataBase(databasePackage));
        }
 /// <summary>
 /// copies only the tagged values necesarry
 /// </summary>
 /// <param name="source">the source element</param>
 /// <param name="target">the target element</param>
 public void copyTaggedValues(UTF_EA.Element source, UTF_EA.Element target)
 {
     //copy tagged values
     foreach (UTF_EA.TaggedValue sourceTaggedValue in source.taggedValues)
     {
         bool updateTaggedValue = true;
         if (this.settings.ignoredTaggedValues.Contains(sourceTaggedValue.name))
         {
             UTF_EA.TaggedValue targetTaggedValue =
                 target.getTaggedValue(sourceTaggedValue.name);
             if (targetTaggedValue != null &&
                 targetTaggedValue.eaStringValue != string.Empty)
             {
                 //don't update any of the tagged values of the ignoredTaggeValues if the value is already filled in.
                 updateTaggedValue = false;
             }
         }
         if (updateTaggedValue)
         {
             target.addTaggedValue(sourceTaggedValue.name,
                                   sourceTaggedValue.eaStringValue);
         }
     }
 }
Example #9
0
 TSF_EA.Element findTarget(TSF_EA.Element sourceElement)
 {
     return(sourceElement.taggedValues.FirstOrDefault(x => x.name == this.settings.linkedElementTagName)?.tagValue as TSF_EA.Element);
 }
Example #10
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);
            }
        }
Example #11
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);
        }