/// <summary> /// Loads the configurations from a saved profile. /// </summary> /// <param name="filename">File name</param> public void LoadProfileSettings(string filename, string testSuiteFolderBin) { using (ProfileUtil profile = ProfileUtil.LoadProfile(filename)) { if (!profile.VerifyVersion(appConfig.TestSuiteName, appConfig.TestSuiteVersion)) { if (profile.Info != null) { throw new InvalidDataException(string.Format( StringResource.ProfileNotMatchError, profile.Info.TestSuiteName, profile.Info.Version, appConfig.TestSuiteName, appConfig.TestSuiteVersion )); } else { throw new InvalidDataException(StringResource.InvalidProfile); } } ptfconfigDirectory = Path.Combine("PtfConfigDirectory", $"{appConfig.TestSuiteName}-{sessionStartTime.ToString("yyyy-MM-dd-HH-mm-ss")}"); string desCfgDir = ptfconfigDirectory; profile.SavePtfCfgTo(desCfgDir, testSuiteFolderBin, appConfig.PipeName); filter.LoadProfile(profile.ProfileStream); ImportPlaylist(profile.PlaylistStream); SetSelectedCaseList(filter.FilterTestCaseList(testSuite.TestCaseList)); int sel, notfound; ApplyPlaylist(out sel, out notfound); } }
private bool NeedUpgradeProfile(string filename) { using (ProfileUtil profile = ProfileUtil.LoadProfile(filename)) { if (profile.Info == null) { throw new InvalidDataException(StringResource.InvalidProfile); } if (profile.Info.TestSuiteName != appConfig.TestSuiteName) { throw new Exception(StringResource.ProfileNotMatchError); } Version profileVersion = new Version(profile.Info.Version); Version testSuiteVersion = new Version(appConfig.TestSuiteVersion); if (profileVersion > testSuiteVersion) { throw new ArgumentException(StringResource.ProfileNewerError); } else if (profileVersion < testSuiteVersion) { throw new ArgumentException(StringResource.TestSuiteNewerThanProfile); } else { return(false); } } }
/// <summary> /// Loads the configurations from a saved profile. /// </summary> /// <param name="filename">File name</param> public void LoadProfileSettings(string filename) { using (ProfileUtil profile = ProfileUtil.LoadProfile(filename)) { if (!profile.VerifyVersion(appConfig.TestSuiteName, appConfig.TestSuiteVersion)) { if (profile.Info != null) { throw new InvalidDataException(string.Format( StringResource.ProfileNotMatchError, profile.Info.TestSuiteName, profile.Info.Version, appConfig.TestSuiteName, appConfig.TestSuiteVersion )); } else { throw new InvalidDataException(StringResource.InvalidProfile); } } string desCfgDir = System.IO.Path.Combine(appConfig.TestSuiteDirectory, "Bin"); profile.SavePtfCfgTo(desCfgDir); filter.LoadProfile(profile.ProfileStream); ImportPlaylist(profile.PlaylistStream); GetSelectedCaseList(); int sel, notfound; ApplyPlaylist(out sel, out notfound); } }
/// <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); }