Inheritance: ItemWithScreen
        public void Save_AppUsageDurationSummary_ValuesIncrement()
        {
            EventMapper eventMapper = new EventMapper(this.client, this.database);
            Guid applicationId = Guid.NewGuid();
            Guid deviceId = Guid.NewGuid();

            AppUsageDurationSummary expected = new AppUsageDurationSummary()
            {
                ApplicationId = applicationId,
                Count = 2,
                Date = date,
                PlatformId = platform,
                Version = version,
                LengthGroup = new SessionLengthGroup()
                {
                    _20sec = 2
                }
            };

            Event eventItem = new Event()
            {
                ApplicationId = applicationId,
                Date = date,
                Version = version,
                PlatformId = platform,
                DateCreatedOnDevice = dateCreatedOnDevice,
                ScreenName = "someScreen",
                EventName = "someEvent",
                DeviceId = deviceId,
                DateCreated = date,
                Length = 20000
            };

            AppUsageDurationSummary summary = new AppUsageDurationSummary(eventItem);

            eventMapper.Save(summary);
            eventMapper.Save(summary);

            IMongoQuery query = Query.And
                (
                    Query<AppUsageSummary>.EQ<DateTime>(mem => mem.Date, date),
                    Query<AppUsageSummary>.EQ<Guid>(mem => mem.ApplicationId, applicationId),
                    Query<AppUsageSummary>.EQ<string>(mem => mem.Version, version),
                    Query<AppUsageSummary>.EQ<PlatformType>(mem => mem.PlatformId, platform)
                );

            AppUsageDurationSummary actual =
                this.GetCollection<AppUsageDurationSummary>().FindOne(query);

            actual.ShouldHave().AllPropertiesBut(x => x.Id)
                .IncludingNestedObjects().EqualTo(expected);
        }
        public AppUsageSummary(Event eventItem, Nullable<DateTime> deviceLastVisit)
            : base(eventItem)
        {
            this.TimeGroup = new TimeOfDayGroup(eventItem.DateCreatedOnDevice.Hour);
            this.WeekGroup = new DayOfWeekGroup(eventItem.DateCreatedOnDevice.DayOfWeek);
            this.FrequencyUsageGroup = new FrequencyOfUsageGroup(deviceLastVisit);
            this.DevicesVisits = new List<DeviceAppVisit>();
            this.DevicesVisits.Add(new DeviceAppVisit(eventItem.DeviceId));
            this.NewReturningGroup = new NewReturningGroup(1, 0);

            if (deviceLastVisit.HasValue)
            {
                this.NewReturningGroup = new NewReturningGroup(0, 1);
            }
        }
 public ScreenSummary(Event eventItem)
     : base(eventItem)
 {
     this.Durations = new List<DurationAggregate>();
     this.Durations.Add(new DurationAggregate(eventItem.ScreenName, eventItem.Length / 1000));
 }
 public void Save(Event entity)
 {
     this.eventMapper.Save(entity);
 }
 public void Save(Event entity)
 {
     base.Save(entity);
 }
 public ScreenRouteSummary(Event evenItem, string lastScreen, string currentScreen)
     : base(evenItem)
 {
     this.ScreenRoutes = new List<ScreenRoute>();
     this.ScreenRoutes.Add(new ScreenRoute(lastScreen, currentScreen));
 }
        public void Log(Event eventItem)
        {
            Application application = this.applicationRepository.Find(eventItem.ApplicationId);

            if (application != null)
            {
                DeviceInfo device = this.deviceRepository.Find(eventItem.DeviceId);

                if (device != null)
                {
                    eventItem.PlatformId = device.PlatformType;

                    switch (eventItem.EventTypeId)
                    {
                        case EventType.ApplicationOpen:
                            Nullable<DateTime> lastDeviceVisit = this.eventRepository
                                .GetDateOfDeviceLastVisit(eventItem.DeviceId, eventItem.ApplicationId);

                            AppUsageSummary appUsageSummary = new AppUsageSummary(eventItem, lastDeviceVisit);
                            this.eventRepository.Save(appUsageSummary);
                            break;

                        case EventType.ApplicationClose:
                            AppUsageDurationSummary appUsageSum = new AppUsageDurationSummary(eventItem);
                            this.eventRepository.Save(appUsageSum);

                            DeviceAppLastScreen appLastScreen =
                                this.eventRepository.GetDeviceAppLastScreenOneBy(eventItem.DeviceId, eventItem.ApplicationId);

                            if (appLastScreen != null)
                            {
                                ScreenRouteSummary routeSum =
                                    new ScreenRouteSummary(eventItem, appLastScreen.ScreenName, string.Empty);

                                this.eventRepository.Save(routeSum);
                                this.eventRepository.Remove(eventItem.DeviceId, eventItem.ApplicationId);
                            }
                            break;

                        case EventType.Event:
                            EventSummary eventSum = new EventSummary(eventItem);
                            this.eventRepository.Save(eventSum);
                            break;

                        case EventType.ScreenClose:
                            ScreenSummary screenUsageSum = new ScreenSummary(eventItem);
                            this.eventRepository.Save(screenUsageSum);
                            this.eventRepository.Remove(eventItem.DeviceId, eventItem.ApplicationId);
                            this.eventRepository.Save(new DeviceAppLastScreen(eventItem));
                            break;

                        case EventType.ScreenOpen:
                            DeviceAppLastScreen lastScreen =
                                this.eventRepository.GetDeviceAppLastScreenOneBy(eventItem.DeviceId, eventItem.ApplicationId);

                            ScreenRouteSummary routeSum2 = new ScreenRouteSummary(eventItem, string.Empty, eventItem.ScreenName);

                            if (lastScreen != null)
                            {
                                if (lastScreen.SessionId == eventItem.SessionId)
                                {
                                    routeSum2 = new ScreenRouteSummary(eventItem, lastScreen.ScreenName, eventItem.ScreenName);
                                }

                                this.eventRepository.Remove(eventItem.DeviceId, eventItem.ApplicationId);
                            }

                            this.eventRepository.Save(routeSum2);
                            this.eventRepository.Save(new DeviceAppLastScreen(eventItem));
                            break;

                        case EventType.ContentLoaded:
                            ContentLoadSummary contentSum = new ContentLoadSummary(eventItem);
                            this.eventRepository.Save(contentSum);
                            break;
                    }

                    if (this.settings.DataLoggingRecordRaw)
                    {
                        this.eventRepository.Save(eventItem);
                    }
                }
                else
                {
                    throw new NoDeviceException(eventItem.DeviceId);
                }
            }
            else
            {
                throw new InactiveApplicationException(eventItem.ApplicationId);
            }
        }
 public AppUsageDurationSummary(Event eventItem)
     : base(eventItem)
 {
     this.LengthGroup = new SessionLengthGroup(eventItem.Length / 1000);
 }
 public EventSummary(Event eventItem)
     : base(eventItem)
 {
     this.ScreenEvents = new List<EventAggregate>();
     this.ScreenEvents.Add(new EventAggregate(eventItem.ScreenName, eventItem.EventName));
 }
        public void Save_AppUsageSummary_ValuesIncrement()
        {
            EventMapper eventMapper = new EventMapper(this.client, this.database);
            Guid applicationId = Guid.NewGuid();
            Guid deviceId = Guid.NewGuid();

            AppUsageSummary expected = new AppUsageSummary()
            {
                ApplicationId = applicationId,
                Count = 2,
                Date = date,
                PlatformId = platform,
                Version = version,
                TimeGroup = new TimeOfDayGroup()
                {
                    _10 = 2
                },
                WeekGroup = new DayOfWeekGroup()
                {
                    Wed = 2
                },
                FrequencyUsageGroup = new FrequencyOfUsageGroup(),
                DevicesVisits = new List<DeviceAppVisit>()
                {
                    new DeviceAppVisit(deviceId)
                    {
                        Count = 2
                    }
                },
                NewReturningGroup = new NewReturningGroup(2, 0)
            };

            Event eventItem = new Event()
            {
                ApplicationId = applicationId,
                Date = date,
                Version = version,
                PlatformId = platform,
                DateCreatedOnDevice = dateCreatedOnDevice,
                DeviceId = deviceId,
                DateCreated = date
            };

            AppUsageSummary summary = new AppUsageSummary(eventItem, null);

            eventMapper.Save(summary);
            eventMapper.Save(summary);

            IMongoQuery query = Query.And
                (
                    Query<AppUsageSummary>.EQ<DateTime>(mem => mem.Date, date),
                    Query<AppUsageSummary>.EQ<Guid>(mem => mem.ApplicationId, applicationId),
                    Query<AppUsageSummary>.EQ<string>(mem => mem.Version, version),
                    Query<AppUsageSummary>.EQ<PlatformType>(mem => mem.PlatformId, platform)
                );

            AppUsageSummary actual = this.GetCollection<AppUsageSummary>().FindOne(query);

            actual.ShouldHave().AllPropertiesBut(x => x.Id)
                .IncludingNestedObjects().EqualTo(expected);
        }
        public void Save_ScreenRoute_ValuesIncrement()
        {
            EventMapper eventMapper = new EventMapper(this.client, this.database);
            Guid applicationId = Guid.NewGuid();
            Guid deviceId = Guid.NewGuid();

            ScreenRouteSummary expected = new ScreenRouteSummary()
            {
                ApplicationId = applicationId,
                Count = 2,
                Date = date,
                PlatformId = platform,
                Version = version,
                ScreenRoutes = new List<ScreenRoute>()
                {
                     new ScreenRoute("screenNameBefore", "screenNameAfter")
                     {
                         Count = 2
                     }
                }
            };

            Event eventItem = new Event()
            {
                ApplicationId = applicationId,
                Date = date,
                Version = version,
                PlatformId = platform,
                DateCreatedOnDevice = dateCreatedOnDevice,
                DeviceId = deviceId,
                DateCreated = date,
                EventTypeId = Model.Enum.EventType.ScreenOpen,
                ScreenName = "screenNameAfter"
            };

            ScreenRouteSummary summary = new ScreenRouteSummary(eventItem, "screenNameBefore", "screenNameAfter");

            eventMapper.Save(summary);
            eventMapper.Save(summary);

            IMongoQuery query = Query.And
                (
                    Query<ScreenRouteSummary>.EQ<DateTime>(mem => mem.Date, date),
                    Query<ScreenRouteSummary>.EQ<Guid>(mem => mem.ApplicationId, applicationId),
                    Query<ScreenRouteSummary>.EQ<string>(mem => mem.Version, version),
                    Query<ScreenRouteSummary>.EQ<PlatformType>(mem => mem.PlatformId, platform)
                );

            ScreenRouteSummary actual = this.GetCollection<ScreenRouteSummary>().FindOne(query);

            actual.ShouldHave().AllPropertiesBut(x => x.Id).IncludingNestedObjects().EqualTo(expected);
        }