public bool UpdateProjectActions(List <ProjectAction> projectActions, string projectId) { IEnumerable <ProjectAction> previousProjectActions = GetAll() .Where(x => x.ProjectId == projectId); IEnumerable <ProjectAction> deletedProjectActions = previousProjectActions .Where(ppa => !projectActions.Any(pa => ppa.Id == pa.Id)); foreach (ProjectAction deletedProjectAction in deletedProjectActions) { Remove(deletedProjectAction.Id); } foreach (ProjectAction projectAction in projectActions) { if (string.IsNullOrEmpty(projectAction.Id)) { Add(projectAction); } else { ProjectAction actionFromDb = previousProjectActions.FirstOrDefault(x => x.Id == projectAction.Id); if (actionFromDb != null && actionFromDb.CompareTo(projectAction) != 0) { Update(projectAction); } } } return(true); }
private static ProjectAction CreateProjectAction(ResolvedAction resolvedAction) { List <ImplicitProjectAction>?implicitActions = null; if (resolvedAction.Action is BuildIntegratedProjectAction buildIntegratedAction) { implicitActions = new List <ImplicitProjectAction>(); foreach (NuGetProjectAction buildAction in buildIntegratedAction.GetProjectActions()) { var implicitAction = new ImplicitProjectAction( CreateProjectActionId(), buildAction.PackageIdentity, buildAction.NuGetProjectActionType); implicitActions.Add(implicitAction); } } string projectId = resolvedAction.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId); var projectAction = new ProjectAction( CreateProjectActionId(), projectId, resolvedAction.Action.PackageIdentity, resolvedAction.Action.NuGetProjectActionType, implicitActions); return(projectAction); }
public void SerializeThenDeserialize_WithValidArguments_RoundTrips(ProjectAction expectedResult) { ProjectAction?actualResult = SerializeThenDeserialize(ProjectActionFormatter.Instance, expectedResult); Assert.NotNull(actualResult); Assert.Equal(expectedResult, actualResult); }
private static void CreateSampleAction(Project project, string name) { ProjectAction action = project.NewAction(); action.Name = name; action.Description = String.Format("Description of {0} {1}", project.Name, name); }
public void Equals_WithObject_WhenArgumentIsEqualProjectAction_ReturnsTrue() { var otherAction = new ProjectAction( Action.Id, Action.ProjectId, Action.PackageIdentity, Action.ProjectActionType, Action.ImplicitActions); Assert.True(Action.Equals(obj: otherAction)); }
public void Equals_WithObject_WhenArgumentIsDifferentProjectAction_ReturnsFalse() { var otherAction = new ProjectAction( id: "b", projectId: "c", new PackageIdentity("d", NuGetVersion.Parse("2.3.4")), NuGetProjectActionType.Install, implicitActions: null); Assert.False(Action.Equals(obj: otherAction)); }
public void Constructor_WhenArgumentsAreValid_InitializesMembers() { const NuGetProjectActionType projectActionType = NuGetProjectActionType.Install; var action = new ProjectAction(Id, ProjectId, PackageIdentity, projectActionType, new[] { ImplicitAction }); Assert.Equal(Id, action.Id); Assert.Equal(ProjectId, action.ProjectId); Assert.Equal(PackageIdentity, action.PackageIdentity); Assert.Equal(projectActionType, action.ProjectActionType); Assert.Equal(new[] { ImplicitAction }, action.ImplicitActions); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync( string projectId, PackageIdentity packageIdentity, bool removeDependencies, bool forceRemove, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectId); Assumes.NotNull(packageIdentity); Assumes.False(packageIdentity.HasVersion); Assumes.NotNull(_state.SourceCacheContext); Assumes.NotNull(_state.ResolvedActions); Assumes.Null(_state.PackageIdentity); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { INuGetProjectContext projectContext = await ServiceLocator.GetInstanceAsync <INuGetProjectContext>(); (bool success, NuGetProject? project) = await TryGetNuGetProjectMatchingProjectIdAsync(projectId); Assumes.True(success); Assumes.NotNull(project); var projectActions = new List <ProjectAction>(); var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove); NuGetPackageManager packageManager = await _sharedState.PackageManager.GetValueAsync(cancellationToken); IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUninstallPackageAsync( project, packageIdentity.Id, uninstallationContext, projectContext, cancellationToken); foreach (NuGetProjectAction action in actions) { var resolvedAction = new ResolvedAction(project, action); var projectAction = new ProjectAction( CreateProjectActionId(), projectId, action.PackageIdentity, action.NuGetProjectActionType, implicitActions: null); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUninstallActionsAsync( IReadOnlyCollection <string> projectIds, PackageIdentity packageIdentity, bool removeDependencies, bool forceRemove, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNull(packageIdentity); Assumes.False(packageIdentity.HasVersion); Assumes.NotNull(_state.SourceCacheContext); Assumes.Null(_state.PackageIdentity); Assumes.True(_state.ResolvedActions.Count == 0); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var projectActions = new List <ProjectAction>(); var uninstallationContext = new UninstallationContext(removeDependencies, forceRemove); NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken); IEnumerable <NuGetProjectAction> projectsWithActions = await packageManager.PreviewProjectsUninstallPackageAsync( projects, packageIdentity.Id, uninstallationContext, projectContext, cancellationToken); foreach (NuGetProjectAction projectWithActions in projectsWithActions) { var resolvedAction = new ResolvedAction(projectWithActions.Project, projectWithActions); var projectAction = new ProjectAction( CreateProjectActionId(), projectWithActions.Project.GetMetadata <string>(NuGetProjectMetadataKeys.ProjectId), projectWithActions.PackageIdentity, projectWithActions.NuGetProjectActionType, implicitActions: null); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
private void ModifyIndentBasedOnAction(ProjectAction projectAction) { switch (projectAction) { case ProjectAction.Start: _Indent++; break; case ProjectAction.End: break; default: throw new ArgumentOutOfRangeException(nameof(projectAction), projectAction, null); } }
private string BuildActionString(ProjectAction projectAction) { switch (projectAction) { case ProjectAction.Start: return("START"); case ProjectAction.End: _Indent--; return("END"); default: throw new ArgumentOutOfRangeException(nameof(projectAction), projectAction, null); } }
private void btnOpenProject_Click(object sender, EventArgs e) { lblError.Text = ""; ExistingConfigPath = txtExistingProjectLocation.Text.Trim(); if (ExistingConfigPath == string.Empty || !File.Exists(ExistingConfigPath) || (Path.GetFileName(ExistingConfigPath) != "project.obconfig" && Path.GetFileName(ExistingConfigPath) != "project.config")) { lblError.Text = "Error: Please enter a valid config file path"; } else { ExistingProjectPath = Directory.GetParent(ExistingConfigPath).ToString(); Action = ProjectAction.OpenProject; DialogResult = DialogResult.OK; } }
public bool IsUserAllowedToDo(int projectId, int userId, ProjectAction action) { var project = GetProjectById(projectId); switch (action) { case ProjectAction.SeeTaskList: return(project.Workspace.Owner.Id == userId || project.Team.Any(t => t.UserId == userId && t.AccessLevel != AccessLevel.Partial)); case ProjectAction.CreateOrEditTask: case ProjectAction.EditTeam: case ProjectAction.ViewReport: return(project.Team.Any(t => t.UserId == userId && t.AccessLevel == AccessLevel.ProjectManager)); } return(false); }
public string Update(ProjectAction model) { try { ProjectAction projectAction = Get(model.Id); dbContext.ProjectActions.Attach(projectAction); projectAction.Id = model.Id; projectAction.ProjectId = model.ProjectId; projectAction.Description = model.Description; dbContext.SaveChanges(); return(model.Id); } catch (DbUpdateConcurrencyException) { return(null); } }
public string Add(ProjectAction model) { if (!string.IsNullOrEmpty(model.Id)) { return(null); } model.Id = null; try { dbContext.ProjectActions.Add(model); dbContext.SaveChanges(); } catch (Exception e) { e = e; } return(model.Id); }
private void btnCreateGalleryProject_Click(object sender, EventArgs e) { if ((ProjectType)cbxProjectType.SelectedValue != ProjectType.OpenBots) { lblError.Text = "Gallery currently only supports OpenBots Projects."; return; } else { lblError.Text = ""; } CreateProject(DialogResult.None); if (string.IsNullOrEmpty(lblError.Text)) { frmGalleryProjectManager gallery = new frmGalleryProjectManager(_newProjectLocation, NewProjectName); gallery.ShowDialog(); if (gallery.DialogResult == DialogResult.OK) { try { ExistingConfigPath = Project.ExtractGalleryProject(NewProjectPath); ExistingProjectPath = Directory.GetParent(ExistingConfigPath).ToString(); Action = ProjectAction.OpenProject; DialogResult = DialogResult.OK; } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; Directory.Delete(NewProjectPath, true); Action = ProjectAction.None; } } else { Directory.Delete(NewProjectPath, true); Action = ProjectAction.None; } gallery.Dispose(); } }
async Task <bool> viewModel_CanDeleteAction(ProjectAction action) { string prompt = String.Format("Delete task {0}?", action.Name); var messageDialog = new MessageDialog(prompt); UICommand yesCommand = new UICommand("Yes"); messageDialog.Commands.Add(yesCommand); messageDialog.Commands.Add(new UICommand("No")); messageDialog.DefaultCommandIndex = 0; messageDialog.CancelCommandIndex = 1; // Show the message dialog var result = await messageDialog.ShowAsync(); return(result == yesCommand); }
public JsonResult RegisterTime(string projectMemberActionId, string projectMemberId, int duration) { if (projectMemberActionId == null || duration <= 0) { return(new JsonResult(new { message = "MissingParameters" })); } DateTime now = DateTime.Now; ProjectAction projectMemberAction = projectActionsRepository.Get(projectMemberActionId); RegisteredAction registeredAction = new RegisteredAction { StartTime = now, Duration = duration, ProjectMemberId = projectMemberId, ProjectActionId = projectMemberActionId }; string result = registeredActionsService.Add(registeredAction); return(new JsonResult(new { result = result })); }
private void CreateProject(DialogResult result) { lblError.Text = ""; _newProjectLocation = txtNewProjectLocation.Text.Trim(); NewProjectName = txtNewProjectName.Text.Trim(); NewProjectType = (ProjectType)cbxProjectType.SelectedValue; if (string.IsNullOrEmpty(NewProjectName) || string.IsNullOrEmpty(_newProjectLocation) || !Directory.Exists(_newProjectLocation)) { lblError.Text = "Error: Please enter a valid project name and location"; } else { try { NewProjectPath = Path.Combine(_newProjectLocation, NewProjectName); string pattern = @"^[A-Za-z0-9_.-]{3,100}$"; Match m = Regex.Match(NewProjectName, pattern); if (!m.Success) { throw new Exception("Project Name contains illegal characters or isn't 3-100 characters long."); } if (!Directory.Exists(NewProjectPath)) { Directory.CreateDirectory(NewProjectPath); Action = ProjectAction.CreateProject; DialogResult = result; } else { lblError.Text = "Error: Project already exists"; } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } } }
public async Task GetPreviewResultsAsync_WithMultipleActions_SortsPackageIdentities() { string projectId = Guid.NewGuid().ToString(); var packageIdentityA = new PackageIdentitySubclass(id: "a", NuGetVersion.Parse("1.0.0")); var packageIdentityB = new PackageIdentitySubclass(id: "b", NuGetVersion.Parse("2.0.0")); var packageIdentityC = new PackageIdentitySubclass(id: "c", NuGetVersion.Parse("3.0.0")); var installAction = new ProjectAction( id: Guid.NewGuid().ToString(), projectId, packageIdentityB, NuGetProjectActionType.Install, implicitActions: new[] { new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityA, NuGetProjectActionType.Install), new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityB, NuGetProjectActionType.Install), new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityC, NuGetProjectActionType.Install) }); IReadOnlyList <PreviewResult> previewResults = await UIActionEngine.GetPreviewResultsAsync( Mock.Of <INuGetProjectManagerService>(), new[] { installAction }, CancellationToken.None); Assert.Equal(1, previewResults.Count); AccessiblePackageIdentity[] addedResults = previewResults[0].Added.ToArray(); Assert.Equal(3, addedResults.Length); Assert.Equal(packageIdentityA.Id, addedResults[0].Id); Assert.Equal(packageIdentityB.Id, addedResults[1].Id); Assert.Equal(packageIdentityC.Id, addedResults[2].Id); }
private void CreateProject(DialogResult result) { lblError.Text = ""; _newProjectLocation = txtNewProjectLocation.Text.Trim(); NewProjectName = txtNewProjectName.Text.Trim(); NewProjectType = (ProjectType)cbxProjectType.SelectedValue; if (string.IsNullOrEmpty(NewProjectName) || string.IsNullOrEmpty(_newProjectLocation) || !Directory.Exists(_newProjectLocation)) { lblError.Text = "Error: Please enter a valid project name and location"; } else { try { NewProjectPath = Path.Combine(_newProjectLocation, NewProjectName); bool isInvalidProjectName = new[] { @"/", @"\" }.Any(c => NewProjectName.Contains(c)); if (isInvalidProjectName) { throw new Exception("Illegal characters in path"); } if (!Directory.Exists(NewProjectPath)) { Directory.CreateDirectory(NewProjectPath); Action = ProjectAction.CreateProject; DialogResult = result; } else { lblError.Text = "Error: Project already exists"; } } catch (Exception ex) { lblError.Text = "Error: " + ex.Message; } } }
/// <summary> /// Posts the information on facebook and twitter /// </summary> /// <param name="user">User to send from</param> /// <param name="project">Related project</param> /// <param name="action">Action that occurred</param> public void Post(User user, Project project, ProjectAction action) { // Make sure we have a user and a project if (user == null || project == null) return; // Build the URL of the project var urlHelper = new UrlHelper(_httpContext.Request.RequestContext); string projectUrl = _coreSettings.Domain.TrimEnd('/') + urlHelper.RouteUrl("ProjectDetailTiny", new { project.Id }); // Try and send a Facebook status update if (!string.IsNullOrEmpty(user.FacebookAccessToken)) { try { string description, message; // Build the message depending on the action that occurred switch (action) { case ProjectAction.Approved: description = "I've just setup a good thing on #WeWillGather, can anyone help?"; message = "I've just setup a good thing on #WeWillGather, can anyone help?"; break; default: description = "I've just signed up to a good thing on #WeWillGather!"; message = "I've just signed up to a good thing on #WeWillGather!"; break; } // Build the parameters var parameters = new Dictionary<string, object>(); parameters["description"] = description; parameters["message"] = message; parameters["name"] = project.Name; parameters["link"] = projectUrl; // Post to the user's wall var fb = new FacebookClient(user.FacebookAccessToken); fb.Post(user.FacebookProfile + "/feed", parameters); } catch { } } // Try and send a Twitter status update if (!string.IsNullOrEmpty(user.TwitterAccessToken) && !string.IsNullOrEmpty(user.TwitterAccessSecret)) { try { // Build the oAuth tokens object var tokens = new OAuthTokens { AccessToken = user.TwitterAccessToken, AccessTokenSecret = user.TwitterAccessSecret, ConsumerKey = _siteSettings.TwitterConsumerKey, ConsumerSecret = _siteSettings.TwitterConsumerSecret }; var siteSettings = EngineContext.Current.Resolve<SiteSettings>(); string message; // Build the message depending on the action that occurred switch (action) { case ProjectAction.Approved: message = string.Format("I've just setup a good thing {0} {1}", projectUrl, siteSettings.TwitterHashTag); break; default: message = string.Format("I've just signed up to a good thing {0} {1}", projectUrl, siteSettings.TwitterHashTag); break; } // Update the Twitter status TwitterStatus.Update(tokens, message); } catch { } } }
public bool IsUserAllowedToDo(int projectId, int userId, ProjectAction action) { var project = GetProjectById(projectId); switch (action) { case ProjectAction.SeeTaskList: return project.Workspace.Owner.Id == userId || project.Team.Any(t => t.UserId == userId && t.AccessLevel != AccessLevel.Partial); case ProjectAction.CreateOrEditTask: case ProjectAction.EditTeam: case ProjectAction.ViewReport: return project.Team.Any(t => t.UserId == userId && t.AccessLevel == AccessLevel.ProjectManager); } return false; }
void ActionAdded(ProjectAction obj) { ActionNameTextBox.Focus(Windows.UI.Xaml.FocusState.Keyboard); }
public async Task GetInstallActionsAsync_WithProjectReferenceProject_WhenUpdatingPackage_ReturnsCorrectActions() { const string projectName = "a"; string projectId = Guid.NewGuid().ToString(); var projectSystemCache = new ProjectSystemCache(); using (TestDirectory testDirectory = TestDirectory.Create()) { var packageV1 = new SimpleTestPackageContext(packageId: "b", version: "1.0.0"); var packageV2 = new SimpleTestPackageContext(packageV1.Id, version: "2.0.0"); string packageSourceDirectoryPath = Path.Combine(testDirectory, "packageSource"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( packageSourceDirectoryPath, PackageSaveMode.Defaultv3, packageV1, packageV2); var packageSource = new PackageSource(packageSourceDirectoryPath); var packageSources = new List <PackageSource>() { packageSource }; Initialize(packageSources); string projectFullPath = Path.Combine(testDirectory.Path, $"{projectName}.csproj"); var unconfiguredProject = new Mock <UnconfiguredProject>(); var configuredProject = new Mock <ConfiguredProject>(); var projectServices = new Mock <ConfiguredProjectServices>(); var packageReferencesService = new Mock <IPackageReferencesService>(); var result = new Mock <IUnresolvedPackageReference>(); unconfiguredProject.Setup(x => x.GetSuggestedConfiguredProjectAsync()) .ReturnsAsync(configuredProject.Object); configuredProject.SetupGet(x => x.Services) .Returns(projectServices.Object); projectServices.SetupGet(x => x.PackageReferences) .Returns(packageReferencesService.Object); packageReferencesService.Setup(x => x.AddAsync(It.IsNotNull <string>(), It.IsNotNull <string>())) .ReturnsAsync(new AddReferenceResult <IUnresolvedPackageReference>(result.Object, added: true)); var nuGetProjectServices = new Mock <INuGetProjectServices>(); nuGetProjectServices.SetupGet(x => x.ScriptService) .Returns(Mock.Of <IProjectScriptHostService>()); var project = new CpsPackageReferenceProject( projectName: projectName, projectUniqueName: projectFullPath, projectFullPath: projectFullPath, projectSystemCache, unconfiguredProject.Object, nuGetProjectServices.Object, projectId); PackageSpec packageSpec = CreatePackageSpec( project.ProjectName, Path.Combine(testDirectory, "package.spec")); DependencyGraphSpec projectRestoreInfo = ProjectJsonTestHelpers.GetDGSpecFromPackageSpecs(packageSpec); projectRestoreInfo.AddProject(packageSpec); var projectNames = new ProjectNames( fullName: projectFullPath, uniqueName: projectFullPath, shortName: projectName, customUniqueName: projectName, projectId: projectId); projectSystemCache.AddProjectRestoreInfo(projectNames, projectRestoreInfo, Array.Empty <IAssetsLogMessage>()); _solutionManager.NuGetProjects.Add(project); string[] projectIds = new[] { projectId }; string[] packageSourceNames = new[] { packageSource.Name }; await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV1.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(1, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV1.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); Assert.Equal(1, action.ImplicitActions.Count); ImplicitProjectAction implicitAction = action.ImplicitActions[0]; Assert.Equal(packageV1.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, implicitAction.ProjectActionType); await projectManager.ExecuteActionsAsync(actions, CancellationToken.None); }); await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV2.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(1, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV2.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); Assert.Equal(2, action.ImplicitActions.Count); ImplicitProjectAction implicitAction = action.ImplicitActions[0]; Assert.Equal(packageV1.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, implicitAction.ProjectActionType); implicitAction = action.ImplicitActions[1]; Assert.Equal(packageV2.Identity, implicitAction.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, implicitAction.ProjectActionType); }); } }
public async Task GetInstallActionsAsync_WithPackagesConfigProject_WhenUpdatingPackage_ReturnsCorrectActions() { const string projectName = "a"; string projectId = Guid.NewGuid().ToString(); var projectSystemCache = new ProjectSystemCache(); using (TestDirectory testDirectory = TestDirectory.Create()) { var packageV1 = new SimpleTestPackageContext(packageId: "b", version: "1.0.0"); var packageV2 = new SimpleTestPackageContext(packageV1.Id, version: "2.0.0"); string packageSourceDirectoryPath = Path.Combine(testDirectory, "packageSource"); await SimpleTestPackageUtility.CreateFolderFeedV3Async( packageSourceDirectoryPath, PackageSaveMode.Defaultv3, packageV1, packageV2); var packageSource = new PackageSource(packageSourceDirectoryPath); var packageSources = new List <PackageSource>() { packageSource }; Initialize(packageSources); string projectFullPath = Path.Combine(testDirectory.Path, $"{projectName}.csproj"); NuGetFramework targetFramework = NuGetFramework.Parse("net46"); var msBuildNuGetProjectSystem = new TestMSBuildNuGetProjectSystem(targetFramework, new TestNuGetProjectContext()); var project = new TestMSBuildNuGetProject(msBuildNuGetProjectSystem, testDirectory.Path, projectFullPath, projectId); _solutionManager.NuGetProjects.Add(project); string[] projectIds = new[] { projectId }; string[] packageSourceNames = new[] { packageSource.Name }; await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV1.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(1, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV1.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); Assert.Empty(action.ImplicitActions); await projectManager.ExecuteActionsAsync(actions, CancellationToken.None); }); await PerformOperationAsync(async (projectManager) => { IReadOnlyList <ProjectAction> actions = await projectManager.GetInstallActionsAsync( projectIds, packageV2.Identity, VersionConstraints.None, includePrelease: true, DependencyBehavior.Lowest, packageSourceNames, CancellationToken.None); Assert.NotEmpty(actions); Assert.Equal(2, actions.Count); ProjectAction action = actions[0]; Assert.Equal(packageV1.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Uninstall, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); action = actions[1]; Assert.Equal(packageV2.Identity, action.PackageIdentity); Assert.Equal(NuGetProjectActionType.Install, action.ProjectActionType); Assert.Equal(projectId, action.ProjectId); }); } }
public ActionHeader(ProjectAction action) { _action = action; }
public async ValueTask <IReadOnlyList <ProjectAction> > GetUpdateActionsAsync( IReadOnlyCollection <string> projectIds, IReadOnlyCollection <PackageIdentity> packageIdentities, VersionConstraints versionConstraints, bool includePrelease, DependencyBehavior dependencyBehavior, IReadOnlyList <string> packageSourceNames, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNullOrEmpty(packageIdentities); Assumes.NotNullOrEmpty(packageSourceNames); Assumes.NotNull(_state.SourceCacheContext); Assumes.NotNull(_state.ResolvedActions); Assumes.Null(_state.PackageIdentity); return(await CatchAndRethrowExceptionAsync(async() => { var primarySources = new List <SourceRepository>(); var secondarySources = new List <SourceRepository>(); IEnumerable <SourceRepository> sourceRepositories = _sharedState.SourceRepositoryProvider.GetRepositories(); var packageSourceNamesSet = new HashSet <string>(packageSourceNames, StringComparer.OrdinalIgnoreCase); foreach (SourceRepository sourceRepository in sourceRepositories) { if (packageSourceNamesSet.Contains(sourceRepository.PackageSource.Name)) { primarySources.Add(sourceRepository); } if (sourceRepository.PackageSource.IsEnabled) { secondarySources.Add(sourceRepository); } } INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var resolutionContext = new ResolutionContext( dependencyBehavior, includePrelease, includeUnlisted: true, versionConstraints, new GatherCache(), _state.SourceCacheContext); NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken); IEnumerable <NuGetProjectAction> actions = await packageManager.PreviewUpdatePackagesAsync( packageIdentities.ToList(), projects, resolutionContext, projectContext, primarySources, secondarySources, cancellationToken); var projectActions = new List <ProjectAction>(); foreach (NuGetProjectAction action in actions) { var resolvedAction = new ResolvedAction(action.Project, action); ProjectAction projectAction = CreateProjectAction(resolvedAction); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public frmProjectBuilder() { InitializeComponent(); txtNewProjectLocation.Text = Folders.GetFolder(FolderType.ScriptsFolder); Action = ProjectAction.None; }
public async ValueTask <IReadOnlyList <ProjectAction> > GetInstallActionsAsync( IReadOnlyCollection <string> projectIds, PackageIdentity packageIdentity, VersionConstraints versionConstraints, bool includePrelease, DependencyBehavior dependencyBehavior, IReadOnlyList <string> packageSourceNames, CancellationToken cancellationToken) { Assumes.NotNullOrEmpty(projectIds); Assumes.NotNull(packageIdentity); Assumes.NotNullOrEmpty(packageSourceNames); Assumes.Null(_state.PackageIdentity); Assumes.True(_state.ResolvedActions.Count == 0); Assumes.NotNull(_state.SourceCacheContext); cancellationToken.ThrowIfCancellationRequested(); return(await CatchAndRethrowExceptionAsync(async() => { _state.PackageIdentity = packageIdentity; IReadOnlyList <SourceRepository> sourceRepositories = GetSourceRepositories( packageSourceNames, cancellationToken); Assumes.NotNullOrEmpty(sourceRepositories); INuGetProjectContext projectContext = await ServiceLocator.GetComponentModelServiceAsync <INuGetProjectContext>(); IReadOnlyList <NuGetProject> projects = await GetProjectsAsync(projectIds, cancellationToken); var resolutionContext = new ResolutionContext( dependencyBehavior, includePrelease, includeUnlisted: false, versionConstraints, new GatherCache(), _state.SourceCacheContext); NuGetPackageManager packageManager = await _sharedState.GetPackageManagerAsync(cancellationToken); IEnumerable <ResolvedAction> resolvedActions = await packageManager.PreviewProjectsInstallPackageAsync( projects, _state.PackageIdentity, resolutionContext, projectContext, sourceRepositories, cancellationToken); var projectActions = new List <ProjectAction>(); foreach (ResolvedAction resolvedAction in resolvedActions) { ProjectAction projectAction = CreateProjectAction(resolvedAction); _state.ResolvedActions[projectAction.Id] = resolvedAction; projectActions.Add(projectAction); } return projectActions; })); }
public async Task GetPreviewResultsAsync_WhenPackageIdentityIsSubclass_ItIsReplacedWithNewPackageIdentity() { string projectId = Guid.NewGuid().ToString(); var packageIdentityA1 = new PackageIdentitySubclass(id: "a", NuGetVersion.Parse("1.0.0")); var packageIdentityA2 = new PackageIdentitySubclass(id: "a", NuGetVersion.Parse("2.0.0")); var packageIdentityB1 = new PackageIdentitySubclass(id: "b", NuGetVersion.Parse("3.0.0")); var packageIdentityB2 = new PackageIdentitySubclass(id: "b", NuGetVersion.Parse("4.0.0")); var uninstallAction = new ProjectAction( id: Guid.NewGuid().ToString(), projectId, packageIdentityA1, NuGetProjectActionType.Uninstall, implicitActions: new[] { new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityA1, NuGetProjectActionType.Uninstall), new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityB1, NuGetProjectActionType.Uninstall) }); var installAction = new ProjectAction( id: Guid.NewGuid().ToString(), projectId, packageIdentityA2, NuGetProjectActionType.Install, implicitActions: new[] { new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityA2, NuGetProjectActionType.Install), new ImplicitProjectAction( id: Guid.NewGuid().ToString(), packageIdentityB2, NuGetProjectActionType.Install) }); IReadOnlyList <PreviewResult> previewResults = await UIActionEngine.GetPreviewResultsAsync( Mock.Of <INuGetProjectManagerService>(), new[] { uninstallAction, installAction }, CancellationToken.None); Assert.Equal(1, previewResults.Count); UpdatePreviewResult[] updatedResults = previewResults[0].Updated.ToArray(); Assert.Equal(2, updatedResults.Length); UpdatePreviewResult updatedResult = updatedResults[0]; Assert.False(updatedResult.Old.GetType().IsSubclassOf(typeof(PackageIdentity))); Assert.False(updatedResult.New.GetType().IsSubclassOf(typeof(PackageIdentity))); Assert.Equal("a.1.0.0 -> a.2.0.0", updatedResult.ToString()); updatedResult = updatedResults[1]; Assert.False(updatedResult.Old.GetType().IsSubclassOf(typeof(PackageIdentity))); Assert.False(updatedResult.New.GetType().IsSubclassOf(typeof(PackageIdentity))); Assert.Equal("b.3.0.0 -> b.4.0.0", updatedResult.ToString()); }
public ActionViewModel(ProjectAction action) { _action = action; }