public void Save(CrashSummary entity)
        {
            try
            {
                IMongoQuery query = Query.And
                                    (
                    Query <CrashSummary> .EQ <DateTime>(mem => mem.Date, entity.Date),
                    Query <CrashSummary> .EQ <Guid>(mem => mem.ApplicationId, entity.ApplicationId),
                    Query <CrashSummary> .EQ <string>(mem => mem.Version, entity.Version),
                    Query <CrashSummary> .EQ <PlatformType>(mem => mem.PlatformId, entity.PlatformId)
                                    );

                IMongoUpdate update = Update <CrashSummary>
                                      .SetOnInsert(x => x.Version, entity.Version)
                                      .SetOnInsert(x => x.Date, entity.Date)
                                      .SetOnInsert(x => x.ApplicationId, entity.ApplicationId)
                                      .SetOnInsert(x => x.PlatformId, entity.PlatformId)
                                      .Inc(mem => mem.Count, entity.Count);

                this.GetCollection <CrashSummary>().FindAndModify(query, SortBy.Descending("Date"), update, false, true);
                this.GetCollection <CrashSummary>().EnsureIndex(IndexKeys.Descending("Date"));
            }
            catch (Exception ex)
            {
                throw new DataAccessLayerException(ex);
            }
        }
Exemple #2
0
        public void Save_SummaryRecord_MatchesSummary()
        {
            CrashMapper crashMapper   = new CrashMapper(this.client, this.database);
            Guid        applicationId = Guid.NewGuid();

            CrashSummary expected = new CrashSummary()
            {
                ApplicationId = applicationId,
                Count         = 2,
                Date          = date,
                PlatformId    = platform,
                Version       = version
            };

            Crash crash = new Crash()
            {
                ApplicationId       = applicationId,
                DeviceId            = Guid.NewGuid(),
                SessionId           = Guid.NewGuid(),
                DateCreatedOnDevice = dateCreatedOnDevice,
                Date        = date,
                DateCreated = DateTime.Now,
                Version     = version,
                PlatformId  = platform
            };

            CrashSummary summary = new CrashSummary(crash);

            crashMapper.Save(summary);

            Crash crash2 = new Crash()
            {
                ApplicationId       = applicationId,
                DeviceId            = Guid.NewGuid(),
                SessionId           = Guid.NewGuid(),
                DateCreatedOnDevice = dateCreatedOnDevice,
                Date        = date,
                DateCreated = DateTime.Now,
                Version     = version,
                PlatformId  = platform
            };

            CrashSummary summary2 = new CrashSummary(crash2);

            crashMapper.Save(summary2);

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

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

            actual.ShouldHave().AllPropertiesBut(x => x.Id).EqualTo(expected);
        }
Exemple #3
0
        public void Log(Crash crash)
        {
            Application application = this.applicationRepository.Find(crash.ApplicationId);

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

                if (device != null)
                {
                    string lastScreenBeforeCrash      = null;
                    DeviceAppLastScreen appLastScreen =
                        this.eventRepository.GetDeviceAppLastScreenOneBy(crash.DeviceId, crash.ApplicationId);

                    if (appLastScreen != null)
                    {
                        lastScreenBeforeCrash = appLastScreen.ScreenName;
                    }

                    crash.Add(device, lastScreenBeforeCrash);

                    CrashSummary crashSummary = new CrashSummary(crash);

                    this.crashRepository.Save(crash);
                    this.crashRepository.Save(crashSummary);
                }
                else
                {
                    throw new NoDeviceException(crash.DeviceId);
                }
            }
            else
            {
                throw new InactiveApplicationException(crash.ApplicationId);
            }
        }
 public void Save(CrashSummary crash)
 {
     this.crashMapper.Save(crash);
 }