Exemple #1
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (_packageRestoreManager != null)
            {
                NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    try
                    {
                        string solutionDirectory = await _solutionManager.GetSolutionDirectoryAsync(CancellationToken.None);
                        _componentModel          = await AsyncServiceProvider.GlobalProvider.GetComponentModelAsync();
                        _vsSolutionManager       = _componentModel.GetService <IVsSolutionManager>();
                        _solutionRestoreWorker   = _componentModel.GetService <ISolutionRestoreWorker>();

                        // if the project is PR and there is no restore running, check for missing assets file
                        // otherwise check for missing packages
                        if (await ExperimentUtility.IsTransitiveOriginExpEnabled.GetValueAsync(CancellationToken.None) &&
                            _projectContextInfo?.ProjectStyle == ProjectModel.ProjectStyle.PackageReference &&
                            _solutionRestoreWorker.IsRunning == false &&
                            await GetMissingAssetsFileStatusAsync(_projectContextInfo.ProjectId))
                        {
                            _packageRestoreManager.RaiseAssetsFileMissingEventForProjectAsync(true);
                        }
                        else
                        {
                            await _packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(solutionDirectory, CancellationToken.None);
                        }
                    }
                    catch (Exception ex)
                    {
                        await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
                        // By default, restore bar is invisible. So, in case of failure of RaisePackagesMissingEventForSolutionAsync, assume it is needed
                        UpdateRestoreBar(packagesMissing: true);
                        var unwrappedException = ExceptionUtility.Unwrap(ex);
                        ShowErrorUI(unwrappedException.Message);
                    }
                }).PostOnFailure(nameof(PackageRestoreBar));
            }
        }
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            if (_packageRestoreManager != null)
            {
                NuGetUIThreadHelper.JoinableTaskFactory.RunAsync(async delegate
                {
                    try
                    {
                        string solutionDirectory = await _solutionManager.GetSolutionDirectoryAsync(CancellationToken.None);

                        // when the control is first loaded, check for missing packages
                        await _packageRestoreManager.RaisePackagesMissingEventForSolutionAsync(solutionDirectory, CancellationToken.None);
                    }
                    catch (Exception ex)
                    {
                        // By default, restore bar is invisible. So, in case of failure of RaisePackagesMissingEventForSolutionAsync, assume it is needed
                        UpdateRestoreBar(packagesMissing: true);
                        var unwrappedException = ExceptionUtility.Unwrap(ex);
                        ShowErrorUI(unwrappedException.Message);
                    }
                }).PostOnFailure(nameof(PackageRestoreBar));
            }
        }