Esempio n. 1
0
        public override bool ProcessRecordAsync()
        {
            if (IsSourceByObject)
            {
                // we've already got the package source
                UpdatePackageSource(InputObject);
                return(true);
            }

            if (string.IsNullOrWhiteSpace(Name) && string.IsNullOrWhiteSpace(Location))
            {
                Error(Constants.Errors.NameOrLocationRequired);
                return(false);
            }

            // otherwise, we're just changing a source by name
            var prov = SelectedProviders.ToArray();

            if (Stopping)
            {
                return(false);
            }

            if (prov.Length == 0)
            {
                if (ProviderName.IsNullOrEmpty() || string.IsNullOrWhiteSpace(ProviderName[0]))
                {
                    return(Error(Constants.Errors.UnableToFindProviderForSource, Name ?? Location));
                }
                return(Error(Constants.Errors.UnknownProvider, ProviderName[0]));
            }

            if (prov.Length > 0)
            {
                var sources = prov.SelectMany(each => each.ResolvePackageSources(this.SuppressErrorsAndWarnings(IsProcessing)).Where(source => source.IsRegistered &&
                                                                                                                                     (Name == null || source.Name.EqualsIgnoreCase(Name)) || (Location == null || source.Location.EqualsIgnoreCase(Location))).ToArray()).ToArray();

                if (sources.Length == 0)
                {
                    return(Error(Constants.Errors.SourceNotFound, Name));
                }

                if (sources.Length > 1)
                {
                    return(Error(Constants.Errors.SourceFoundInMultipleProviders, Name, prov.Select(each => each.ProviderName).JoinWithComma()));
                }

                UpdatePackageSource(sources[0]);
            }
            return(true);
        }
Esempio n. 2
0
        protected virtual void SearchForPackages()
        {
            try {
                var providers = SelectedProviders.ToArray();

                // filter the items into three types of searches
                _names = CollectionExtensions.IsNullOrEmpty(Name) ? CollectionExtensions.SingleItemAsEnumerable(string.Empty) : Name.Where(each => !IsUri(each) && !IsFile(each)).ToArray();

                foreach (var n in _names)
                {
                    Debug("Calling SearchForPackages. Name='{0}'", n);
                }

                ProcessRequests(providers.Where(pv => string.Equals(pv.ProviderName, "bootstrap", StringComparison.OrdinalIgnoreCase)).ToArray());

                ProcessRequests(providers.Where(pv => !string.Equals(pv.ProviderName, "bootstrap", StringComparison.OrdinalIgnoreCase)).ToArray());
            } catch (Exception ex) {
                Debug(ex.ToString());
            }
        }
Esempio n. 3
0
        public override bool ProcessRecordAsync()
        {
            if (IsSourceByObject)
            {
                foreach (var source in InputObject)
                {
                    if (Stopping)
                    {
                        return(false);
                    }

                    var provider = SelectProviders(source.ProviderName).FirstOrDefault();
                    if (provider == null)
                    {
                        if (string.IsNullOrWhiteSpace(source.ProviderName))
                        {
                            return(Error(Constants.Errors.UnableToFindProviderForSource, source.Name));
                        }
                        return(Error(Constants.Errors.UnknownProvider, source.ProviderName));
                    }
                    Unregister(source);
                }
                return(true);
            }


            if (string.IsNullOrWhiteSpace(Source) && string.IsNullOrWhiteSpace(Location))
            {
                Error(Constants.Errors.NameOrLocationRequired);
                return(false);
            }

            // otherwise, we're just deleting a source by name
            var prov = SelectedProviders.ToArray();

            if (Stopping)
            {
                return(false);
            }

            if (prov.Length == 0)
            {
                if (ProviderName.IsNullOrEmpty() || string.IsNullOrWhiteSpace(ProviderName[0]))
                {
                    return(Error(Constants.Errors.UnableToFindProviderForSource, Source ?? Location));
                }
                return(Error(Constants.Errors.UnknownProvider, ProviderName[0]));
            }

            if (prov.Length > 0)
            {
                var sources = prov.SelectMany(each => each.ResolvePackageSources(this.SuppressErrorsAndWarnings(IsProcessing)).Where(source => source.IsRegistered && (source.Name.EqualsIgnoreCase(Source) || source.Location.EqualsIgnoreCase(Source) || source.Location.EqualsIgnoreCase(Location))).ToArray()).ToArray();

                if (sources.Length == 0)
                {
                    return(Error(Constants.Errors.SourceNotFound, Source ?? Location));
                }

                if (sources.Length > 1)
                {
                    return(Error(Constants.Errors.SourceFoundInMultipleProviders, Source ?? Location, prov.Select(each => each.ProviderName).JoinWithComma()));
                }

                return(Unregister(sources[0]));
            }

            return(true);
        }
