protected override async Task Handle(ReportLocationCommand request, CancellationToken cancellationToken)
        {
            var profile = await repository.GetProfileAsync(request.ProfileId, request.DeviceId, cancellationToken);

            if (profile == null)
            {
                throw new DomainException("Profile not found.");
            }


            var locations = request.Locations.Select(x =>
            {
                var time = timeConvertService.UnixTimeStampToDateTime(x.RecordTimestamp);
                return(new Location(request.ProfileId, x.Latitude, x.Longitude, x.Accuracy, time));
            }).ToList();

            profile.AddLocations(locations);

            //foreach (var location in locations)
            //{
            //    await repository.CreateLocationAsync(location, cancellationToken);
            //}

            await repository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
예제 #2
0
        protected override async Task Handle(NotifyAreaExitCommand request, CancellationToken cancellationToken)
        {
            var now     = DateTime.UtcNow;
            var profile = await repository.GetProfileAsync(request.ProfileId, request.DeviceId, cancellationToken);

            if (profile == null)
            {
                throw new DomainException("Profile not found.");
            }

            if (!profile.ActiveQuarantine(DateTime.UtcNow))
            {
                throw new DomainException("Profile is not in quarantine.");
            }

            var exit = new AreaExit(profile.Id, request.Severity, timeConvertService.UnixTimeStampToDateTime(request.RecordTimestamp));

            profile.AddAreaExit(exit);

            var check = new PresenceCheck(profile.Id, now, now, PresenceCheckStatus.LEFT);

            check.SetSeverity(exit.Severity);
            profile.AddPresenceCheck(check);

            await repository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
예제 #3
0
        protected override async Task Handle(AddContactsCommand request, CancellationToken cancellationToken)
        {
            var profile = await repository.GetProfileAsync(request.SourceProfileId, request.SourceDeviceId, cancellationToken);

            if (profile == null)
            {
                throw new DomainException("Profile not found.");
            }

            var t        = convertService.UnixTimeStampToDateTime(request.Contacts.First().Timestamp);
            var f        = t.Date;
            var contacts = request.Contacts
                           .Select(x => new Contact(
                                       profile.Id, profile.DeviceId, x.SeenProfileId, null,
                                       convertService.UnixTimeStampToDateTime(x.Timestamp).Date, x.Duration))
                           .ToList();

            profile.AddContact(contacts);
            await repository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }
예제 #4
0
        protected override async Task Handle(ConvertContactsTimestampCommand request, CancellationToken cancellationToken)
        {
            var contacts = await context.Contacts.ToListAsync(cancellationToken);

            foreach (var contact in contacts)
            {
                if (contact.Timestamp.HasValue)
                {
                    var creationDate = convertService.UnixTimeStampToDateTime(contact.Timestamp.Value).Date;
                    contact.SetCreationDate(creationDate);
                }
            }

            await context.SaveChangesAsync(cancellationToken);
        }
        protected override async Task Handle(NotifyAreaExitCommand request, CancellationToken cancellationToken)
        {
            var profile = await repository.GetProfileAsync(request.ProfileId, request.DeviceId, cancellationToken);

            if (profile == null)
            {
                throw new DomainException("Profile not found.");
            }

            if (!profile.IsInQuarantine)
            {
                throw new DomainException("Profile is not in quarantine.");
            }

            var exit = new AreaExit(request.Latitude, request.Longitude, request.Accuracy, timeConvertService.UnixTimeStampToDateTime(request.RecordTimestamp));

            profile.AddAreaExit(exit);

            await repository.UnitOfWork.SaveChangesAsync(cancellationToken);
        }