Esempio n. 1
0
        /// <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);
            }
        }
        /// <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);
            }
        }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Creates a new PTM profile
        /// </summary>
        /// <param name="filename">The file name to save the profile</param>
        /// <param name="testSuiteName">The test suite name</param>
        /// <param name="version">The test suite version</param>
        /// <returns>An instance of ProfileUtil</returns>
        public static ProfileUtil CreateProfile(string filename, string testSuiteName, string version)
        {
            ProfileUtil profile = new ProfileUtil();

            profile.profilePackage = Package.Open(filename, FileMode.Create);

            PackagePart profilePart = profile.profilePackage.CreatePart(profilePartUri, System.Net.Mime.MediaTypeNames.Text.Xml);

            profile.profileStream = profilePart.GetStream();

            PackagePart playlist = profile.profilePackage.CreatePart(playlistPartUri, System.Net.Mime.MediaTypeNames.Text.Xml);

            profile.playlistStream = playlist.GetStream();

            PackagePart profileInfo = profile.profilePackage.CreatePart(profileInfoPartUri, System.Net.Mime.MediaTypeNames.Text.Xml);

            profile.Info = new ProfileInfo()
            {
                TestSuiteName = testSuiteName, Version = version
            };
            var stream = profileInfo.GetStream();

            profile.Info.WriteTo(stream);
            stream.Flush();
            stream.Close();

            return(profile);
        }
Esempio n. 5
0
        /// <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);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Loads the profile from file.
        /// </summary>
        /// <param name="filename">The file name</param>
        /// <returns>An instance of ProfileUtil</returns>
        public static ProfileUtil LoadProfile(string filename)
        {
            ProfileUtil util = new ProfileUtil();

            util.profilePackage = Package.Open(filename, FileMode.Open);
            if (util.profilePackage.PartExists(playlistPartUri))
            {
                PackagePart playlist = util.profilePackage.GetPart(playlistPartUri);
                util.playlistStream = playlist.GetStream();
            }
            if (util.profilePackage.PartExists(profilePartUri))
            {
                PackagePart profilePart = util.profilePackage.GetPart(profilePartUri);
                util.profileStream = profilePart.GetStream();
            }
            if (util.profilePackage.PartExists(profileInfoPartUri))
            {
                PackagePart profileInfoPart = util.profilePackage.GetPart(profileInfoPartUri);
                util.Info = ProfileInfo.Readfrom(profileInfoPart.GetStream());
            }
            return(util);
        }
Esempio n. 7
0
        /// <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);
        }
        /// <summary>
        /// Creates a new PTM profile
        /// </summary>
        /// <param name="filename">The file name to save the profile</param>
        /// <param name="testSuiteName">The test suite name</param>
        /// <param name="version">The test suite version</param>
        /// <returns>An instance of ProfileUtil</returns>
        public static ProfileUtil CreateProfile(string filename, string testSuiteName, string version)
        {
            ProfileUtil profile = new ProfileUtil();
            profile.profilePackage = Package.Open(filename, FileMode.Create);

            PackagePart profilePart = profile.profilePackage.CreatePart(profilePartUri, System.Net.Mime.MediaTypeNames.Text.Xml);
            profile.profileStream = profilePart.GetStream();

            PackagePart playlist = profile.profilePackage.CreatePart(playlistPartUri, System.Net.Mime.MediaTypeNames.Text.Xml);
            profile.playlistStream = playlist.GetStream();

            PackagePart profileInfo = profile.profilePackage.CreatePart(profileInfoPartUri, System.Net.Mime.MediaTypeNames.Text.Xml);
            profile.Info = new ProfileInfo() { TestSuiteName = testSuiteName, Version = version };
            var stream = profileInfo.GetStream();
            profile.Info.WriteTo(stream);
            stream.Flush();
            stream.Close();

            return profile;
        }
 /// <summary>
 /// Loads the profile from file.
 /// </summary>
 /// <param name="filename">The file name</param>
 /// <returns>An instance of ProfileUtil</returns>
 public static ProfileUtil LoadProfile(string filename)
 {
     ProfileUtil util = new ProfileUtil();
     util.profilePackage = Package.Open(filename, FileMode.Open);
     if (util.profilePackage.PartExists(playlistPartUri))
     {
         PackagePart playlist = util.profilePackage.GetPart(playlistPartUri);
         util.playlistStream = playlist.GetStream();
     }
     if (util.profilePackage.PartExists(profilePartUri))
     {
         PackagePart profilePart = util.profilePackage.GetPart(profilePartUri);
         util.profileStream = profilePart.GetStream();
     }
     if (util.profilePackage.PartExists(profileInfoPartUri))
     {
         PackagePart profileInfoPart = util.profilePackage.GetPart(profileInfoPartUri);
         util.Info = ProfileInfo.Readfrom(profileInfoPart.GetStream());
     }
     return util;
 }