Beispiel #1
0
        /// <summary>
        /// Builds a list of NugetPackages from the XML returned from the HTTP GET request issued at the given URL.
        /// Note that NuGet uses an Atom-feed (XML Syndicaton) superset called OData.
        /// See here http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
        /// </summary>
        /// <param name="url"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private List <NugetPackage> GetPackagesFromUrl(string url, string password)
        {
            NugetHelper.LogVerbose("Getting packages from: {0}", url);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <NugetPackage> packages = new List <NugetPackage>();

            // Mono doesn't have a Certificate Authority, so we have to provide all validation manually.  Currently just accept anything.
            // See here: http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https

            // remove all handlers
            ServicePointManager.ServerCertificateValidationCallback = null;

            // add anonymous handler
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) => true;

            Stream       responseStream = NugetHelper.RequestUrl(url, password, timeOut: 5000);
            StreamReader streamReader   = new StreamReader(responseStream);

            packages = NugetODataResponse.Parse(XDocument.Load(streamReader));

            foreach (var package in packages)
            {
                package.PackageSource = this;
            }

            stopwatch.Stop();
            NugetHelper.LogVerbose("Retreived {0} packages in {1} ms", packages.Count, stopwatch.ElapsedMilliseconds);

            return(packages);
        }
Beispiel #2
0
        /// <summary>
        /// Builds a list of NugetPackages from the XML returned from the HTTP GET request issued at the given URL.
        /// Note that NuGet uses an Atom-feed (XML Syndicaton) superset called OData.
        /// See here http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private List <NugetPackage> GetPackagesFromUrl(string url)
        {
            NugetHelper.LogVerbose("Getting packages from: {0}", url);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <NugetPackage> packages = new List <NugetPackage>();

            try
            {
                HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
                getRequest.Timeout          = 5000;
                getRequest.ReadWriteTimeout = 5000;
                Stream       responseStream = getRequest.GetResponse().GetResponseStream();
                StreamReader streamReader   = new StreamReader(responseStream);

                packages = NugetODataResponse.Parse(XDocument.Load(streamReader));

                foreach (var package in packages)
                {
                    package.PackageSource = this;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogErrorFormat(e.ToString());
            }

            stopwatch.Stop();
            NugetHelper.LogVerbose("Retreived {0} packages in {1} ms", packages.Count, stopwatch.ElapsedMilliseconds);

            return(packages);
        }