示例#1
0
        protected override void OnStartProcessingRequest(ProcessRequestArgs args)
        {
            base.OnStartProcessingRequest(args);

            // Determine the client compatibility based on the request URI. Note that the request URI may not be
            // exactly the same as the URI for the HTTP request itself. This edge case occurs when a batch request is
            // made. In batching, this method is called for each operation in the batch (which each have their own
            // request URI.
            CurrentDataSource.ClientCompatibility = ClientCompatibilityFactory.FromUri(args?.RequestUri);
        }
示例#2
0
        public IQueryable <ODataPackage> FindPackagesById(string id, string semVerLevel)
        {
            var clientCompatibility = ClientCompatibilityFactory.FromProperties(semVerLevel);

            return(Repository
                   .FindPackagesById(id, clientCompatibility)
                   .Where(package => package.Listed)
                   .Select(package => package.AsODataPackage(clientCompatibility))
                   .AsQueryable()
                   .InterceptWith(new NormalizeVersionInterceptor()));
        }
示例#3
0
        public IQueryable <ODataPackage> Search(
            string searchTerm,
            string targetFramework,
            bool includePrerelease,
            bool?includeDelisted,
            string semVerLevel)
        {
            var targetFrameworks    = string.IsNullOrEmpty(targetFramework) ? Enumerable.Empty <string>() : targetFramework.Split('|');
            var clientCompatibility = ClientCompatibilityFactory.FromProperties(semVerLevel);

            return(Repository
                   .Search(
                       searchTerm,
                       targetFrameworks,
                       includePrerelease,
                       clientCompatibility)
                   .Select(package => package.AsODataPackage(clientCompatibility))
                   .AsQueryable()
                   .InterceptWith(new NormalizeVersionInterceptor()));
        }
示例#4
0
        public IQueryable <ODataPackage> GetUpdates(
            string packageIds,
            string versions,
            bool includePrerelease,
            bool includeAllVersions,
            string targetFrameworks,
            string versionConstraints,
            string semVerLevel)
        {
            if (String.IsNullOrEmpty(packageIds) || String.IsNullOrEmpty(versions))
            {
                return(Enumerable.Empty <ODataPackage>().AsQueryable());
            }

            var idValues              = packageIds.Trim().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            var versionValues         = versions.Trim().Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
            var targetFrameworkValues = String.IsNullOrEmpty(targetFrameworks) ? null :
                                        targetFrameworks.Split('|').Select(VersionUtility.ParseFrameworkName).ToList();
            var versionConstraintValues = String.IsNullOrEmpty(versionConstraints)
                                            ? new string[idValues.Length]
                                            : versionConstraints.Split('|');

            if (idValues.Length == 0 || idValues.Length != versionValues.Length || idValues.Length != versionConstraintValues.Length)
            {
                // Exit early if the request looks invalid
                return(Enumerable.Empty <ODataPackage>().AsQueryable());
            }

            var packagesToUpdate = new List <IPackageMetadata>();

            for (var i = 0; i < idValues.Length; i++)
            {
                packagesToUpdate.Add(new PackageBuilder {
                    Id = idValues[i], Version = new SemanticVersion(versionValues[i])
                });
            }

            var versionConstraintsList = new IVersionSpec[versionConstraintValues.Length];

            for (var i = 0; i < versionConstraintsList.Length; i++)
            {
                if (!String.IsNullOrEmpty(versionConstraintValues[i]))
                {
                    VersionUtility.TryParseVersionSpec(versionConstraintValues[i], out versionConstraintsList[i]);
                }
            }

            var clientCompatibility = ClientCompatibilityFactory.FromProperties(semVerLevel);

            return(Repository
                   .GetUpdatesCore(
                       packagesToUpdate,
                       includePrerelease,
                       includeAllVersions,
                       targetFrameworkValues,
                       versionConstraintsList,
                       clientCompatibility)
                   .Select(package => package.AsODataPackage(clientCompatibility))
                   .AsQueryable()
                   .InterceptWith(new NormalizeVersionInterceptor()));
        }