Example #1
0
        private PerformanceData GetPagePerformance(Uri root, Uri uri)
        {
            SqlConnectionInfo sci  = SqlTrace.GetTraceSqlConnectionInfo();
            Server            srvr = new Server(sci.ServerName);

            Assert.AreNotEqual("SqlServer Express not supported.", srvr.Information.Edition, "Express Edition");
            TraceServer traceServerReader = SqlTrace.BeginTrace(sci);

            TestPage(root, uri);
            return(SqlTrace.EndTrace(uri.ToString(), traceServerReader));
        }
Example #2
0
        public void TestDeep(Cookie cookie, SqlConnectionInfo sci)
        {
            Uri root = new Uri("http://localhost/SnCoreWeb/Default.aspx");

            List <Uri> queue   = new List <Uri>(2500);
            List <Uri> visited = new List <Uri>(5000);

            PerformanceDataCollection perfdata = (sci == null ? null : new PerformanceDataCollection());

            double totaltime  = 0;
            int    totalcount = 0;

            queue.Add(root);

            Dictionary <Uri, Uri> references = new Dictionary <Uri, Uri>();

            references.Add(root, new Uri("http://localhost/SnCoreWeb/"));

            while (queue.Count > 0)
            {
                Uri        topofqueue = queue[0];
                List <Uri> links;
                double     ts = 0;

                PerformanceData perf = (perfdata != null ? new PerformanceData(topofqueue.ToString()) : null);
                try
                {
                    TraceServer traceServerReader = (sci == null ? null : SqlTrace.BeginTrace(sci));
                    TestPage(references[topofqueue], topofqueue, cookie, out links, out ts);
                    if (perfdata != null)
                    {
                        perfdata.Add(SqlTrace.EndTrace(topofqueue.ToString(), traceServerReader));
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    Console.WriteLine("{0}: {1}", topofqueue, ex.Message);
                    throw ex;
                }
                finally
                {
                    totalcount++;
                    totaltime += ts;
                    // add to visited links
                    visited.Add(topofqueue);
                    // remove from queue
                    queue.RemoveAt(0);
                }

                if (perfdata != null)
                {
                    perfdata.Add(perf);
                }

                // -----------------
                Console.Write("{0}/{1} [avg: {2}]", totalcount, queue.Count, (totaltime / totalcount).ToString("0.00"));
                if (perf != null)
                {
                    Console.Write("[SQL: {0} in {1}] ", perf.Queries, perf.TotalDuration);
                }
                Console.Write(" => ");

                int count = 0;
                foreach (Uri uri in links)
                {
                    Uri fulluri = uri;

                    if (!root.IsBaseOf(fulluri))
                    {
                        // Console.WriteLine("\tSkipping {0}.", uri);
                        continue;
                    }

                    if (references.ContainsKey(fulluri) || queue.Contains(fulluri) || visited.Contains(fulluri))
                    {
                        continue;
                    }

                    if (fulluri.PathAndQuery.Contains("/docs/html/"))
                    {
                        continue;
                    }

                    Assert.IsFalse(fulluri.ToString().Contains("\0"),
                                   string.Format("Uri {0} in {1} contains non-ASCII character.", fulluri, topofqueue));

                    Assert.IsFalse(fulluri.ToString().Contains("<%"),
                                   string.Format("Uri {0} in {1} contains non-executed ASP.NET code.", fulluri, topofqueue));

                    Assert.IsFalse(fulluri.ToString().Contains("id=0"),
                                   string.Format("Uri {0} in {1} contains a link to a zero id.", fulluri, topofqueue));

                    references.Add(fulluri, topofqueue);

                    // Console.WriteLine("\tAdding {0}.", fulluri.OriginalString);
                    queue.Add(fulluri);
                    count++;
                }

                if ((perfdata != null) && (((totalcount > 0) && ((totalcount % 100) == 0)) || (queue.Count == 0)))
                {
                    perfdata.DumpPigs();
                }
            }
        }