public IEnumerable <IRepository> GetRepositories(PackageOperationType packageOperationType)
        {
            //todo get repositories based on packageOperationType
            //currenly returns all available repositories
            //create package metadata provider from context
            using (var context = _repositoryContextService.AcquireContext())
            {
                var projects = _extensibleProjectLocator.GetAllExtensibleProjects();

                var localRepos = _projectManager.AsLocalRepositories(projects);

                var repos = context == SourceContext.EmptyContext ? new List <SourceRepository>()
                    : context.Repositories ?? context.PackageSources.Select(src => _repositoryContextService.GetRepository(src));

                var repositoryModelList = new List <IRepository>();

                //wrap all source repository object in repository model
                repositoryModelList.AddRange(
                    repos.Select(
                        source => CreateModelRepositoryFromSourceRepository(source)
                        ));

                repositoryModelList.AddRange(
                    localRepos.Select(
                        source => CreateModelRepositoryFromSourceRepository(source)

                        ));

                return(repositoryModelList);
            }
        }
示例#2
0
        public async Task <IEnumerable <IPackageSearchMetadata> > LoadAsync(string searchTerm, PageContinuation pageContinuation, SearchFilter searchFilter, CancellationToken token)
        {
            Argument.IsValid(nameof(pageContinuation), pageContinuation, pageContinuation.IsValid);

            var source           = pageContinuation.Source.PackageSources.FirstOrDefault();
            var observedProjects = _extensibleProjectLocator.GetAllExtensibleProjects();

            SourceRepository repository = null;

            if (source is not null)
            {
                repository = _repositoryProvider.CreateRepository(source);
            }
            else
            {
                repository = observedProjects.FirstOrDefault().AsSourceRepository(_repositoryProvider);
            }

            try
            {
                var localPackages = await _projectManager.CreatePackagesCollectionFromProjectsAsync(observedProjects, token);

                var pagedPackages = localPackages
                                    .GetLatest(VersionComparer.Default)
                                    .Where(package => package.Id.IndexOf(searchTerm ?? String.Empty, StringComparison.OrdinalIgnoreCase) != -1)
                                    .OrderBy(package => package.Id)
                                    .Skip(pageContinuation.GetNext());


                if (pageContinuation.Size > 0)
                {
                    pagedPackages = pagedPackages.Take(pageContinuation.Size).ToList();
                }

                List <IPackageSearchMetadata> combinedFindedMetadata = new List <IPackageSearchMetadata>();

                foreach (var package in pagedPackages)
                {
                    var metadata = await GetPackageMetadataAsync(package, searchFilter.IncludePrerelease, token);

                    if (metadata is not null)
                    {
                        combinedFindedMetadata.Add(metadata);
                    }
                }

                return(combinedFindedMetadata);
            }
            catch (FatalProtocolException ex) when(token.IsCancellationRequested)
            {
                //task is cancelled, supress
                throw new OperationCanceledException("Search request was canceled", ex, token);
            }
        }
        protected override Task InitializeAsync()
        {
            if (!_extensiblesManager.IsConfigLoaded)
            {
                _extensiblesManager.RestoreStateFromConfig();
            }

            var availableProjects = _extensiblesManager.GetAllExtensibleProjects();

            Projects = new ObservableCollection <CheckableUnit <IExtensibleProject> >(availableProjects
                                                                                      .Select(x =>
                                                                                              new CheckableUnit <IExtensibleProject>(true, x, NotifyOnProjectSelectionChanged)));

            Projects.ForEach(x => ProjectsModel.Add(x.Value));

            return(base.InitializeAsync());
        }
        protected override Task InitializeAsync()
        {
            var registeredProjects = _extensiblesManager.GetAllExtensibleProjects(onlyEnabled: false);

            if (!_extensiblesManager.IsConfigLoaded)
            {
                _extensiblesManager.RestoreStateFromConfig();
            }

            ExtensiblesCollection = new ObservableCollection <CheckableUnit <IExtensibleProject> >(
                registeredProjects
                .Select(
                    x => new CheckableUnit <IExtensibleProject>(_extensiblesManager.IsEnabled(x), x, ExtensibleProjectStatusChange))
                );

            return(base.InitializeAsync());
        }
        private async Task BatchUpdateExecuteAsync()
        {
            try
            {
                _progressManager.ShowBar(this);

                var batchedPackages = _parentManagerPage.PackageItems.Where(x => x.IsChecked).ToList();

                if (batchedPackages.Any(x => x.ValidationContext.HasErrors))
                {
                    await _messageService.ShowErrorAsync("Can't perform update. One or multiple package cannot be updated due to validation errors", "Can't update packages");

                    return;
                }

                var projects = _projectLocator.GetAllExtensibleProjects()
                               .Where(x => _projectLocator.IsEnabled(x)).ToList();

                using (var cts = new CancellationTokenSource())
                {
                    var updatePackageList = new List <IPackageDetails>();

                    foreach (var package in batchedPackages)
                    {
                        var targetProjects = new List <IExtensibleProject>();

                        foreach (var project in projects)
                        {
                            if (!await _projectManager.IsPackageInstalledAsync(project, package.Identity, cts.Token))
                            {
                                targetProjects.Add(project);
                            }
                        }

                        var targetVersion = (await package.LoadVersionsAsync() ?? package.Versions)?.FirstOrDefault();

                        if (targetVersion is null)
                        {
                            Log.Warning("Cannot perform upgrade because of 'Target version' is null");
                            return;
                        }


                        var updatePackageDetails = PackageDetailsFactory.Create(PackageOperationType.Update, package.GetMetadata(), targetVersion, null);
                        updatePackageList.Add(updatePackageDetails);
                    }

                    using (var operationContext = _packageOperationContextService.UseOperationContext(PackageOperationType.Update, updatePackageList.ToArray()))
                    {
                        foreach (var updatePackageDetails in updatePackageList)
                        {
                            await _packageCommandService.ExecuteUpdateAsync(updatePackageDetails, operationContext, cts.Token);
                        }
                    }
                }

                await Task.Delay(200);
            }
            catch (Exception ex)
            {
                Log.Error(ex, $"Error when updating package");
            }
            finally
            {
                _progressManager.HideBar(this);

                _parentManagerPage.StartLoadingTimerOrInvalidateData();
            }
        }