private async Task PersistMonitorStatus(IStatusMonitor monitor, CancellationToken stoppingToken)
 {
     var client = _statusMonitorClientFactory.Create();
     await client.UpdateStatusAsync(new StatusMonitorRequest
     {
         MonitorName = monitor.Name,
         Status      = monitor.Status.ToString(),
         DisplayName = GetDisplayName(monitor.Name),
         LocationId  = GetLocationId(monitor.Name)
     }, stoppingToken);
 }
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var client = _statusMonitorClientFactory.Create();

                    var monitorConfigs = (await client
                                          .GetConfigurationsAsync(stoppingToken))
                                         .Where(m => m.Active)
                                         .ToList();

                    foreach (var monitorConfiguration in monitorConfigs)
                    {
                        var existingMonitor =
                            _statusMonitorConfiguration.Monitors.FirstOrDefault(
                                m => m.Name == monitorConfiguration.MonitorName);
                        if (existingMonitor != null)
                        {
                            UpdateMonitor(existingMonitor, monitorConfiguration);
                        }
                        else
                        {
                            AddMonitor(monitorConfiguration);
                        }
                    }

                    _statusMonitorConfiguration.Monitors
                    .Where(m => monitorConfigs.All(config => config.MonitorName != m.Name))
                    .ToList()
                    .ForEach(m => _statusMonitorConfiguration.Monitors.Remove(m));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Unable to refresh configuration. {ex.Message}");
                }
                finally
                {
                    await Task.Delay(_configurationRefreshInterval, stoppingToken);
                }
            }
        }