Beispiel #1
0
        /// <summary>
        /// Perform a user action.
        /// </summary>
        /// <remarks>This needs to be called from a background thread. It may hang on the UI thread.</remarks>
        public async Task PerformAction(INuGetUI uiService, UserAction userAction, DependencyObject windowOwner, CancellationToken token)
        {
            try
            {
                uiService.ShowProgressDialog(windowOwner);

                var projects = uiService.Projects;

                // TODO: should stable packages allow prerelease dependencies if include prerelease was checked?
                // Allow prerelease packages only if the target is prerelease
                bool includePrelease = userAction.PackageIdentity.Version.IsPrerelease || userAction.Action == NuGetProjectActionType.Uninstall;
                bool includeUnlisted = userAction.Action == NuGetProjectActionType.Uninstall;

                ResolutionContext resolutionContext = new ResolutionContext(uiService.DependencyBehavior, includePrelease, includeUnlisted);

                IEnumerable <Tuple <NuGetProject, NuGetProjectAction> > actions = await GetActions(
                    uiService,
                    projects,
                    userAction,
                    removeDependencies : uiService.RemoveDependencies,
                    forceRemove : uiService.ForceRemove,
                    resolutionContext : resolutionContext,
                    projectContext : uiService.ProgressWindow,
                    token : token);

                IEnumerable <PreviewResult> results = GetPreviewResults(actions);

                // preview window
                if (uiService.DisplayPreviewWindow)
                {
                    var shouldContinue = false;

                    shouldContinue = uiService.PromptForPreviewAcceptance(results);

                    if (!shouldContinue)
                    {
                        return;
                    }
                }

                bool accepted = await CheckLicenseAcceptance(uiService, results, token);

                if (!accepted)
                {
                    return;
                }

                if (!token.IsCancellationRequested)
                {
                    // execute the actions
                    await ExecuteActions(actions, uiService.ProgressWindow, userAction, token);

                    // update
                    uiService.RefreshPackageStatus();
                }
            }
            catch (Exception ex)
            {
                uiService.ShowError(ex);
            }
            finally
            {
                uiService.CloseProgressDialog();
            }
        }
        /// <summary>
        /// Perform a user action.
        /// </summary>
        /// <remarks>This needs to be called from a background thread. It may hang on the UI thread.</remarks>
        public async Task PerformAction(INuGetUI uiService, UserAction userAction, DependencyObject windowOwner, CancellationToken token)
        {
            try
            {
                uiService.ShowProgressDialog(windowOwner);

                var projects = uiService.Projects;

                // TODO: should stable packages allow prerelease dependencies if include prerelease was checked?
                // Allow prerelease packages only if the target is prerelease
                bool includePrelease = userAction.PackageIdentity.Version.IsPrerelease || userAction.Action == NuGetProjectActionType.Uninstall;
                bool includeUnlisted = userAction.Action == NuGetProjectActionType.Uninstall;

                ResolutionContext resolutionContext = new ResolutionContext(uiService.DependencyBehavior, includePrelease, includeUnlisted);

                IEnumerable<Tuple<NuGetProject, NuGetProjectAction>> actions = await GetActions(
                    uiService,
                    projects,
                    userAction,
                    removeDependencies: uiService.RemoveDependencies,
                    forceRemove: uiService.ForceRemove,
                    resolutionContext: resolutionContext,
                    projectContext: uiService.ProgressWindow,
                    token: token);
                IEnumerable<PreviewResult> results = GetPreviewResults(actions);

                // preview window
                if (uiService.DisplayPreviewWindow)
                {
                    var shouldContinue = false;

                    shouldContinue = uiService.PromptForPreviewAcceptance(results);

                    if (!shouldContinue)
                    {
                        return;
                    }
                }

                bool accepted = await CheckLicenseAcceptance(uiService, results, token);
                if (!accepted)
                {
                    return;
                }

                if (!token.IsCancellationRequested)
                {
                    // execute the actions
                    await ExecuteActions(actions, uiService.ProgressWindow, userAction, token);

                    // update
                    uiService.RefreshPackageStatus();
                }
            }
            catch (Exception ex)
            {
                uiService.ShowError(ex);
            }
            finally
            {
                uiService.CloseProgressDialog();
            }
        }