Ejemplo n.º 1
0
        private async void ReloadPage(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("Initiating Page reload");
            ReloadingIndicator.Visibility = Visibility.Visible;

            List <Service> services = null;

            try
            {
                services = await Connection.RefreshServiceCache();
            }
            catch (Exception ex)
            {
                UIElementCollection children = ((Panel)_rootBox.Parent).Children;
                foreach (UIElement uiElement in children.Where(it => it != _rootBox).ToArray())
                {
                    children.Remove(uiElement);
                }
                _rootBox.ServiceName = "Status Server is Unreachable";
                _rootBox.StatusText  = $"Could not fetch services - [{ex.GetType().Name}]: {ex.Message}";
                _rootBox.StatusColor = ServiceBox.ConvertColor(ServiceStatus.OfflineColor);
                services             = new List <Service>();
            }

            foreach (Service service in services)
            {
                ServiceBox existing = ComputeServiceBox(service);
                existing.UpdateDisplay(service);
            }

            ReloadingIndicator.Visibility = Visibility.Collapsed;
            Debug.WriteLine(
                $"Reload complete with {services.Count} services; Stacker has {ServiceList.Children.Count} children");
        }
Ejemplo n.º 2
0
        private ServiceBox ComputeServiceBox(Service service)
        {
            ServiceBox @default = ServiceList.Children
                                  .Select(each => each as ServiceBox)
                                  .Where(each => each != null)
                                  .FirstOrDefault(box => box.Name.Equals($"status-{service.Name}"));

            if (@default != null)
            {
                return(@default);
            }
            ServiceBox inst = new ServiceBox(service.Name);

            ServiceList.Children.Add(inst);
            return(inst);
        }