WindowsInstallerUtils.cs :  » Installers-Generators » WiX » Microsoft » Deployment » Test » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Installers Generators » WiX 
WiX » Microsoft » Deployment » Test » WindowsInstallerUtils.cs

namespace Microsoft.Deployment.Test{
    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Deployment.WindowsInstaller;

    public class WindowsInstallerUtils
    {
        public static void InitializeProductDatabase(Database db)
        {
            InitializeProductDatabase(db, false);
        }

        public static void InitializeProductDatabase(Database db, bool sixtyFourBit)
        {
            db.SummaryInfo.CodePage = (short) Encoding.Default.CodePage;
            db.SummaryInfo.Title = "Windows Installer Test";
            db.SummaryInfo.Subject = db.SummaryInfo.Title;
            db.SummaryInfo.Author = typeof(WindowsInstallerUtils).Assembly.FullName;
            db.SummaryInfo.CreatingApp = db.SummaryInfo.Author;
            db.SummaryInfo.Comments = typeof(WindowsInstallerUtils).FullName + ".CreateBasicDatabase()";
            db.SummaryInfo.Keywords = "Installer,MSI,Database";
            db.SummaryInfo.PageCount = 300;
            db.SummaryInfo.WordCount = 0;
            db.SummaryInfo.RevisionNumber = Guid.NewGuid().ToString("B").ToUpper();
            db.SummaryInfo.Template = (sixtyFourBit ? "x64" : "Intel") + ";0";

            foreach (TableInfo tableInfo in Schema.Tables)
            {
                db.Execute(tableInfo.SqlCreateString);
            }

            db.Execute("INSERT INTO `Directory` (`Directory`, `DefaultDir`) VALUES ('TARGETDIR', 'SourceDir')");
            db.Execute("INSERT INTO `Directory` (`Directory`, `Directory_Parent`, `DefaultDir`) VALUES ('ProgramFilesFolder', 'TARGETDIR', '.')");

            foreach (Action action in Sequence.InstallExecute)
            {
                db.Execute("INSERT INTO `InstallExecuteSequence` (`Action`, `Sequence`) VALUES ('{0}', {1})",
                    action.Name, action.Sequence);
            }
        }

        public const string UpgradeCode = "{05955FE8-005F-4695-A81F-D559338065BB}";

        public static void CreateTestProduct(Database db)
        {
            Guid productGuid = Guid.NewGuid();

            string[] properties = new string[]
            {
                "ProductCode", productGuid.ToString("B").ToUpper(),
                "UpgradeCode", UpgradeCode,
                "ProductName", "Windows Installer Test Product " + productGuid.ToString("P").ToUpper(),
                "ProductVersion", "1.0.0.0000",
            };

            using (View view = db.OpenView("INSERT INTO `Property` (`Property`, `Value`) VALUES (?, ?)"))
            {
                using (Record rec = new Record(2))
                {
                    for (int i = 0; i < properties.Length; i += 2)
                    {
                        rec[1] = properties[i];
                        rec[2] = properties[i + 1];
                        view.Execute(rec);
                    }
                }
            }

            int randomId = new Random().Next(10000);
            string productDir = "TestDir" + randomId;
            db.Execute(
                "INSERT INTO `Directory` (`Directory`, `Directory_Parent`, `DefaultDir`) " +
                "VALUES ('TestDir', 'ProgramFilesFolder', 'TestDir|{0}:.')", productDir);

            string compId = Guid.NewGuid().ToString("B").ToUpper();
            db.Execute(
                "INSERT INTO `Component` " +
                    "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " +
                    "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')",
                "TestRegComp1",
                compId,
                "TestDir",
                (int) ComponentAttributes.RegistryKeyPath,
                "TestReg1");

            string productReg = "TestReg" + randomId;
            db.Execute(
                "INSERT INTO `Registry` (`Registry`, `Root`, `Key`, `Component_`) VALUES ('{0}', {1}, '{2}', '{3}')",
                "TestReg1",
                -1,
                @"Software\Microsoft\Windows Installer Test\" + productReg,
                "TestRegComp1");

            db.Execute(
                "INSERT INTO `Feature` (`Feature`, `Title`, `Level`, `Attributes`) VALUES ('{0}', '{1}', {2}, {3})",
                "TestFeature1",
                "Test Feature 1",
                1,
                (int) FeatureAttributes.None);

            db.Execute(
                "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')",
                "TestFeature1",
                "TestRegComp1");
        }

        public static void AddFeature(Database db, string featureName)
        {
            db.Execute(
                "INSERT INTO `Feature` (`Feature`, `Title`, `Level`, `Attributes`) VALUES ('{0}', '{1}', {2}, {3})",
                featureName,
                featureName,
                1,
                (int) FeatureAttributes.None);
        }

        public static void AddRegistryComponent(Database db,
            string featureName, string compName, string compId,
            string keyName, string keyValueName, string value)
        {
            db.Execute(
                "INSERT INTO `Component` " +
                    "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " +
                    "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')",
                compName,
                compId,
                "TestDir",
                (int) ComponentAttributes.RegistryKeyPath,
                compName + "Reg1");
            db.Execute(
                "INSERT INTO `Registry` (`Registry`, `Root`, `Key`, `Name`, `Value`, `Component_`) VALUES ('{0}', {1}, '{2}', '{3}', '{4}', '{5}')",
                compName + "Reg1",
                -1,
                @"Software\Microsoft\Windows Installer Test\" + keyName,
                keyValueName,
                value,
                compName);
            db.Execute(
                "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')",
                featureName,
                compName);
        }

        public static void AddFileComponent(Database db,
            string featureName, string compName, string compId,
            string fileKey, string fileName)
        {
            db.Execute(
                "INSERT INTO `Component` " +
                    "(`Component`, `ComponentId`, `Directory_`, `Attributes`, `KeyPath`) " +
                    "VALUES ('{0}', '{1}', '{2}', {3}, '{4}')",
                compName,
                compId,
                "TestDir",
                (int) ComponentAttributes.None,
                fileKey);
            db.Execute(
                "INSERT INTO `File` " +
                    "(`File`, `Component_`, `FileName`, `FileSize`, `Attributes`, `Sequence`) " +
                    "VALUES ('{0}', '{1}', '{2}', 1, 0, 1)",
                fileKey,
                compName,
                fileName);
            db.Execute(
                "INSERT INTO `FeatureComponents` (`Feature_`, `Component_`) VALUES ('{0}', '{1}')",
                featureName,
                compName);
        }
    }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.