Beispiel #1
0
        public void Save_ContentLoadSummary_ValuesIncrement()
        {
            EventMapper eventMapper   = new EventMapper(this.client, this.database);
            Guid        applicationId = Guid.NewGuid();
            Guid        deviceId      = Guid.NewGuid();

            ContentLoadSummary expected = new ContentLoadSummary()
            {
                ApplicationId = applicationId,
                Count         = 2,
                Date          = date,
                PlatformId    = platform,
                Version       = version,
                Loads         = new List <ContentDurationAggregate>()
                {
                    new ContentDurationAggregate("someScreen", "someContent", 46)
                    {
                        Count = 2
                    }
                }
            };

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

            ContentLoadSummary summary = new ContentLoadSummary(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)
                                );

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

            actual.ShouldHave().AllPropertiesBut(x => x.Id)
            .IncludingNestedObjects().EqualTo(expected);
        }
        public void Save(ContentLoadSummary entity)
        {
            try
            {
                IMongoQuery queryBase = Query.And
                                        (
                    Query <ContentLoadSummary> .EQ <DateTime>(mem => mem.Date, entity.Date),
                    Query <ContentLoadSummary> .EQ <Guid>(mem => mem.ApplicationId, entity.ApplicationId),
                    Query <ContentLoadSummary> .EQ <string>(mem => mem.Version, entity.Version),
                    Query <ContentLoadSummary> .EQ <PlatformType>(mem => mem.PlatformId, entity.PlatformId)
                                        );

                IMongoUpdate update = Update <ContentLoadSummary>
                                      .SetOnInsert(x => x.Version, entity.Version)
                                      .SetOnInsert(x => x.Date, entity.Date)
                                      .SetOnInsert(x => x.ApplicationId, entity.ApplicationId)
                                      .SetOnInsert(x => x.PlatformId, entity.PlatformId)
                                      .SetOnInsert(x => x.Loads, new List <ContentDurationAggregate>())
                                      .Inc(mem => mem.Count, entity.Count);

                this.GetCollection <ContentLoadSummary>().FindAndModify(queryBase, SortBy.Descending("Date"), update, false, true);
                this.GetCollection <ContentLoadSummary>().EnsureIndex(IndexKeys.Descending("Date"));

                IMongoQuery queryLoadInsert = Query.And
                                              (
                    queryBase,
                    Query.NE("Loads.ScreenContent", BsonValue.Create(entity.Loads.First().ScreenContent))
                                              );

                IMongoUpdate insertLoad = Update
                                          .Push("Loads", BsonValue.Create(entity.Loads.First().CopyOnlyKey().ToBsonDocument()));

                this.GetCollection <ContentLoadSummary>().Update(queryLoadInsert, insertLoad);


                IMongoQuery queryLoadUpdate = Query.And
                                              (
                    queryBase,
                    Query.EQ("Loads.ScreenContent", BsonValue.Create(entity.Loads.First().ScreenContent))
                                              );

                IMongoUpdate updateContentLoad = Update
                                                 .Inc("Loads.$.Seconds", entity.Loads.First().Seconds)
                                                 .Inc("Loads.$.Count", 1);

                this.GetCollection <ContentLoadSummary>().Update(queryLoadUpdate, updateContentLoad);
            }
            catch (Exception ex)
            {
                throw new DataAccessLayerException(ex);
            }
        }
Beispiel #3
0
 public void Save(ContentLoadSummary summary)
 {
     this.eventMapper.Save(summary);
 }
Beispiel #4
0
        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 void Save(ContentLoadSummary summary)
 {
     this.eventMapper.Save(summary);
 }
        public void Save(ContentLoadSummary entity)
        {
            try
            {
                IMongoQuery queryBase = Query.And
                    (
                        Query<ContentLoadSummary>.EQ<DateTime>(mem => mem.Date, entity.Date),
                        Query<ContentLoadSummary>.EQ<Guid>(mem => mem.ApplicationId, entity.ApplicationId),
                        Query<ContentLoadSummary>.EQ<string>(mem => mem.Version, entity.Version),
                        Query<ContentLoadSummary>.EQ<PlatformType>(mem => mem.PlatformId, entity.PlatformId)
                    );

                IMongoUpdate update = Update<ContentLoadSummary>
                    .SetOnInsert(x => x.Version, entity.Version)
                    .SetOnInsert(x => x.Date, entity.Date)
                    .SetOnInsert(x => x.ApplicationId, entity.ApplicationId)
                    .SetOnInsert(x => x.PlatformId, entity.PlatformId)
                    .SetOnInsert(x => x.Loads, new List<ContentDurationAggregate>())
                    .Inc(mem => mem.Count, entity.Count);

                this.GetCollection<ContentLoadSummary>().FindAndModify(queryBase, SortBy.Descending("Date"), update, false, true);
                this.GetCollection<ContentLoadSummary>().EnsureIndex(IndexKeys.Descending("Date"));

                IMongoQuery queryLoadInsert = Query.And
                    (
                        queryBase,
                        Query.NE("Loads.ScreenContent", BsonValue.Create(entity.Loads.First().ScreenContent))
                    );

                IMongoUpdate insertLoad = Update
                    .Push("Loads", BsonValue.Create(entity.Loads.First().CopyOnlyKey().ToBsonDocument()));

                this.GetCollection<ContentLoadSummary>().Update(queryLoadInsert, insertLoad);

                IMongoQuery queryLoadUpdate = Query.And
                    (
                        queryBase,
                        Query.EQ("Loads.ScreenContent", BsonValue.Create(entity.Loads.First().ScreenContent))
                    );

                IMongoUpdate updateContentLoad = Update
                    .Inc("Loads.$.Seconds", entity.Loads.First().Seconds)
                    .Inc("Loads.$.Count", 1);

                this.GetCollection<ContentLoadSummary>().Update(queryLoadUpdate, updateContentLoad);
            }
            catch (Exception ex)
            {
                throw new DataAccessLayerException(ex);
            }
        }
        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 void Save_ContentLoadSummary_ValuesIncrement()
        {
            EventMapper eventMapper = new EventMapper(this.client, this.database);
            Guid applicationId = Guid.NewGuid();
            Guid deviceId = Guid.NewGuid();

            ContentLoadSummary expected = new ContentLoadSummary()
            {
                ApplicationId = applicationId,
                Count = 2,
                Date = date,
                PlatformId = platform,
                Version = version,
                Loads = new List<ContentDurationAggregate>()
                {
                    new ContentDurationAggregate("someScreen", "someContent", 46)
                    {
                        Count = 2
                    }
                }
            };

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

            ContentLoadSummary summary = new ContentLoadSummary(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)
                );

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

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