public async Task Reload() { _packages.Clear(); await Task.Run(() => { lock (_riLock) { dynamic find = _ri.Invoke("Find-Package"); foreach (var result in find) { var pkg = new Package(result.Name, result.Name, result.Version, string.Empty, result.Summary, result.Summary, new List<IPackage>(), new List<IPackage>(), new List<IPackage>(), new List<string>(), new List<string>(), new List<string>()); _packages.Add(pkg); } dynamic get = _ri.Invoke("Get-Package"); foreach (var result in get) { var pkg = new Package(result.Name, result.Name, result.Version, string.Empty, result.Summary, result.Summary, new List<IPackage>(), new List<IPackage>(), new List<IPackage>(), new List<string>(), new List<string>(), new List<string>()); if (result.Status == "Installed") { pkg.AddFlags("installed"); } var ex = _packages.FirstOrDefault(n => n.Name == pkg.Name && n.Version == pkg.Version); if (ex != null && result.Status == "Installed") ex.AddFlags("installed"); else _packages.Add(pkg); } foreach (var package in _packages) { var id = package.Id; var allVersions = Packages.Where(n => n.Id == id).ToList(); package.AddAllVersions(allVersions); } } }); }
private void SetUpdatableFlag(Package package) { var latest = _packages.SingleOrDefault(n => n.Id == package.Id && n.Flags.All(m => m != "installed") && n.Flags.Any(m => m == "latest")); if (latest != null) { package.AddFlags("updatable"); } else { package.RemoveFlags("updatable"); } }