Subtext.Installation.SqlInstaller.ListInstallationScripts C# (CSharp) Method

ListInstallationScripts() public method

Returns a collection of installation script names with a version less than or equal to the max version.
public ListInstallationScripts ( System.Version minVersionExclusive, System.Version maxVersionInclusive ) : string[]
minVersionExclusive System.Version The min verison exclusive.
maxVersionInclusive System.Version The max version inclusive.
return string[]
        public string[] ListInstallationScripts(Version minVersionExclusive, Version maxVersionInclusive)
        {
            Assembly assembly = Assembly.GetExecutingAssembly();
            string[] resourceNames = assembly.GetManifestResourceNames();
            StringCollection collection = new StringCollection();
            foreach (string resourceName in resourceNames)
            {
                SqlInstallationProvider.InstallationScriptInfo scriptInfo = SqlInstallationProvider.InstallationScriptInfo.Parse(resourceName);
                if (scriptInfo == null) continue;

                if ((minVersionExclusive == null || scriptInfo.Version > minVersionExclusive)
                    && (maxVersionInclusive == null || scriptInfo.Version <= maxVersionInclusive))
                {
                    collection.Add(scriptInfo.ScriptName);
                }
            }

            string[] scripts = new string[collection.Count];
            collection.CopyTo(scripts, 0);
            Array.Sort(scripts);

            return scripts;
        }

Usage Example

コード例 #1
0
        public void ListInstallationScriptsReturnsCorrectScripts()
        {
            SqlInstaller installer = new SqlInstaller("null");
            string[] scripts = installer.ListInstallationScripts(null, new Version(1, 5, 0, 0));
            Assert.AreEqual(2, scripts.Length, "We expected to see two scripts.");
            Assert.AreEqual("Installation.01.00.00.sql", scripts[0], "Expected the initial 1.0 installation file.");
            Assert.AreEqual("Installation.01.05.00.sql", scripts[1], "Expected the bugfix 1.5 installation file.");

            scripts = installer.ListInstallationScripts(null, new Version(1, 0, 3, 0));
            Assert.AreEqual(1, scripts.Length, "We expected to see one script.");
            Assert.AreEqual("Installation.01.00.00.sql", scripts[0], "Expected the initial 1.0 installation file.");

            scripts = installer.ListInstallationScripts(null, new Version(0, 0, 3, 0));
            Assert.AreEqual(0, scripts.Length, "We expected to see no scripts.");

            scripts = installer.ListInstallationScripts(new Version(1, 1, 0, 0), new Version(1, 5, 0, 0));
            Assert.AreEqual(1, scripts.Length, "We expected to see one script.");
            Assert.AreEqual("Installation.01.05.00.sql", scripts[0], "Expected the bugfix 1.5.0 installation file.");

            scripts = installer.ListInstallationScripts(new Version(1, 1, 0, 0), new Version(1, 9, 0, 0));
            Assert.AreEqual(2, scripts.Length, "We expected to see two script.");
            Assert.AreEqual("Installation.01.09.00.sql", scripts[1], "Expected the 1.9.0 installation file.");
        }