/// <summary> /// Re-applies in-memory profiles to the newly created snapshot. Note that we don't want to merge in the error /// profile /// </summary> protected static void MergeExistingInMemoryProfiles(LaunchSettingsData newSnapshot, ILaunchSettings prevSnapshot) { for (int i = 0; i < prevSnapshot.Profiles.Count; i++) { ILaunchProfile profile = prevSnapshot.Profiles[i]; if (profile.IsInMemoryObject() && !string.Equals(profile.CommandName, ErrorProfileCommandName)) { Assumes.NotNull(newSnapshot.Profiles); // Does it already have one with this name? if (newSnapshot.Profiles.FirstOrDefault((p1, p2) => LaunchProfile.IsSameProfileName(p1.Name, p2.Name), profile) == null) { // Create a new one from the existing in-memory profile and insert it in the same location, or the end if it // is beyond the end of the list if (i > newSnapshot.Profiles.Count) { newSnapshot.Profiles.Add(LaunchProfileData.FromILaunchProfile(profile)); } else { newSnapshot.Profiles.Insert(i, LaunchProfileData.FromILaunchProfile(profile)); } } } } }
public void LaunchProfileData_FromILaunchProfileTests(bool isInMemory) { var profile = new LaunchProfile() { Name = "Test", CommandName = "Test", ExecutablePath = "c:\\this\\is\\a\\exe\\path", CommandLineArgs = "args", WorkingDirectory = "c:\\wprking\\directory\\", LaunchBrowser = true, LaunchUrl = "LaunchPage.html", EnvironmentVariables = new Dictionary <string, string>() { { "var1", "Value1" }, { "var2", "Value2" } }.ToImmutableDictionary(), OtherSettings = new Dictionary <string, object>(StringComparer.Ordinal) { { "setting1", true }, { "setting2", "mysetting" } }.ToImmutableDictionary(), DoNotPersist = isInMemory }; var data = LaunchProfileData.FromILaunchProfile(profile); Assert.True(data.Name == profile.Name); Assert.True(data.ExecutablePath == profile.ExecutablePath); Assert.True(data.CommandLineArgs == profile.CommandLineArgs); Assert.True(data.WorkingDirectory == profile.WorkingDirectory); Assert.True(data.LaunchBrowser == profile.LaunchBrowser); Assert.True(data.LaunchUrl == profile.LaunchUrl); Assert.True(DictionaryEqualityComparer <string, string> .Instance.Equals(data.EnvironmentVariables.ToImmutableDictionary(), profile.EnvironmentVariables)); Assert.True(DictionaryEqualityComparer <string, string> .Instance.Equals(data.EnvironmentVariables.ToImmutableDictionary(), profile.EnvironmentVariables)); Assert.Equal(isInMemory, data.InMemoryProfile); }
/// <summary> /// Re-applies in-memory profiles to the newly created snapshot /// </summary> protected void MergeExistingInMemoryProfiles(LaunchSettingsData newSnapshot, ILaunchSettings prevSnapshot) { for (int i = 0; i < prevSnapshot.Profiles.Count; i++) { var profile = prevSnapshot.Profiles[i]; if (profile.IsInMemoryObject()) { // Does it already have one with this name? if (newSnapshot.Profiles.FirstOrDefault(p => LaunchProfile.IsSameProfileName(p.Name, profile.Name)) == null) { // Create a new one from the existing in-memory profile and insert it in the same location, or the end if it // is beyond the end of the list if (i > newSnapshot.Profiles.Count) { newSnapshot.Profiles.Add(LaunchProfileData.FromILaunchProfile(profile)); } else { newSnapshot.Profiles.Insert(i, LaunchProfileData.FromILaunchProfile(profile)); } } } } }