protected virtual void ProcessWebPartDeletes( Microsoft.SharePoint.WebPartPages.SPLimitedWebPartManager wpManager, IEnumerable<WebPart> spWebPartDefenitions, DeleteWebPartsDefinition definition) { var webParts2Delete = new List<WebPart>(); if (definition.WebParts.Any()) { foreach (var webPartMatch in definition.WebParts) { var currentWebPartMatch = FindWebPartMatch(spWebPartDefenitions, webPartMatch); if (currentWebPartMatch != null && !webParts2Delete.Contains(currentWebPartMatch)) webParts2Delete.Add(currentWebPartMatch); } } else { webParts2Delete.AddRange(spWebPartDefenitions); } // clean up for (var index = 0; index < webParts2Delete.Count; index++) wpManager.DeleteWebPart(webParts2Delete[index]); }
public void CanDeploy_DeleteWebpart_ByTitle() { var wpPage = ModelGeneratorService.GetRandomDefinition<WikiPageDefinition>(); var title1 = "title1_" + Rnd.String(); var title2 = "title2_" + Rnd.String(); var wp1 = ModelGeneratorService.GetRandomDefinition<WebPartDefinition>(def => { def.Title = title1; }); var wp2 = ModelGeneratorService.GetRandomDefinition<WebPartDefinition>(def => { def.Title = title2; }); var model = SPMeta2Model.NewWebModel(web => { web.AddHostList(BuiltInListDefinitions.SitePages, list => { list.AddWikiPage(wpPage, page => { page.AddWebParts(new[] { wp1, wp2 }); }); }); }); var wpDeletionDef = new DeleteWebPartsDefinition { }; wpDeletionDef.WebParts.Add(new WebPartMatch { Title = title1 }); var deleteModel = SPMeta2Model.NewWebModel(web => { web.AddHostList(BuiltInListDefinitions.SitePages, list => { list.AddHostWikiPage(wpPage, page => { page.AddDeleteWebParts(wpDeletionDef); }); }); }); TestModel(model, deleteModel); }
protected virtual void ProcessWebPartDeletes( IEnumerable<Microsoft.SharePoint.Client.WebParts.WebPartDefinition> spWebPartDefenitions, DeleteWebPartsDefinition definition) { var webParts2Delete = new List<Microsoft.SharePoint.Client.WebParts.WebPartDefinition>(); if (definition.WebParts.Any()) { foreach (var webPartMatch in definition.WebParts) { var currentWebPartMatch = FindWebPartMatch(spWebPartDefenitions, webPartMatch); if (currentWebPartMatch != null && !webParts2Delete.Contains(currentWebPartMatch)) webParts2Delete.Add(currentWebPartMatch); } } else { webParts2Delete.AddRange(spWebPartDefenitions); } // clean up foreach (var wp in webParts2Delete) wp.DeleteWebPart(); }
public static ModelNode AddDeleteWebParts(this ModelNode model, DeleteWebPartsDefinition definition, Action<ModelNode> action) { return model.AddDefinitionNode(definition, action); }
public static ModelNode AddDeleteWebParts(this ModelNode model, DeleteWebPartsDefinition definition) { return AddDeleteWebParts(model, definition, null); }