Ejemplo n.º 1
0
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            try
            {
                var digitalTwinClient = DigitalTwinClientConnections.GetOrAdd(ClientConnectionKey, _ => CreateDigitalTwinClient(_hostName));
                var response          = digitalTwinClient.GetModelsAsync(cancellationToken: cancellationToken);
                var models            = new List <DigitalTwinsModelData>();
                await foreach (var model in response)
                {
                    models.Add(model);
                }

                var unregistered = _models.Where(x => !models.Any(m => m.Id == x));
                return(unregistered.Any()
                    ? new HealthCheckResult(
                           context.Registration.FailureStatus,
                           "The digital twin is out of sync with the models provided",
                           null,
                           new Dictionary <string, object>()
                {
                    [nameof(unregistered)] = unregistered
                })
                    : HealthCheckResult.Healthy());
            }
            catch (Exception ex)
            {
                return(new HealthCheckResult(context.Registration.FailureStatus, exception: ex));
            }
        }
        public async Task <HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
        {
            try
            {
                var digitalTwinClient = DigitalTwinClientConnections.GetOrAdd(ClientConnectionKey, _ => CreateDigitalTwinClient(_hostName));
                _ = await digitalTwinClient.GetDigitalTwinAsync <BasicDigitalTwin>(_instanceName, cancellationToken : cancellationToken);

                return(HealthCheckResult.Healthy());
            }
            catch (Exception ex)
            {
                return(new HealthCheckResult(context.Registration.FailureStatus, exception: ex));
            }
        }