예제 #1
0
        public async Task <IActionResult> Restore(Guid id, int revision)
        {
            var model = new CommonResult {
                IsOk = false
            };

            var projectUid = id;

            if (projectUid.IsEmptyGuid())
            {
                return(Json(model));
            }

            if (revision < 1)
            {
                return(Json(model));
            }

            var request  = new ProjectRestoreRequest(CurrentUser.Id, projectUid, revision);
            var response = await _projectService.RestoreProject(request);

            if (response.Status.IsNotSuccess)
            {
                model.Messages = response.ErrorMessages;
                return(Json(model));
            }

            model.IsOk = true;
            CurrentUser.IsActionSucceed = true;
            return(Json(model));
        }
예제 #2
0
        public static ProjectRestoreRequest GetProjectRestoreRequest()
        {
            var project = GetOrganizationOneProjectOne();
            var request = new ProjectRestoreRequest(CurrentUserId, project.OrganizationUid, One);

            return(request);
        }
예제 #3
0
        public async Task <ProjectRestoreResponse> RestoreProject(ProjectRestoreRequest request)
        {
            var response = new ProjectRestoreResponse();

            var currentUser = _cacheManager.GetCachedCurrentUser(request.CurrentUserId);

            if (await _organizationRepository.Any(x => x.Id == currentUser.OrganizationId && !x.IsActive))
            {
                response.SetInvalid();
                return(response);
            }

            var project = await _projectRepository.Select(x => x.Uid == request.ProjectUid);

            if (project.IsNotExist())
            {
                response.SetInvalid();
                response.InfoMessages.Add("project_not_found");
                return(response);
            }

            var revisions = await _projectRepository.SelectRevisions(project.Id);

            if (revisions.All(x => x.Revision != request.Revision))
            {
                response.SetInvalid();
                response.InfoMessages.Add("revision_not_found");
                return(response);
            }

            var result = await _projectRepository.RestoreRevision(request.CurrentUserId, project.Id, request.Revision);

            if (result)
            {
                response.Status = ResponseStatus.Success;
                return(response);
            }

            response.SetFailed();
            return(response);
        }
예제 #4
0
        public async Task WalkDependenciesAsync_WithCancellationToken_ThrowsAsync()
        {
            using (var pathContext = new SimpleTestPathContext())
            {
                var projectName      = "TestProject";
                var projectDirectory = Path.Combine(pathContext.SolutionRoot, projectName);
                var packageSpec      = PackageReferenceSpecBuilder.Create(projectName, projectDirectory)
                                       .WithTargetFrameworks(new string[] { "net46", "net47" })
                                       .WithPackagesLockFile()
                                       .Build();

                var restoreRequest = ProjectTestHelpers.CreateRestoreRequest(packageSpec, pathContext, _logger);

                var projectRestoreRequest = new ProjectRestoreRequest(restoreRequest, packageSpec, restoreRequest.ExistingLockFile, _collector);;

                var cmd = new ProjectRestoreCommand(projectRestoreRequest);

                // Assert exception
                var ex = await Assert.ThrowsAnyAsync <OperationCanceledException>(async() =>
                {
                    var cts = new CancellationTokenSource();
                    cts.Cancel();
                    // Act: call TryRestoreAsync() that calls WalkDependenciesAsync()
                    await cmd.TryRestoreAsync(
                        projectRange: It.IsAny <LibraryRange>(),
                        frameworkRuntimePairs: new FrameworkRuntimePair[] {
                        new FrameworkRuntimePair(NuGetFramework.Parse("net46"), null),
                        new FrameworkRuntimePair(NuGetFramework.Parse("net47"), null),
                    },
                        userPackageFolder: It.IsAny <NuGetv3LocalRepository>(),
                        fallbackPackageFolders: It.IsAny <IReadOnlyList <NuGetv3LocalRepository> >(),
                        remoteWalker: It.IsAny <RemoteDependencyWalker>(),
                        context: It.IsAny <RemoteWalkContext>(),
                        forceRuntimeGraphCreation: false,
                        token: cts.Token,
                        telemetryActivity: TelemetryActivity.Create(Guid.NewGuid(), "TestTelemetry"),
                        telemetryPrefix: "testTelemetryPrefix");
                });
            }
        }
예제 #5
0
        public static ProjectRestoreRequest GetProjectRestoreRequest()
        {
            var request = new ProjectRestoreRequest(CurrentUserId, OrganizationOneUid, One);

            return(request);
        }