Beispiel #1
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <long, ReportStaging> start, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > first, Dictionary <long, List <ReportResultAll> > last)
        {
            ConsoleSpinner spinner      = new ConsoleSpinner();
            bool           waitFlag     = false;
            DateTime       wait_expired = DateTime.UtcNow;

            while (!waitFlag)
            {
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }
                spinner.Turn();
                waitFlag = true;
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 1 second(s)");
                }
                Thread.Sleep(1000);
                foreach (ReportTrace rt in trace)
                {
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (token.debug && token.verbosity > 0)
                        {
                            Console.WriteLine("Testing report.Id {0}", rt.reportId);
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Found report.Id {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getFirstandLastReport(result, start, end, first, last);
                                }
                                else
                                {
                                    rt.isRead = true;
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #2
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > last)
        {
            bool waitFlag = false;

            while (!waitFlag)
            {
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);

                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(2) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Got status for reportId {0}", rt.reportId);
                            }
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (token.debug && token.verbosity > 0)
                                {
                                    Console.WriteLine("Got data for reportId {0}", rt.reportId);
                                }
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #3
0
        private bool fetchReports(List <ReportTrace> trace, getScanResults scanResults, Dictionary <long, Dictionary <DateTime, Dictionary <string, ReportResultExtended> > > fix, Dictionary <string, ReportResultExtended> resultAll, List <ReportResultExtended> report_output)
        {
            bool waitFlag = false;
            //ConsoleSpinner spinner = new ConsoleSpinner();
            DateTime wait_expired = DateTime.UtcNow;


            while (!waitFlag)
            {
                //spinner.Turn();
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }
                waitFlag = true;
                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);
                foreach (ReportTrace rt in trace)
                {
                    if (token.debug && token.verbosity > 0)
                    {
                        Console.WriteLine("Looping thru {0}, isRead {1}", rt.reportId, rt.isRead);
                    }
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(1) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (token.debug && token.verbosity > 0)
                        {
                            Console.WriteLine("Checking for report.Id {0}", rt.reportId);
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Found report.Id {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(rt.reportId, result, resultAll, fix, report_output))
                                {
                                    rt.isRead = true;
                                }
                                else
                                {
                                    rt.isRead = true;
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                    Console.Error.WriteLine("Failed processing reportId {0}", rt.reportId);
                                }
                            }
                            else
                            {
                                Console.Error.WriteLine("Failed retrieving reportId {0}", rt.reportId);
                                rt.isRead = true;
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }
Beispiel #4
0
        public bool fetchReportsbyDate()
        {
            List <ReportTrace>                         trace     = new List <ReportTrace>();
            List <ReportResultNew>                     resultNew = new List <ReportResultNew>();
            Dictionary <long, ReportStaging>           start     = new Dictionary <long, ReportStaging>();
            Dictionary <long, ReportStaging>           end       = new Dictionary <long, ReportStaging>();
            Dictionary <long, List <ReportResultNew> > last      = new Dictionary <long, List <ReportResultNew> >();
            Dictionary <long, ScanCount>               scanCount = new Dictionary <long, ScanCount>();
            bool              waitFlag    = false;
            getScanResults    scanResults = new getScanResults();
            getScans          scans       = new getScans();
            List <ScanObject> scan        = scans.getScan(token);

            foreach (ScanObject s in scan)
            {
                if ((s.DateAndTime != null) && (s.Status.Id == 7) && (s.DateAndTime.StartedOn > token.start_time) && (s.DateAndTime.StartedOn < token.end_time))
                {
                    setCount(s.Project.Id, scanCount);
                    findFirstorLastScan(s.Project.Id, s, start, true);
                    findFirstorLastScan(s.Project.Id, s, end, false);

                    ReportResult result = scanResults.SetResultRequest(s.Id, "XML", token);
                    if (result != null)
                    {
                        trace.Add(new ReportTrace(s.Project.Id, s.Id, result.ReportId));
                    }
                }
            }
            while (!waitFlag)
            {
                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (process_CxResponse(result, resultNew))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                            }
                        }
                    }
                }
            }

            List <ReportOutput> reportOutputs = totalScansandReports(start, end, resultNew, last, scanCount);

            if (token.pipe)
            {
                foreach (ReportOutput csv in reportOutputs)
                {
                    Console.WriteLine("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15}", csv.ProjectName, csv.LastHigh, csv.LastMedium, csv.LastLow, csv.NewHigh, csv.NewMedium, csv.NewLow, csv.DiffHigh, csv.DiffMedium, csv.DiffLow, csv.NotExploitable, csv.Confirmed, csv.ToVerify, csv.firstScan, csv.lastScan, csv.ScanCount);
                }
            }
            else
            {
                csvHelper csvHelper = new csvHelper();
                csvHelper.writeCVSFile(reportOutputs, token);
            }
            return(true);
        }
Beispiel #5
0
        public bool waitForResult(List <ReportTrace> trace, getScanResults scanResults, List <ReportResultAll> resultNew, Dictionary <DateTimeOffset, Dictionary <long, Dictionary <string, ReportResultExtended> > > extendedScan, Dictionary <long, ReportStaging> end, Dictionary <long, List <ReportResultAll> > last)
        {
            bool     waitFlag     = false;
            DateTime wait_expired = DateTime.UtcNow;

            while (!waitFlag)
            {
                if (wait_expired.AddMinutes(2) < DateTime.UtcNow)
                {
                    Console.Error.WriteLine("waitForResult timeout! {0}", getTimeOutObjects(trace));
                    break;
                }

                if (token.debug && token.verbosity > 0)
                {
                    Console.WriteLine("Sleeping 3 second(s)");
                }
                Thread.Sleep(3000);

                foreach (ReportTrace rt in trace)
                {
                    waitFlag = true;
                    if (!rt.isRead)
                    {
                        waitFlag = false;
                        if (rt.TimeStamp.AddMinutes(2) < DateTime.UtcNow)
                        {
                            Console.Error.WriteLine("ReportId/ScanId {0}/{1} timeout!", rt.reportId, rt.scanId);
                            rt.isRead = true;
                            continue;
                        }
                        if (scanResults.GetResultStatus(rt.reportId, token))
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Got status for reportId {0}", rt.reportId);
                            }
                            Thread.Sleep(2000);
                            var result = scanResults.GetResult(rt.reportId, token);
                            if (result != null)
                            {
                                if (token.debug && token.verbosity > 0)
                                {
                                    Console.WriteLine("Got data for reportId {0}", rt.reportId);
                                }
                                if (process_CxResponse(result, rt.reportId, rt.projectId, rt.scanTime, extendedScan))
                                {
                                    rt.isRead = true;
                                    getlastReport(result, end, last);
                                }
                                else
                                {
                                    rt.isRead = true;
                                    Console.Error.WriteLine("Failed processing reportId {0}", rt.reportId);
                                    if (token.debug && token.verbosity > 1)
                                    {
                                        Console.Error.WriteLine("Dumping XML:");
                                        Console.Error.Write(result.ToString());
                                    }
                                }
                            }
                            else
                            {
                                Console.Error.WriteLine("Failed retrieving reportId {0}", rt.reportId);
                                rt.isRead = true;
                            }
                        }
                        else
                        {
                            if (token.debug && token.verbosity > 0)
                            {
                                Console.WriteLine("Waiting for reportId {0}", rt.reportId);
                            }
                        }
                    }
                }
            }
            return(true);
        }