internal void RefreshContainersList() { IsRefreshEnabled = false; try { StatusText = UIResources.SearchingStatusText; ContainerInstances?.Clear(); IEnumerable <IContainerInstance> containers; if (SelectedConnection is LocalConnectionViewModel) { containers = DockerHelper.GetLocalDockerContainers(); } else { StatusText = UIResources.SSHConnectingStatusText; var connection = SelectedConnection.Connection; if (connection == null) { StatusText = UIResources.SSHConnectionFailedStatusText; return; } containers = DockerHelper.GetRemoteDockerContainers(connection); } ContainerInstances = new ObservableCollection <IContainerInstance>(containers); OnPropertyChanged(nameof(ContainerInstances)); if (ContainerInstances.Count() > 0) { StatusText = String.Format(CultureInfo.CurrentCulture, UIResources.ContainersFoundStatusText, ContainerInstances.Count()); } else { StatusText = String.Empty; } } catch (Exception ex) { StatusText = String.Format(CultureInfo.CurrentCulture, UIResources.ErrorStatusTextFormat, ex.Message); StatusIsError = true; return; } finally { IsRefreshEnabled = true; } }
internal void RefreshContainersList() { IsRefreshEnabled = false; // Clear everything before retreiving the container list ContainerInstances?.Clear(); UpdateStatusMessage(string.Empty, false); // Set the status ContainersFoundText = UIResources.QueryingForContainersMessage; // Tell the dispatcher to run the Refresh task with a lower priority than Render. // This is so that the UI does any necessary updating before the refresh task has completed. // Render = 7 // Loaded = 6 - Operations are processed when layout and render has finished but just before items at input priority are serviced. // https://docs.microsoft.com/en-us/dotnet/api/system.windows.threading.dispatcherpriority Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Input, (Action)(() => { RefreshContainersListInternal(); })); }
internal void RefreshContainersList() { IsRefreshEnabled = false; try { IContainerViewModel selectedContainer = SelectedContainerInstance; SelectedContainerInstance = null; ContainersFoundText = UIResources.SearchingStatusText; // Clear everything ContainerInstances?.Clear(); UpdateStatusMessage(string.Empty, false); IEnumerable <DockerContainerInstance> containers; if (SelectedConnection is LocalConnectionViewModel) { containers = DockerHelper.GetLocalDockerContainers(Hostname); } else { ContainersFoundText = UIResources.SSHConnectingStatusText; var connection = SelectedConnection.Connection; if (connection == null) { UpdateStatusMessage(UIResources.SSHConnectionFailedStatusText, isError: true); return; } containers = DockerHelper.GetRemoteDockerContainers(connection, Hostname); } ContainerInstances = new ObservableCollection <IContainerViewModel>(containers.Select(item => new DockerContainerViewModel(item)).ToList()); OnPropertyChanged(nameof(ContainerInstances)); if (ContainerInstances.Count() > 0) { if (selectedContainer != null) { var found = ContainerInstances.FirstOrDefault(c => selectedContainer.Equals(c)); if (found != null) { SelectedContainerInstance = found; return; } } SelectedContainerInstance = ContainerInstances[0]; } } catch (Exception ex) { UpdateStatusMessage(UIResources.ErrorStatusTextFormat.FormatCurrentCultureWithArgs(ex.Message), isError: true); return; } finally { if (ContainerInstances.Count() > 0) { ContainersFoundText = UIResources.ContainersFoundStatusText.FormatCurrentCultureWithArgs(ContainerInstances.Count()); } else { ContainersFoundText = UIResources.NoContainersFound; } IsRefreshEnabled = true; } }