private void CreateMsiFeatures(Dtf.Database db)
        {
            if (db.Tables.Contains("Feature"))
            {
                using (Dtf.View featureView = db.OpenView("SELECT `Component_` FROM `FeatureComponents` WHERE `Feature_` = ?"))
                    using (Dtf.View componentView = db.OpenView("SELECT `FileSize` FROM `File` WHERE `Component_` = ?"))
                    {
                        using (Dtf.Record featureRecord = new Dtf.Record(1))
                            using (Dtf.Record componentRecord = new Dtf.Record(1))
                            {
                                using (Dtf.View allFeaturesView = db.OpenView("SELECT * FROM `Feature`"))
                                {
                                    allFeaturesView.Execute();

                                    while (true)
                                    {
                                        using (Dtf.Record allFeaturesResultRecord = allFeaturesView.Fetch())
                                        {
                                            if (null == allFeaturesResultRecord)
                                            {
                                                break;
                                            }

                                            string featureName = allFeaturesResultRecord.GetString(1);

                                            // Calculate the Feature size.
                                            featureRecord.SetString(1, featureName);
                                            featureView.Execute(featureRecord);

                                            // Loop over all the components for the feature to calculate the size of the feature.
                                            long size = 0;
                                            while (true)
                                            {
                                                using (Dtf.Record componentResultRecord = featureView.Fetch())
                                                {
                                                    if (null == componentResultRecord)
                                                    {
                                                        break;
                                                    }
                                                    string component = componentResultRecord.GetString(1);
                                                    componentRecord.SetString(1, component);
                                                    componentView.Execute(componentRecord);

                                                    while (true)
                                                    {
                                                        using (Dtf.Record fileResultRecord = componentView.Fetch())
                                                        {
                                                            if (null == fileResultRecord)
                                                            {
                                                                break;
                                                            }

                                                            string fileSize = fileResultRecord.GetString(1);
                                                            size += Convert.ToInt32(fileSize, CultureInfo.InvariantCulture.NumberFormat);
                                                        }
                                                    }
                                                }
                                            }

                                            WixBundleMsiFeatureRow feature = (WixBundleMsiFeatureRow)this.MsiFeatureTable.CreateRow(this.Facade.Package.SourceLineNumbers);
                                            feature.ChainPackageId = this.Facade.Package.WixChainItemId;
                                            feature.Name           = featureName;
                                            feature.Parent         = allFeaturesResultRecord.GetString(2);
                                            feature.Title          = allFeaturesResultRecord.GetString(3);
                                            feature.Description    = allFeaturesResultRecord.GetString(4);
                                            feature.Display        = allFeaturesResultRecord.GetInteger(5);
                                            feature.Level          = allFeaturesResultRecord.GetInteger(6);
                                            feature.Directory      = allFeaturesResultRecord.GetString(7);
                                            feature.Attributes     = allFeaturesResultRecord.GetInteger(8);
                                            feature.Size           = size;
                                        }
                                    }
                                }
                            }
                    }
            }
        }
Exemple #2
0
        private void CreateMsiFeatures(Dtf.Database db)
        {
            if (db.Tables.Contains("Feature"))
            {
                using (var featureView = db.OpenView("SELECT `Component_` FROM `FeatureComponents` WHERE `Feature_` = ?"))
                    using (var componentView = db.OpenView("SELECT `FileSize` FROM `File` WHERE `Component_` = ?"))
                    {
                        using (var featureRecord = new Dtf.Record(1))
                            using (var componentRecord = new Dtf.Record(1))
                            {
                                using (var allFeaturesView = db.OpenView("SELECT * FROM `Feature`"))
                                {
                                    allFeaturesView.Execute();

                                    while (true)
                                    {
                                        using (var allFeaturesResultRecord = allFeaturesView.Fetch())
                                        {
                                            if (null == allFeaturesResultRecord)
                                            {
                                                break;
                                            }

                                            var featureName = allFeaturesResultRecord.GetString(1);

                                            // Calculate the Feature size.
                                            featureRecord.SetString(1, featureName);
                                            featureView.Execute(featureRecord);

                                            // Loop over all the components for the feature to calculate the size of the feature.
                                            long size = 0;
                                            while (true)
                                            {
                                                using (var componentResultRecord = featureView.Fetch())
                                                {
                                                    if (null == componentResultRecord)
                                                    {
                                                        break;
                                                    }

                                                    var component = componentResultRecord.GetString(1);
                                                    componentRecord.SetString(1, component);
                                                    componentView.Execute(componentRecord);

                                                    while (true)
                                                    {
                                                        using (var fileResultRecord = componentView.Fetch())
                                                        {
                                                            if (null == fileResultRecord)
                                                            {
                                                                break;
                                                            }

                                                            var fileSize = fileResultRecord.GetString(1);
                                                            size += Convert.ToInt32(fileSize, CultureInfo.InvariantCulture.NumberFormat);
                                                        }
                                                    }
                                                }
                                            }

                                            this.Section.AddSymbol(new WixBundleMsiFeatureSymbol(this.Facade.PackageSymbol.SourceLineNumbers, new Identifier(AccessModifier.Section, this.Facade.PackageId, featureName))
                                            {
                                                PackageRef  = this.Facade.PackageId,
                                                Name        = featureName,
                                                Parent      = allFeaturesResultRecord.GetString(2),
                                                Title       = allFeaturesResultRecord.GetString(3),
                                                Description = allFeaturesResultRecord.GetString(4),
                                                Display     = allFeaturesResultRecord.GetInteger(5),
                                                Level       = allFeaturesResultRecord.GetInteger(6),
                                                Directory   = allFeaturesResultRecord.GetString(7),
                                                Attributes  = allFeaturesResultRecord.GetInteger(8),
                                                Size        = size
                                            });
                                        }
                                    }
                                }
                            }
                    }
            }
        }