/// <summary>
        ///     Finds a package given a local filename
        /// </summary>
        /// <param name="file"></param>
        /// <param name="id"></param>
        /// <param name="request"></param>
        public void FindPackageByFile(string file, int id, ChocolateyRequest request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", PackageProviderName, file, id);

            var pkgItem = request.GetPackageByFilePath(Path.GetFullPath(file));

            if (pkgItem != null)
            {
                request.YieldPackage(pkgItem, file);
            }
        }
        /// <summary>
        ///     Returns the packages that are installed
        /// </summary>
        /// <param name="name">the package name to match. Empty or null means match everything</param>
        /// <param name="requiredVersion">
        ///     the specific version asked for. If this parameter is specified (ie, not null or empty
        ///     string) then the minimum and maximum values are ignored
        /// </param>
        /// <param name="minimumVersion">
        ///     the minimum version of packages to return . If the <code>requiredVersion</code> parameter
        ///     is specified (ie, not null or empty string) this should be ignored
        /// </param>
        /// <param name="maximumVersion">
        ///     the maximum version of packages to return . If the <code>requiredVersion</code> parameter
        ///     is specified (ie, not null or empty string) this should be ignored
        /// </param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, ChocolateyRequest request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::GetInstalledPackages' '{1}','{2}','{3}','{4}'", PackageProviderName, name,
                requiredVersion, minimumVersion, maximumVersion);

            if (requiredVersion != null) {
                minimumVersion = null;
                maximumVersion = null;
            } else {
                minimumVersion = minimumVersion.FixVersion();
                maximumVersion = maximumVersion.FixVersion();
            }

            if (!IsValidVersionRange(minimumVersion, maximumVersion)) {
                request.Error(ErrorCategory.InvalidArgument, minimumVersion + maximumVersion,
                    Constants.Messages.InvalidVersionRange, minimumVersion, maximumVersion);
                return;
            }

            // look in the destination directory for directories that contain nupkg files.
            var subdirs = Directory.EnumerateDirectories(request.Destination);
            foreach (var subdir in subdirs) {
                var nupkgs = Directory.EnumerateFileSystemEntries(subdir, "*.nupkg", SearchOption.TopDirectoryOnly);

                foreach (var pkgFile in nupkgs) {
                    var pkgItem = request.GetPackageByFilePath(pkgFile);

                    if (pkgItem != null && pkgItem.IsInstalled) {
                        if (pkgItem.Id.Equals(name, StringComparison.CurrentCultureIgnoreCase)) {
                            if (!string.IsNullOrWhiteSpace(requiredVersion)) {
                                if (pkgItem.Package.Version != new SemanticVersion(requiredVersion)) {
                                    continue;
                                }
                            } else {
                                if (!string.IsNullOrWhiteSpace(minimumVersion) &&
                                    pkgItem.Package.Version < new SemanticVersion(minimumVersion)) {
                                    continue;
                                }
                                if (!string.IsNullOrWhiteSpace(maximumVersion) &&
                                    pkgItem.Package.Version < new SemanticVersion(maximumVersion)) {
                                    continue;
                                }
                            }
                            request.YieldPackage(pkgItem, name);
                            break;
                        }
                        if (string.IsNullOrEmpty(name) ||
                            pkgItem.Id.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) > -1) {
                            if (!request.YieldPackage(pkgItem, name)) {
                                return;
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        ///     Finds a package given a local filename
        /// </summary>
        /// <param name="file"></param>
        /// <param name="id"></param>
        /// <param name="request"></param>
        public void FindPackageByFile(string file, int id, ChocolateyRequest request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::FindPackageByFile' '{1}','{2}'", PackageProviderName, file, id);

            var pkgItem = request.GetPackageByFilePath(Path.GetFullPath(file));
            if (pkgItem != null) {
                request.YieldPackage(pkgItem, file);
            }
        }
        /// <summary>
        ///     Returns the packages that are installed
        /// </summary>
        /// <param name="name">the package name to match. Empty or null means match everything</param>
        /// <param name="requiredVersion">
        ///     the specific version asked for. If this parameter is specified (ie, not null or empty
        ///     string) then the minimum and maximum values are ignored
        /// </param>
        /// <param name="minimumVersion">
        ///     the minimum version of packages to return . If the <code>requiredVersion</code> parameter
        ///     is specified (ie, not null or empty string) this should be ignored
        /// </param>
        /// <param name="maximumVersion">
        ///     the maximum version of packages to return . If the <code>requiredVersion</code> parameter
        ///     is specified (ie, not null or empty string) this should be ignored
        /// </param>
        /// <param name="request">
        ///     An object passed in from the CORE that contains functions that can be used to interact with
        ///     the CORE and HOST
        /// </param>
        public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, ChocolateyRequest request)
        {
            // Nice-to-have put a debug message in that tells what's going on.
            request.Debug("Calling '{0}::GetInstalledPackages' '{1}','{2}','{3}','{4}'", PackageProviderName, name,
                          requiredVersion, minimumVersion, maximumVersion);

            if (requiredVersion != null)
            {
                minimumVersion = null;
                maximumVersion = null;
            }
            else
            {
                minimumVersion = minimumVersion.FixVersion();
                maximumVersion = maximumVersion.FixVersion();
            }

            if (!IsValidVersionRange(minimumVersion, maximumVersion))
            {
                request.Error(ErrorCategory.InvalidArgument, minimumVersion + maximumVersion,
                              Constants.Messages.InvalidVersionRange, minimumVersion, maximumVersion);
                return;
            }

            // look in the destination directory for directories that contain nupkg files.
            var subdirs = Directory.EnumerateDirectories(request.Destination);

            foreach (var subdir in subdirs)
            {
                var nupkgs = Directory.EnumerateFileSystemEntries(subdir, "*.nupkg", SearchOption.TopDirectoryOnly);

                foreach (var pkgFile in nupkgs)
                {
                    var pkgItem = request.GetPackageByFilePath(pkgFile);

                    if (pkgItem != null && pkgItem.IsInstalled)
                    {
                        if (pkgItem.Id.Equals(name, StringComparison.CurrentCultureIgnoreCase))
                        {
                            if (!string.IsNullOrWhiteSpace(requiredVersion))
                            {
                                if (pkgItem.Package.Version != new SemanticVersion(requiredVersion))
                                {
                                    continue;
                                }
                            }
                            else
                            {
                                if (!string.IsNullOrWhiteSpace(minimumVersion) &&
                                    pkgItem.Package.Version < new SemanticVersion(minimumVersion))
                                {
                                    continue;
                                }
                                if (!string.IsNullOrWhiteSpace(maximumVersion) &&
                                    pkgItem.Package.Version < new SemanticVersion(maximumVersion))
                                {
                                    continue;
                                }
                            }
                            request.YieldPackage(pkgItem, name);
                            break;
                        }
                        if (string.IsNullOrEmpty(name) ||
                            pkgItem.Id.IndexOf(name, StringComparison.CurrentCultureIgnoreCase) > -1)
                        {
                            if (!request.YieldPackage(pkgItem, name))
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }