예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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);
        }