/// <summary> /// Validate site and web scoped features /// </summary> /// <param name="source">Source features</param> /// <param name="target">Target features</param> /// <returns>True if both source and target features match, false otherwise</returns> public static bool Validate(Features source, Features target) { bool isSiteFeaturesMatch = ValidateFeatures(source.SiteFeatures, target.SiteFeatures); Console.WriteLine("Site Features validation " + isSiteFeaturesMatch); bool isWebFeaturesMatch = ValidateFeatures(source.WebFeatures, target.WebFeatures); Console.WriteLine("Web Features validation " + isWebFeaturesMatch); if (!isSiteFeaturesMatch || !isWebFeaturesMatch) { return false; } else { return true; } }
public override ProvisioningTemplate CreateEntities(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo) { var context = web.Context as ClientContext; bool isSubSite = web.IsSubSite(); var webFeatures = web.Features; var siteFeatures = context.Site.Features; context.Load(webFeatures, fs => fs.Include(f => f.DefinitionId)); if (!isSubSite) { context.Load(siteFeatures, fs => fs.Include(f => f.DefinitionId)); } context.ExecuteQueryRetry(); var features = new Features(); foreach (var feature in webFeatures) { features.WebFeatures.Add(new Feature() { Deactivate = false, ID = feature.DefinitionId }); } // if this is a sub site then we're not creating site collection scoped feature entities if (!isSubSite) { foreach (var feature in siteFeatures) { features.SiteFeatures.Add(new Feature() { Deactivate = false, ID = feature.DefinitionId }); } } template.Features = features; // If a base template is specified then use that one to "cleanup" the generated template model if (creationInfo.BaseTemplate != null) { template = CleanupEntities(template, creationInfo.BaseTemplate, isSubSite); } return template; }