Example #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))
            ));
 }
Example #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()
            ));
 }
Example #8
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))
            ));
 }
Example #9
0
 public ISet <InstallationDto> GetAll()
 {
     return(TracedOperation.CallSync
            (
                _logger,
                InstallationOperationType.GetAllInstallations,
                "none",
                () => _repository.FindAll()
                .Select(InstallationDto.FromDomain)
                .ToHashSet()
            ));
 }
Example #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))
            ));
 }
 public async Task <Either <AirlyClientError, GetMeasurementByInstallationIdResponse> > GetMeasurementByInstallationId(GetMeasurementByInstallationIdRequest request)
 {
     return(await TracedOperation.CallAsync
            (
                "AirlyClient",
                AirlyClientFunction.AirlyClientFunctionType.GetMeasurementByInstallationId,
                request,
                () =>
     {
         string query = AirlyClientUrlBuilder.GetQuery(request.ToQueryParams());
         string url = _options.GetUrl(AirlyClientFunction.GetMeasurementByInstallationId, query);
         return GetHttpResponseAsync <GetMeasurementByInstallationIdResponse>(url);
     }
            ));
 }
 public async Task <Either <AirlyClientError, IEnumerable <GetInstallationsNearestResponse> > > GetInstallationsNearest(GetInstallationsNearestRequest request)
 {
     return(await TracedOperation.CallAsync
            (
                "AirlyClient",
                AirlyClientFunction.AirlyClientFunctionType.GetInstallationsNearest,
                request,
                () =>
     {
         string query = AirlyClientUrlBuilder.GetQuery(request.ToQueryParams());
         string url = _options.GetUrl(AirlyClientFunction.GetInstallationsNearest, query);
         return GetHttpResponseAsync <IEnumerable <GetInstallationsNearestResponse> >(url);
     }
            ));
 }
Example #13
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));
 }
Example #14
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);
     }
            ));
 }