예제 #1
0
        public void CollectStats()
        {
            var dataMock = new DataServiceMock();
            var timeMock = new MockedTimeSource();

            var authService  = new VitaAuthService(dataMock);
            var trackService = new TrackingService(timeMock);

            ITrackingReport report = null;

            trackService.Reports.Subscribe(x => report = x);

            ITrackingSession session = SessionTrackingScenarioOne(timeMock, trackService);

            trackService.PublishReports();

            Assert.IsNotNull(report);
            Assert.AreEqual(report.Topics.Count(), 3);
            Assert.IsTrue(report.Topics.All(x => x.ImpressionCount == 1));
            Assert.AreEqual(report.Topics[0].Url, "person");
            Assert.AreEqual(report.Topics[0].TopicDetail, "S");
            Assert.AreEqual(report.Topics[0].ImpressionTimeSpan, TimeSpan.FromSeconds(20 + 12 + 0));
            Assert.AreEqual(report.Topics[1].ImpressionTimeSpan, TimeSpan.FromSeconds(20 + 60 + 60));
            Assert.AreEqual(report.Topics[2].ImpressionTimeSpan, TimeSpan.FromSeconds(2 + 18 + 42));
        }
예제 #2
0
        private void HandleNewReport(ITrackingReport report)
        {
            if (report.Code == "xx")
            {
                TrackingService.AppendLog("do not send report to xx");
                return;
            }

            TrackingService.AppendLog("generating mail");

            var messageLines = new List <String>();

            messageLines.Add($"Login code '{report.Code}' from: {report.Ip} at {report.StartTime} for {FormatDuration(report.Duration)}");
            messageLines.Add(String.Empty);
            messageLines.AddRange(report.Topics.Select(x => $"{x.Url}/{x.TopicDetail}/{x.Title} for { FormatDuration(x.ImpressionTimeSpan)}"));

            var mail = new MailMessage("*****@*****.**", "*****@*****.**");

            mail.Subject = $"CV report for {report.Code}, duration {report.Duration}";

            mail.Body       = String.Join("\r\n", messageLines);
            mail.IsBodyHtml = false;
            var client = new SmtpClient("mrxn.de", 587);

            client.Send(mail);

            TrackingService.AppendLog("mail sent");
        }