public void TestAddAccessPoints() { var capabilityList = CapabilityListTest.CreateTestCapabilityList(); var feed1 = new Feed { Name = "Test", CapabilityLists = { capabilityList } }; var feed2 = new Feed { Name = "Test", CapabilityLists = { capabilityList } }; using var applyFlag1 = new TemporaryFlagFile("0install-unit-tests"); using var applyFlag2 = new TemporaryFlagFile("0install-unit-tests"); var accessPoints1 = new AccessPoint[] { new MockAccessPoint { ID = "id1", Capability = "my_ext1", ApplyFlagPath = applyFlag1 } }; var accessPoints2 = new AccessPoint[] { new MockAccessPoint { ID = "id2", Capability = "my_ext2", ApplyFlagPath = applyFlag2 } }; _integrationManager.AppList.Entries.Count.Should().Be(0); var appEntry1 = _integrationManager.AddApp(new FeedTarget(FeedTest.Test1Uri, feed1)); _integrationManager.AddAccessPoints(appEntry1, feed1, accessPoints1); _integrationManager.AppList.Entries.Count.Should().Be(1, because: "Should implicitly create missing AppEntries"); applyFlag1.Set.Should().BeTrue(because: "Should apply AccessPoint"); applyFlag1.Set = false; _integrationManager.Invoking(x => x.AddAccessPoints(appEntry1, feed1, accessPoints1)) .Should().NotThrow(because: "Duplicate access points should be silently reapplied"); applyFlag1.Set.Should().BeTrue(because: "Duplicate access points should be silently reapplied"); _integrationManager.AddAccessPoints(appEntry1, feed1, accessPoints2); applyFlag2.Set = false; var appEntry2 = _integrationManager.AddApp(new FeedTarget(FeedTest.Test2Uri, feed2)); _integrationManager.Invoking(x => x.AddAccessPoints(appEntry2, feed2, accessPoints2)) .Should().Throw <ConflictException>(because: "Should prevent access point conflicts"); applyFlag2.Set.Should().BeFalse(because: "Should prevent access point conflicts"); }
public void TestAddAccessPoints() { var capabilityList = CapabilityListTest.CreateTestCapabilityList(); var feed1 = new Feed { Name = "Test", CapabilityLists = { capabilityList } }; var feed2 = new Feed { Name = "Test", CapabilityLists = { capabilityList } }; using (var applyFlag1 = new TemporaryFlagFile("0install-unit-tests")) using (var applyFlag2 = new TemporaryFlagFile("0install-unit-tests")) { var accessPoints1 = new AccessPoint[] { new MockAccessPoint { ID = "id1", Capability = "my_ext1", ApplyFlagPath = applyFlag1 } }; var accessPoints2 = new AccessPoint[] { new MockAccessPoint { ID = "id2", Capability = "my_ext2", ApplyFlagPath = applyFlag2 } }; Assert.AreEqual(0, _integrationManager.AppList.Entries.Count); var appEntry1 = _integrationManager.AddApp(new FeedTarget(FeedTest.Test1Uri, feed1)); _integrationManager.AddAccessPoints(appEntry1, feed1, accessPoints1); Assert.AreEqual(1, _integrationManager.AppList.Entries.Count, "Should implicitly create missing AppEntries"); Assert.IsTrue(applyFlag1.Set, "Should apply AccessPoint"); applyFlag1.Set = false; Assert.DoesNotThrow(() => _integrationManager.AddAccessPoints(appEntry1, feed1, accessPoints1), "Duplicate access points should be silently reapplied"); Assert.IsTrue(applyFlag1.Set, "Duplicate access points should be silently reapplied"); _integrationManager.AddAccessPoints(appEntry1, feed1, accessPoints2); applyFlag2.Set = false; var appEntry2 = _integrationManager.AddApp(new FeedTarget(FeedTest.Test2Uri, feed2)); Assert.Throws <ConflictException>(() => _integrationManager.AddAccessPoints(appEntry2, feed2, accessPoints2), "Should prevent access point conflicts"); Assert.IsFalse(applyFlag2.Set, "Should prevent access point conflicts"); } }
/// <inheritdoc/> public override ExitCode Execute() { var importList = XmlStorage.LoadXml<AppList>(AdditionalArgs[0]); using (var integrationManager = new IntegrationManager(Handler, MachineWide)) { foreach (var importEntry in importList.Entries) { var interfaceUri = importEntry.InterfaceUri; var appEntry = GetAppEntry(integrationManager, ref interfaceUri); if (importEntry.AccessPoints != null) { var feed = FeedManager[interfaceUri]; integrationManager.AddAccessPoints(appEntry, feed, importEntry.AccessPoints.Entries); } } } return ExitCode.OK; }
/// <summary> /// Creates a new alias. /// </summary> /// <param name="aliasName">The name of the alias to create.</param> /// <param name="interfaceUri">The interface URI the alias shall point to.</param> /// <param name="command">A command within the interface the alias shall point to; can be <c>null</c>.</param> /// <returns>The exit status code to end the process with.</returns> private ExitCode CreateAlias(string aliasName, FeedUri interfaceUri, string command = null) { CheckInstallBase(); using (var integrationManager = new IntegrationManager(Handler, MachineWide)) { // Check this before modifying the environment bool needsReopenTerminal = NeedsReopenTerminal(integrationManager.MachineWide); var appEntry = GetAppEntry(integrationManager, ref interfaceUri); // Apply the new alias var alias = new AppAlias {Name = aliasName, Command = command}; integrationManager.AddAccessPoints(appEntry, FeedManager[interfaceUri], new AccessPoint[] {alias}); string message = string.Format(Resources.AliasCreated, aliasName, appEntry.Name); if (needsReopenTerminal) message += Environment.NewLine + Resources.ReopenTerminal; Handler.OutputLow(Resources.DesktopIntegration, message); return ExitCode.OK; } }