Beispiel #1
0
        public async Task EnumerateLocalPackagesAndSetCache(ICollection <IPackageViewModel> packages, Dictionary <string, SemanticVersion> chocoPackageList, string libPath)
        {
            foreach (var nupkgFile in Directory.EnumerateFiles(libPath, "*.nupkg", SearchOption.AllDirectories))
            {
                var packageInfo = await NupkgReader.GetPackageInformation(nupkgFile);

                if (
                    !chocoPackageList.Any(
                        e =>
                        string.Equals(e.Key, packageInfo.Id, StringComparison.CurrentCultureIgnoreCase) &&
                        e.Value == packageInfo.Version))
                {
                    continue;
                }

                this.PopulatePackages(packageInfo, packages);
            }

            Cache.Set(
                BasePackageService.LocalPackagesCacheKeyName,
                packages,
                new CacheItemPolicy
            {
                AbsoluteExpiration = DateTime.Now.AddHours(1)
            });
        }
Beispiel #2
0
        /// <summary>
        /// Placehoder. Will eventually allow one to call chocolatey and list all the packages from a specificed file system source.
        /// </summary>
        /// <param name="directoryPath">The file system directory.</param>
        /// <returns>List of packages in directory.</returns>
        public async Task <IEnumerable <IPackageViewModel> > GetPackagesFromLocalDirectory(Dictionary <string, string> requestedPackages, string directoryPath)
        {
            var packages = new List <IPackageViewModel>();

            foreach (var nupkgFile in Directory.EnumerateFiles(directoryPath, "*.nupkg", SearchOption.AllDirectories))
            {
                var packageInfo = await NupkgReader.GetPackageInformation(nupkgFile);

                if (!requestedPackages.Any(e => String.Equals(e.Key, packageInfo.Id, StringComparison.CurrentCultureIgnoreCase) && new SemanticVersion(e.Value) == packageInfo.Version))
                {
                    continue;
                }

                var packageConfigEntry =
                    PackageConfigEntries().SingleOrDefault(
                        entry => String.Compare(entry.Id, packageInfo.Id, StringComparison.OrdinalIgnoreCase) == 0 && entry.Version == packageInfo.Version);

                if (packageConfigEntry != null)
                {
                    packageInfo.Source = packageConfigEntry.Source;
                }

                packages.Add(packageInfo);
            }
            return(packages);
        }
Beispiel #3
0
        /// <summary>
        /// Placeholder. Will eventually allow one to call Chocolatey and list all the packages from a specified file system source.
        /// </summary>
        /// <param name="requestedPackages">
        /// The requested Packages.
        /// </param>
        /// <param name="directoryPath">
        /// The file system directory.
        /// </param>
        /// <returns>
        /// List of packages in directory.
        /// </returns>
        public async Task <IEnumerable <IPackageViewModel> > GetPackagesFromLocalDirectory(Dictionary <string, string> requestedPackages, string directoryPath)
        {
            var packages = new List <IPackageViewModel>();

            foreach (var nupkgFile in Directory.EnumerateFiles(directoryPath, "*.nupkg", SearchOption.AllDirectories))
            {
                var packageInfo = await NupkgReader.GetPackageInformation(nupkgFile);

                if (
                    !requestedPackages.Any(
                        e =>
                        string.Equals(e.Key, packageInfo.Id, StringComparison.CurrentCultureIgnoreCase) &&
                        new SemanticVersion(e.Value) == packageInfo.Version))
                {
                    continue;
                }

                this.PopulatePackages(packageInfo, packages);
            }

            return(packages);
        }
Beispiel #4
0
        /// <summary>
        /// Retrives the currently installed packages.
        /// If the package list is cached, retrive it from there.
        /// Else, scan the file system for packages and pull the appropriate information from there.
        /// </summary>
        /// <param name="force">Forces a cache reset.</param>
        /// <returns>List of currently installed packages.</returns>
        public async Task <IEnumerable <IPackageViewModel> > GetInstalledPackages(bool force = false)
        {
            // Ensure that we only retrieve the packages one at a to refresh the Cache.
            using (await _getInstalledLock.LockAsync())
            {
                List <IPackageViewModel> packages;
                if (!force)
                {
                    packages = (List <IPackageViewModel>)Cache.Get(LocalPackagesCacheKeyName);
                    if (packages != null)
                    {
                        return(packages);
                    }
                }

                await _progressService.StartLoading("Chocolatey Service");

                _progressService.WriteMessage("Retrieving installed packages...");

                var chocoPath = Settings.Default.chocolateyInstall;
                if (string.IsNullOrWhiteSpace(chocoPath) || !Directory.Exists(chocoPath))
                {
                    throw new InvalidDataException(
                              "Invalid Chocolatey Path. Check that chocolateyInstall is correct in the app.config.");
                }

                var libPath = Path.Combine(chocoPath, "lib");

                var chocoPackageList = (await RunIndirectChocolateyCommand("list -lo", false))
                                       .Where(p => PackageRegex.IsMatch(p.ToString()))
                                       .Select(p => PackageRegex.Match(p.ToString()))
                                       .ToDictionary(m => m.Groups["Name"].Value, m => new SemanticVersion(m.Groups["VersionString"].Value));

                packages = new List <IPackageViewModel>();
                foreach (var nupkgFile in Directory.EnumerateFiles(libPath, "*.nupkg", SearchOption.AllDirectories))
                {
                    var packageInfo = await NupkgReader.GetPackageInformation(nupkgFile);

                    if (
                        !chocoPackageList.Any(
                            e =>
                            String.Equals(e.Key, packageInfo.Id, StringComparison.CurrentCultureIgnoreCase) &&
                            e.Value == packageInfo.Version))
                    {
                        continue;
                    }

                    var packageConfigEntry =
                        PackageConfigEntries().SingleOrDefault(
                            entry =>
                            String.Compare(entry.Id, packageInfo.Id, StringComparison.OrdinalIgnoreCase) == 0 &&
                            entry.Version == packageInfo.Version);

                    if (packageConfigEntry != null)
                    {
                        packageInfo.Source = packageConfigEntry.Source;
                    }

                    packages.Add(packageInfo);
                }

                Cache.Set(LocalPackagesCacheKeyName, packages, new CacheItemPolicy
                {
                    AbsoluteExpiration = DateTime.Now.AddHours(1)
                });

                await _progressService.StopLoading();

                return(packages);
            }
        }