protected override (int, IIncrementalSource <LiveInfoListItemViewModel>) GenerateIncrementalSource()
        {
            var query = LiveSearchOptionsQuery.Create(Keyword, SelectedLiveStatus.Value);

            if (SelectedProviders.Any())
            {
                query.UseProviderTypes(SelectedProviders);
            }

            query.UseSortOrder(SelectedSearchSort.Value);
            if (IsTagSearch.Value is true)
            {
                query.UseIsTagSearch(true);
            }

            if (IsTimeshiftAvairable.Value is true)
            {
                query.UseTimeshiftIsAvailable(true);
            }

            if (IsDisableGrouping.Value is true)
            {
                query.UseDisableGrouping(true);
            }

            if (IsHideMemberOnly.Value is true)
            {
                query.UseHideMemberOnly(true);
            }
            _query = query;

            return(LiveSearchSource.OneTimeLoadCount, new LiveSearchSource(query, _reservation, SearchProvider, NiconicoSession, _nicoLiveCacheRepository));
        }
Exemple #2
0
        public override bool ProcessRecordAsync()
        {
            SelectedProviders.ParallelForEach(provider => {
                _providersProcessed.GetOrAdd(provider.ProviderName, () => false);

                try {
                    if (Name.IsNullOrEmpty())
                    {
                        foreach (var pkg in ProcessProvider(provider))
                        {
                            if (IsPackageInVersionRange(pkg))
                            {
                                WriteObject(pkg);
                            }
                        }
                    }
                    else
                    {
                        foreach (var n in Name)
                        {
                            foreach (var pkg in ProcessNames(provider, n))
                            {
                                if (IsPackageInVersionRange(pkg))
                                {
                                    WriteObject(pkg);
                                }
                            }
                        }
                    }
                } catch (Exception e) {
                    e.Dump();
                }
            });
            return(true);
        }
        public override bool ProcessRecordAsync()
        {
            if (IsPackageByObject)
            {
                return(UninstallPackages(InputObject));
            }

            // otherwise, it's just packages by name
            _resultsPerName = new Dictionary <string, List <SoftwareIdentity> >();
            SelectedProviders.ParallelForEach(provider => {
                foreach (var n in Name)
                {
                    var c = _resultsPerName.GetOrAdd(n, () => new List <SoftwareIdentity>());
                    foreach (var pkg in ProcessNames(provider, n))
                    {
                        lock (c) {
                            if (IsPackageInVersionRange(pkg))
                            {
                                c.Add(pkg);
                            }
                        }
                    }
                }
            });

            return(true);
        }
Exemple #4
0
        public override bool ProcessRecordAsync()
        {
            // keep track of what package names the user asked for.
            if (!Name.IsNullOrEmpty())
            {
                foreach (var name in Name)
                {
                    _namesProcessed.GetOrAdd(name, () => false);
                }
            }

            var requests = (Name.IsNullOrEmpty() ?

                            // if the user didn't specify any names
                            SelectedProviders.Select(pv => new {
                query = "?",
                packages = pv.GetInstalledPackages("", this.ProviderSpecific(pv)).CancelWhen(_cancellationEvent.Token)
            }) :

                            // if the user specified a name,
                            SelectedProviders.SelectMany(pv => {
                // for a given provider, if we get an error, we want just that provider to stop.
                var host = this.ProviderSpecific(pv);

                return(Name.Select(name => new {
                    query = name,
                    packages = pv.GetInstalledPackages(name, host).CancelWhen(_cancellationEvent.Token)
                }));
            })).ToArray();

            while (WaitForActivity(requests.Select(each => each.packages)))
            {
                // keep processing while any of the the queries is still going.

                foreach (var result in requests.Where(each => each.packages.HasData))
                {
                    // look only at requests that have data waiting.

                    foreach (var package in result.packages.GetConsumingEnumerable())
                    {
                        // process the results for that set.

                        if (IsPackageInVersionRange(package))
                        {
                            // it only counts if the package is in the range we're looking for.

                            // mark down that we found something for that query
                            _namesProcessed.AddOrSet(result.query, true);

                            ProcessPackage(result.query, package);
                        }
                    }
                }

                // just work with whatever is not yet consumed
                requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
            }
            return(true);
        }
