GetPackageSources() 정적인 개인적인 메소드

static private GetPackageSources ( IRequest request ) : PackageSource>.IDictionary
request IRequest
리턴 PackageSource>.IDictionary
예제 #1
0
        /// <summary>
        /// Resolves and returns Package Sources to the client.
        ///
        /// Specified sources are passed in via the request object (<c>request.GetSources()</c>).
        ///
        /// Sources are returned using <c>request.YieldPackageSource(...)</c>
        /// </summary>
        /// <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 ResolvePackageSources(IRequest request)
        {
            request.Debug("Calling '{0}::ResolvePackageSources'", PackageProviderName);

            if (request.Sources.Any())
            {
                // the system is requesting sources that match the values passed.
                // if the value passed can be a legitimate source, but is not registered, return a package source marked unregistered.
                var packageSources = ProviderStorage.GetPackageSources(request);

                if (request.IsCanceled)
                {
                    return;
                }

                foreach (var source in request.Sources.AsNotNull())
                {
                    if (packageSources.ContainsKey(source))
                    {
                        var packageSource = packageSources[source];

                        // YieldPackageSource returns false when operation was cancelled
                        if (!request.YieldPackageSource(packageSource.Name, packageSource.Location, packageSource.Trusted, packageSource.IsRegistered, packageSource.IsValidated))
                        {
                            return;
                        }
                    }
                    else
                    {
                        request.Warning("Package Source '{0}' not found.", source);
                    }
                }
            }
            else
            {
                // the system is requesting all the registered sources
                var packageSources = ProviderStorage.GetPackageSources(request);
                foreach (var entry in packageSources.AsNotNull())
                {
                    var packageSource = entry.Value;

                    // YieldPackageSource returns false when operation was cancelled
                    if (!request.YieldPackageSource(packageSource.Name, packageSource.Location, packageSource.Trusted, packageSource.IsRegistered, packageSource.IsValidated))
                    {
                        return;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Searches package sources given name and version information
        ///
        /// Package information must be returned using <c>request.YieldPackage(...)</c> function.
        /// </summary>
        /// <param name="name">a name or partial name of the package(s) requested</param>
        /// <param name="requiredVersion">A specific version of the package. Null or empty if the user did not specify</param>
        /// <param name="minimumVersion">A minimum version of the package. Null or empty if the user did not specify</param>
        /// <param name="maximumVersion">A maximum version of the package. Null or empty if the user did not specify</param>
        /// <param name="id">if this is greater than zero (and the number should have been generated using <c>StartFind(...)</c>, the core is calling this multiple times to do a batch search request. The operation can be delayed until <c>CompleteFind(...)</c> is called</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 FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, IRequest request)
        {
            request.Debug("Calling '{0}::FindPackage' '{1}','{2}','{3}','{4}'", PackageProviderName, requiredVersion, minimumVersion, maximumVersion, id);

            List <PackageSource> sources;
            var providerPackageSources = ProviderStorage.GetPackageSources(request);

            if (request.Sources != null && request.Sources.Any())
            {
                sources = new List <PackageSource>();

                foreach (var userRequestedSource in request.Sources)
                {
                    if (providerPackageSources.ContainsKey(userRequestedSource))
                    {
                        sources.Add(providerPackageSources[userRequestedSource]);
                    }
                }
            }
            else
            {
                sources = providerPackageSources.Select(i => i.Value).ToList();
            }

            if (request.IsCanceled)
            {
                return;
            }

            foreach (var source in sources)
            {
                var downloadLinks    = new HashSet <Uri>();
                var webSearch        = new WebSearch(source);
                var downloadWebsites = webSearch.Search(name, 3);

                foreach (var downloadWebsite in downloadWebsites)
                {
                    try
                    {
                        var downloadLink = DownloadLinkFinder.GetDownloadLink(downloadWebsite).Result;

                        // TODO: for now we're returning all potential downloads for the user to choose from
                        // TODO: we could provide our own ranking, e.g. check if downloadLink is the same domain as url
                        if (downloadLink != null && downloadLinks.Add(downloadLink))
                        {
                            var domainName    = downloadLink.GetLeftPart(UriPartial.Authority).Replace("/www.", "/").Replace("http://", "").Replace("https://", "");
                            var packageSource = new PackageSource(domainName, domainName);
                            var packageItem   = new PackageItem(packageSource, downloadLink.ToString(), "");

                            // YieldPackage returns false when operation was cancelled
                            if (!request.YieldPackage(packageItem, name))
                            {
                                return;
                            }
                        }
                    }
                    catch (Exception)
                    {
                        continue;
                    }
                }
            }
        }