public async Task SynchronizeConfiguration(bool firstLoad) { var result = await GetConfiguration(); if (result == null) { return; } var isDirty = false; var servicesToDelete = _list.Select(i => i.Key) .Except(result.Select(i => i.ServiceName)) .ToList(); var servicesToAdd = result.Select(i => i.ServiceName) .Except(_list.Select(i => i.Key)) .ToList(); // Existing foreach (var existing in _list) { var remote = result.SingleOrDefault(i => i.ServiceName == existing.Key); if (remote == null) { continue; } existing.Value.AdminServiceUrl = remote.AdminServiceUrl; existing.Value.ServiceName = remote.ServiceName; existing.Value.AlwaysStarted = remote.AlwaysStarted; existing.Value.MainAssembly = remote.MainAssembly; existing.Value.PalaceApiKey = remote.PalaceApiKey; existing.Value.SSLCertificate = remote.SSLCertificate; existing.Value.Arguments = remote.Arguments; existing.Value.InstallationFolder = remote.InstallationFolder; existing.Value.PackageFileName = remote.PackageFileName; } foreach (var serviceName in servicesToAdd) { var serviceToAdd = result.SingleOrDefault(i => i.ServiceName == serviceName); if (serviceToAdd != null) { _list.TryAdd(serviceName, serviceToAdd); if (!firstLoad) { serviceToAdd.MarkHasNew = true; } isDirty = true; } } foreach (var delete in servicesToDelete) { var existing = _list.SingleOrDefault(i => i.Key == delete); if (existing.Key != null) { existing.Value.MarkToDelete = true; } } if (isDirty) { Logger.LogInformation("Configuration changed detected"); } }