Ejemplo n.º 1
0
        /// <summary>
        /// Creates a component group with a given name.
        /// </summary>
        /// <param name="wix">The Wix document element.</param>
        private void CreateComponentGroup(Wix.Wix wix)
        {
            Wix.ComponentGroup componentGroup = new Wix.ComponentGroup();
            componentGroup.Id = this.componentGroupName;
            this.componentGroups.Add(componentGroup);

            Wix.Fragment cgFragment = new Wix.Fragment();
            cgFragment.AddChild(componentGroup);
            wix.AddChild(cgFragment);

            int componentCount = 0;
            for (; componentCount < this.components.Count; componentCount++)
            {
                Wix.Component c = this.components[componentCount] as Wix.Component;

                if (this.createFragments)
                {
                    if (c.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = c.ParentElement as Wix.Directory;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);
                    }
                    else if (c.ParentElement is Wix.DirectoryRef)
                    {
                        Wix.DirectoryRef parentDirectory = c.ParentElement as Wix.DirectoryRef;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);

                        // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef
                        if (0 < fragments.Count && parentDirectory.ParentElement is Wix.Fragment)
                        {
                            Wix.Fragment parentFragment = parentDirectory.ParentElement as Wix.Fragment;
                            int childCount = 0;
                            foreach (Wix.ISchemaElement element in parentFragment.Children)
                            {
                                childCount++;
                            }

                            // Component should always have an Id but the SortedList creation allows for null and bases the name on the fragment count which we cannot reverse engineer here.
                            if (1 == childCount && !String.IsNullOrEmpty(c.Id))
                            {
                                int removeIndex = fragments.IndexOfKey(String.Concat("Component:", c.Id));
                                if (0 <= removeIndex)
                                {
                                    fragments.RemoveAt(removeIndex);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Wix.ComponentRef componentRef = new Wix.ComponentRef();
                    componentRef.Id = c.Id;
                    componentGroup.AddChild(componentRef);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a component group with a given name.
        /// </summary>
        /// <param name="wix">The Wix document element.</param>
        private void CreateComponentGroup(Wix.Wix wix)
        {
            Wix.ComponentGroup componentGroup = new Wix.ComponentGroup();
            componentGroup.Id = this.componentGroupName;
            this.componentGroups.Add(componentGroup);

            Wix.Fragment cgFragment = new Wix.Fragment();
            cgFragment.AddChild(componentGroup);
            wix.AddChild(cgFragment);

            int componentCount = 0;

            for (; componentCount < this.components.Count; componentCount++)
            {
                Wix.Component c = this.components[componentCount] as Wix.Component;

                if (this.createFragments)
                {
                    if (c.ParentElement is Wix.Directory)
                    {
                        Wix.Directory parentDirectory = c.ParentElement as Wix.Directory;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);
                    }
                    else if (c.ParentElement is Wix.DirectoryRef)
                    {
                        Wix.DirectoryRef parentDirectory = c.ParentElement as Wix.DirectoryRef;

                        componentGroup.AddChild(c);
                        c.Directory = parentDirectory.Id;
                        parentDirectory.RemoveChild(c);

                        // Remove whole fragment if moving the component to the component group just leaves an empty DirectoryRef
                        if (0 < fragments.Count && parentDirectory.ParentElement is Wix.Fragment)
                        {
                            Wix.Fragment parentFragment = parentDirectory.ParentElement as Wix.Fragment;
                            int          childCount     = 0;
                            foreach (Wix.ISchemaElement element in parentFragment.Children)
                            {
                                childCount++;
                            }

                            // Component should always have an Id but the SortedList creation allows for null and bases the name on the fragment count which we cannot reverse engineer here.
                            if (1 == childCount && !String.IsNullOrEmpty(c.Id))
                            {
                                int removeIndex = fragments.IndexOfKey(String.Concat("Component:", c.Id));
                                if (0 <= removeIndex)
                                {
                                    fragments.RemoveAt(removeIndex);
                                }
                            }
                        }
                    }
                }
                else
                {
                    Wix.ComponentRef componentRef = new Wix.ComponentRef();
                    componentRef.Id = c.Id;
                    componentGroup.AddChild(componentRef);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Mutate a WiX document.
        /// </summary>
        /// <param name="wix">The Wix document element.</param>
        public override void Mutate(Wix.Wix wix)
        {
            this.components.Clear();
            this.directories.Clear();
            this.directoryRefs.Clear();
            this.features.Clear();
            this.files.Clear();
            this.fragments.Clear();
            this.rootElement = null;

            // index elements in this wix document
            this.IndexElement(wix);

            this.MutateWix(wix);

            this.MutateFiles();

            this.MutateDirectories();

            this.MutateComponents();

            // add the components to the product feature after all the identifiers have been set
            if (TemplateType.Product == this.templateType)
            {
                Wix.Feature feature = (Wix.Feature) this.features[0];

                foreach (Wix.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        feature.AddChild(componentRef);
                    }
                }
            }
            // create a ComponentGroup with all the components
            else if (TemplateType.Fragment == this.templateType && !this.createFragments)
            {
                Wix.ComponentGroup componentGroup = new Wix.ComponentGroup();
                componentGroup.Id = "ComponentGroup1";

                foreach (Wix.Component component in this.components)
                {
                    if (null != component.Id)
                    {
                        Wix.ComponentRef componentRef = new Wix.ComponentRef();
                        componentRef.Id = component.Id;
                        componentGroup.AddChild(componentRef);
                    }
                }

                Wix.Fragment fragment = new Wix.Fragment();
                this.fragments.Add("ComponentGroup:1", fragment);
                fragment.AddChild(componentGroup);
            }

            foreach (Wix.Fragment fragment in this.fragments.Values)
            {
                wix.AddChild(fragment);
            }
        }