private static void ProcessPageLayoutSettings(PublishingWeb publishingWeb, PageLayoutAndSiteTemplateSettingsDefinition definition)
        {
            var web = publishingWeb.Web;

            if (definition.InheritPageLayouts.HasValue && definition.InheritPageLayouts.Value)
            {
                publishingWeb.InheritAvailablePageLayouts();
            }
            else if (definition.UseAnyPageLayout.HasValue && definition.UseAnyPageLayout.Value)
            {
                publishingWeb.AllowAllPageLayouts(definition.ResetAllSubsitesToInheritPageLayouts.HasValue
                    ? definition.ResetAllSubsitesToInheritPageLayouts.Value
                    : false);
            }
            else if (definition.UseDefinedPageLayouts.HasValue && definition.UseDefinedPageLayouts.Value)
            {
                var publishingSite = new PublishingSite(web.Site);
                var pageLayouts    = publishingSite.PageLayouts;

                var selectedPageLayouts = new List <PageLayout>();

                foreach (var selectedLayoutName in definition.DefinedPageLayouts)
                {
                    var targetLayout = pageLayouts.FirstOrDefault(t => t.Name.ToUpper() == selectedLayoutName.ToUpper());

                    if (targetLayout != null)
                    {
                        selectedPageLayouts.Add(targetLayout);
                    }
                }

                if (selectedPageLayouts.Any())
                {
                    publishingWeb.SetAvailablePageLayouts(selectedPageLayouts.ToArray(),
                                                          definition.ResetAllSubsitesToInheritPageLayouts.HasValue
                            ? definition.ResetAllSubsitesToInheritPageLayouts.Value
                            : false);
                }
            }
        }
        private static void ProcessPageLayoutSettings(PublishingWeb publishingWeb, PageLayoutAndSiteTemplateSettingsDefinition definition)
        {
            var web = publishingWeb.Web;

            if (definition.InheritPageLayouts.HasValue && definition.InheritPageLayouts.Value)
                publishingWeb.InheritAvailablePageLayouts();
            else if (definition.UseAnyPageLayout.HasValue && definition.UseAnyPageLayout.Value)
            {
                publishingWeb.AllowAllPageLayouts(definition.ResetAllSubsitesToInheritPageLayouts.HasValue
                    ? definition.ResetAllSubsitesToInheritPageLayouts.Value
                    : false);
            }
            else if (definition.UseDefinedPageLayouts.HasValue && definition.UseDefinedPageLayouts.Value)
            {
                var publishingSite = new PublishingSite(web.Site);
                var pageLayouts = publishingSite.PageLayouts;

                var selectedPageLayouts = new List<PageLayout>();

                foreach (var selectedLayoutName in definition.DefinedPageLayouts)
                {
                    var targetLayout = pageLayouts.FirstOrDefault(t => t.Name.ToUpper() == selectedLayoutName.ToUpper());

                    if (targetLayout != null)
                        selectedPageLayouts.Add(targetLayout);
                }

                if (selectedPageLayouts.Any())
                {
                    publishingWeb.SetAvailablePageLayouts(selectedPageLayouts.ToArray(),
                        definition.ResetAllSubsitesToInheritPageLayouts.HasValue
                            ? definition.ResetAllSubsitesToInheritPageLayouts.Value
                            : false);
                }
            }
        }