private string GenerateReportEmailBody(DateTime reportDate) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(GetStyleSheet()); sb.Append("<p><table><tr><td class=\"mainheader\" width=\"100%\">Weblog Daily Email Report (" + reportDate.ToLongDateString() + " UTC)</td></tr></table></p>"); try { Hashtable referrerUrls = new Hashtable(); Hashtable userAgents = new Hashtable(); Hashtable searchUrls = new Hashtable(); Hashtable userDomains = new Hashtable(); SiteConfig siteConfig = SiteConfig.GetSiteConfig( configPath ); ILoggingDataService logService = LoggingDataServiceFactory.GetService(logPath); string siteRoot = siteConfig.Root.ToUpper(); LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetReferralsForDay(reportDate)); foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); // Let Utils.ParseSearchString decide whether it's a search engine referrer. HyperLink link = SiteUtilities.ParseSearchString(log.UrlReferrer); if (link != null) { string linktext = "<a href=\"" + link.NavigateUrl + "\">" + link.Text + "</a>"; exclude = true; if (!searchUrls.Contains(linktext)) { searchUrls[linktext] = 0; } searchUrls[linktext] = ((int) searchUrls[linktext]) + 1; } } if (!exclude) { string linktext = log.UrlReferrer; if (linktext.Length > 0) linktext = "<a href=\"" + log.UrlReferrer + "\">" + log.UrlReferrer + "</a>"; if (!referrerUrls.Contains(linktext)) { referrerUrls[linktext] = 0; } referrerUrls[linktext] = ((int) referrerUrls[linktext]) + 1; log.UserAgent = HttpUtility.HtmlEncode(log.UserAgent); if (!userAgents.Contains(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = ((int) userAgents[log.UserAgent]) + 1; log.UserDomain = HttpUtility.HtmlEncode(log.UserDomain); if(!userDomains.Contains(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = ((int) userDomains[log.UserDomain]) + 1; } } sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("Summary", "Hits")); sb.Append(MakeTableRow("Internet Searches", GetTotal(searchUrls))); sb.Append(MakeTableRow("Referrers", GetTotal(referrerUrls) )); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("Internet Searches", "Count")); sb.Append(MakeTableRowsFromArray(searchUrls)); sb.Append("</table>"); sb.Append("</p>"); sb.Append( "<p>"); sb.Append( "<table width=\"100%\">"); sb.Append( MakeTableHeader("Referrers", "Count")); sb.Append( MakeTableRowsFromArray(referrerUrls)); sb.Append( "</table>"); sb.Append( "</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("User Agents", "Count")); sb.Append(MakeTableRowsFromArray(userAgents)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("User Domains", "Count")); sb.Append(MakeTableRowsFromArray(userDomains)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<br/><br/>"); } catch ( Exception e) { sb.Append("<p>Error : " + e.ToString() + "</p>"); } return sb.ToString(); }
private void CrosspostReferrersBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); string siteRoot = siteConfig.Root.ToUpper(); Dictionary<string, int> CrosspostReferrerUrls = new Dictionary<string, int>(); Dictionary<string, int> userAgents = new Dictionary<string, int>(); Dictionary<string, int> referrerUrls = new Dictionary<string, int>(); Dictionary<string, int> userDomains = new Dictionary<string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetCrosspostReferrersForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetCrosspostReferrersForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetCrosspostReferrersForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); } if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { if (!referrerUrls.ContainsKey(log.UrlReferrer)) { referrerUrls[log.UrlReferrer] = 0; } referrerUrls[log.UrlReferrer] = referrerUrls[log.UrlReferrer] + 1; if (!CrosspostReferrerUrls.ContainsKey(log.UrlRequested)) { CrosspostReferrerUrls[log.UrlRequested] = 0; } CrosspostReferrerUrls[log.UrlRequested] = CrosspostReferrerUrls[log.UrlRequested] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if(!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(CrosspostReferrerUrls), resmgr.GetString("text_activity_read_posts"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildCrosspostReferrersRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(referrerUrls), resmgr.GetString("text_activity_referrer_urls"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildReferrerRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private void ClickThroughsBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); Dictionary <string, int> clickThroughUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetClickThroughsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetClickThroughsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetClickThroughsForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { string key = log.UrlRequested + "°" + log.UrlReferrer; if (!clickThroughUrls.ContainsKey(key)) { clickThroughUrls[key] = 0; } clickThroughUrls[key] = clickThroughUrls[key] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(clickThroughUrls), resmgr.GetString("text_activity_click_throughs"), resmgr.GetString("text_activity_clicks"), new StatisticsBuilderCallback(this.BuildClickThroughsRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private void ClickThroughsBox_PreRender(object sender, EventArgs e) { if (_robotDefinition == null) { return; } Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); Dictionary <string, int> clickThroughUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); DateTime serverTimeUtc = DateTime.Now.ToUniversalTime(); DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(serverTimeUtc); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day); serverTimeUtc = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, 23, 59, 59).ToUniversalTime(); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc)); // depending on the offset (positive or negative) we want to grab events in the // next or previos day to account for timezone difference. if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.Now); int offset = ts.Hours; if (serverTimeUtc.Date != serverTimeUtc.AddHours(offset).Date) { logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc.AddHours(offset))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (_robotDefinition.IsRobot(log)) { exclude = true; } if (!exclude) { string key = log.UrlRequested + "°" + log.UrlReferrer; if (!clickThroughUrls.ContainsKey(key)) { clickThroughUrls[key] = 0; } clickThroughUrls[key] = clickThroughUrls[key] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; // AG User domain added. if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(clickThroughUrls), resmgr.GetString("text_activity_click_throughs"), resmgr.GetString("text_activity_clicks"), new StatisticsBuilderCallback(this.BuildClickThroughsRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private string GenerateReportEmailBody(DateTime reportDate) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append(GetStyleSheet()); sb.Append("<p><table><tr><td class=\"mainheader\" width=\"100%\">Weblog Daily Email Report (" + reportDate.ToLongDateString() + " UTC)</td></tr></table></p>"); try { Dictionary <string, int> referrerUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> searchUrls = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); SiteConfig siteConfig = SiteConfig.GetSiteConfig(configPath); ILoggingDataService logService = LoggingDataServiceFactory.GetService(logPath); string siteRoot = siteConfig.Root.ToUpper(); LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetReferralsForDay(reportDate)); foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); // Let Utils.ParseSearchString decide whether it's a search engine referrer. HyperLink link = SiteUtilities.ParseSearchString(log.UrlReferrer); if (link != null) { string linktext = "<a href=\"" + link.NavigateUrl + "\">" + link.Text + "</a>"; exclude = true; if (!searchUrls.ContainsKey(linktext)) { searchUrls[linktext] = 0; } searchUrls[linktext] = searchUrls[linktext] + 1; } } if (!exclude) { string linktext = log.UrlReferrer; if (linktext.Length > 0) { linktext = "<a href=\"" + log.UrlReferrer + "\">" + log.UrlReferrer + "</a>"; } if (!referrerUrls.ContainsKey(linktext)) { referrerUrls[linktext] = 0; } referrerUrls[linktext] = referrerUrls[linktext] + 1; log.UserAgent = HttpUtility.HtmlEncode(log.UserAgent); if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; log.UserDomain = HttpUtility.HtmlEncode(log.UserDomain); if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("Summary", "Hits")); sb.Append(MakeTableRow("Internet Searches", GetTotal(searchUrls))); sb.Append(MakeTableRow("Referrers", GetTotal(referrerUrls))); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("Internet Searches", "Count")); sb.Append(MakeTableRowsFromArray(searchUrls)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("Referrers", "Count")); sb.Append(MakeTableRowsFromArray(referrerUrls)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("User Agents", "Count")); sb.Append(MakeTableRowsFromArray(userAgents)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<p>"); sb.Append("<table width=\"100%\">"); sb.Append(MakeTableHeader("User Domains", "Count")); sb.Append(MakeTableRowsFromArray(userDomains)); sb.Append("</table>"); sb.Append("</p>"); sb.Append("<br/><br/>"); } catch (Exception e) { sb.Append("<p>Error : " + e.ToString() + "</p>"); } return(sb.ToString()); }
private void ReferrersBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); string siteRoot = siteConfig.Root.ToUpper(); Dictionary <string, int> referrerUrls = new Dictionary <string, int>(); Dictionary <string, int> userAgents = new Dictionary <string, int>(); Dictionary <string, int> searchUrls = new Dictionary <string, int>(); Dictionary <string, int> userDomains = new Dictionary <string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetReferralsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); // Let Utils.ParseSearchString decide whether it's a search engine referrer. if (SiteUtilities.ParseSearchString(log.UrlReferrer) != null) { exclude = true; bool addToSearches = true; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { addToSearches = false; } } if (addToSearches) { if (!searchUrls.ContainsKey(log.UrlReferrer)) { searchUrls[log.UrlReferrer] = 0; } searchUrls[log.UrlReferrer] = searchUrls[log.UrlReferrer] + 1; } } } if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { if (!referrerUrls.ContainsKey(log.UrlReferrer)) { referrerUrls[log.UrlReferrer] = 0; } referrerUrls[log.UrlReferrer] = referrerUrls[log.UrlReferrer] + 1; log.UserAgent = Server.HtmlEncode(log.UserAgent); if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } Table rollupTable = new Table(); rollupTable.CssClass = "statsTableStyle"; TableRow row = new TableRow(); row.CssClass = "statsTableHeaderRowStyle"; row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells[0].CssClass = "statsTableHeaderColumnStyle"; row.Cells[1].CssClass = "statsTableHeaderNumColumnStyle"; row.Cells[0].Text = resmgr.GetString("text_activity_summary"); row.Cells[1].Text = resmgr.GetString("text_activity_hits"); rollupTable.Rows.Add(row); //SDH: I know this is gross, but I didn't want to totally rewrite this whole thing, I just wanted to get the rollup to work string total = String.Empty; Table internetSearchesTable = BuildStatisticsTable(GenerateSortedSearchStringItemList(searchUrls), resmgr.GetString("text_activity_internet_searches"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildSearchesRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_internet_searches")); Table userDomainsTable = BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), out total, null); Table userAgentsTable = BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null); Table referrerUrlsTable = BuildStatisticsTable(GenerateSortedItemList(referrerUrls), resmgr.GetString("text_activity_referrer_urls"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildReferrerRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_referrer_urls")); root.Controls.Add(rollupTable); root.Controls.Add(internetSearchesTable); root.Controls.Add(referrerUrlsTable); root.Controls.Add(userDomainsTable); root.Controls.Add(userAgentsTable); //root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), CONSTUSERAGENTSLIST, CONSTHITS, new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null)); DataBind(); }
private void ClickThroughsBox_PreRender(object sender, EventArgs e) { if (_robotDefinition == null) { return; } Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); IBlogDataService dataService = BlogDataServiceFactory.GetService(SiteConfig.GetContentPathFromCurrentContext(), logService); Dictionary<string, int> clickThroughUrls = new Dictionary<string, int>(); Dictionary<string, int> userAgents = new Dictionary<string, int>(); Dictionary<string, int> userDomains = new Dictionary<string, int>(); DateTime serverTimeUtc = DateTime.Now.ToUniversalTime(); DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(serverTimeUtc); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day); serverTimeUtc = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, 23, 59, 59).ToUniversalTime(); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc)); // depending on the offset (positive or negative) we want to grab events in the // next or previos day to account for timezone difference. if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.Now); int offset = ts.Hours; if (serverTimeUtc.Date != serverTimeUtc.AddHours(offset).Date) logItems.AddRange(logService.GetClickThroughsForDay(serverTimeUtc.AddHours(offset))); } foreach (LogDataItem log in logItems) { bool exclude = false; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (_robotDefinition.IsRobot(log)) { exclude = true; } if (!exclude) { string key = log.UrlRequested + "°" + log.UrlReferrer; if (!clickThroughUrls.ContainsKey(key)) { clickThroughUrls[key] = 0; } clickThroughUrls[key] = clickThroughUrls[key] + 1; if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; // AG User domain added. if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(clickThroughUrls), resmgr.GetString("text_activity_click_throughs"), resmgr.GetString("text_activity_clicks"), new StatisticsBuilderCallback(this.BuildClickThroughsRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), dataService)); root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), dataService)); DataBind(); }
private void ReferrersBox_PreRender(object sender, EventArgs e) { Control root = contentPlaceHolder; SiteConfig siteConfig = SiteConfig.GetSiteConfig(); ILoggingDataService logService = LoggingDataServiceFactory.GetService(SiteConfig.GetLogPathFromCurrentContext()); string siteRoot = siteConfig.Root.ToUpper(); Dictionary<string, int> referrerUrls = new Dictionary<string, int>(); Dictionary<string, int> userAgents = new Dictionary<string, int>(); Dictionary<string, int> searchUrls = new Dictionary<string, int>(); Dictionary<string, int> userDomains = new Dictionary<string, int>(); // get the user's local time DateTime utcTime = DateTime.UtcNow; DateTime localTime = siteConfig.GetConfiguredTimeZone().ToLocalTime(utcTime); if (Request.QueryString["date"] != null) { try { DateTime popUpTime = DateTime.ParseExact(Request.QueryString["date"], "yyyy-MM-dd", CultureInfo.InvariantCulture); utcTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, utcTime.Hour, utcTime.Minute, utcTime.Second); localTime = new DateTime(popUpTime.Year, popUpTime.Month, popUpTime.Day, localTime.Hour, localTime.Minute, localTime.Second); } catch (FormatException ex) { ErrorTrace.Trace(System.Diagnostics.TraceLevel.Error, ex); } } LogDataItemCollection logItems = new LogDataItemCollection(); logItems.AddRange(logService.GetReferralsForDay(localTime)); if (siteConfig.AdjustDisplayTimeZone) { newtelligence.DasBlog.Util.WindowsTimeZone tz = siteConfig.GetConfiguredTimeZone(); TimeSpan ts = tz.GetUtcOffset(DateTime.UtcNow); int offset = ts.Hours; if (offset < 0) { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(1))); } else { logItems.AddRange(logService.GetReferralsForDay(localTime.AddDays(-1))); } } foreach (LogDataItem log in logItems) { bool exclude = false; if (log.UrlReferrer != null) { exclude = log.UrlReferrer.ToUpper().StartsWith(siteRoot); // Let Utils.ParseSearchString decide whether it's a search engine referrer. if (SiteUtilities.ParseSearchString(log.UrlReferrer) != null) { exclude = true; bool addToSearches = true; if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { addToSearches = false; } } if (addToSearches) { if (!searchUrls.ContainsKey(log.UrlReferrer)) { searchUrls[log.UrlReferrer] = 0; } searchUrls[log.UrlReferrer] = searchUrls[log.UrlReferrer] + 1; } } } if (siteConfig.AdjustDisplayTimeZone) { if (siteConfig.GetConfiguredTimeZone().ToLocalTime(log.RequestedUtc).Date != localTime.Date) { exclude = true; } } if (!exclude) { if (!referrerUrls.ContainsKey(log.UrlReferrer)) { referrerUrls[log.UrlReferrer] = 0; } referrerUrls[log.UrlReferrer] = referrerUrls[log.UrlReferrer] + 1; log.UserAgent = Server.HtmlEncode(log.UserAgent); if (!userAgents.ContainsKey(log.UserAgent)) { userAgents[log.UserAgent] = 0; } userAgents[log.UserAgent] = userAgents[log.UserAgent] + 1; if (!userDomains.ContainsKey(log.UserDomain)) { userDomains[log.UserDomain] = 0; } userDomains[log.UserDomain] = userDomains[log.UserDomain] + 1; } } Table rollupTable = new Table(); rollupTable.CssClass = "statsTableStyle"; TableRow row = new TableRow(); row.CssClass = "statsTableHeaderRowStyle"; row.Cells.Add(new TableCell()); row.Cells.Add(new TableCell()); row.Cells[0].CssClass = "statsTableHeaderColumnStyle"; row.Cells[1].CssClass = "statsTableHeaderNumColumnStyle"; row.Cells[0].Text = resmgr.GetString("text_activity_summary"); row.Cells[1].Text = resmgr.GetString("text_activity_hits"); rollupTable.Rows.Add(row); //SDH: I know this is gross, but I didn't want to totally rewrite this whole thing, I just wanted to get the rollup to work string total = String.Empty; Table internetSearchesTable = BuildStatisticsTable(GenerateSortedSearchStringItemList(searchUrls), resmgr.GetString("text_activity_internet_searches"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildSearchesRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_internet_searches")); Table userDomainsTable = BuildStatisticsTable(GenerateSortedItemList(userDomains), resmgr.GetString("text_activity_user_domains"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildUserDomainRow), out total, null); Table userAgentsTable = BuildStatisticsTable(GenerateSortedItemList(userAgents), resmgr.GetString("text_activity_user_agent"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null); Table referrerUrlsTable = BuildStatisticsTable(GenerateSortedItemList(referrerUrls), resmgr.GetString("text_activity_referrer_urls"), resmgr.GetString("text_activity_hits"), new StatisticsBuilderCallback(this.BuildReferrerRow), out total, null); BuildRow(total, rollupTable, resmgr.GetString("text_activity_referrer_urls")); root.Controls.Add(rollupTable); root.Controls.Add(internetSearchesTable); root.Controls.Add(referrerUrlsTable); root.Controls.Add(userDomainsTable); root.Controls.Add(userAgentsTable); //root.Controls.Add(BuildStatisticsTable(GenerateSortedItemList(userAgents), CONSTUSERAGENTSLIST, CONSTHITS, new StatisticsBuilderCallback(this.BuildAgentsRow), out total, null)); DataBind(); }