Exemple #5
0
        public override bool ProcessRecordAsync()
        {
            if (IsSourceByObject)
            {
                // we've already got the package source
                UpdatePackageSource(InputObject);
                return(true);
            }

            if (string.IsNullOrWhiteSpace(Name) && string.IsNullOrWhiteSpace(Location))
            {
                Error(Constants.Errors.NameOrLocationRequired);
                return(false);
            }

            // otherwise, we're just changing a source by name
            var prov = SelectedProviders.ToArray();

            if (Stopping)
            {
                return(false);
            }

            if (prov.Length == 0)
            {
                if (ProviderName.IsNullOrEmpty() || string.IsNullOrWhiteSpace(ProviderName[0]))
                {
                    return(Error(Constants.Errors.UnableToFindProviderForSource, Name ?? Location));
                }
                return(Error(Constants.Errors.UnknownProvider, ProviderName[0]));
            }

            if (prov.Length > 0)
            {
                var sources = prov.SelectMany(each => each.ResolvePackageSources(this.SuppressErrorsAndWarnings(IsProcessing)).Where(source => source.IsRegistered &&
                                                                                                                                     (Name == null || source.Name.EqualsIgnoreCase(Name)) || (Location == null || source.Location.EqualsIgnoreCase(Location))).ToArray()).ToArray();

                if (sources.Length == 0)
                {
                    return(Error(Constants.Errors.SourceNotFound, Name));
                }

                if (sources.Length > 1)
                {
                    return(Error(Constants.Errors.SourceFoundInMultipleProviders, Name, prov.Select(each => each.ProviderName).JoinWithComma()));
                }

                UpdatePackageSource(sources[0]);
            }
            return(true);
        }
Exemple #6
0
        protected virtual void SearchForPackages()
        {
            try {
                var providers = SelectedProviders.ToArray();

                // filter the items into three types of searches
                _names = CollectionExtensions.IsNullOrEmpty(Name) ? CollectionExtensions.SingleItemAsEnumerable(string.Empty) : Name.Where(each => !IsUri(each) && !IsFile(each)).ToArray();

                foreach (var n in _names)
                {
                    Debug("Calling SearchForPackages. Name='{0}'", n);
                }

                ProcessRequests(providers.Where(pv => string.Equals(pv.ProviderName, "bootstrap", StringComparison.OrdinalIgnoreCase)).ToArray());

                ProcessRequests(providers.Where(pv => !string.Equals(pv.ProviderName, "bootstrap", StringComparison.OrdinalIgnoreCase)).ToArray());
            } catch (Exception ex) {
                Debug(ex.ToString());
            }
        }
