Ejemplo n.º 1
0
        public int CreateOrUpdateStats(string ticket, TransitBrowser[] t_browsers, TransitReferrerHost[] t_rhs, TransitReferrerSearchQuery[] t_rsqs)
        {
            using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
            {
                ISession session = DBlog.Data.Hibernate.Session.Current;
                int increment = 0;

                if (t_browsers != null)
                {
                    if (t_browsers.Length > increment) increment = t_browsers.Length;
                    foreach (TransitBrowser t_browser in t_browsers)
                    {
                        Browser browser = t_browser.GetBrowser(session);
                        session.SaveOrUpdate(browser);
                    }
                }

                if (t_rhs != null)
                {
                    if (t_rhs.Length > increment) increment = t_rhs.Length;
                    foreach (TransitReferrerHost t_rh in t_rhs)
                    {
                        ReferrerHost rh = t_rh.GetReferrerHost(session);
                        session.SaveOrUpdate(rh);
                    }
                }

                if (t_rsqs != null)
                {
                    if (t_rsqs.Length > increment) increment = t_rsqs.Length;
                    foreach (TransitReferrerSearchQuery t_rsq in t_rsqs)
                    {
                        ReferrerSearchQuery rsq = t_rsq.GetReferrerSearchQuery(session);
                        session.SaveOrUpdate(rsq);
                    }
                }

                TransitCounter.IncrementCounters(session, increment);

                session.Flush();
                return Math.Max(t_browsers.Length, t_rhs.Length);
            }
        }
Ejemplo n.º 2
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;
    }
Ejemplo n.º 3
0
 public int CreateOrUpdateReferrerHost(string ticket, TransitReferrerHost t_referrerhost)
 {
     using (DBlog.Data.Hibernate.Session.OpenConnection(GetNewConnection()))
     {
         ISession session = DBlog.Data.Hibernate.Session.Current;
         CheckAdministrator(session, ticket);
         ReferrerHost referrerhost = t_referrerhost.GetReferrerHost(session);
         session.SaveOrUpdate(referrerhost);
         session.Flush();
         return referrerhost.Id;
     }
 }