protected override void ProcessRecord()
        {
            WriteDebug("Entering GetInstalledPSResource");

            GetHelper getHelper = new GetHelper(this);

            foreach (PSResourceInfo pkg in getHelper.FilterPkgPaths(Name, _versionRange, _pathsToSearch))
            {
                WriteObject(pkg);
            }
        }
Esempio n. 2
0
        // Check if any of the pkg versions are already installed, if they are we'll remove them from the list of packages to install
        public IEnumerable <PSResourceInfo> FilterByInstalledPkgs(IEnumerable <PSResourceInfo> packagesToInstall)
        {
            List <string> pkgNames = new List <string>();

            foreach (var pkg in packagesToInstall)
            {
                pkgNames.Add(pkg.Name);
            }

            List <string> _pathsToSearch = new List <string>();
            GetHelper     getHelper      = new GetHelper(_cmdletPassedIn);

            // _pathsToInstallPkg will only contain the paths specified within the -Scope param (if applicable)
            // _pathsToSearch will contain all resource package subdirectories within _pathsToInstallPkg path locations
            // e.g.:
            // ./InstallPackagePath1/PackageA
            // ./InstallPackagePath1/PackageB
            // ./InstallPackagePath2/PackageC
            // ./InstallPackagePath3/PackageD
            foreach (var path in _pathsToInstallPkg)
            {
                _pathsToSearch.AddRange(Utils.GetSubDirectories(path));
            }

            IEnumerable <PSResourceInfo> pkgsAlreadyInstalled = getHelper.FilterPkgPaths(pkgNames.ToArray(), _versionRange, _pathsToSearch);

            // If any pkg versions are already installed, write a message saying it is already installed and continue processing other pkg names
            if (pkgsAlreadyInstalled.Any())
            {
                foreach (PSResourceInfo pkg in pkgsAlreadyInstalled)
                {
                    _cmdletPassedIn.WriteWarning(string.Format("Resource '{0}' with version '{1}' is already installed.  If you would like to reinstall, please run the cmdlet again with the -Reinstall parameter", pkg.Name, pkg.Version));

                    // remove this pkg from the list of pkg names install
                    packagesToInstall.ToList().Remove(pkg);
                }
            }

            return(packagesToInstall);
        }