/// <summary> /// Records the request in the database for statistics/tracking purposes. /// </summary> /// <param name="ev">The ev.</param> /// <returns></returns> public static void Track(EntryView ev) { if(QueueStats) { Stats.AddQuedStats(ev); } else { Stats.TrackEntry(ev); } }
public void RecordAggregatorView(EntryView entryView) { if (!Settings.EnableAggBugs || SubtextContext.HttpContext.Request.HttpMethod == "POST") { return; } entryView.PageViewType = PageViewType.AggView; try { SubtextContext.Repository.TrackEntry(entryView); } catch (SqlException e) { Log.Error("Could not record Aggregator view", e); } }
public ActionResult RecordAggregatorView(int id) { if (CachedVersionIsOkay(SubtextContext.HttpContext.Request)) { return new NotModifiedResult(); } if (id > 0) { var entryView = new EntryView { BlogId = SubtextContext.Blog.Id, EntryId = id, PageViewType = PageViewType.AggView }; StatisticsService.RecordAggregatorView(entryView); } return new CacheableFileContentResult(AggregatorOnePixelBlankGif, "image/gif", DateTime.UtcNow, HttpCacheability.Public); }
/// <summary> /// Adds <see cref="EntryView"/> instance to the stats queue. /// </summary> /// <param name="entryView">Ev.</param> /// <returns></returns> public static void AddQuedStats(EntryView entryView) { //Check for the limit if (queuedStatsList.Count >= Config.Settings.Tracking.QueueStatsCount) { //aquire the lock using(TimedLock.Lock(queuedStatsList)) { //make sure the pool queue was not cleared during a wait for the lock if(queuedStatsList.Count >= Config.Settings.Tracking.QueueStatsCount) { EntryView[] entryViewCopies = new EntryView[queuedStatsList.Count]; queuedStatsList.CopyTo(entryViewCopies, 0); ClearTrackEntryQueue(new List<EntryView>(entryViewCopies)); queuedStatsList.Clear(); } } } queuedStatsList.Add(entryView); }
public void CanSetAndGetSimpleProperties() { var view = new EntryView(); UnitTestHelper.AssertSimpleProperties(view); }
public void Create(int index) { EntryView view = new EntryView(); view.EntryId = entryId; view.BlogId = Config.CurrentBlog.Id; view.PageViewType = PageViewType.WebView; view.ReferralUrl = string.Format("http://localhost:{0}/{1}/", index, UnitTestHelper.GenerateRandomString()); Stats.AddQuedStats(view); Stats.ClearQueue(true); Thread.Sleep(100); //There's no way to fully wait for the worker processes. }
public void RecordWebView(EntryView entryView) { if (!Settings.EnableWebStats || SubtextContext.HttpContext.Request.HttpMethod == "POST") { return; } entryView.ReferralUrl = GetReferral(SubtextContext); entryView.PageViewType = PageViewType.WebView; try { SubtextContext.Repository.TrackEntry(entryView); } catch (Exception e) { // extra precautions for web view because it's not done via image bug. Log.Error("Could not record Web view", e); } }
/// <summary> /// Records the request in the database for statistics/tracking purposes. /// </summary> /// <param name="context">The context.</param> /// <param name="EntryID">The entry ID.</param> /// <param name="BlogId">The blog ID.</param> /// <returns></returns> public static void Track(HttpContext context, int EntryID, int BlogId) { if (context == null) { throw new ArgumentNullException("context", Resources.ArgumentNull_Generic); } if (!WebTrack || !FilterUserAgent(context.Request.UserAgent) || context.Request.HttpMethod == "POST") return; string refUrl = GetReferral(context.Request); EntryView ev = new EntryView(); ev.EntryId = EntryID; ev.BlogId = BlogId; ev.ReferralUrl = refUrl; ev.PageViewType = PageViewType.WebView; Track(ev); }
/// <summary> /// Clears the queue of statistics. If save is specified, then /// stats are saved to an <see cref="EntryView"/> /// </summary> /// <param name="save">Save.</param> /// <returns></returns> public static void ClearQueue(bool save) { using(TimedLock.Lock(queuedStatsList)) { if(save) { EntryView[] entryViews = new EntryView[queuedStatsList.Count]; queuedStatsList.CopyTo(entryViews, 0); ClearTrackEntryQueue(new List<EntryView>(entryViews)); } queuedStatsList.Clear(); } }
public override bool TrackEntry(EntryView entryView) { return ThreadHelper.FireAndForget(o => _procedures.TrackEntry(entryView.EntryId, entryView.BlogId, entryView.ReferralUrl, entryView.PageViewType == PageViewType.WebView), "Exception while tracking an entry"); }
private static void TrackReferral(int entryId) { EntryView referral = new EntryView(); referral.EntryId = entryId; referral.BlogId = Config.CurrentBlog.Id; referral.PageViewType = PageViewType.WebView; referral.ReferralUrl = "http://haacked.com/"; Stats.TrackEntry(referral); }
private static void TestTrackingEntryViews(TrackEntries track, int expectedWebCount, int expectedAggCount) { UnitTestHelper.SetupBlog(); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "the title for this post", "test"); int entryId = Entries.Create(entry); EntryView entryView = new EntryView(); entryView.BlogId = Config.CurrentBlog.Id; entryView.EntryId = entryId; entryView.PageViewType = PageViewType.WebView; track(entryView, entryView); IPagedCollection<Entry> entries = Entries.GetPagedEntries(PostType.BlogPost, NullValue.NullInt32, 0, 10); EntryStatsView entryStatsView = (EntryStatsView)entries[0]; Assert.AreEqual(expectedWebCount, entryStatsView.WebCount); if (expectedWebCount > 0) { Assert.LowerEqualThan(entryStatsView.WebLastUpdated, DateTime.Now.AddMinutes(1)); Assert.GreaterEqualThan(entryStatsView.WebLastUpdated, DateTime.Now.AddDays(-1)); } Assert.AreEqual(expectedAggCount, entryStatsView.AggCount); if (expectedAggCount > 0) { Assert.LowerEqualThan(entryStatsView.AggLastUpdated, DateTime.Now.AddMinutes(1)); Assert.GreaterEqualThan(entryStatsView.AggLastUpdated, DateTime.Now.AddDays(-1)); } }
private static void TestQueueing(TrackEntries track) { try { UnitTestHelper.SetupBlog(); Config.Settings.Tracking.QueueStats = true; Config.Settings.Tracking.QueueStatsCount = 2; Stats.ClearQueue(false); Entry entry = UnitTestHelper.CreateEntryInstanceForSyndication("test", "the title for this post", "test"); int entryId = Entries.Create(entry); EntryView entryView = new EntryView(); entryView.BlogId = Config.CurrentBlog.Id; entryView.EntryId = entryId; entryView.PageViewType = PageViewType.WebView; Stats.AddQuedStats(entryView); Stats.AddQuedStats(entryView); //Should be nothing in the db yet.. IPagedCollection<Entry> entries = Entries.GetPagedEntries(PostType.BlogPost, NullValue.NullInt32, 0, 10); EntryStatsView entryStatsView = (EntryStatsView) entries[0]; Assert.AreEqual(0, entryStatsView.WebCount); track(entryView); //Stats.AddQuedStats(entryView); Thread.Sleep(2000); //Wait a moment for the asynch tracking to kick in. entries = Entries.GetPagedEntries(PostType.BlogPost, NullValue.NullInt32, 0, 10); entryStatsView = (EntryStatsView) entries[0]; Console.WriteLine("Number of entries in the queue: {0}", Stats.QueueCount); } finally { //Can't run this test in a transaction. This is the best I can do. BlogInfo.ClearBlogContent(Config.CurrentBlog.Id); } }
public override bool TrackEntry(EntryView ev) { return DbProvider.Instance().TrackEntry(ev); }
public void CtorInitializesIdsToNullValue() { var view = new EntryView(); Assert.AreEqual(NullValue.NullInt32, view.EntryId); Assert.AreEqual(NullValue.NullInt32, view.BlogId); }
public abstract bool TrackEntry(EntryView ev);
/// <summary> /// Calls out to the data provider to track the specified /// <see cref="EntryView"/> instance. /// </summary> /// <param name="ev">Ev.</param> /// <returns></returns> public static void TrackEntry(EntryView ev) { ObjectProvider.Instance().TrackEntry(ev); }