Beispiel #1
0
        private void InitLinqTestDatabase(QDatabase db)
        {
            WindowsInstallerUtils.InitializeProductDatabase(db);
            WindowsInstallerUtils.CreateTestProduct(db);

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

            WindowsInstallerUtils.AddRegistryComponent(
                db, "TestFeature2", "MyTestRegComp",
                Guid.NewGuid().ToString("B"),
                "SOFTWARE\\Microsoft\\DTF\\Test",
                "MyTestRegComp", "test");
            WindowsInstallerUtils.AddRegistryComponent(
                db, "TestFeature2", "MyTestRegComp2",
                Guid.NewGuid().ToString("B"),
                "SOFTWARE\\Microsoft\\DTF\\Test",
                "MyTestRegComp2", "test2");
            WindowsInstallerUtils.AddRegistryComponent(
                db, "TestFeature2", "excludeComp",
                Guid.NewGuid().ToString("B"),
                "SOFTWARE\\Microsoft\\DTF\\Test",
                "MyTestRegComp3", "test3");

            db.Commit();

            db.Log = Console.Out;
        }
Beispiel #2
0
        public void LinqWhereNull()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                var features = from f in db.Features
                               where f.Description != null
                               select f;

                int count = 0;
                foreach (var f in features)
                {
                    Console.WriteLine(f);
                    Assert.AreEqual<string>("TestFeature2", f.Feature);
                    count++;
                }

                Assert.AreEqual<int>(1, count);

                var features2 = from f in db.Features
                                where f.Description == null
                                select f;

                count = 0;
                foreach (var f in features2)
                {
                    Console.WriteLine(f);
                    Assert.AreEqual<string>("TestFeature1", f.Feature);
                    count++;
                }

                Assert.AreEqual<int>(1, count);
            }
        }
