Beispiel #1
0
        /// <summary>
        /// The internal implementation to perform user action.
        /// </summary>
        /// <param name="resolveActionsAsync">A function that returns a task that resolves the user
        /// action into project actions.</param>
        /// <param name="executeActionsAsync">A function that returns a task that executes
        /// the project actions.</param>
        private async Task PerformActionImplAsync(
            INuGetUI uiService,
            Func <Task <IReadOnlyList <ResolvedAction> > > resolveActionsAsync,
            Func <IReadOnlyList <ResolvedAction>, Task> executeActionsAsync,
            DependencyObject windowOwner,
            CancellationToken token)
        {
            try
            {
                uiService.ShowProgressDialog(windowOwner);

                var actions = await resolveActionsAsync();

                var results = GetPreviewResults(actions);

                // Show the preview window.
                if (uiService.DisplayPreviewWindow)
                {
                    var shouldContinue = uiService.PromptForPreviewAcceptance(results);
                    if (!shouldContinue)
                    {
                        return;
                    }
                }

                // Show the license acceptance window.
                var accepted = await CheckLicenseAcceptanceAsync(uiService, results, token);

                if (!accepted)
                {
                    return;
                }

                // Warn about the fact that the "dotnet" TFM is deprecated.
                if (uiService.DisplayDeprecatedFrameworkWindow)
                {
                    var shouldContinue = ShouldContinueDueToDotnetDeprecation(uiService, actions, token);
                    if (!shouldContinue)
                    {
                        return;
                    }
                }

                if (!token.IsCancellationRequested)
                {
                    // execute the actions
                    await executeActionsAsync(actions);

                    // fires ActionsExecuted event to update the UI
                    uiService.OnActionsExecuted(actions);
                }
            }
            catch (System.Net.Http.HttpRequestException ex)
            {
                if (ex.InnerException != null)
                {
                    uiService.ShowError(ex.InnerException);
                }
                else
                {
                    uiService.ShowError(ex);
                }
            }
            catch (Exception ex)
            {
                uiService.ShowError(ex);
            }
            finally
            {
                uiService.CloseProgressDialog();
            }
        }
Beispiel #2
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();
            }
        }