예제 #1
0
 public bool Delete(InstallationDeleteCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.DeleteInstallation,
                command,
                () => _repository.DeleteById(command.Id)
            ));
 }
 public bool IsOutdatedByInstallationExternalId(long installationExternalId)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.IsOutdatedByInstallationExternalId,
                installationExternalId,
                () => _repository.IsOutdatedByInstallationExternalId(installationExternalId)
            ));
 }
 public bool Delete(MeasurementDeleteCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.DeleteMeasurement,
                command,
                () => _repository.DeleteById(command.Id)
            ));
 }
 public ISet <MeasurementDto> GetAllOutdatedMeasurement()
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.GetAllOutdatedMeasurements,
                "none",
                () => _repository.FindAllOutdated()
                .Select(MeasurementDto.FromDomain)
                .ToHashSet()
            ));
 }
 public Either <MeasurementError, MeasurementDto> GetByExternalId(long externalId)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.GetIMeasurementById,
                externalId,
                () => _repository.FindByExternalId(externalId)
                .Map(MeasurementDto.FromDomain)
                .ToEither(MeasurementError.NotFoundByExternalId(externalId))
            ));
 }
 // TODO based of installation id!!!
 public Either <MeasurementError, MeasurementDto> Create(MeasurementCreateCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.CreateMeasurement,
                command,
                () => _repository.TrySave(command.ToDomain())
                .Map(MeasurementDto.FromDomain)
                .ToEither(MeasurementError.DuplicateExternalId(command.ExternalId))
            ));
 }
예제 #7
0
 public ISet <InstallationDto> GetAllNearby(InstallationGetAllNearbyCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.GetAllInstallationsNearby,
                command,
                () => _repository.FindAllByLocation(command.Latitude, command.Longitude, command.Radius)
                .Select(InstallationDto.FromDomain)
                .ToHashSet()
            ));
 }
예제 #8
0
 public ISet <InstallationDto> GetAll()
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.GetAllInstallations,
                "none",
                () => _repository.FindAll()
                .Select(InstallationDto.FromDomain)
                .ToHashSet()
            ));
 }
예제 #9
0
 public Either <InstallationError, InstallationDto> GetByExternalId(long id)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.GetInstallationByExternalId,
                id,
                () => _repository.FindByExternalId(id)
                .Map(InstallationDto.FromDomain)
                .ToEither(InstallationError.NotFoundByExternalId(id))
            ));
 }
예제 #10
0
 public Either <InstallationError, InstallationDto> CreateInstallation(InstallationCreateCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.CreateInstallation,
                command,
                () => _repository.TrySave(command.ToDomain())
                .Map(InstallationDto.FromDomain)
                .ToEither(InstallationError.DuplicateExternalId(command.ExternalId))
            ));
 }
예제 #11
0
 public Either <InstallationError, IEnumerable <InstallationCreateCommand> > GetInstallationsNearby(InstallationGetAllNearbyCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                ClientOperationType.GetNearbyInstallations,
                command,
                () => SynchronizeHttpCall // TODO move this to `TracedOperationClass` cos like that it kills a purpose of this class xD
                (
                    _airlyClient.GetInstallationsNearest(AirMonitorToAirlyClientInstallationAdapter.FromCommand(command))
                )
            )
            .Map(AirlyClientToAirMonitorInstallationAdapter.FromResponse)
            .MapLeft(AirlyClientToAirMonitorInstallationAdapter.ErrorFromResponse));
 }
예제 #12
0
 public Either <MeasurementError, MeasurementCreateCommand> GetMeasurementByInstallationId(MeasurementGetByInstallationExternalIdCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                ClientOperationType.GetMeasurementByInstallationId,
                command,
                () => SynchronizeHttpCall // TODO move this to `TracedOperationClass` cos like that it kills a purpose of this class xD
                (
                    _airlyClient.GetMeasurementByInstallationId(AirMonitorToAirlyClientMeasurementAdapter.FromCommand(command))
                )
            )
            .Map(AirlyClientToAirMonitorMeasurementAdapter.FromApi)
            .Peek(createCommand => createCommand.ExternalId = command.InstallationExternalId)
            .MapLeft(AirlyClientToAirMonitorMeasurementAdapter.ErrorFromResponse));
 }
 public Either <MeasurementError, MeasurementDto> Update(MeasurementCreateCommand command)
 {
     return(TracedOperation.CallSync
            (
                _logger,
                MeasurementOperationType.UpdateMeasurement,
                command,
                // TODO refactor
                () =>
     {
         if (_repository.ExistsByExternalId(command.ExternalId))
         {
             _repository.DeleteByExternalId(command.ExternalId);
         }
         return Create(command);
     }
            ));
 }