Beispiel #3
0
        public MSIInstaller(FileInfo file)
        {
            this._file = file;
            try {
                using(QDatabase  msi = new QDatabase(file.FullName))
                {
                    _company =msi.SummaryInfo.Author;
                    _created = msi.SummaryInfo.CreateTime;
                    _guid =msi.SummaryInfo.RevisionNumber;
                    _comments =msi.SummaryInfo.Comments;
                    _subject = msi.SummaryInfo.Subject;

                    var props = msi.Properties.Select(xx => xx);
                    properties = new List<Property_>(props);

                    var p = properties.Where(xx => xx.Property.Equals("ProductVersion")).FirstOrDefault();
                    if (p != null) {
                        _version = p.Value;
                    }
                    p = properties.Where(xx => xx.Property == "Manufacturer").FirstOrDefault();
                    if (p != null) {
                        _creator = p.Value;
                    }
                    this._isInstaller = true;
                }
            } catch (InstallerException ex) {
                this._isInstaller = false;
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Converts any Database instance into a queryable database.
 /// </summary>
 /// <param name="db"></param>
 /// <returns>Queryable database instance that operates on the same
 /// MSI handle.</returns>
 /// <remarks>
 /// This extension method is meant for convenient on-the-fly conversion.
 /// If the existing database instance already happens to be a QDatabase,
 /// then it is returned unchanged. Otherwise since the new database
 /// carries the same MSI handle, only one of the instances needs to be
 /// closed, not both.
 /// </remarks>
 public static QDatabase AsQueryable(this Database db)
 {
     QDatabase qdb = db as QDatabase;
     if (qdb == null && db != null)
     {
         qdb = new QDatabase(db.Handle, true, db.FilePath, db.OpenMode);
     }
     return qdb;
 }
Beispiel #5
0
        /// <summary>
        /// Converts any Database instance into a queryable database.
        /// </summary>
        /// <param name="db"></param>
        /// <returns>Queryable database instance that operates on the same
        /// MSI handle.</returns>
        /// <remarks>
        /// This extension method is meant for convenient on-the-fly conversion.
        /// If the existing database instance already happens to be a QDatabase,
        /// then it is returned unchanged. Otherwise since the new database
        /// carries the same MSI handle, only one of the instances needs to be
        /// closed, not both.
        /// </remarks>
        public static QDatabase AsQueryable(this Database db)
        {
            QDatabase qdb = db as QDatabase;

            if (qdb == null && db != null)
            {
                qdb = new QDatabase(db.Handle, true, db.FilePath, db.OpenMode);
            }
            return(qdb);
        }
Beispiel #6
0
        internal Query(QDatabase db, Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            this.db = db;
            this.queryableExpression = expression;
            this.tables              = new List <TableInfo>();
            this.recordTypes         = new List <Type>();
            this.selectors           = new List <string>();
            this.whereParameters     = new List <object>();
            this.orderbyColumns      = new List <TableColumn>();
            this.selectColumns       = new List <TableColumn>();
            this.joinColumns         = new List <TableColumn>();
            this.projectionDelegates = new List <Delegate>();
        }
Beispiel #7
0
        public void LinqSimple()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                var comps = from c in db.Components
                            select c;

                int count = 0;
                foreach (var c in comps)
                {
                    Console.WriteLine(c);
                    count++;
                }

                Assert.AreEqual<int>(4, count);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Creates a new QTable with an explicit table name.
        /// </summary>
        /// <param name="db">database that contains the table</param>
        /// <param name="table">name of the table</param>
        public QTable(QDatabase db, string table)
        {
            if (db == null)
            {
                throw new ArgumentNullException("db");
            }

            if (String.IsNullOrEmpty(table))
            {
                throw new ArgumentNullException("table");
            }

            this.db        = db;
            this.tableInfo = db.Tables[table];
            if (this.tableInfo == null)
            {
                throw new ArgumentException(
                          "Table does not exist in database: " + table);
            }
        }
Beispiel #9
0
        public void LinqFourWayJoin()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);
                int count;

                IList<string> pretest = db.ExecuteStringQuery(
                    "SELECT `Feature`.`Feature` " +
                    "FROM `Feature`, `FeatureComponents`, `Component`, `Registry` " +
                    "WHERE `Feature`.`Feature` = `FeatureComponents`.`Feature_` " +
                    "AND `FeatureComponents`.`Component_` = `Component`.`Component` " +
                    "AND `Component`.`Component` = `Registry`.`Component_` " +
                    "AND (`Registry`.`Registry` = 'MyTestRegCompReg1')");
                Assert.AreEqual<int>(1, pretest.Count);

                var features = from f in db.Features
                               join fc in db.FeatureComponents on f.Feature equals fc.Feature_
                               join c in db.Components on fc.Component_ equals c.Component
                               join r in db.Registries on c.Component equals r.Component_
                               where r.Registry == "MyTestRegCompReg1"
                               select f.Feature;

                count = 0;
                foreach (var featureName in features)
                {
                    Console.WriteLine(featureName);
                    count++;
                }
                Assert.AreEqual<int>(1, count);

            }
        }
Beispiel #10
0
 /// <summary>
 /// Creates a new QTable, inferring the table name
 /// from the name of the record type parameter.
 /// </summary>
 /// <param name="db">database that contains the table</param>
 public QTable(QDatabase db)
     : this(db, InferTableName())
 {
 }
Beispiel #11
0
        public void LinqUpdateNullableString()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                string newDescription = "New updated feature description.";

                var features = from f in db.Features
                               where f.Description != null
                               select f;

                int count = 0;
                foreach (var f in features)
                {
                    Console.WriteLine(f);
                    Assert.AreEqual<string>("TestFeature2", f.Feature);
                    f.Description = newDescription;
                    count++;
                }

                Assert.AreEqual<int>(1, count);

                var features2 = from f in db.Features
                                where f.Description == newDescription
                                select f;
                count = 0;
                foreach (var f in features2)
                {
                    Console.WriteLine(f);
                    Assert.AreEqual<string>("TestFeature2", f.Feature);
                    f.Description = null;
                    count++;
                }

                Assert.AreEqual<int>(1, count);

                var features3 = from f in db.Features
                                where f.Description == null
                                select f.Feature;
                count = 0;
                foreach (var f in features3)
                {
                    Console.WriteLine(f);
                    count++;
                }

                Assert.AreEqual<int>(2, count);

                db.Commit();
            }
        }
