private async Task RetrieveServerXenkoVersions() { try { #if SIMULATE_OFFLINE var serverPackages = new List <IPackage>(); #else var serverPackages = await RunLockTask(() => store.FindSourcePackages(store.MainPackageIds, CancellationToken.None).Result.OrderByDescending(p => p.Version).ToList()); #endif // Check if we could connect to the server var wasOffline = IsOffline; IsOffline = serverPackages.Count == 0; // Inform the user if we just switched offline if (IsOffline && !wasOffline) { var message = Strings.ErrorOfflineMode; if (!string.IsNullOrEmpty(LastErrorOrWarning)) { message += Environment.NewLine + Environment.NewLine + Strings.Details + Environment.NewLine + LastErrorOrWarning; } await ServiceProvider.Get <IDialogService>().MessageBox(message, MessageBoxButton.OK, MessageBoxImage.Information); } // We are offline, let's stop here if (IsOffline) { return; } lock (objectLock) { // Retrieve all server packages (ignoring dev ones) var packages = serverPackages .Where(x => !string.Equals(x.Source, Environment.ExpandEnvironmentVariables(store.DevSource), StringComparison.OrdinalIgnoreCase)) .GroupBy(p => $"{p.Version.Version.Major}.{p.Version.Version.Minor}", p => p); foreach (var package in packages) { var serverPackage = package.FirstOrDefault(); if (serverPackage != null) { // Find if we already have this package in our list int index = xenkoVersions.BinarySearch(Tuple.Create(serverPackage.Version.Version.Major, serverPackage.Version.Version.Minor)); XenkoStoreVersionViewModel version; if (index < 0) { // If not, add it version = new XenkoStoreVersionViewModel(this, store, null, serverPackage.Version.Version.Major, serverPackage.Version.Version.Minor); Dispatcher.Invoke(() => xenkoVersions.Add(version)); } else { // If yes, update it and remove it from the list of old version version = (XenkoStoreVersionViewModel)xenkoVersions[index]; } version.UpdateServerPackage(serverPackage); } } } } catch (Exception e) { // TODO: error e.Ignore(); } finally { Dispatcher.Invoke(() => { // Allow to install the latest version if any version is found var latestVersion = xenkoVersions.FirstOrDefault(); if (latestVersion != null) { // Latest version not installed and can be downloaded if (latestVersion.CanBeDownloaded) { InstallLatestVersionCommand.IsEnabled = !latestVersion.CanDelete && latestVersion.CanBeDownloaded; } } OnPropertyChanging(nameof(ActiveDocumentationPages)); OnPropertyChanged(nameof(ActiveDocumentationPages)); }); } }