private async Task <bool> StartRestoreJobAsync( SolutionRestoreRequest request, bool isSolutionLoadRestore, CancellationToken token) { await TaskScheduler.Default; using (var jobCts = CancellationTokenSource.CreateLinkedTokenSource(token)) { return(await _lockService.Value.ExecuteNuGetOperationAsync(async() => { var componentModel = await _componentModel.GetValueAsync(jobCts.Token); using (var logger = new RestoreOperationLogger(_outputConsoleProvider)) { try { // Start logging await logger.StartAsync( request.RestoreSource, _errorList, JoinableTaskFactory, jobCts); // Run restore var job = componentModel.GetService <ISolutionRestoreJob>(); return await job.ExecuteAsync(request, _restoreJobContext, logger, isSolutionLoadRestore, jobCts.Token); } finally { // Complete all logging await logger.StopAsync(); } } }, jobCts.Token)); } }
/// <summary> /// Restore job entry point. Not re-entrant. /// </summary> public async Task <bool> ExecuteAsync( SolutionRestoreRequest request, SolutionRestoreJobContext jobContext, RestoreOperationLogger logger, CancellationToken token) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (jobContext == null) { throw new ArgumentNullException(nameof(jobContext)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger; // update instance attributes with the shared context values _dependencyGraphProjectCacheHash = jobContext.DependencyGraphProjectCacheHash; _nuGetProjectContext = jobContext.NuGetProjectContext; using (var ctr1 = token.Register(() => _status = NuGetOperationStatus.Cancelled)) { try { await RestoreAsync(request.ForceRestore, request.RestoreSource, token); } catch (OperationCanceledException) when(token.IsCancellationRequested) { } catch (Exception e) { // Log the exception to the console and activity log await _logger.LogExceptionAsync(e); } finally { // update shared context values with instance attributes jobContext.DependencyGraphProjectCacheHash = _dependencyGraphProjectCacheHash; } } return(_status == NuGetOperationStatus.NoOp || _status == NuGetOperationStatus.Succeeded); }
/// <summary> /// Restore job entry point. Not re-entrant. /// </summary> public async Task <bool> ExecuteAsync( SolutionRestoreRequest request, SolutionRestoreJobContext jobContext, RestoreOperationLogger logger, bool isSolutionLoadRestore, CancellationToken token) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (jobContext == null) { throw new ArgumentNullException(nameof(jobContext)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } _logger = logger; // update instance attributes with the shared context values _nuGetProjectContext = jobContext.NuGetProjectContext; _nuGetProjectContext.OperationId = request.OperationId; _isSolutionLoadRestore = isSolutionLoadRestore; try { await RestoreAsync(request.ForceRestore, request.RestoreSource, token); } catch (OperationCanceledException) { } catch (Exception e) { // Log the exception to the console and activity log await _logger.LogExceptionAsync(e); } return(_status == NuGetOperationStatus.NoOp || _status == NuGetOperationStatus.Succeeded); }