Beispiel #12
0
        public void LinqInsertDelete()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                var newProp = db.Properties.NewRecord();
                newProp.Property = "TestNewProp1";
                newProp.Value = "TestNewValue";
                newProp.Insert();

                string prop = (from p in db.Properties
                            where p.Property == "TestNewProp1"
                            select p.Value).AsEnumerable().First();
                Assert.AreEqual<string>("TestNewValue", prop);

                newProp.Delete();

                int propCount = (from p in db.Properties
                                 where p.Property == "TestNewProp1"
                                 select p.Value).AsEnumerable().Count();
                Assert.AreEqual<int>(0, propCount);

                db.Commit();
            }
        }
Beispiel #13
0
        public void LinqShapeSelect()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                Console.WriteLine("Running LINQ query 1.");
                var features1 = from f in db.Features
                                select new { Name = f.Feature,
                                             Desc = f.Description };

                int count = 0;
                foreach (var f in features1)
                {
                    Console.WriteLine(f);
                    count++;
                }

                Assert.AreEqual<int>(2, count);

                Console.WriteLine();
                Console.WriteLine("Running LINQ query 2.");
                var features2 = from f in db.Features
                                where f.Description != null
                                select new { Name = f.Feature,
                                             Desc = f.Description.ToLower() };

                count = 0;
                foreach (var f in features2)
                {
                    Console.WriteLine(f);
                    Assert.AreEqual<string>("TestFeature2", f.Name);
                    count++;
                }

                Assert.AreEqual<int>(1, count);
            }
        }
        private void MatchWindows()
        {
            string productName = null;
            using (QDatabase database = new QDatabase(this._args.Package, DatabaseOpenMode.ReadOnly))
            {

                var properties = from p in database.Properties
                                 where p.Property == "ProductVersion" || p.Property == "ProductName"
                                 select p;

                foreach (var property in properties)
                {
                    if (property.Property.Equals("ProductVersion") && String.IsNullOrWhiteSpace(this._args.Version))
                    {
                        this._args.Version = property.Value;
                    }
                    else if (property.Property.Equals("ProductName"))
                    {
                        productName = property.Value;
                    }
                }
            }

            List<AppInfo> apps = this._envelope.Apps.Where(p => p.Platform == AppInfoPlatforms.Windows).ToList();
            if (!this.MatchCommonSwitches(apps) && productName != null)
            {
                foreach (AppInfo app in apps)
                {
                    if (app.Title.Contains(productName))
                    {
                        this._matchingApps.Add(app);
                    }
                }
            }
        }
Beispiel #15
0
        public void LinqTwoWayJoin()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);
                int count;

                var regs = from r in db.Registries
                           join c in db["Component"] on r.Component_ equals c["Component"]
                           where c["Component"] == "MyTestRegComp" &&
                                 r.Root == RegistryRoot.UserOrMachine
                           select new { Reg = r.Registry, Dir = c["Directory_"] };

                count = 0;
                foreach (var r in regs)
                {
                    Console.WriteLine(r);
                    count++;
                }
                Assert.AreEqual<int>(1, count);

                var regs2 = from r in db.Registries
                            join c in db.Components on r.Component_ equals c.Component
                            where c.Component == "MyTestRegComp" &&
                                  r.Root == RegistryRoot.UserOrMachine
                            select new { Reg = r, Dir = c.Directory_ };

                count = 0;
                foreach (var r in regs2)
                {
                    Assert.IsNotNull(r.Reg.Registry);
                    Console.WriteLine(r);
                    count++;
                }
                Assert.AreEqual<int>(1, count);

                var regs3 = from r in db.Registries
                            join c in db.Components on r.Component_ equals c.Component
                            where c.Component == "MyTestRegComp" &&
                                  r.Root == RegistryRoot.UserOrMachine
                            select r;

                count = 0;
                foreach (var r in regs3)
                {
                    Assert.IsNotNull(r.Registry);
                    Console.WriteLine(r);
                    count++;
                }
                Assert.AreEqual<int>(1, count);

            }
        }