Exemple #7
0
        public override bool ProcessRecordAsync()
        {
            // keep track of what package names the user asked for.
            if (!Name.IsNullOrEmpty())
            {
                foreach (var name in Name)
                {
                    _namesProcessed.GetOrAdd(name, () => false);
                }
            }

            var requests = (Name.IsNullOrEmpty() ?

                            // if the user didn't specify any names
                            SelectedProviders.Select(pv => new {
                query = "?",
                packages = pv.GetInstalledPackages("", RequiredVersion, MinimumVersion, MaximumVersion, this.ProviderSpecific(pv)).CancelWhen(CancellationEvent.Token)
            }) :

                            // if the user specified a name,
                            SelectedProviders.SelectMany(pv => {
                // for a given provider, if we get an error, we want just that provider to stop.
                var host = this.ProviderSpecific(pv);

                return(Name.Select(name => new {
                    query = name,
                    packages = pv.GetInstalledPackages(name, RequiredVersion, MinimumVersion, MaximumVersion, host).CancelWhen(CancellationEvent.Token)
                }));
            })).ToArray();

            var potentialPackagesToProcess = new System.Collections.ObjectModel.Collection <SoftwareIdentity>();

            while (WaitForActivity(requests.Select(each => each.packages)))
            {
                // keep processing while any of the the queries is still going.
                foreach (var result in requests.Where(each => each.packages.HasData))
                {
                    // look only at requests that have data waiting.

                    foreach (var package in result.packages.GetConsumingEnumerable())
                    {
                        // process the results for that set.

                        if (IsPackageInVersionRange(package))
                        {
                            // it only counts if the package is in the range we're looking for.

                            // mark down that we found something for that query
                            _namesProcessed.AddOrSet(result.query, true);
                            potentialPackagesToProcess.Add(package);
                        }
                    }
                }
                // just work with whatever is not yet consumed
                requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
            } // end of WaitForActivity()

            // post processing the potential packages as we have to display only
            // 1 package per name (note multiple versions of the same package may be installed)
            // In general, it is good practice to show only the latest one.
            foreach (var potentialPackage in from p in potentialPackagesToProcess
                     group p by p.Name
                     into grouping
                     select grouping.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).First()
                     )
            {
                ProcessPackage(potentialPackage.CanonicalId, potentialPackage);
            }

            return(true);
        }
        public override bool ProcessRecordAsync()
        {
            if (IsSourceByObject)
            {
                foreach (var source in InputObject)
                {
                    if (Stopping)
                    {
                        return(false);
                    }

                    var provider = SelectProviders(source.ProviderName).FirstOrDefault();
                    if (provider == null)
                    {
                        if (string.IsNullOrWhiteSpace(source.ProviderName))
                        {
                            return(Error(Constants.Errors.UnableToFindProviderForSource, source.Name));
                        }
                        return(Error(Constants.Errors.UnknownProvider, source.ProviderName));
                    }
                    Unregister(source);
                }
                return(true);
            }


            if (string.IsNullOrWhiteSpace(Source) && string.IsNullOrWhiteSpace(Location))
            {
                Error(Constants.Errors.NameOrLocationRequired);
                return(false);
            }

            // otherwise, we're just deleting a source by name
            var prov = SelectedProviders.ToArray();

            if (Stopping)
            {
                return(false);
            }

            if (prov.Length == 0)
            {
                if (ProviderName.IsNullOrEmpty() || string.IsNullOrWhiteSpace(ProviderName[0]))
                {
                    return(Error(Constants.Errors.UnableToFindProviderForSource, Source ?? Location));
                }
                return(Error(Constants.Errors.UnknownProvider, ProviderName[0]));
            }

            if (prov.Length > 0)
            {
                var sources = prov.SelectMany(each => each.ResolvePackageSources(this.SuppressErrorsAndWarnings(IsProcessing)).Where(source => source.IsRegistered && (source.Name.EqualsIgnoreCase(Source) || source.Location.EqualsIgnoreCase(Source) || source.Location.EqualsIgnoreCase(Location))).ToArray()).ToArray();

                if (sources.Length == 0)
                {
                    return(Error(Constants.Errors.SourceNotFound, Source ?? Location));
                }

                if (sources.Length > 1)
                {
                    return(Error(Constants.Errors.SourceFoundInMultipleProviders, Source ?? Location, prov.Select(each => each.ProviderName).JoinWithComma()));
                }

                return(Unregister(sources[0]));
            }

            return(true);
        }
Exemple #9
0
        protected void SearchForPackages()
        {
            var providers = SelectedProviders.ToArray();


            // filter the items into three types of searches
            _names = Name.IsNullOrEmpty() ? string.Empty.SingleItemAsEnumerable() : Name.Where(each => !IsUri(each) && !IsFile(each)).ToArray();


            var requests = SelectedProviders.SelectMany(pv => {
                // for a given provider, if we get an error, we want just that provider to stop.
                var host = this.ProviderSpecific(pv);

                var a = _uris.Select(uri => new {
                    query = new List <string> {
                        uri.AbsolutePath
                    },
                    provider = pv,
                    packages = pv.FindPackageByUri(uri, host).CancelWhen(CancellationEvent.Token)
                });

                var b = _files.Keys.Where(file => pv.IsSupportedFile(_files[file].Item2)).Select(file => new {
                    query    = _files[file].Item1,
                    provider = pv,
                    packages = pv.FindPackageByFile(file, host)
                });

                var c = _names.Select(name => new {
                    query = new List <string> {
                        name
                    },
                    provider = pv,
                    packages = pv.FindPackage(name, RequiredVersion, MinimumVersion, MaximumVersion, host)
                });

                return(a.Concat(b).Concat(c));
            }).ToArray();

            if (AllVersions || !SpecifiedMinimumOrMaximum)
            {
                // the user asked for every version or they didn't specify any version ranges
                // either way, that means that we can just return everything that we're finding.

                while (WaitForActivity(requests.Select(each => each.packages)))
                {
                    // keep processing while any of the the queries is still going.

                    foreach (var result in requests.Where(each => each.packages.HasData))
                    {
                        // look only at requests that have data waiting.

                        foreach (var package in result.packages.GetConsumingEnumerable())
                        {
                            // process the results for that set.
                            ProcessPackage(result.provider, result.query, package);
                        }
                    }

                    // filter out whatever we're done with.
                    requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
                }
            }
            else
            {
                // now this is where it gets a bit funny.
                // the user specified a min or max
                // and so we have to only return the highest one in the set for a given package.

                while (WaitForActivity(requests.Select(each => each.packages)))
                {
                    // keep processing while any of the the queries is still going.
                    foreach (var perProvider in requests.GroupBy(each => each.provider))
                    {
                        foreach (var perQuery in perProvider.GroupBy(each => each.query))
                        {
                            if (perQuery.All(each => each.packages.IsCompleted && !each.packages.IsConsumed))
                            {
                                foreach (var pkg in from p in perQuery.SelectMany(each => each.packages.GetConsumingEnumerable())
                                         group p by new { p.Name, p.Source }
                                         // for a given name
                                         into grouping
                                         // get the latest version only
                                         select grouping.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance).First())
                                {
                                    ProcessPackage(perProvider.Key, perQuery.Key, pkg);
                                }
                            }
                        }
                    }
                    // filter out whatever we're done with.
                    requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
                }
            }

            // dispose of any requests that didn't get cleaned up earlier.
            foreach (var i in requests)
            {
                i.packages.Dispose();
            }
        }
