public static async Task <PackageSearchResults> Search(string queryString, IChocolateyService chocolateyService, Func <IPackageViewModel> packageFactory, PackageSearchOptions options, Uri source)
        {
            List <IPackageViewModel> packages;

            if ((packages = (List <IPackageViewModel>)Cache.Get(GetMemoryCacheKey(source, queryString, options))) == null)
            {
                var queryCommand = string.Format("list {0} {1} {2} -source \"{3}\"", queryString,
                                                 options.IncludePrerelease ? "-pre" : "", options.IncludeAllVersions ? "-all" : "", source);

                var chocoPackageList = (await chocolateyService.RunIndirectChocolateyCommand(queryCommand, false))
                                       .ToDictionary(o => o.ToString().Split(' ')[0], o => o.ToString().Split(' ')[1]);

                packages = (await chocolateyService.GetPackagesFromLocalDirectory(chocoPackageList, source.ToString())).ToList();

                Cache.Set(GetMemoryCacheKey(source, queryString, options), packages, new CacheItemPolicy
                {
                    AbsoluteExpiration = DateTime.Now.AddHours(1)
                });
            }

            IQueryable <IPackageViewModel> query = packages.AsQueryable();

            if (!string.IsNullOrWhiteSpace(options.SortColumn))
            {
                query = options.SortDescending
                    ? query.OrderByDescending(options.SortColumn)
                    : query.OrderBy(options.SortColumn);
            }

            return(new PackageSearchResults
            {
                Packages = query.Skip(options.CurrentPage * options.PageSize).Take(options.PageSize),
                TotalCount = packages.Count
            });
        }
 public static async Task <bool> TestPath(Uri source, IChocolateyService chocolateyService)
 {
     return
         ((await
           chocolateyService.RunIndirectChocolateyCommand(string.Format("list -source \"{0}\"", source), false)).Count > 0);
 }