/// <summary> /// Saves the configurations as a profile. /// </summary> /// <param name="filename">File name</param> public void SaveProfileSettings(string filename) { string profileName = System.IO.Path.GetFileNameWithoutExtension(filename); string[] ptfConfigFiles = Directory.GetFiles( Path.Combine(appConfig.TestSuiteDirectory, "Bin"), "*.ptfconfig", SearchOption.TopDirectoryOnly); using (ProfileUtil profile = ProfileUtil.CreateProfile(filename, appConfig.TestSuiteName, appConfig.TestSuiteVersion)) { foreach (string settingsConfigFile in ptfConfigFiles) { profile.AddPtfCfg(settingsConfigFile); } filter.SaveProfile(profile.profileStream); ExportPlaylist(profile.PlaylistStream, true); } }
/// <summary> /// Upgrade the saved profile if needed. /// </summary> /// <param name="filename">File name of the saved profile</param> /// <param name="testSuiteFolderBin">Test Suite Bin Folder</param> /// <param name="newFilename">File name of the newly upgraded profile</param> /// <returns>Return true when the file is upgraded, false when no need to upgrade the profile.</returns> public bool TryUpgradeProfileSettings(string filename, string testSuiteFolderBin, out string newFilename) { newFilename = null; // 1. Check whether the profile is created in an old version if (!NeedUpgradeProfile(filename)) { return(false); } // 2. Set the new profile name newFilename = GenerateNewProfileName(filename); // 3. Create the new ptm file using (ProfileUtil oldProfile = ProfileUtil.LoadProfile(filename)) using (ProfileUtil newProfile = ProfileUtil.CreateProfile(newFilename, appConfig.TestSuiteName, appConfig.TestSuiteVersion)) { // Copy profile and playlist ProfileUtil.CopyStream(oldProfile.ProfileStream, newProfile.ProfileStream); ProfileUtil.CopyStream(oldProfile.PlaylistStream, newProfile.PlaylistStream); // Create a temp folder to save ptfconfig files string tmpDir = Path.Combine(Path.GetTempPath(), $"PTM-{Guid.NewGuid()}"); Directory.CreateDirectory(tmpDir); oldProfile.SavePtfCfgTo(tmpDir, testSuiteFolderBin, appConfig.PipeName); MergeWithDefaultPtfConfig(tmpDir); foreach (string ptfconfig in Directory.GetFiles(tmpDir)) { newProfile.AddPtfCfg(ptfconfig); } Directory.Delete(tmpDir, true); } return(true); }