public void ClearAllHasChangesTest() { var group = new LaunchGroup(null, new[] { new LaunchGroup(null, new[] { new LaunchGroup {HasChanges = true}, }, new[] { new Launcher {HasChanges = true}, }) {HasChanges = true}, }, new[] { new Launcher {HasChanges = true}, }) {HasChanges = true}; Assert.IsTrue(group.HasChanges, "All Groups and Launchers should have changes"); Assert.IsTrue(group.Groups[0].HasChanges, "All Groups and Launchers should have changes"); Assert.IsTrue(group.Groups[0].Groups[0].HasChanges, "All Groups and Launchers should have changes"); Assert.IsTrue(group.Groups[0].Launchers[0].HasChanges, "All Groups and Launchers should have changes"); Assert.IsTrue(group.Launchers[0].HasChanges, "All Groups and Launchers should have changes"); group.ClearAllHasChanges(); Assert.IsFalse(group.HasChanges, "All Groups and Launchers should not have changes"); Assert.IsFalse(group.Groups[0].HasChanges, "All Groups and Launchers should not have changes"); Assert.IsFalse(group.Groups[0].Groups[0].HasChanges, "All Groups and Launchers should not have changes"); Assert.IsFalse(group.Groups[0].Launchers[0].HasChanges, "All Groups and Launchers should not have changes"); Assert.IsFalse(group.Launchers[0].HasChanges, "All Groups and Launchers should not have changes"); }
public void HasChangesTest() { LaunchGroup group = new LaunchGroup(); LaunchGroup childGroup = new LaunchGroup(); Launcher childLauncher = new Launcher(); Assert.IsFalse(group.HasChanges); group.Name = "a"; Assert.IsTrue(group.HasChanges, "Changing Name should cause HasChanges to be true"); group.ClearAllHasChanges(); group.EnvironmentVariables.Add(new EnvironmentVariable("A", "A")); Assert.IsTrue(group.HasChanges, "New environment variables should cause HasChanges to be true"); group.ClearAllHasChanges(); group.EnvironmentVariables["A"] = "B"; Assert.IsTrue(group.HasChanges, "Updating environment variables should cause HasChanges to be true"); group.ClearAllHasChanges(); group.Groups.Add(childGroup); Assert.IsTrue(group.HasChanges, "New child groups should cause HasChages to be true"); group.ClearAllHasChanges(); childGroup.Name = "a"; Assert.IsTrue(group.HasChanges, "Changes to child groups should cause HasChanges to be true"); group.ClearAllHasChanges(); group.Launchers.Add(childLauncher); Assert.IsTrue(group.HasChanges, "New child launchers should cause HasChanges to be true"); group.ClearAllHasChanges(); childLauncher.Name = "A"; Assert.IsTrue(group.HasChanges, "Changes to child launchers should cause HasChanges to be true"); }
/// <summary> /// Initializes a new instance of the <see cref = "LaunchGroup" /> class. /// </summary> /// <param name = "parent">The parent of this group.</param> /// <param name = "groups">The child groups of this group.</param> /// <param name = "launchers">The child launchers of this group.</param> public LaunchGroup(LaunchGroup parent = null, IEnumerable <LaunchGroup> groups = null, IEnumerable <Launcher> launchers = null) { Groups = new ObservableCollection <LaunchGroup>(); Launchers = new ObservableCollection <Launcher>(); EnvironmentVariables = new EnvironmentVariableCollection(); Parent = parent; HasChanges = false; if (groups != null) { foreach (var group in groups) { Groups.Add(group); } } if (launchers != null) { foreach (var launcher in launchers) { Launchers.Add(launcher); } } }
/// <summary> /// Initializes a new instance of the <see cref = "LaunchGroup" /> class. /// </summary> /// <param name = "parent">The parent of this group.</param> /// <param name = "groups">The child groups of this group.</param> /// <param name = "launchers">The child launchers of this group.</param> public LaunchGroup(LaunchGroup parent = null, IEnumerable<LaunchGroup> groups = null, IEnumerable<Launcher> launchers = null) { Groups = new ObservableCollection<LaunchGroup>(); Launchers = new ObservableCollection<Launcher>(); EnvironmentVariables = new EnvironmentVariableCollection(); Parent = parent; HasChanges = false; if (groups != null) { foreach (var group in groups) { Groups.Add(group); } } if (launchers != null) { foreach (var launcher in launchers) { Launchers.Add(launcher); } } }
/// <summary> /// Initializes a new instance of the <see cref = "Launcher" /> class. /// </summary> /// <param name = "parent">The <see cref = "LaunchGroup" /> that contains this Launcher.</param> public Launcher(LaunchGroup parent = null) { Parent = parent; EnvironmentVariables = new EnvironmentVariableCollection(); Arguments = string.Empty; File = string.Empty; Name = string.Empty; WorkingDirectory = string.Empty; HasChanges = false; }
/// <summary> /// Initializes a new instance of the <see cref = "Launcher" /> class. /// </summary> /// <param name = "parent">The <see cref = "LaunchGroup" /> that contains this Launcher.</param> public Launcher(LaunchGroup parent = null) { Parent = parent; EnvironmentVariables = new EnvironmentVariableCollection(); Arguments = string.Empty; File = string.Empty; Name = string.Empty; WorkingDirectory = string.Empty; HasChanges = false; }
/// <summary> /// Determines whether the specified <see cref = "LaunchGroup" /> is equal to the current <see cref = "LaunchGroup" />. /// </summary> /// <returns> /// true if the specified <see cref = "LaunchGroup" /> is equal to the current <see cref = "LaunchGroup" />; otherwise, false. /// </returns> /// <param name = "other">The <see cref = "LaunchGroup" /> to compare with the current <see cref = "LaunchGroup" />. </param> /// <filterpriority>2</filterpriority> public bool Equals(LaunchGroup other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.mEnvironmentVariables, mEnvironmentVariables) && other.mGroups != null && mGroups != null && other.mGroups.SequenceEqual(mGroups) && other.mLaunchers != null && mLaunchers != null && other.mLaunchers.SequenceEqual(mLaunchers) && Equals(other.mName, mName)); }
/// <summary> /// Gets all the environment variables to be used when launching this application, starting /// with the topmost parent and overriding values down to the launcher's settings. /// </summary> public EnvironmentVariableCollection AggregateEnvironmentVariables() { var envVars = new Stack <EnvironmentVariableCollection>(); envVars.Push(EnvironmentVariables); LaunchGroup parent = mParent; while (parent != null) { envVars.Push(parent.EnvironmentVariables); parent = parent.Parent; } var aggregatedEnvVars = new EnvironmentVariableCollection(envVars.Pop()); while (envVars.Count > 0) { aggregatedEnvVars.UpdateWith(envVars.Pop()); } return(aggregatedEnvVars); }
public void AggregateEnvironmentVariablesTest() { var launcher = new Launcher(); LaunchGroup group = new LaunchGroup(null, new[] { new LaunchGroup(null, null, new[] { launcher }), }); group.EnvironmentVariables.UpdateWith( new EnvironmentVariable("A", "A"), new EnvironmentVariable("B", "B"), new EnvironmentVariable("D", "D")); group.Groups[0].EnvironmentVariables.UpdateWith( new EnvironmentVariable("C", "C"), new EnvironmentVariable("B", "B2")); launcher.EnvironmentVariables.UpdateWith( new EnvironmentVariable("D", "D2"), new EnvironmentVariable("E", "E")); var envVars = launcher.AggregateEnvironmentVariables(); Assert.That(envVars, Contains.Item(new EnvironmentVariable("A", "A"))); Assert.That(envVars, Contains.Item(new EnvironmentVariable("B", "B2"))); Assert.That(envVars, Contains.Item(new EnvironmentVariable("C", "C"))); Assert.That(envVars, Contains.Item(new EnvironmentVariable("D", "D2"))); Assert.That(envVars, Contains.Item(new EnvironmentVariable("E", "E"))); }
public void SaveLoadTest() { var tempFile = Path.GetTempFileName(); var launchGroup = new LaunchGroup { Name = "Root", EnvironmentVariables = { {"Var1", "Val1"}, {"Var2", "Val2"} } }; launchGroup.Groups.Add(new LaunchGroup { Name = "LG1", EnvironmentVariables = { {"Var3", "Val3"} } }); launchGroup.Launchers.Add(new Launcher { Arguments = "abc", File = "somefile", Name = "test", WorkingDirectory = "aaaa", EnvironmentVariables = { {"Var4", "Val4"} } }); launchGroup.SaveTo(tempFile); var newGroup = LaunchGroup.LoadFrom(tempFile); Assert.AreNotSame(launchGroup, newGroup, "LoadFrom should have created a new group"); Assert.AreEqual(launchGroup, newGroup, "LoadFrom should have loaded a group equal to the saved one"); }
/// <summary> /// Determines whether the specified <see cref = "LaunchGroup" /> is equal to the current <see cref = "LaunchGroup" />. /// </summary> /// <returns> /// true if the specified <see cref = "LaunchGroup" /> is equal to the current <see cref = "LaunchGroup" />; otherwise, false. /// </returns> /// <param name = "other">The <see cref = "LaunchGroup" /> to compare with the current <see cref = "LaunchGroup" />. </param> /// <filterpriority>2</filterpriority> public bool Equals(LaunchGroup other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return Equals(other.mEnvironmentVariables, mEnvironmentVariables) && other.mGroups != null && mGroups != null && other.mGroups.SequenceEqual(mGroups) && other.mLaunchers != null && mLaunchers != null && other.mLaunchers.SequenceEqual(mLaunchers) && Equals(other.mName, mName); }