public void GetPackagesToDownload(IEnumerable <string> allMissing) { IEnumerable <string> depsToDownload = allMissing.Intersect(DownloadableDeps); while (depsToDownload.Count() > 0) { Package pkg = CachedPackages.First(x => x.PackageId == DownloadableDepsPackages[depsToDownload.First()]); PkgsToDownload.Add(pkg.PackageId); depsToDownload = depsToDownload.Except(pkg.FilesContained); } }
public async Task ResolveConflicts() { HashSet <string> conflictDeps = MainWindow.RW.AllInstalledDeps.Intersect(DownloadableDeps).Except(InstalledPackages.SelectMany(x => x.FilesContained)).ToHashSet(); HashSet <int> conflictPackages = new HashSet <int>(); while (conflictDeps.Count > 0) { Package pkg = CachedPackages.First(x => x.FilesContained.Contains(conflictDeps.First())); conflictPackages.Add(pkg.PackageId); conflictDeps.ExceptWith(pkg.FilesContained); } //HashSet<int> conflictPackages = conflictPkgs.Select(x => x.PackageId).ToHashSet(); bool rewriteAll = false; bool keepAll = false; for (int i = 0; i < conflictPackages.Count; i++) { int id = conflictPackages.ElementAt(i); if (Settings.Default.IgnoredPackages?.Contains(id) == true) { continue; } Package p = CachedPackages.FirstOrDefault(x => x.PackageId == id); bool rewrite = false; if (!rewriteAll && !keepAll) { Task <ContentDialogResult> t = null; MainWindow.Dispatcher.Invoke(() => { MainWindow.ContentDialog = new ConflictPackageDialog(p.DisplayName); t = MainWindow.ContentDialog.ShowAsync(); }); ContentDialogResult result = await t; ConflictPackageDialog dlg = (ConflictPackageDialog)MainWindow.ContentDialog; rewrite = dlg.RewriteLocal; rewriteAll = dlg.RewriteAll; keepAll = dlg.KeepAll; } if (rewrite || rewriteAll) { PkgsToDownload.Add(id); HashSet <int> depsPkgs = new HashSet <int>(); await GetDependencies(new HashSet <int>() { id }, depsPkgs); PkgsToDownload.UnionWith(depsPkgs); } else { if (Settings.Default.IgnoredPackages == null) { Settings.Default.IgnoredPackages = new List <int>(); } Settings.Default.IgnoredPackages.Add(id); Settings.Default.Save(); } } }
public async Task VerifyCache() { List <Package> localCache = SqLiteAdapter.LoadPackages(true); ServerVersions = new Dictionary <int, int>(); localCache.ForEach(x => ServerVersions[x.PackageId] = x.Version); Tuple <IEnumerable <Package>, HashSet <int> > tRemoteCache = await WebWrapper.ValidateCache(ServerVersions); IEnumerable <Package> remoteCache = tRemoteCache.Item1; HashSet <int> remoteVersions = tRemoteCache.Item2; lock (CachedPackages) { CachedPackages = remoteCache.ToList(); localCache.ForEach(x => { if (!remoteVersions.Contains(x.PackageId)) { CachedPackages.Add(x); } else { ServerVersions[x.PackageId] = CachedPackages.First(y => y.PackageId == x.PackageId).Version; } }); foreach (Package pkg in remoteCache) { ServerVersions[pkg.PackageId] = pkg.Version; } } if (remoteVersions.Count > 0) { new Task(() => { foreach (Package pkg in CachedPackages) { SqLiteAdapter.SavePackage(pkg, true); } SqLiteAdapter.FlushToFile(true); }).Start(); } CachedPackages.ForEach(x => { if (x.IsPaid) { x.FilesContained.ForEach(y => { DownloadablePaidDepsPackages[y] = x.PackageId; DownloadablePaidDeps.Add(y); }); } else { x.FilesContained.ForEach(y => { DownloadableDepsPackages[y] = x.PackageId; DownloadableDeps.Add(y); }); } }); }