Exemple #10
0
        public override bool ProcessRecordAsync()
        {
            ValidateVersion(RequiredVersion);
            ValidateVersion(MinimumVersion);
            ValidateVersion(MaximumVersion);

            // If AllVersions is specified, make sure other version parameters are not supplied
            if (AllVersions.IsPresent)
            {
                if ((!string.IsNullOrWhiteSpace(RequiredVersion)) || (!string.IsNullOrWhiteSpace(MinimumVersion)) || (!string.IsNullOrWhiteSpace(MaximumVersion)))
                {
                    Error(Constants.Errors.AllVersionsCannotBeUsedWithOtherVersionParameters);
                }
            }

            // Cannot have Max/Min version parameters with RequiredVersion
            if (RequiredVersion != null)
            {
                if ((!string.IsNullOrWhiteSpace(MaximumVersion)) || (!string.IsNullOrWhiteSpace(MinimumVersion)))
                {
                    Error(Constants.Errors.VersionRangeAndRequiredVersionCannotBeSpecifiedTogether);
                }
            }

            // keep track of what package names the user asked for.
            if (!Name.IsNullOrEmpty())
            {
                foreach (var name in Name)
                {
                    _namesProcessed.GetOrAdd(name, () => false);
                }
            }

            var requests = (Name.IsNullOrEmpty() ?

                            // if the user didn't specify any names
                            SelectedProviders.Select(pv => new {
                query = "?",
                packages = pv.GetInstalledPackages("", RequiredVersion, MinimumVersion, MaximumVersion, this.ProviderSpecific(pv)).CancelWhen(CancellationEvent.Token)
            }) :

                            // if the user specified a name,
                            SelectedProviders.SelectMany(pv => {
                // for a given provider, if we get an error, we want just that provider to stop.
                var host = this.ProviderSpecific(pv);

                return(Name.Select(name => new {
                    query = name,
                    packages = pv.GetInstalledPackages(name, RequiredVersion, MinimumVersion, MaximumVersion, host).CancelWhen(CancellationEvent.Token)
                }));
            })).ToArray();

            var potentialPackagesToProcess = new System.Collections.ObjectModel.Collection <SoftwareIdentity>();

            while (WaitForActivity(requests.Select(each => each.packages)))
            {
                // keep processing while any of the the queries is still going.
                foreach (var result in requests.Where(each => each.packages.HasData))
                {
                    // look only at requests that have data waiting.

                    foreach (var package in result.packages.GetConsumingEnumerable())
                    {
                        // process the results for that set.

                        if (IsPackageInVersionRange(package))
                        {
                            // it only counts if the package is in the range we're looking for.

                            // mark down that we found something for that query
                            _namesProcessed.AddOrSet(result.query, true);

                            // If AllVersions is specified, process the package immediately
                            if (AllVersions)
                            {
                                // Process the package immediately if -AllVersions are required
                                ProcessPackage(package);
                            }
                            else
                            {
                                // Save to perform post-processing to eliminate duplicate versions and group by Name
                                potentialPackagesToProcess.Add(package);
                            }
                        }
                    }
                }
                // just work with whatever is not yet consumed
                requests = requests.FilterWithFinalizer(each => each.packages.IsConsumed, each => each.packages.Dispose()).ToArray();
            } // end of WaitForActivity()

            // Peform post-processing only if -AllVersions is not specified
            if (!AllVersions)
            {
                // post processing the potential packages as we have to display only
                // 1 package per name (note multiple versions of the same package may be installed)
                // In general, it is good practice to show only the latest one.

                // However there are cases when the same package can be found by different providers. in that case, we will show
                // the packages from different providers even through they have the same package name. This is important because uninstall-package
                // inherts from get-package, so that when the first provider does not implement the uninstall-package(), such as Programs, others will
                // perform the uninstall.

                //grouping packages by package name first
                var enumerablePotentialPackages = from p in potentialPackagesToProcess
                                                  group p by p.Name
                                                  into grouping
                                                  select grouping.OrderByDescending(pp => pp, SoftwareIdentityVersionComparer.Instance);

                //each group of packages with the same name, return the first if the packages are from the same provider
                foreach (var potentialPackage in enumerablePotentialPackages.Select(pp => (from p in pp
                                                                                           group p by p.ProviderName
                                                                                           into grouping
                                                                                           select grouping.OrderByDescending(each => each, SoftwareIdentityVersionComparer.Instance).First())).SelectMany(pkgs => pkgs.ToArray()))
                {
                    ProcessPackage(potentialPackage);
                }
            }

            return(true);
        }
        protected void SearchForPackages()
        {
            var providers = SelectedProviders.ToArray();

            if (!Name.IsNullOrEmpty())
            {
                Name.ParallelForEach(name => {
                    var found = false;

                    if (Uri.IsWellFormedUriString(name, UriKind.Absolute))
                    {
                        // try everyone as via uri
                        var packageUri = new Uri(name, UriKind.Absolute);
                        if (!packageUri.IsFile)
                        {
                            providers.ParallelForEach(provider => {
                                try {
                                    found = found | FindViaUri(provider, name, packageUri);
                                } catch (Exception e) {
                                    e.Dump();
                                }
                            });
                            // we're done searching for this provider
                            return;
                        }
                        // file uris should be treated like files, not uris.
                    }

                    var files = FindFiles(name);
                    if (files.Any())
                    {
                        lock (_filesWithoutMatches) {
                            foreach (var file in files)
                            {
                                _filesWithoutMatches.Add(file, name);
                            }
                        }

                        // they specified something that looked kinda like a
                        // file path, and it actually matched some files on disk
                        // so we're going to assume that they meant to treat it
                        // as a file.
                        files.ParallelForEach(file => {
                            SelectProvidersSupportingFile(providers, file).ParallelForEach(pv => {
                                try {
                                    FindViaFile(pv, name, file);
                                } catch (Exception e) {
                                    e.Dump();
                                }
                            });
                        });
                        return;
                    }

                    _resultsPerName.GetOrAdd(name, null);

                    // it didn't match any files
                    // and it's not a uri of any kind
                    // so we'll just ask if there is a package by that name.
                    providers.ParallelForEach(provider => {
                        try {
#if DEEP_DEBUG
                            Console.WriteLine("Processing find via name [{0}]", provider.Name);
#endif
                            FindViaName(provider, name);
#if DEEP_DEBUG
                            Console.WriteLine("Done Processing find via name [{0}]", provider.Name);
#endif
                        } catch (Exception e) {
                            e.Dump();
                        }
                    });
                });
            }
            else
            {
                providers.ParallelForEach(provider => {
                    try {
                        if (!FindViaName(provider, string.Empty))
                        {
                            // nothing found?
                            _providersNotFindingAnything.AddLocked(provider);
                        }
                    } catch (Exception e) {
                        e.Dump();
                    }
                });
            }

            /*
             * Parallel.ForEach(SelectedProviders, provider => {
             *  try {
             *      if (!Name.IsNullOrEmpty()) {
             *          foreach (var each in Name) {
             *              // check if the parameter is an uri
             *              if (FindViaUri(provider, each)) {
             *                  continue;
             *              }
             *
             *              // then if it's a file
             *              if (FindViaFile(provider, each)) {
             *                  continue;
             *              }
             *
             *              // otherwise, it's just a name
             *              FindViaName(provider, each);
             *          }
             *          return;
             *      }
             *
             *      // no package name passed in.
             *      if (!FindViaName(provider, string.Empty)) {
             *          // nothing found?
             *          _providersNotFindingAnything.AddLocked(provider);
             *      }
             *  } catch (Exception e) {
             *      e.Dump();
             *  }
             * });
             */
        }