Beispiel #16
0
        public void LinqOrderBy()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                var actions = from a in db.InstallExecuteSequences
                              orderby a.Sequence
                              select a.Action;
                foreach (var a in actions)
                {
                    Console.WriteLine(a);
                }

                var files = from f in db.Files
                            orderby f.FileSize, f["Sequence"]
                            where f.Attributes == FileAttributes.None
                            select f;

                foreach (var f in files)
                {
                    Console.WriteLine(f);
                }
            }
        }
Beispiel #17
0
        public void LinqQueryQRecord()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                var installFilesSeq = (from a in db["InstallExecuteSequence"]
                                       where a["Action"] == "InstallFiles"
                                       select a["Sequence"]).AsEnumerable().First();
                Assert.AreEqual<string>("4000", installFilesSeq);
            }
        }
Beispiel #18
0
 public void EnumTable()
 {
     using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
     {
         this.InitLinqTestDatabase(db);
         int count = 0;
         foreach (var comp in db.Components)
         {
             Console.WriteLine(comp);
             count++;
         }
         Assert.AreNotEqual<int>(0, count);
     }
 }
Beispiel #19
0
        public void LinqWhereOperators()
        {
            using (QDatabase db = new QDatabase("testlinq.msi", DatabaseOpenMode.Create))
            {
                this.InitLinqTestDatabase(db);

                for (int i = 0; i < 100; i++)
                {
                    var newFile = db.Files.NewRecord();
                    newFile.File = "TestFile" + i;
                    newFile.Component_ = "TestComponent";
                    newFile.FileName = "TestFile" + i + ".txt";
                    newFile.FileSize = i % 10;
                    newFile.Sequence = i;
                    newFile.Insert();
                }

                var files1 = from f in db.Files where f.Sequence < 40 select f;
                Assert.AreEqual<int>(40, files1.AsEnumerable().Count());

                var files2 = from f in db.Files where f.Sequence <= 40 select f;
                Assert.AreEqual<int>(41, files2.AsEnumerable().Count());

                var files3 = from f in db.Files where f.Sequence > 40 select f;
                Assert.AreEqual<int>(59, files3.AsEnumerable().Count());

                var files4 = from f in db.Files where f.Sequence >= 40 select f;
                Assert.AreEqual<int>(60, files4.AsEnumerable().Count());

                var files5 = from f in db.Files where 40 < f.Sequence select f;
                Assert.AreEqual<int>(59, files5.AsEnumerable().Count());

                var files6 = from f in db.Files where 40 <= f.Sequence select f;
                Assert.AreEqual<int>(60, files6.AsEnumerable().Count());

                var files7 = from f in db.Files where 40 > f.Sequence select f;
                Assert.AreEqual<int>(40, files7.AsEnumerable().Count());

                var files8 = from f in db.Files where 40 >= f.Sequence select f;
                Assert.AreEqual<int>(41, files8.AsEnumerable().Count());

                var files9 = from f in db.Files where f.Sequence == 40 select f;
                Assert.AreEqual<int>(40, files9.AsEnumerable().First().Sequence);

                var files10 = from f in db.Files where f.Sequence != 40 select f;
                Assert.AreEqual<int>(99, files10.AsEnumerable().Count());

                var files11 = from f in db.Files where 40 == f.Sequence select f;
                Assert.AreEqual<int>(40, files11.AsEnumerable().First().Sequence);

                var files12 = from f in db.Files where 40 != f.Sequence select f;
                Assert.AreEqual<int>(99, files12.AsEnumerable().Count());
            }
        }