Esempio n. 4
0
        protected void SearchForPackages()
        {
            var providers = SelectedProviders.ToArray();


            // filter the items into three types of searches
            _names = Name.IsNullOrEmpty() ? string.Empty.SingleItemAsEnumerable() : Name.Where(each => !IsUri(each) && !IsFile(each)).ToArray();


            var requests = SelectedProviders.SelectMany(pv => {
                // for a given provider, if we get an error, we want just that provider to stop.
                var host = this.ProviderSpecific(pv);

                var a = _uris.Select(uri => new {
                    query = new List <string> {
                        uri.AbsolutePath
                    },
                    provider = pv,
                    packages = pv.FindPackageByUri(uri, host).CancelWhen(CancellationEvent.Token)
                });

                var b = _files.Keys.Where(file => pv.IsSupportedFile(_files[file].Item2)).Select(file => new {
                    query    = _files[file].Item1,
                    provider = pv,
                    packages = pv.FindPackageByFile(file, host)
                });

                var c = _names.Select(name => new {
                    query = new List <string> {
                        name
                    },
                    provider = pv,
                    packages = pv.FindPackage(name, RequiredVersion, MinimumVersion, MaximumVersion, host)
                });

                return(a.Concat(b).Concat(c));
            }).ToArray();

            if (AllVersions || !SpecifiedMinimumOrMaximum)
            {
                // the user asked for every version or they didn't specify any version ranges
                // either way, that means that we can just return everything that we're finding.

                while (WaitForActivity(requests.Select(each => each.packages)))
                {
                    // keep processing while any of the the queries is still going.

                    foreach (var result in requests.Where(each => each.packages.HasData))
                    {
                        // look only at requests that have data waiting.

                        foreach (var package in result.packages.GetConsumingEnumerable())
                        {
                            // process the results for that set.
                            ProcessPackage(result.provider, result.query, package);
                        }
                    }

                    // filter out whatever we're done with.
                    requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
                }
            }
            else
            {
                // now this is where it gets a bit funny.
                // the user specified a min or max
                // and so we have to only return the highest one in the set for a given package.

                while (WaitForActivity(requests.Select(each => each.packages)))
                {
                    // keep processing while any of the the queries is still going.
                    foreach (var perProvider in requests.GroupBy(each => each.provider))
                    {
                        foreach (var perQuery in perProvider.GroupBy(each => each.query))
                        {
                            if (perQuery.All(each => each.packages.IsCompleted && !each.packages.IsConsumed))
                            {
                                foreach (var pkg in from p in perQuery.SelectMany(each => each.packages.GetConsumingEnumerable())
                                         group p by new { p.Name, p.Source }
                                         // for a given name
                                         into grouping
                                         // get the latest version only
                                         select grouping.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).First())
                                {
                                    ProcessPackage(perProvider.Key, perQuery.Key, pkg);
                                }
                            }
                        }
                    }
                    // filter out whatever we're done with.
                    requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
                }
            }

            // dispose of any requests that didn't get cleaned up earlier.
            foreach (var i in requests)
            {
                i.packages.Dispose();
            }
        }
        protected void SearchForPackages()
        {
            var providers = SelectedProviders.ToArray();

            if (!Name.IsNullOrEmpty())
            {
                Name.ParallelForEach(name => {
                    var found = false;

                    if (Uri.IsWellFormedUriString(name, UriKind.Absolute))
                    {
                        // try everyone as via uri
                        var packageUri = new Uri(name, UriKind.Absolute);
                        if (!packageUri.IsFile)
                        {
                            providers.ParallelForEach(provider => {
                                try {
                                    found = found | FindViaUri(provider, name, packageUri);
                                } catch (Exception e) {
                                    e.Dump();
                                }
                            });
                            // we're done searching for this provider
                            return;
                        }
                        // file uris should be treated like files, not uris.
                    }

                    var files = FindFiles(name);
                    if (files.Any())
                    {
                        lock (_filesWithoutMatches) {
                            foreach (var file in files)
                            {
                                _filesWithoutMatches.Add(file, name);
                            }
                        }

                        // they specified something that looked kinda like a
                        // file path, and it actually matched some files on disk
                        // so we're going to assume that they meant to treat it
                        // as a file.
                        files.ParallelForEach(file => {
                            SelectProvidersSupportingFile(providers, file).ParallelForEach(pv => {
                                try {
                                    FindViaFile(pv, name, file);
                                } catch (Exception e) {
                                    e.Dump();
                                }
                            });
                        });
                        return;
                    }

                    _resultsPerName.GetOrAdd(name, null);

                    // it didn't match any files
                    // and it's not a uri of any kind
                    // so we'll just ask if there is a package by that name.
                    providers.ParallelForEach(provider => {
                        try {
#if DEEP_DEBUG
                            Console.WriteLine("Processing find via name [{0}]", provider.Name);
#endif
                            FindViaName(provider, name);
#if DEEP_DEBUG
                            Console.WriteLine("Done Processing find via name [{0}]", provider.Name);
#endif
                        } catch (Exception e) {
                            e.Dump();
                        }
                    });
                });
            }
            else
            {
                providers.ParallelForEach(provider => {
                    try {
                        if (!FindViaName(provider, string.Empty))
                        {
                            // nothing found?
                            _providersNotFindingAnything.AddLocked(provider);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                });
            }

            /*
             * Parallel.ForEach(SelectedProviders, provider => {
             *  try {
             *      if (!Name.IsNullOrEmpty()) {
             *          foreach (var each in Name) {
             *              // check if the parameter is an uri
             *              if (FindViaUri(provider, each)) {
             *                  continue;
             *              }
             *
             *              // then if it's a file
             *              if (FindViaFile(provider, each)) {
             *                  continue;
             *              }
             *
             *              // otherwise, it's just a name
             *              FindViaName(provider, each);
             *          }
             *          return;
             *      }
             *
             *      // no package name passed in.
             *      if (!FindViaName(provider, string.Empty)) {
             *          // nothing found?
             *          _providersNotFindingAnything.AddLocked(provider);
             *      }
             *  } catch (Exception e) {
             *      e.Dump();
             *  }
             * });
             */
        }