private void AskToRestartService() { try { ConfigClient c = App.GetDefaultConfigClient(); List <Guid> pendingRestartGuids = c.GetManagementAgentsPendingRestart()?.ToList(); if (pendingRestartGuids != null && pendingRestartGuids.Count > 0) { IDictionary <Guid, string> mapping = c.GetManagementAgentNameIDs(); IEnumerable <string> pendingRestartItems = mapping.Where(t => pendingRestartGuids.Contains(t.Key)).Select(t => t.Value); string pendingRestartItemList = string.Join("\r\n", pendingRestartItems); if (MessageBox.Show($"The configuration for the following management agents have changed\r\n\r\n{pendingRestartItemList}\r\n\r\nDo you want to restart them now?", "Restart management agents", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes) { try { c.InvokeThenClose(t => t.RestartChangedControllers()); } catch (Exception ex) { Trace.WriteLine("Error restarting controllers"); Trace.WriteLine(ex.ToString()); MessageBox.Show($"Could not restart the management agents\n\n{ex.Message}", "Restart management agents", MessageBoxButton.OK, MessageBoxImage.Error); } } } } catch (EndpointNotFoundException ex) { Trace.WriteLine(ex.ToString()); MessageBox.Show($"Could not contact the AutoSync service", "AutoSync service unavailable", MessageBoxButton.OK, MessageBoxImage.Error); this.ConfigFile = null; } catch (Exception ex) { Trace.WriteLine("Error determining controllers to restart"); Trace.WriteLine(ex.ToString()); MessageBox.Show($"Could not determine if any management agents required a restart\n\n{ex.Message}", "Restart management agents", MessageBoxButton.OK, MessageBoxImage.Error); } }