public void CreateOrUpdateDupExTest()
        {
            TransitReferrerHost host = new TransitReferrerHost();

            host.LastSource   = string.Format("http://{0}", Guid.NewGuid().ToString());
            host.LastUrl      = string.Format("http://{0}", Guid.NewGuid().ToString());
            host.Name         = Guid.NewGuid().ToString();
            host.RequestCount = 1;
            host.Id           = Blog.CreateOrUpdateReferrerHost(Ticket, host);

            string rollupname = Guid.NewGuid().ToString();

            TransitReferrerHostRollup rollup = new TransitReferrerHostRollup();

            rollup.Name   = string.Format("%.{0}", rollupname);
            rollup.Rollup = host.Name;
            rollup.Id     = Blog.CreateOrUpdateReferrerHostRollup(Ticket, rollup);

            TransitReferrerHost host2 = new TransitReferrerHost();

            host2.LastSource   = host2.LastUrl = string.Format("http://{0}", Guid.NewGuid().ToString());
            host2.Name         = string.Format("www.{0}", rollupname);
            host2.RequestCount = 1;
            host2.Id           = Blog.CreateOrUpdateReferrerHost(Ticket, host2);

            Assert.AreEqual(host.Id, host2.Id, "Rollup did not translate a LIKE host.");

            Blog.DeleteReferrerHost(Ticket, host.Id);
            Blog.DeleteReferrerHostRollup(Ticket, rollup.Id);
        }
 public BlogReferrerHostTest()
 {
     mReferrerHost              = new TransitReferrerHost();
     mReferrerHost.Name         = Guid.NewGuid().ToString();
     mReferrerHost.LastSource   = string.Format("http://{0}", Guid.NewGuid().ToString());
     mReferrerHost.LastUrl      = string.Format("http://{0}", Guid.NewGuid().ToString());
     mReferrerHost.RequestCount = 1;
 }
Beispiel #3
0
        public void ExistingReferrerHostRollupTest()
        {
            int count = 10;
            // create hosts
            TransitReferrerHost host = new TransitReferrerHost();

            host.LastSource   = host.LastUrl = "http://localhost";
            host.RequestCount = 1;

            string root = Guid.NewGuid().ToString();

            for (int i = 0; i < count; i++)
            {
                host.Name = string.Format("www.{0}.{1}", root, i);
                Blog.CreateOrUpdateReferrerHost(Ticket, host);
                Console.WriteLine("Created {0}", host.Name);
            }

            // create a rollup, should merge hosts
            TransitReferrerHostRollup rollup = new TransitReferrerHostRollup();

            rollup.Name   = string.Format("www.{0}.%", root);
            rollup.Rollup = string.Format("www.{0}.target", root);
            rollup.Id     = Blog.CreateOrUpdateReferrerHostRollup(Ticket, rollup);

            // additional host will auto-rollup
            for (int i = 0; i < count; i++)
            {
                host.Name = string.Format("www.{0}.{1}", root, i);
                Blog.CreateOrUpdateReferrerHost(Ticket, host);
                Console.WriteLine("Created {0}", host.Name);
            }

            // get the rollup host
            TransitReferrerHost[] hosts = Blog.GetReferrerHosts(Ticket, null);

            bool found = false;

            foreach (TransitReferrerHost rh in hosts)
            {
                if (rh.Name == rollup.Rollup)
                {
                    Console.WriteLine("Found {0} with {1} hits", rh.Name, rh.RequestCount);
                    Assert.AreEqual(rh.RequestCount, count * 2);
                    found = true;
                    Blog.DeleteReferrerHost(Ticket, rh.Id);
                }
            }

            Assert.IsTrue(found);
            Blog.DeleteReferrerHostRollup(Ticket, rollup.Id);
        }
Beispiel #4
0
        public void CreateOrUpdateStatsTest()
        {
            TransitReferrerHost host = new TransitReferrerHost();

            host.LastSource   = Guid.NewGuid().ToString();
            host.LastUrl      = Guid.NewGuid().ToString();
            host.Name         = Guid.NewGuid().ToString();
            host.RequestCount = 1;
            host.Id           = Blog.CreateOrUpdateReferrerHost(Ticket, host);

            TransitBrowser browser = new TransitBrowser();

            browser.Name     = Guid.NewGuid().ToString();
            browser.Platform = Guid.NewGuid().ToString();
            browser.Version  = Guid.NewGuid().ToString().Substring(0, 10);
            browser.Id       = Blog.CreateOrUpdateBrowser(Ticket, browser);

            TransitReferrerSearchQuery query = new TransitReferrerSearchQuery();

            query.RequestCount = 1;
            query.SearchQuery  = Guid.NewGuid().ToString();
            query.Id           = Blog.CreateOrUpdateReferrerSearchQuery(Ticket, query);

            List <TransitReferrerHost> hosts = new List <TransitReferrerHost>();

            hosts.Add(host);

            List <TransitBrowser> browsers = new List <TransitBrowser>();

            browsers.Add(browser);

            List <TransitReferrerSearchQuery> queries = new List <TransitReferrerSearchQuery>();

            queries.Add(query);

            int result = Blog.CreateOrUpdateStats(Ticket, browsers.ToArray(), hosts.ToArray(), queries.ToArray());

            Assert.AreEqual(result, Math.Max(Math.Max(browsers.Count, hosts.Count), queries.Count));

            Blog.DeleteReferrerHost(Ticket, host.Id);
            Blog.DeleteBrowser(Ticket, browser.Id);
            Blog.DeleteReferrerSearchQuery(Ticket, query.Id);
        }
