Пример #1
0
        public static bool ValidToXSD(EAValidatorController controller, string file)
        {
            bool   valid           = true;
            string schemaNamespace = "";
            string schemaFileName  = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + @"\Files\check.xsd";

            if (!(FileOrDirectoryExists(schemaFileName)))
            {
                controller.addLineToEAOutput("XSD schema not found: ", schemaFileName);
                return(false);
            }
            XmlSchemaSet schemas = new XmlSchemaSet();

            schemas.Add(schemaNamespace, schemaFileName);
            string    filename = new FileInfo(file).Name;
            string    message  = String.Empty;
            XDocument doc      = XDocument.Load(file);

            doc.Validate(schemas, (o, e) => {
                controller.addLineToEAOutput(filename + ": ", e.Message);
                message = message + System.Environment.NewLine + "-> " + e.Message;
                valid   = false;
            });
            if (!String.IsNullOrEmpty(message))
            {
                message = filename + " : " + message;
                MessageBox.Show(message);
            }
            return(valid);
        }
Пример #2
0
        private void openEAValidator()
        {
            // Open the EA Validator (user control)
            if (this.model == null)
            {
                return;
            }
            var controller = new EAValidatorController(this.model);

            this.ucEAValidator.setController(controller);
        }
Пример #3
0
        private void openEAValidator()
        {
            // Open the EA Validator (user control)
            if (this.model == null)
            {
                return;
            }
            var controller = new EAValidatorController(this.model, this.settings);

            this.ucEAValidator.setController(controller);
            //make sure to show the validator GUI
            showValidatorTab();
        }
Пример #4
0
        private List <Validation> CheckFoundElements(EAValidatorController controller, string foundelementguids)
        {
            // Prepare
            var validations = new List <Validation>();
            int numberOfValidationResults = 0;

            // Replace SearchTerm with list of guids
            var qryToCheckFoundElements = this.QueryToCheckFoundElements;

            qryToCheckFoundElements = qryToCheckFoundElements.Replace(controller.settings.ElementGuidsInQueryToCheckFoundElements, foundelementguids);

            // Search for Parameters in query and replace them
            foreach (KeyValuePair <string, string> parameter in this.QueryToCheckFoundElementsParameters)
            {
                string searchKey = "#" + parameter.Key + "#";
                qryToCheckFoundElements = qryToCheckFoundElements.Replace(searchKey, parameter.Value);
            }

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

                // Parse xml document with results and create validation for every row found
                foreach (XmlNode validationNode in results.SelectNodes("//Row"))
                {
                    // Set status of Check to FAILED
                    this.SetStatus("Failed");

                    // Add results of validation to list
                    validations.Add(new Validation(this, validationNode));
                    numberOfValidationResults += 1;
                }
                this.NumberOfValidationResults = numberOfValidationResults.ToString();
            }
            catch (Exception)
            {
                //MessageBox.Show("Error in query: " + qryToCheckFoundElements);
                this.SetStatus("ERROR");
            }

            return(validations);
        }
Пример #5
0
        }                                                           // Proposed Solution of the check

        public Check(string file, string extension, EAValidatorController controller, TSF_EA.Model model)
        {
            // Constructor
            this.model = model;

            // Initiate the Check
            SetDefaultValues();

            // Load file contents into the Check class
            switch (extension)
            {
            case "xml":
                // Checks are grouped per directory
                string path = Path.GetDirectoryName(file);
                this.Group = path.Substring(path.LastIndexOf("\\") + 1);

                // Load xml-document
                XmlDocument xmldoc = new XmlDocument();
                xmldoc.Load(file);

                // Interprete xml node and subnodes
                XmlNode node = xmldoc.DocumentElement.SelectSingleNode(controller.settings.XML_CheckMainNode);
                foreach (XmlNode subNode in node.ChildNodes)
                {
                    InterpreteCheckSubNode(subNode);
                }
                break;

            default:
                break;
            }

            // Verify that the check has all mandatory content
            if (!this.HasMandatoryContent())
            {
                MessageBox.Show("XML file does not have all mandatory content." + " - " + file);
            }
        }
Пример #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);
        }
Пример #7
0
        public void setController(EAValidatorController controller)
        {
            this.controller = controller;
            // Load files from directory as checks
            this.controller.loadChecksFromDirectory(this.controller.settings.ValidationChecks_Directory);

            // Show checks/validations in objectListViews
            //this.olvColCheckDescription.HeaderCheckState = CheckState.Checked;
            if (this.controller.rootGroup != null)
            {
                this.olvChecks.Objects = new List <object>()
                {
                    this.controller.rootGroup
                };
                this.olvChecks.ExpandAll();
                this.olvChecks.CheckAll();
            }
            else
            {
                this.olvChecks.ClearObjects();
            }
            this.Initiate();
        }
 public void setController(EAValidatorController controller)
 {
     this.controller = controller;
     Initiate();
 }
Пример #9
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);
        }