Exemplo n.º 1
0
        protected void upLoadButton_Click1(object sender, EventArgs e)
        {
            string selectedVersionValue = "10";
            if (VersionDropDownList != null)
            {
                selectedVersionValue = VersionDropDownList.Value;
            }
            if (FileUpload1.HasFile)
            {
                if (FileUpload1.PostedFile.ContentType == "text/xml")
                {
                    //if there is a file
                    //valadate it by pass in input stream as xmlreader
                    Stream responseStream = FileUpload1.PostedFile.InputStream;
                    XmlReader xmlreader = XmlReader.Create(responseStream);

                    //validating xml with Phase 1 still.
                    Phase1_DOEgbXML.DOEgbXMLValidator val = new Phase1_DOEgbXML.DOEgbXMLValidator();
                    //Run the DOEgbXMLValidator...
                    if (!val.IsValidXmlEx(xmlreader, selectedVersionValue) || val.nErrors > 0 || val.nWarnings > 0)
                    {
                        //if it is not valid
                        if (PrintFriendly != null)
                            PrintFriendly.Visible = false;

                        if (DownloadLogButton != null)
                            DownloadLogButton.Visible = false;

                        //setup errorlog
                        string errorLog = "";
                        string errorDes = "";
                        if (val.nErrors > 0 || val.nWarnings > 0)
                        {
                            errorLog += "<p class='text-error'><div class='alert alert-danger'>" + "Find " + val.nErrors + " Errors and " + val.nWarnings + " Warnings <br/> <br/>" + val.Errors + "</div></p>";
                            errorDes = "Find ";
                            if (val.nErrors > 0)
                            {
                                errorDes += val.nErrors;
                                if (val.nWarnings > 0)
                                    errorDes += " Errors and";
                                else
                                    errorDes += " Errors";

                            }
                            if (val.nWarnings > 0)
                                errorDes += val.nWarnings + " Warnings";
                        }
                        else
                        {
                            errorLog += "<p class='text-error'><div class='alert alert-danger'>" + "Your XML File is severely deficient structurally.  It may be missing element tags or is not valid XML.  The test has failed. <br /><br/>" + val.BigError + "<br />" + "</div></p>";
                            errorDes = "Your XML File is severely deficient structurally.";
                        }
                        // Session.Add("table", errorLog);
                        Session["table"] = errorLog;

                        TestResultPanel.Controls.Clear();
                        ResultSummaryLabel.Text = "<h3>Result Summary</h3>";
                        ResultSummaryLabel.Text += "<table class='table'>";
                        ResultSummaryLabel.Text += "<tr class='alert alert-danger'>" +
                                        "<td>" + "gbXML schema Test" + "</td>" +
                                        "<td>" + errorDes + "</td>" +
                                        "<td>" + "Fail" + "</td>" +
                                        "<td>" + "<a href='TestDetailPage.aspx?type=Error' target='_blank'>" + "More Detail" + "</a>" + "</td>" +
                                        "</tr>";
                        ResultSummaryLabel.Text += "</table><br/>";
                        ResultsSections.Visible = true;
                    }
                    else if (val.nErrors == 0 && val.nWarnings == 0)
                    {
                        //if it is valid
                        // Show Results
                        ResultsSections.Visible = true;

                        //run test
                        XMLParser parser = new XMLParser();

                        responseStream.Position = 0;
                        XmlReader xmlreader2 = XmlReader.Create(responseStream);

                        //run through reports
                        ProcessValidXML(parser, xmlreader2);

                        //show summary table
                        ResultSummaryLabel.Text = summaryTable;

                        //show test section table // TODO: Replace with a panel?
                        //TestResultLabel.Text = table;

                        //store reportlist in session for TestDetailPage.
                        Session["reportList"] = ReportList;

                        LogLabel.Text = log;
                        //TableLabel.Text = table;
                        //remove extra tag
                        TableLabel.Text = TableLabel.Text.Replace("<a href='PrintFriendlyTablePage.aspx' target='_blank'>", "");
                        TableLabel.Text = TableLabel.Text.Replace("</a>", "");
                        DownloadLogButton.Visible = true;
                        PrintFriendly.Visible = true;
                    }
                    //this should never happen
                    else
                    {
                        ResultSummaryLabel.Text = "?????????something is very wrong";
                        TestResultPanel.Controls.Clear();
                    }
                }
                //if the file type is not xml
                else
                {
                    if (PrintFriendly != null)
                        PrintFriendly.Visible = false;

                    if (DownloadLogButton != null)
                        DownloadLogButton.Visible = false;

                    ResultSummaryLabel.Text = "";
                    TestResultPanel.Controls.Clear();
                    ResultSummaryLabel.Text = "<h3>Result Summary</h3>";
                    ResultSummaryLabel.Text += "<table class='table'>";
                    ResultSummaryLabel.Text += "<tr class='alert alert-danger'>" +
                                    "<td>" + "gbXML schema Test" + "</td>" +
                                    "<td>" + "You have not specified a right type of file." + "</td>" +
                                    "<td>" + "Fail" + "</td>" +
                                    "</tr>";
                    ResultSummaryLabel.Text += "</table><br/>";
                    ResultsSections.Visible = true;
                }
            }
            //if there is no file
            else
            {
                if (PrintFriendly != null)
                    PrintFriendly.Visible = false;

                if (DownloadLogButton != null)
                    DownloadLogButton.Visible = false;

                ResultSummaryLabel.Text = "";
                TestResultPanel.Controls.Clear();
                ResultSummaryLabel.Text = "<h3>Result Summary</h3>";
                ResultSummaryLabel.Text += "<table class='table'>";
                ResultSummaryLabel.Text += "<tr class='alert alert-danger'>" +
                                "<td>" + "gbXML schema Test" + "</td>" +
                                "<td>" + "You have not specified a file." + "</td>" +
                                "<td>" + "Fail" + "</td>" +
                                "</tr>";
                ResultSummaryLabel.Text += "</table><br/>";
                ResultsSections.Visible = true;
            }
        }