Beispiel #5
0
    public void Flush(SessionManager manager)
    {
        if (mRequests == null)
        {
            return;
        }

        List <TransitBrowser>             browsers = new List <TransitBrowser>();
        List <TransitReferrerHost>        rhs      = new List <TransitReferrerHost>();
        List <TransitReferrerSearchQuery> rsqs     = new List <TransitReferrerSearchQuery>();

        // TODO: use a unique sorted collection

        foreach (HttpRequest request in mRequests)
        {
            try
            {
                if (request.Browser != null)
                {
                    TransitBrowser browser = new TransitBrowser();
                    browser.Name     = request.Browser.Browser;
                    browser.Platform = request.Browser.Platform;
                    browser.Version  = request.Browser.Version;
                    browsers.Add(browser);
                }

                string host = string.Empty;
                try
                {
                    host = request.Url.Host;
                }
                catch (ArgumentException)
                {
                    // host isn't available on localhost
                }

                string urlreferrer = string.Empty;
                try
                {
                    if (request.UrlReferrer != null)
                    {
                        urlreferrer = request.UrlReferrer.Host;
                    }
                }
                catch (ArgumentException)
                {
                    // referrer host not available
                }

                // don't track navigation between pages
                if (!string.IsNullOrEmpty(urlreferrer) && urlreferrer != host)
                {
                    TransitReferrerHost rh = new TransitReferrerHost();
                    rh.Name         = request.UrlReferrer.Host;
                    rh.LastSource   = request.UrlReferrer.ToString();
                    rh.LastUrl      = request.RawUrl;
                    rh.RequestCount = 1;
                    rhs.Add(rh);

                    string q = request.QueryString["q"];
                    if (string.IsNullOrEmpty(q))
                    {
                        q = request.QueryString["s"];
                    }
                    if (string.IsNullOrEmpty(q))
                    {
                        q = request.QueryString["search"];
                    }
                    if (string.IsNullOrEmpty(q))
                    {
                        q = request.QueryString["query"];
                    }

                    if (!string.IsNullOrEmpty(q))
                    {
                        TransitReferrerSearchQuery trsq = new TransitReferrerSearchQuery();
                        trsq.RequestCount = 1;
                        trsq.SearchQuery  = q;
                        rsqs.Add(trsq);
                    }
                }
            }
            catch (Exception ex)
            {
                manager.BlogService.EventLogWriteEntry(string.Format("CreateOrUpdateStats for a single request failed. {0}",
                                                                     ex.Message), EventLogEntryType.Warning);
            }
        }

        try
        {
            manager.BlogService.CreateOrUpdateStats(
                manager.Ticket, browsers.ToArray(), rhs.ToArray(), rsqs.ToArray());
        }
        catch (Exception ex)
        {
            manager.BlogService.EventLogWriteEntry(string.Format("CreateOrUpdateStats failed. {0}",
                                                                 ex.Message), EventLogEntryType.Error);
        }

        mRequests = new List <HttpRequest>();

        try
        {
            manager.BlogService.IncrementPostCounters(manager.Ticket, mPostCounters.ToArray());
        }
        catch (Exception ex)
        {
            manager.BlogService.EventLogWriteEntry(string.Format("IncrementPostCounters failed. {0}",
                                                                 ex.Message), EventLogEntryType.Error);
        }

        mPostCounters = new List <int>();

        try
        {
            manager.BlogService.IncrementImageCounters(manager.Ticket, mImageCounters.ToArray());
        }
        catch (Exception ex)
        {
            manager.BlogService.EventLogWriteEntry(string.Format("IncrementImageCounters failed. {0}",
                                                                 ex.Message), EventLogEntryType.Error);
        }

        mImageCounters = new List <int>();

        LastFlush = DateTime.UtcNow;
    }