Exemplo n.º 1
0
        /// <summary>
        /// Ctor's
        /// </summary>
        /// <param name="request">The nuget request object</param>
        /// <param name="queryUrl">Packagesource location</param>
        internal HttpClientPackageRepository(string queryUrl, NuGetRequest request)
        {
            // Validate the url

            Uri newUri;
            Uri validatedUri = null;

            if (Uri.TryCreate(queryUrl, UriKind.Absolute, out newUri))
            {
                validatedUri = NuGetPathUtility.ValidateUri(newUri, request);
            }

            if (validatedUri == null)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Messages.InvalidQueryUrl, queryUrl));
            }

            queryUrl = validatedUri.AbsoluteUri;

            // if a query is http://www.nuget.org/api/v2 then we add / to the end
            if (!queryUrl.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                queryUrl = String.Concat(queryUrl, "/");
            }

            _queryUri = queryUrl;

            //we are constructing the url query like http://www.nuget.org/api/v2/FindPackagesById()?id='JQuery'
            _nugetFindPackageIdQueryFormat = PathUtility.UriCombine(_queryUri, NuGetConstant.FindPackagesById);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets if the Location URI is valid.
        /// </summary>
        /// <returns>True if Location is valid and sets Location to the validated URI; false otherwise.</returns>
        public bool ValidateLocation()
        {
            if (!this.LocationValid.HasValue)
            {
                lock (validationLock)
                {
                    if (!this.LocationValid.HasValue)
                    {
                        Uri locationUri;
                        if (Uri.TryCreate(this.Location, UriKind.Absolute, out locationUri))
                        {
                            Uri validatedUri = NuGetPathUtility.ValidateUri(locationUri, this.Request);
                            if (validatedUri != null)
                            {
                                this.Location      = validatedUri.AbsoluteUri;
                                this.LocationValid = true;
                            }
                            else
                            {
                                this.LocationValid = false;
                            }
                        }
                    }
                }
            }

            return(this.LocationValid.Value);
        }