public void EventProcessingDelay() { var channel = new Mock <IDataChannel>(); var provider = new RepositoryProvider(TestHelper.Directory, TimeSpan.FromDays(1), 10000); var actual = new List <Event>(); channel.Setup(x => x.WriteEvents(It.IsAny <IEnumerable <Event> >())) .Callback <IEnumerable <Event> >(x => actual.AddRange(x)); var watch = Stopwatch.StartNew(); using (var tracker = new Tracker(channel.Object, provider)) { tracker.EventProcessingDelay = 250; tracker.Start(); tracker.Wait(x => x.EventProcessorRunning); actual.Wait(x => x.Count == 1); Thread.Sleep(50); tracker.AddEvent("Event"); actual.Wait(x => x.Count == 2); } watch.Stop(); Console.WriteLine(watch.Elapsed.TotalMilliseconds); Assert.IsTrue(watch.Elapsed.TotalMilliseconds > 250); Assert.IsTrue(watch.Elapsed.TotalMilliseconds < 1000); actual.Wait(x => x.Count == 2); Assert.AreEqual(2, actual.Count); Assert.AreEqual("Session", actual[0].Name); Assert.AreEqual("Event", actual[1].Name); Assert.AreEqual(0, actual[1].ElapsedTime.TotalMilliseconds); }
private static void MouseEvent(object sender, MouseEventArgs e) { try { _tracker.AddEvent("Mouse Click", new EventValue("Point", e.Location)); } catch (Exception ex) { // We will just publish all analytics exception because we do not want to negatively affect the user experience by // tell them an error occurred on something not important to their business work flow. _tracker.AddException(ex); } }
public void EventWithElapsedTime() { var channel = new Mock <IDataChannel>(); var provider = new RepositoryProvider(TestHelper.Directory, TimeSpan.FromDays(1), 10000); var actual = new List <Event>(); var elapsedTime = TimeSpan.FromTicks(5646134); channel.Setup(x => x.WriteEvents(It.IsAny <IEnumerable <Event> >())) .Callback <IEnumerable <Event> >(x => actual.AddRange(x)); using (TestHelper.CreateDataContext()) { using (var tracker = new Tracker(channel.Object, provider)) { tracker.Start(); tracker.AddEvent("Boom", elapsedTime); } Assert.AreEqual(2, actual.Count); Assert.AreEqual(TimeSpan.Zero, actual[0].ElapsedTime); Assert.AreEqual(elapsedTime, actual[1].ElapsedTime); Assert.AreEqual(elapsedTime, actual[1].CompletedOn - actual[1].CreatedOn); } }
private void Print_Click(object sender, EventArgs e) { _tracker.AddEvent("Print", new EventValue("Color", Colors.SelectedItem)); }