Exemplo n.º 2
0
        public void ProcessRequest(HttpContext context)
        {
            var formdata = context.Request.Form;
            string testcaseName = formdata["testcase"].Replace('+',' ');
            string schemaversion = formdata["schema"];
            gbXMLReport gbr = new gbXMLReport();
            gbr.gbxml_testcase = testcaseName;
            gbr.gbxml_version = schemaversion;
            
            logger.Info("Received XML file from user at UTC time " + DateTime.UtcNow);
            var file = context.Request.Files[0];
            if (file.ContentType == "text/xml")
            {
                logger.Info("File has extension XML.");
                DOEgbXMLValidator val = new DOEgbXMLValidator(schemaversion);
                XMLParser parser = new XMLParser();
                //if there is a file
                //valadate it by pass in input stream as xmlreader
                Stream responseStream = file.InputStream;
                XmlReader xmlreader = XmlReader.Create(responseStream);

                //if it is not valid
                if (!val.IsValidXmlEx(xmlreader) || val.nErrors > 0 || val.nWarnings > 0)
                {
                    //if (PrintFriendlyButton != null)
                    //    PrintFriendlyButton.Visible = false;

                    //if (DownloadLogButton != null)
                    //    DownloadLogButton.Visible = false;


                    //setup errorlog
                    if (val.nErrors > 0 || val.nWarnings > 0)
                    {
                        gbr.XMLSchemaErrors = val.nErrors.ToString();
                        gbr.XMLSchemaWarnings = val.nWarnings.ToString();
                        logger.Info("Found " + val.nErrors + " Errors and " + val.nWarnings + " Warnings " + val.Errors);
                        gbr.message = val.Errors;
                        gbr.schema_compliance_results = "FAIL";
                        gbr.detailed_compliance_results = "DID NOT ATTEMPT DUE TO SCHEMA FAILURE";
                        
                    }
                    else
                    {
                        gbr.XMLSchemaWarnings = "Infinity";
                        gbr.XMLSchemaErrors = "Infinity";

                        logger.Info("Your XML File is severely deficient structurally.  It may be missing element tags or is not valid XML.  The test has failed. " + val.BigError);
                        gbr.message = "Your XML File is severely deficient structurally.";
                        gbr.schema_compliance_results = "FAIL";
                        gbr.detailed_compliance_results = "DID NOT ATTEMPT DUE TO SCHEMA FAILURE";
                    }
                }
                else{
                    //the xml itself is totally valid
                    gbr.schema_compliance_results = "PASS";
                    gbr.message = "The XML uploaded is validated against schema " + gbr.gbxml_version;
                    gbr.XMLSchemaErrors = val.nErrors.ToString();
                    gbr.XMLSchemaWarnings = val.nWarnings.ToString();

                    //run test

                    responseStream.Position = 0;
                    XmlReader xmlreader2 = XmlReader.Create(responseStream);
                    //start test
                    parser.StartTest(xmlreader2, testcaseName, ref gbr);

                    //see if any of the PassOverall are failed
                    var campusProps = gbr.CampusReport;
                    var surffailures = campusProps.SurfacesReport.FindAll(x => x.FoundMatch == false);
                    if (surffailures.Count > 0) gbr.detailed_compliance_results = "FAIL";
                    var spacefailures = campusProps.SpacesReport.FindAll(x => x.FoundMatch == false);
                    if (spacefailures.Count > 0) gbr.detailed_compliance_results = "FAIL";
                    var surfsummaryfail = campusProps.SurfacesSummary.FindAll(x => x.PassedAllTests == false);
                    if (surfsummaryfail.Count > 0) gbr.detailed_compliance_results = "FAIL";
                    var spacesummaryfail = campusProps.SpacesSummary.FindAll(x => x.PassedAllTests == false);
                    if (spacesummaryfail.Count > 0) gbr.detailed_compliance_results = "FAIL";
                    //TODO: building summary, stories summary
                }
            }
            else{
                //the stuff is not even xml
                logger.Info("Your file does not end in .xml");
                gbr.message = "The file does not end in .xml";
                gbr.schema_compliance_results = "FAIL";
            }

            context.Response.ContentType = "application/json";
            context.Response.Write(JsonConvert.SerializeObject(gbr));
        }
