void BuildFeaturesHierarchy() { features = Runtime.Session.Features; //build the hierarchy tree var rootItems = features.Where(x => x.ParentName.IsEmpty()) .OrderBy(x => x.RawDisplay) .ToArray(); var itemsToProcess = new Queue <FeatureItem>(rootItems); //features to find the children for while (itemsToProcess.Any()) { var item = itemsToProcess.Dequeue(); //create the view of the feature var view = new ReadOnlyTreeNode { Text = item.Title, Tag = item, //link view to model IsReadOnly = item.DisallowAbsent, DefaultChecked = item.DefaultIsToBeInstalled(), Checked = item.DefaultIsToBeInstalled() }; item.View = view; if (item.Parent != null && item.Display != FeatureDisplay.hidden) { (item.Parent.View as TreeNode).Nodes.Add(view); //link child view to parent view } // even if the item is hidden process all its children so the correct hierarchy is established // find all children features.Where(x => x.ParentName == item.Name) .ForEach(c => { c.Parent = item; //link child model to parent model itemsToProcess.Enqueue(c); //schedule for further processing }); if (UserSelectedItems != null) { view.Checked = UserSelectedItems.Contains((view.Tag as FeatureItem).Name); } if (item.Display == FeatureDisplay.expand) { view.Expand(); } } //add views to the treeView control rootItems.Where(x => x.Display != FeatureDisplay.hidden) .Select(x => x.View) .Cast <TreeNode>() .ForEach(node => featuresTree.Nodes.Add(node)); isAutoCheckingActive = true; }
void BuildFeaturesHierarchy() { //Cannot use MsiRuntime.Session.Features (FeatureInfo collection). //This WiX feature is just not implemented yet. All members except 'Name' throw InvalidHandeException //Thus instead of using FeatureInfo just collect the names and query database for the rest of the properties. string[] names = MsiRuntime.Session.Features.Select(x => x.Name).ToArray(); features = names.Select(name => new FeatureItem(MsiRuntime.Session, name)).ToArray(); //build the hierarchy tree var rootItems = features.Where(x => x.ParentName.IsEmpty()) .OrderBy(x => x.RawDisplay) .ToArray(); var itemsToProcess = new Queue <FeatureItem>(rootItems); //features to find the children for while (itemsToProcess.Any()) { var item = itemsToProcess.Dequeue(); //create the view of the feature var view = new ReadOnlyTreeNode { Text = item.Title, Tag = item, //link view to model IsReadOnly = item.DisallowAbsent, DefaultChecked = item.DefaultIsToBeInstalled(), Checked = item.DefaultIsToBeInstalled() }; item.View = view; if (item.Parent != null && item.Display != FeatureDisplay.hidden) { (item.Parent.View as TreeNode).Nodes.Add(view); //link child view to parent view } // even if the item is hidden process all its children so the correct hierarchy is established // find all children features.Where(x => x.ParentName == item.Name) .ForEach(c => { c.Parent = item; //link child model to parent model itemsToProcess.Enqueue(c); //schedule for further processing }); if (UserSelectedItems != null) { view.Checked = UserSelectedItems.Contains((view.Tag as FeatureItem).Name); } if (item.Display == FeatureDisplay.expand) { view.Expand(); } } //add views to the treeView control rootItems.Where(x => x.Display != FeatureDisplay.hidden) .Select(x => x.View) .Cast <TreeNode>() .ForEach(node => featuresTree.Nodes.Add(node)); isAutoCheckingActive = true; }