コード例 #1
0
        /// <summary>
        /// Searches for packages based on the configured parameters.
        /// </summary>
        /// <param name="behavior">The <see cref="CompositeSearchBehavior" /> value.</param>
        /// <param name="limit">The limit on the number of matches returned.</param>
        /// <returns>A list of <see cref="MatchResult" /> objects.</returns>
        protected IReadOnlyList <MatchResult> FindPackages(
            CompositeSearchBehavior behavior,
            uint limit)
        {
            PackageCatalog      catalog = this.GetPackageCatalog(behavior);
            FindPackagesOptions options = this.GetFindPackagesOptions(limit);

            return(GetMatchResults(catalog, options));
        }
コード例 #2
0
        private static void SetQueryInFindPackagesOptions(
            ref FindPackagesOptions options,
            PackageFieldMatchOption match,
            string value)
        {
            var selector = ComObjectFactory.Value.CreatePackageMatchFilter();

            selector.Field  = PackageMatchField.CatalogDefault;
            selector.Value  = value ?? string.Empty;
            selector.Option = match;
            options.Selectors.Add(selector);
        }
コード例 #3
0
        private static IReadOnlyList <MatchResult> GetMatchResults(
            PackageCatalog catalog,
            FindPackagesOptions options)
        {
            FindPackagesResult result = catalog.FindPackages(options);

            if (result.Status == FindPackagesResultStatus.Ok)
            {
                return(result.Matches);
            }
            else
            {
                throw new FindPackagesException(result.Status);
            }
        }
コード例 #4
0
 private static void AddFilterToFindPackagesOptionsIfNotNull(
     ref FindPackagesOptions options,
     PackageMatchField field,
     PackageFieldMatchOption match,
     string value)
 {
     if (value != null)
     {
         var filter = ComObjectFactory.Value.CreatePackageMatchFilter();
         filter.Field  = field;
         filter.Value  = value;
         filter.Option = match;
         options.Filters.Add(filter);
     }
 }
コード例 #5
0
        private void AddAttributedFiltersToFindPackagesOptions(
            ref FindPackagesOptions options,
            PackageFieldMatchOption match)
        {
            IEnumerable <PropertyInfo> properties = this
                                                    .GetType()
                                                    .GetProperties()
                                                    .Where(property => Attribute.IsDefined(property, typeof(FilterAttribute)));

            foreach (PropertyInfo info in properties)
            {
                if (info.GetCustomAttribute(typeof(FilterAttribute), true) is FilterAttribute attribute)
                {
                    PackageMatchField field = attribute.Field;
                    string            value = info.GetValue(this, null) as string;
                    AddFilterToFindPackagesOptionsIfNotNull(ref options, field, match, value);
                }
            }
        }