コード例 #1
0
        public async Task ProcessUpdateNotification(StravaUpdateNotification updateNotification)
        {
            StravaSubscription subscription = await _stravaSubscriptionService.GetSubscriptionAsync();

            if (updateNotification.SubscriptionId != subscription.Id)
            {
                _logger.LogWarning($"Received Strava update for unrecognised subscription ID: {updateNotification.SubscriptionId}.");
                return;
            }

            Integration integration = await _integrationRepository.GetIntegrationAsync(Provider.Strava, updateNotification.OwnerId.ToString());

            if (integration is null)
            {
                _logger.LogWarning($"Received Strava update for owner ID with no integration '{updateNotification.OwnerId}'.");
                return;
            }

            await _eventPublisher.PublishAsync(
                new IntegrationProviderUpdateEvent(
                    id : Guid.NewGuid().ToString(),
                    subject : updateNotification.OwnerId.ToString(),
                    eventTime : _dateTimeProvider.UtcNow,
                    dataVersion : EventConstants.EventDataVersion,
                    data : new IntegrationProviderEventData
            {
                OperationId = _operationContext.OperationId,
                SourceSystem = EventConstants.IntegrationsApi,
                SubjectSystem = Provider.Strava.ToString(),
                Provider = Provider.Strava,
                ProviderData = updateNotification,
                UserId = integration.UserId
            }));
        }
コード例 #2
0
        public async Task <ActionResult> TestStravaUpdate([FromBody] StravaUpdateNotification update, [FromQuery] string userId)
        {
            if (string.IsNullOrEmpty(userId))
            {
                return(BadRequest());
            }

            _logger.LogInformation($"TestStravaUpdate: {JsonSerializer.Serialize(update)}");

            await _eventHandler.ProcessAsync(
                new IntegrationProviderUpdateEvent(
                    id : Guid.NewGuid().ToString(),
                    subject : update.OwnerId.ToString(),
                    eventTime : DateTime.UtcNow,
                    dataVersion : EventConstants.EventDataVersion,
                    data : new IntegrationProviderEventData
            {
                OperationId = "test",
                SourceSystem = EventConstants.IntegrationsApi,
                SubjectSystem = Provider.Strava.ToString(),
                Provider = Provider.Strava,
                ProviderData = JObject.FromObject(update),
                UserId = userId
            }));

            return(Ok());
        }
コード例 #3
0
        public async Task ProcessAsync(IEvent @event)
        {
            var providerUpdateEvent = (IntegrationProviderUpdateEvent)@event;

            _logger.Information(nameof(StravaProviderUpdateEventHandler), providerUpdateEvent.Properties);

            StravaUpdateNotification stravaUpdate =
                ((JObject)providerUpdateEvent.Data.ProviderData)
                .ToObject <StravaUpdateNotification>();

            if (stravaUpdate.ObjectType != "activity")
            {
                _logger.LogWarning($"Unsupported Strava object type '{stravaUpdate.ObjectType}'.");
                return;
            }

            string accessToken = await _stravaAuthenticationService.GetAccessTokenAsync(stravaUpdate.OwnerId);

            if (accessToken is null)
            {
                _logger.LogWarning($"Failed to retrieve Strava access token for owner ID '{stravaUpdate.OwnerId}'.");
                return;
            }

            DetailedActivity activity = await _stravaClient.GetActivityAsync(stravaUpdate.ObjectId, accessToken);

            if (activity.Type != ActivityType.Ride)
            {
                _logger.LogWarning($"Unsupported Strava activity type '{activity.Type}'.");
                return;
            }

            await _fhirClient.EnsurePatientDeviceAsync(providerUpdateEvent.Data.UserId);

            IoMTModel ioMTModel = new BikeRide
            {
                Distance            = activity.Distance.Value,
                Duration            = activity.ElapsedTime.Value,
                DeviceId            = providerUpdateEvent.Data.UserId,
                PatientId           = providerUpdateEvent.Data.UserId,
                MeasurementDateTime = activity.StartDate.Value
            };

            await _iomtDataPublisher.PublishAsync(ioMTModel);
        }