public void InstallerViewTables()
        {
            string dbFile = "InstallerViewTables.msi";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                db.Commit();

                using (View view1 = db.OpenView("SELECT `Property`, `Value` FROM `Property` WHERE `Value` IS NOT NULL"))
                {
                    IList<TableInfo> viewTables = view1.Tables;
                    Assert.IsNotNull(viewTables);
                    Assert.AreEqual<int>(1, viewTables.Count);
                    Assert.AreEqual<String>("Property", viewTables[0].Name);
                }

                using (View view2 = db.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES ('TestViewTables', 1)"))
                {
                    IList<TableInfo> viewTables = view2.Tables;
                    Assert.IsNotNull(viewTables);
                    Assert.AreEqual<int>(1, viewTables.Count);
                    Assert.AreEqual<String>("Property", viewTables[0].Name);
                }

                using (View view3 = db.OpenView("UPDATE `Property` SET `Value` = 2 WHERE `Property` = 'TestViewTables'"))
                {
                    IList<TableInfo> viewTables = view3.Tables;
                    Assert.IsNotNull(viewTables);
                    Assert.AreEqual<int>(1, viewTables.Count);
                    Assert.AreEqual<String>("Property", viewTables[0].Name);
                }

                using (View view4 = db.OpenView("alter table Property hold"))
                {
                    IList<TableInfo> viewTables = view4.Tables;
                    Assert.IsNotNull(viewTables);
                    Assert.AreEqual<int>(1, viewTables.Count);
                    Assert.AreEqual<String>("Property", viewTables[0].Name);
                }
            }
        }
        public void InstallerDatabaseSchema()
        {
            string dbFile = "InstallerDatabaseSchema.msi";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                db.Commit();
            }

            Assert.IsTrue(File.Exists(dbFile), "Checking whether created database file " + dbFile + " exists.");

            using (Database db = new Database(dbFile, DatabaseOpenMode.ReadOnly))
            {
                TableCollection tables = db.Tables;
                Assert.AreEqual<int>(Schema.Tables.Count, tables.Count, "Counting tables.");
                Assert.AreEqual<int>(Schema.Property.Columns.Count, tables["Property"].Columns.Count, "Counting columns in Property table.");

                foreach (TableInfo tableInfo in tables)
                {
                    Console.WriteLine(tableInfo.Name);
                    foreach (ColumnInfo columnInfo in tableInfo.Columns)
                    {
                        Console.WriteLine("\t{0} {1}", columnInfo.Name, columnInfo.ColumnDefinitionString);
                    }
                }
            }
        }
        public void InstallerTransactTwoProducts()
        {
            string dbFile1 = "InstallerTransactProduct1.msi";
            string dbFile2 = "InstallerTransactProduct2.msi";
            string productCode1;
            string productCode2;

            using (Database db1 = new Database(dbFile1, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db1);
                WindowsInstallerUtils.CreateTestProduct(db1);

                productCode1 = db1.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                db1.Commit();
            }

            using (Database db2 = new Database(dbFile2, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db2);
                WindowsInstallerUtils.CreateTestProduct(db2);

                productCode2 = db2.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                db2.Commit();
            }

            ProductInstallation installation1 = new ProductInstallation(productCode1);
            ProductInstallation installation2 = new ProductInstallation(productCode2);
            Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed before starting.");
            Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed before starting.");

            Installer.SetInternalUI(InstallUIOptions.Silent);
            ExternalUIHandler prevHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUILogger,
                InstallLogModes.FatalExit |
                InstallLogModes.Error |
                InstallLogModes.Warning |
                InstallLogModes.User |
                InstallLogModes.Info |
                InstallLogModes.ResolveSource |
                InstallLogModes.OutOfDiskSpace |
                InstallLogModes.ActionStart |
                InstallLogModes.ActionData |
                InstallLogModes.CommonData |
                InstallLogModes.Progress |
                InstallLogModes.Initialize |
                InstallLogModes.Terminate |
                InstallLogModes.ShowDialog);
            Assert.IsNull(prevHandler, "Checking that returned previous UI handler is null.");

            Transaction transaction = new Transaction("TestInstallTransaction", TransactionAttributes.None);

            Exception caughtEx = null;
            try
            {
                Installer.InstallProduct(dbFile1, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product 1: " + caughtEx);

            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine();

            try
            {
                Installer.InstallProduct(dbFile2, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product 2: " + caughtEx);

            transaction.Commit();
            transaction.Close();

            prevHandler = Installer.SetExternalUI(prevHandler, InstallLogModes.None);
            Assert.AreEqual<ExternalUIHandler>(WindowsInstallerTest.ExternalUILogger, prevHandler, "Checking that previously-set UI handler is returned.");

            Assert.IsTrue(installation1.IsInstalled, "Checking that product 1 is installed.");
            Assert.IsTrue(installation2.IsInstalled, "Checking that product 2 is installed.");

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine("===================================================================");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            ExternalUIRecordHandler prevRecHandler = Installer.SetExternalUI(WindowsInstallerTest.ExternalUIRecordLogger,
                InstallLogModes.FatalExit |
                InstallLogModes.Error |
                InstallLogModes.Warning |
                InstallLogModes.User |
                InstallLogModes.Info |
                InstallLogModes.ResolveSource |
                InstallLogModes.OutOfDiskSpace |
                InstallLogModes.ActionStart |
                InstallLogModes.ActionData |
                InstallLogModes.CommonData |
                InstallLogModes.Progress |
                InstallLogModes.Initialize |
                InstallLogModes.Terminate |
                InstallLogModes.ShowDialog);
            Assert.IsNull(prevRecHandler, "Checking that returned previous UI record handler is null.");

            transaction = new Transaction("TestUninstallTransaction", TransactionAttributes.None);

            try
            {
                Installer.InstallProduct(dbFile1, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while removing product 1: " + caughtEx);

            try
            {
                Installer.InstallProduct(dbFile2, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while removing product 2: " + caughtEx);

            transaction.Commit();
            transaction.Close();

            Assert.IsFalse(installation1.IsInstalled, "Checking that product 1 is not installed after removing.");
            Assert.IsFalse(installation2.IsInstalled, "Checking that product 2 is not installed after removing.");

            prevRecHandler = Installer.SetExternalUI(prevRecHandler, InstallLogModes.None);
            Assert.AreEqual<ExternalUIRecordHandler>(WindowsInstallerTest.ExternalUIRecordLogger, prevRecHandler, "Checking that previously-set UI record handler is returned.");
        }
示例#4
0
        private void CreateCustomActionProduct(
            string msiFile, string customActionFile, IList<string> customActions, bool sixtyFourBit)
        {
            using (Database db = new Database(msiFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db, sixtyFourBit);
                WindowsInstallerUtils.CreateTestProduct(db);

                if (!File.Exists(customActionFile))
                    throw new FileNotFoundException(customActionFile);

                using (Record binRec = new Record(2))
                {
                    binRec[1] = Path.GetFileName(customActionFile);
                    binRec.SetStream(2, customActionFile);

                    db.Execute("INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)", binRec);
                }

                using (Record binRec2 = new Record(2))
                {
                    binRec2[1] = "TestData";
                    binRec2.SetStream(2, new MemoryStream(Encoding.UTF8.GetBytes("This is a test data stream.")));

                    db.Execute("INSERT INTO `Binary` (`Name`, `Data`) VALUES (?, ?)", binRec2);
                }

                for (int i = 0; i < customActions.Count; i++)
                {
                    db.Execute(
                        "INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) VALUES ('{0}', 1, '{1}', '{2}')",
                        customActions[i],
                        Path.GetFileName(customActionFile),
                        customActions[i]);
                    db.Execute(
                        "INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) VALUES ('{0}', '', {1})",
                        customActions[i],
                        101 + i);
                }

                db.Execute("INSERT INTO `Property` (`Property`, `Value`) VALUES ('SampleCATest', 'TestValue')");

                db.Commit();
            }
        }
示例#5
0
        /// <summary>
        /// adds or updates a property in an msi file.
        /// </summary>
        /// <param name="msiFile">full path to the msi file to update</param>
        /// <param name="propertyName">name of property to add or update</param>
        /// <param name="propertyValue">value of property</param>
        public static void SetPropertyInMsi(string msiFile, string propertyName, string propertyValue)
        {
            Database db = new Database(msiFile, DatabaseOpenMode.Direct);

            string sql;
            try
            {
                // GetProperty will throw if the propertyName does not exist in the property table
                GetProperty(db, propertyName);
                sql = string.Format("UPDATE `Property` SET `Value` = '{0}' WHERE `Property` = '{1}'", propertyValue, propertyName);
            }
            catch
            {
                sql = string.Format("INSERT INTO `Property` (`Property`, `Value`) VALUES ('{0}', '{1}')", propertyName, propertyValue);
            }
            db.Execute(sql);
            db.Commit();
            db.Close();
        }
示例#6
0
        // This test does not pass if run normally.
        // It only passes when a failure is injected into the EmbeddedUI launcher.
        ////[TestMethod]
        public void EmbeddedUIInitializeFails()
        {
            string dbFile = "EmbeddedUIInitializeFails.msi";
            string productCode;

            string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir);
            string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll";

            // A number that will be used to check whether a type 19 CA runs.
            const string magicNumber = "3.14159265358979323846264338327950";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                WindowsInstallerUtils.CreateTestProduct(db);

                const string failureActionName = "EmbeddedUIInitializeFails";
                db.Execute("INSERT INTO `CustomAction` (`Action`, `Type`, `Source`, `Target`) " +
                    "VALUES ('{0}', 19, '', 'Logging magic number: {1}')", failureActionName, magicNumber);

                // This type 19 CA (launch condition) is given a condition of 'UILevel = 3' so that it only runs if the
                // installation is running in BASIC UI mode, which is what we expect if the EmbeddedUI fails to initialize.
                db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Condition`, `Sequence`) " +
                    "VALUES ('{0}', 'UILevel = 3', 1)", failureActionName);

                productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                using (Record uiRec = new Record(5))
                {
                    uiRec[1] = "TestEmbeddedUI";
                    uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll";
                    uiRec[3] = 1;
                    uiRec[4] = (int)(
                        EmbeddedExternalUI.TestLogModes |
                        InstallLogModes.Progress |
                        InstallLogModes.Initialize |
                        InstallLogModes.Terminate |
                        InstallLogModes.ShowDialog);
                    uiRec.SetStream(5, Path.Combine(uiDir, uiFile));
                    db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec);
                }

                db.Commit();
            }

            Installer.SetInternalUI(InstallUIOptions.Full);

            ProductInstallation installation = new ProductInstallation(productCode);
            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting.");

            string logFile = "install.log";
            Exception caughtEx = null;
            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, logFile);
                Installer.InstallProduct(dbFile, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsInstanceOfType(caughtEx, typeof(InstallerException),
                "Excpected InstallerException installing product; caught: " + caughtEx);

            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed.");

            string logText = File.ReadAllText(logFile);
            Assert.IsTrue(logText.Contains(magicNumber), "Checking that the type 19 custom action ran.");
        }
示例#7
0
        public void EmbeddedUISingleInstall()
        {
            string dbFile = "EmbeddedUISingleInstall.msi";
            string productCode;

            string uiDir = Path.GetFullPath(EmbeddedExternalUI.EmbeddedUISampleBinDir);
            string uiFile = "Microsoft.Deployment.Samples.EmbeddedUI.dll";

            using (Database db = new Database(dbFile, DatabaseOpenMode.CreateDirect))
            {
                WindowsInstallerUtils.InitializeProductDatabase(db);
                WindowsInstallerUtils.CreateTestProduct(db);

                productCode = db.ExecuteStringQuery("SELECT `Value` FROM `Property` WHERE `Property` = 'ProductCode'")[0];

                using (Record uiRec = new Record(5))
                {
                    uiRec[1] = "TestEmbeddedUI";
                    uiRec[2] = Path.GetFileNameWithoutExtension(uiFile) + ".Wrapper.dll";
                    uiRec[3] = 1;
                    uiRec[4] = (int) (
                        EmbeddedExternalUI.TestLogModes |
                        InstallLogModes.Progress |
                        InstallLogModes.Initialize |
                        InstallLogModes.Terminate |
                        InstallLogModes.ShowDialog);
                    uiRec.SetStream(5, Path.Combine(uiDir, uiFile));
                    db.Execute(db.Tables["MsiEmbeddedUI"].SqlInsertString, uiRec);
                }

                db.Commit();
            }

            Installer.SetInternalUI(InstallUIOptions.Full);

            ProductInstallation installation = new ProductInstallation(productCode);
            Assert.IsFalse(installation.IsInstalled, "Checking that product is not installed before starting.");

            Exception caughtEx = null;
            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "install.log");
                Installer.InstallProduct(dbFile, String.Empty);
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while installing product: " + caughtEx);

            Assert.IsTrue(installation.IsInstalled, "Checking that product is installed.");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("===================================================================");
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();

            try
            {
                Installer.EnableLog(EmbeddedExternalUI.TestLogModes, "uninstall.log");
                Installer.InstallProduct(dbFile, "REMOVE=All");
            }
            catch (Exception ex) { caughtEx = ex; }
            Assert.IsNull(caughtEx, "Exception thrown while uninstalling product: " + caughtEx);
        }