Ejemplo n.º 1
0
        public async Task WithingsDeviceNotificationMessage(
            [ServiceBusTrigger(NotificationQueueName, Connection = "SB_CONNECTION_STRING")] string queueItem,
            [DurableClient] IDurableOrchestrationClient jobClient,
            CancellationToken cancellationToken)
        {
            var message = json.Load <CallbackReceivedMessage>(queueItem);

            var consent = await consentStore.FetchConsentByExternalId(converter.System, message.WithingsUserId.ToString(), cancellationToken);

            if (consent == null)
            {
                log.LogWarning("Skipping Withings notification for unknown user: withingsUserId={withingsUserId}", message.WithingsUserId);
                return;
            }

            await jobClient.RunSingleton(
                consent.UserId,
                workflow : nameof(WithingsDeviceNotificationWorkflow),
                jobArguments : new StartNotificationIngestionMessage
            {
                UserId         = consent.UserId,
                StartDateEpoch = message.StartDateEpoch,
                EndDateEpoch   = message.EndDateEpoch,
            },
                log,
                guidFactory,
                blocking : true);
        }
Ejemplo n.º 2
0
        public async Task <T?> FetchItem <T>(string key)
            where T : class
        {
            var cache = client.GetDatabase();

            var cacheResponse = await cache.StringGetAsync(key);

            if (cacheResponse.IsNullOrEmpty)
            {
                return(null);
            }

            return(json.Load <T>(cacheResponse));
        }
Ejemplo n.º 3
0
        public async Task <TResult> Send <TResult, TException>(HttpRequestMessage request, CancellationToken cancellationToken)
            where TResult : class
            where TException : ApiException, new()
        {
            var client = factory.CreateClient();

            client.Timeout = Timeout;

            var response = await client.SendAsync(request, cancellationToken);

            await ThrowIfFailed <TException>(response);

            var responseContent = await response.Content.ReadAsStringAsync();

            return(json.Load <TResult>(responseContent));
        }