public bool Validate(PageCollection sourcePages, Microsoft.SharePoint.Client.ClientContext ctx) { int scount = 0; int tcount = 0; Web web = ctx.Web; ctx.Load(web, w => w.Url, w => w.ServerRelativeUrl); ctx.ExecuteQueryRetry(); foreach (var sourcePage in sourcePages) { string pageUrl = sourcePage.Url.ToString(); pageUrl = pageUrl.Replace("{site}", web.ServerRelativeUrl); Microsoft.SharePoint.Client.File file = web.GetFileByServerRelativeUrl(pageUrl); ctx.Load(file, page => page.ListItemAllFields, page => page.ListItemAllFields.RoleAssignments.Include(roleAsg => roleAsg.Member, roleAsg => roleAsg.RoleDefinitionBindings.Include(roleDef => roleDef.Name))); ctx.ExecuteQueryRetry(); if (file != null) { #region Page - Fields if (sourcePage.Fields.Count > 0) { scount = 0; tcount = 0; string sourceWikifield = sourcePage.Fields["WikiField"].ToString(); string targetwikiField = (string)file.ListItemAllFields["WikiField"]; if (sourceWikifield.Trim() != RemoveHTMLTags(targetwikiField).Trim()) { return(false); } } #endregion #region Page - Webparts if (!ctx.Web.IsNoScriptSite() && sourcePage.WebParts.Count > 0) { LimitedWebPartManager wpm = file.GetLimitedWebPartManager(PersonalizationScope.Shared); ctx.Load(wpm.WebParts, wps => wps.Include(wp => wp.WebPart.Title, wp => wp.WebPart.Properties)); ctx.ExecuteQueryRetry(); if (wpm.WebParts.Count > 0) { foreach (var spwp in sourcePage.WebParts) { scount++; foreach (WebPartDefinition wpd in wpm.WebParts) { if (spwp.Title == wpd.WebPart.Title) { tcount++; //Page - Webpart Properties Microsoft.SharePoint.Client.WebParts.WebPart wp = wpd.WebPart; var isWebPropertiesMatch = CSOMWebPartPropertiesValidation(spwp.Contents, wp.Properties); if (!isWebPropertiesMatch) { return(false); } } else { return(false); } } } if (scount != tcount) { return(false); } } else { return(false); } } #endregion #region Page - Security scount = 0; tcount = 0; if (sourcePage.Security != null && file.ListItemAllFields.RoleAssignments.Count > 0) { bool securityResult = ValidateSecurityCSOM(ctx, sourcePage.Security, file.ListItemAllFields); if (!securityResult) { return(false); } } #endregion } else { return(false); } } return(true); }
public bool Validate(Core.Framework.Provisioning.Model.FileCollection sourceFiles, Microsoft.SharePoint.Client.ClientContext ctx) { int scount = 0; int tcount = 0; try { // Check if this is not a noscript site as we're not allowed to write to the web property bag is that one bool isNoScriptSite = ctx.Web.IsNoScriptSite(); foreach (var sf in sourceFiles) { scount++; string fileName = sf.Src; string folderName = sf.Folder; string fileUrl = UrlUtility.Combine(ctx.Web.ServerRelativeUrl, folderName + "/" + fileName); // Skip the files we skipped to provision (if any) if (ObjectFiles.SkipFile(isNoScriptSite, fileName, folderName)) { continue; } var file = ctx.Web.GetFileByServerRelativeUrl(UrlUtility.Combine(ctx.Web.ServerRelativeUrl, folderName + "/" + fileName)); ctx.Load(file, f => f.Exists, f => f.Length); ctx.ExecuteQueryRetry(); if (file.Exists) { tcount++; #region File - Security if (sf.Security != null) { ctx.Load(file, f => f.ListItemAllFields); ctx.ExecuteQueryRetry(); bool isSecurityMatch = ValidateSecurityCSOM(ctx, sf.Security, file.ListItemAllFields); if (!isSecurityMatch) { return(false); } } #endregion #region Overwrite validation if (sf.Overwrite == false) { // lookup the original added file size...should be different from the one we retrieved from SharePoint since we opted to NOT overwrite var files = System.IO.Directory.GetFiles(@".\framework\functional\templates"); foreach (var f in files) { if (f.Contains(sf.Src)) { if (new System.IO.FileInfo(f).Length == file.Length) { return(false); } } } } #endregion } else { return(false); } } } catch (Exception ex) { // Return false if we get an exception Console.WriteLine(ex.ToDetailedString(ctx)); return(false); } return(true); }