Exemplo n.º 3
0
        private void ProcessValidXML(XMLParser parser, XmlReader xmlreader2)
        {
            // Phase 2 Testing
            XmlDocument myxml = new XmlDocument();
            myxml.Load(xmlreader2);
            //3-get the namespace
            XmlNamespaceManager nsm = parser.getnsmanager(myxml);
            //figure out if metric or USIP (we have not found a reason to use this yet)
            parser.getunits(nsm, myxml);

            /* Begin Parsing the XML and reporting on it----------------------------------------------------------*/

            //make a reporting object
            DOEgbXMLPhase2Report report = new DOEgbXMLPhase2Report();

            /* Basic Uniqueness Constraints check-------------------------------------------------*/

            //Basic requirements check

            // Setup the results view for the log and web.
            log = "";
            TestResultPanel.Controls.Add(new LiteralControl("<div class='well-lg'><h3>Test Sections</h3><table class='table table-bordered'><tr class='info'><td>Test Section Name</td><td>Tolerances</td><td>Pass/Fail</td></tr>"));

            //first create a list of lists that is indexed identically to the drop down list the user selects
            TestDetail = new DOEgbXMLTestDetail();
            //then populate the list of lists.  All indexing is done "by hand" in InitializeTestResultStrings()
            TestDetail.InitializeTestResultStrings();                        //Set up the Global Pass/Fail criteria for the test case file
            TestCriteria = new DOEgbXMLTestCriteriaObject();
            TestCriteria.InitializeTestCriteriaWithTestName(TestToRun); // ("Test1");

            // Reports
            //ensure that all names of spaces are unique--------------------------------------------------------------------------------------------------------Unique_Space_ID_Test//
            report.testType = TestType.Unique_Space_ID_Test;
            report = DOEgbXML.gbXMLSpaces.UniqueSpaceIdTest2(myxml, nsm, report);
            ProcessReport(report, true);
            report.Clear();

            //ensure that all space boundary names are unique--------------------------------------------------------------------------------------------------Unique_Space_Boundary//
            XmlNodeList nodes = myxml.SelectNodes("/gbXMLv5:gbXML/gbXMLv5:Campus/gbXMLv5:Building/gbXMLv5:Space/gbXMLv5:SpaceBoundary", nsm);
            if (nodes.Count > 0)
            {
                spaceBoundsPresent = true;
                report.testType = TestType.Unique_Space_Boundary;
                report = DOEgbXML.gbXMLSpaces.UniqueSpaceBoundaryIdTest2(myxml, nsm, report);
                ProcessReport(report, true);
                report.Clear();
            }
            else
            {
                //needs to be included so the report can be processed
                report.testType = TestType.Unique_Space_Boundary;
                report.passOrFail = true;
                report.longMsg = "A test is usually performed here to ensure Space Boundaries have valid naming conventions.  This test was skipped (legally) because your file does not have space boundaries present.  Continuing to next test.";
                ProcessReport(report, true);
                report.Clear();
            }

            //Space Tests
            //make a simplified representation of the spaces
            List<DOEgbXML.gbXMLSpaces> spaces = DOEgbXML.gbXMLSpaces.getSimpleSpaces(myxml, nsm);

            //4-check for self-intersecting polygons
            //report = DOEgbXML.gbXMLSpaces.SpaceSurfacesSelfIntersectionTest(spaces, report);
            //report.Clear();

            //check that all polyloops are in a counterclockwise direction-----------------------------------------------------------------------------------------Space_Surfaces_CC//
            report = DOEgbXML.gbXMLSpaces.SpaceSurfacesCCTest2(spaces, report);
            report.testType = TestType.Space_Surfaces_CC;
            ProcessReport(report, true);
            report.Clear();

            //check for non-planar objects for all Spaces' polyloops-------------------------------------------------------------------------------------------Space_Surfaces_Planar//
            report.coordtol = DOEgbXMLBasics.Tolerances.VectorAngleTolerance;
            report = DOEgbXML.gbXMLSpaces.SpaceSurfacesPlanarTest(spaces, report);
            report.testType = TestType.Space_Surfaces_Planar;
            ProcessReport(report, true);
            report.Clear();

            //valid space enclosure?---------------------------------------------------------------------------------------------------------------------------Check_Space_Enclosure//
            report.tolerance = 0.0001;
            //when we are comparing angles in this function, we are testing the angle between dot products
            report.vectorangletol = DOEgbXMLBasics.Tolerances.dotproducttol;
            report.lengthtol = DOEgbXMLBasics.Tolerances.lengthTolerance;
            //toler
            report.coordtol = DOEgbXMLBasics.Tolerances.coordToleranceIP;
            report = Validator.CheckSpaceEnclosureSG(spaces, report);
            report.testType = TestType.Check_Space_Enclosure;
            ProcessReport(report, true);
            report.Clear();

            /* Surface tests----------------------------------------------------------------------------------*/
            /* Basic Requirements ----------------------------------------------------------------------------*/

            //Are there at least 4 surface definitions?  (see the surface requirements at the campus node)-------------------------------------------------------At_Least_4_Surfaces//
            report.testType = TestType.At_Least_4_Surfaces;
            report = SurfaceDefinitions.AtLeast4Surfaces(myxml, nsm, report);
            ProcessReport(report, true);
            report.Clear();

            //Does the AdjacentSpaceId not exceed the max number allowable?-----------------------------------------------------------------------------------------Two_Adj_Space_Id//
            //this needs to be updated!
            report.testType = TestType.Two_Adj_Space_Id;
            report = SurfaceDefinitions.AtMost2SpaceAdjId(myxml, nsm, report);
            ProcessReport(report, true);
            report.Clear();

            //Are all required elements and attributes in place?---------------------------------------------------------------------------------------------Required_Surface_Fields//
            //report.testType = TestType.Required_Surface_Fields;
            //report = SurfaceDefinitions.RequiredSurfaceFields(myxml, nsm, report);
            //ProcessReport(report, true);
            //report.Clear();

            //ensure that all names of surfaces are unique------------------------------------------------------------------------------------------------------Surface_ID_Uniqueness//
            report.testType = TestType.Surface_ID_Uniqueness;
            report = DOEgbXML.SurfaceDefinitions.SurfaceIDUniquenessTest(myxml, nsm, report);
            ProcessReport(report, true);
            report.Clear();

            //now grab all the surfaceIds and make them available------------------------------------------------------------------------------------------------Surface_Adj_Id_Match//
            List<string> spaceIds = new List<string>();
            foreach (gbXMLSpaces s in spaces)
            {
                spaceIds.Add(s.id);
            }

            List<SurfaceDefinitions> surfaces = DOEgbXML.XMLParser.MakeSurfaceList(myxml, nsm);
            //make sure the surface Adjacent space Id names match only the the space Ids gathered above.  The adjacent space Ids can't have their own special values
            report.testType = TestType.Surface_Adj_Id_Match;
            report = DOEgbXML.SurfaceDefinitions.SurfaceAdjSpaceIdTest(spaceIds, surfaces, report);
            ProcessReport(report, true);
            report.Clear();

            //Surface_ID_SB_Match------------------------------------------------------------------------------------------------------------------------------Surface_ID_SB_Match//
            if (spaceBoundsPresent)
            {
                report.tolerance = DOEgbXMLBasics.Tolerances.coordToleranceIP;
                report.testType = TestType.Surface_ID_SB_Match;
                report = SurfaceDefinitions.SurfaceMatchesSpaceBoundary(myxml, nsm, report);
                ProcessReport(report, true);
                report.Clear();
            }
            else
            {
                report.testType = TestType.Surface_ID_SB_Match;
                report.passOrFail = true;
                report.longMsg = "A test is usually performed here to ensure Space Boundaries and Surfaces share the same ID.  This test was skipped (legally) because your file does not have space boundaries present.  Continuing to next test.";
                ProcessReport(report, true);
                report.Clear();
            }

            //Does the polyloop right hand rule vector form the proper azimuth and tilt? (with and without a CADModelAzimuth)----------------------------------Surface_Tilt_Az_Check//
            report.tolerance = DOEgbXMLBasics.Tolerances.VectorAngleTolerance;
            report.vectorangletol = DOEgbXMLBasics.Tolerances.VectorAngleTolerance;
            report.testType = TestType.Surface_Tilt_Az_Check;
            report = SurfaceDefinitions.SurfaceTiltAndAzCheck(myxml, nsm, report);
            ProcessReport(report, true);
            report.Clear();

            //planar surface test-------------------------------------------------------------------------------------------------------------------------------Surface_Planar_Test//
            report.vectorangletol = DOEgbXMLBasics.Tolerances.VectorAngleTolerance;
            report = SurfaceDefinitions.TestSurfacePlanarTest(surfaces, report);
            report.testType = TestType.Surface_Planar_Test;
            ProcessReport(report, true);
            report.Clear();

            //I must take the surfaces, group them, and rearrange any interior surfaces' coordinates that should be pointed the opposite way
            string searchpath = "/gbXMLv5:gbXML/gbXMLv5:Campus/gbXMLv5:Building/gbXMLv5:Space";
            List<string> spaceids = DOEgbXML.gbXMLSpaces.getSpaceIds(myxml, nsm, searchpath);
            Dictionary<string, List<SurfaceDefinitions>> enclosure = new Dictionary<string, List<SurfaceDefinitions>>();
            foreach (string id in spaceids)
            {
                //find all surfaces with this adjacent space id, get their polyloops, and then match their polyloops
                List<SurfaceDefinitions> surflist = new List<SurfaceDefinitions>();

                foreach (SurfaceDefinitions surf in surfaces)
                {
                    foreach (var adj in surf.AdjSpaceId)
                    {
                        if (adj == id)
                        {
                            surflist.Add(surf);
                            //don't want to add surfaces twice (slab on grade)
                            break;
                        }
                    }
                }
                enclosure[id] = surflist;
            }

            //counter clockwise winding test-------------------------------------------------------------------------------------------------------------------------Surface_CC_Test//
            report.testType = TestType.Surface_CC_Test;
            report = SurfaceDefinitions.SurfaceCCTest(enclosure, report);
            ProcessReport(report, true);
            report.Clear();

            //self intersecting polygon test
            //report = SurfaceDefinitions.SurfaceSelfIntersectionTest(surfaces, report);
            //report.Clear();

            //Is the Lower Left Corner properly defined?

            //surface enclosure tests------------------------------------------------------------------------------------------------------------------------Check_Surface_Enclosure//
            report.tolerance = 0.0001;
            report.vectorangletol = DOEgbXMLBasics.Tolerances.dotproducttol;
            report.lengthtol = DOEgbXMLBasics.Tolerances.lengthTolerance;
            report.coordtol = .01;
            report.testType = TestType.Check_Surface_Enclosure;
            report = Validator.CheckSurfaceEnclosure(enclosure, report);
            ProcessReport(report, true);
            report.Clear();

            TestResultPanel.Controls.Add(new LiteralControl("</table></div>"));
            CreateSummaryTable();
        }