Exemplo n.º 1
0
        void AddItems(WixEntity[] items)
        {
            Shortcuts        = items.OfType <FileShortcut>().ToArray();
            Associations     = items.OfType <FileAssociation>().ToArray();
            IISVirtualDirs   = items.OfType <IISVirtualDir>().ToArray();
            ServiceInstaller = items.OfType <ServiceInstaller>().FirstOrDefault();
            Permissions      = items.OfType <FilePermission>().ToArray();
            GenericItems     = items.OfType <IGenericEntity>().Where(val => val.GetType() != typeof(ServiceInstaller)).ToArray();

            FirewallExceptions = items.OfType <FirewallException>().ToArray();

            var firstUnExpectedItem = items.Except(Shortcuts)
                                      .Except(Associations)
                                      .Except(IISVirtualDirs)
                                      .Except(Permissions)
                                      .Except(FirewallExceptions)
                                      .Except(GenericItems.Cast <WixEntity>())
                                      .Where(x => x != ServiceInstaller)
                                      .ToArray();

            if (firstUnExpectedItem.Any())
            {
                throw new ApplicationException("{0} is unexpected. Only {2}, {3}, {4}, {5}, {6} and {7} items can be added to {1}".FormatWith(
                                                   firstUnExpectedItem.First().GetType(),
                                                   this.GetType(),
                                                   typeof(FileShortcut),
                                                   typeof(FileAssociation),
                                                   typeof(ServiceInstaller),
                                                   typeof(FilePermission),
                                                   typeof(FirewallException),
                                                   typeof(IGenericEntity)));
            }
        }