本文整理汇总了C#中Web.IsNoScriptSite方法的典型用法代码示例。如果您正苦于以下问题:C# Web.IsNoScriptSite方法的具体用法?C# Web.IsNoScriptSite怎么用?C# Web.IsNoScriptSite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web.IsNoScriptSite方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// 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 = web.IsNoScriptSite();
if (isNoScriptSite)
{
return parser;
}
web.SetPropertyBagValue("_PnP_ProvisioningTemplateId", template.Id != null ? template.Id : "");
web.AddIndexedPropertyBagKey("_PnP_ProvisioningTemplateId");
ProvisioningTemplateInfo info = new ProvisioningTemplateInfo();
info.TemplateId = template.Id != null ? template.Id : "";
info.TemplateVersion = template.Version;
info.TemplateSitePolicy = template.SitePolicy;
info.Result = true;
info.ProvisioningTime = DateTime.Now;
string jsonInfo = JsonConvert.SerializeObject(info);
web.SetPropertyBagValue("_PnP_ProvisioningTemplateInfo", jsonInfo);
}
return parser;
}
示例2: Validate
public static bool Validate(CustomActions sourceCustomActions, CustomActions targetCustomActions, TokenParser tokenParser, Web web)
{
if (web.IsNoScriptSite())
{
Console.WriteLine("Skipping validation of custom actions due to noscript site.");
return true;
}
Console.WriteLine("Custom Action validation started...");
bool isSiteCustomActionsMatch = false;
bool isWebCustomActionsMatch = false;
if (sourceCustomActions.SiteCustomActions.Count > 0)
{
isSiteCustomActionsMatch = ValidateCustomActions(sourceCustomActions.SiteCustomActions, targetCustomActions.SiteCustomActions, tokenParser, web);
Console.WriteLine("Site Custom Actions validation " + isSiteCustomActionsMatch);
}
if (sourceCustomActions.WebCustomActions.Count > 0)
{
isWebCustomActionsMatch = ValidateCustomActions(sourceCustomActions.WebCustomActions, targetCustomActions.WebCustomActions, tokenParser, web);
Console.WriteLine("Web Custom Actions validation " + isWebCustomActionsMatch);
}
if (!isSiteCustomActionsMatch || !isWebCustomActionsMatch)
{
return false;
}
else
{
return true;
}
}
示例3: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
var site = context.Site;
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
// if this is a sub site then we're not enabling the site collection scoped custom actions
if (!web.IsSubSite())
{
var siteCustomActions = template.CustomActions.SiteCustomActions;
ProvisionCustomActionImplementation(site, siteCustomActions, parser, scope, isNoScriptSite);
}
var webCustomActions = template.CustomActions.WebCustomActions;
ProvisionCustomActionImplementation(web, webCustomActions, parser, scope, isNoScriptSite);
// Switch parser context back to it's original context
parser.Rebase(web);
}
return parser;
}
示例4: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// if this is a sub site then we're not provisioning content types. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Context_web_is_subweb__Skipping_content_types_);
return parser;
}
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
web.Context.Load(web.ContentTypes, ct => ct.IncludeWithDefaultProperties(c => c.StringId, c => c.FieldLinks,
c => c.FieldLinks.Include(fl => fl.Id, fl => fl.Required, fl => fl.Hidden)));
web.Context.Load(web.Fields, fld => fld.IncludeWithDefaultProperties(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingCTs = web.ContentTypes.ToList();
var existingFields = web.Fields.ToList();
foreach (var ct in template.ContentTypes.OrderBy(ct => ct.Id)) // ordering to handle references to parent content types that can be in the same template
{
var existingCT = existingCTs.FirstOrDefault(c => c.StringId.Equals(ct.Id, StringComparison.OrdinalIgnoreCase));
if (existingCT == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Creating_new_Content_Type___0_____1_, ct.Id, ct.Name);
var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
if (ct.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Recreating_existing_Content_Type___0_____1_, ct.Id, ct.Name);
existingCT.DeleteObject();
web.Context.ExecuteQueryRetry();
var newCT = CreateContentType(web, ct, parser, template.Connector ?? null, scope, existingCTs, existingFields, isNoScriptSite);
if (newCT != null)
{
existingCTs.Add(newCT);
}
}
else
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Updating_existing_Content_Type___0_____1_, ct.Id, ct.Name);
UpdateContentType(web, existingCT, ct, parser, scope, isNoScriptSite);
}
}
}
}
return parser;
}
示例5: WillProvision
public override bool WillProvision(Web web, ProvisioningTemplate template)
{
if (!_willProvision.HasValue)
{
_willProvision = !web.IsNoScriptSite();
}
return _willProvision.Value;
}
示例6: LocalizationValidator
public LocalizationValidator(Web web)
: base()
{
// optionally override schema version
// SchemaVersion = "http://schemas.dev.office.com/PnP/2016/05/ProvisioningSchema";
// XPathQuery = "/pnp:Templates/pnp:ProvisioningTemplate/pnp:ContentTypes/pnp:ContentType";
isNoScriptSite = web.IsNoScriptSite();
}
示例7: ContentTypeValidator
public ContentTypeValidator(Web web)
: base()
{
// optionally override schema version
SchemaVersion = XMLConstants.PROVISIONING_SCHEMA_NAMESPACE_2015_12;
XPathQuery = "/pnp:Templates/pnp:ProvisioningTemplate/pnp:ContentTypes/pnp:ContentType";
// Check if this is not a noscript site as we're not allowed to update some properties
isNoScriptSite = web.IsNoScriptSite();
}
示例8: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.AuditSettings != null)
{
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
var site = (web.Context as ClientContext).Site;
site.EnsureProperties(s => s.Audit, s => s.AuditLogTrimmingRetention, s => s.TrimAuditLog);
var siteAuditSettings = site.Audit;
var isDirty = false;
if (template.AuditSettings.AuditFlags != siteAuditSettings.AuditFlags)
{
site.Audit.AuditFlags = template.AuditSettings.AuditFlags;
site.Audit.Update();
isDirty = true;
}
if (!isNoScriptSite)
{
if (template.AuditSettings.AuditLogTrimmingRetention != site.AuditLogTrimmingRetention)
{
site.AuditLogTrimmingRetention = template.AuditSettings.AuditLogTrimmingRetention;
isDirty = true;
}
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Audit_SkipAuditLogTrimmingRetention);
}
if (template.AuditSettings.TrimAuditLog != site.TrimAuditLog)
{
site.TrimAuditLog = template.AuditSettings.TrimAuditLog;
isDirty = true;
}
if (isDirty)
{
web.Context.ExecuteQueryRetry();
}
}
}
return parser;
}
示例9: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.Lists.Any())
{
var rootWeb = (web.Context as ClientContext).Site.RootWeb;
web.EnsureProperties(w => w.ServerRelativeUrl);
web.Context.Load(web.Lists, lc => lc.IncludeWithDefaultProperties(l => l.RootFolder.ServerRelativeUrl));
web.Context.ExecuteQueryRetry();
var existingLists = web.Lists.AsEnumerable().ToList();
var serverRelativeUrl = web.ServerRelativeUrl;
var processedLists = new List<ListInfo>();
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
#region Lists
foreach (var templateList in template.Lists)
{
// Check for the presence of the references content types and throw an exception if not present or in template
if (templateList.ContentTypesEnabled)
{
var existingCts = web.Context.LoadQuery(web.AvailableContentTypes);
web.Context.ExecuteQueryRetry();
foreach (var ct in templateList.ContentTypeBindings)
{
var found = template.ContentTypes.Any(t => t.Id.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
if (found == false)
{
found = existingCts.Any(t => t.StringId.ToUpperInvariant() == ct.ContentTypeId.ToUpperInvariant());
}
if (!found)
{
scope.LogError("Referenced content type {0} not available in site or in template", ct.ContentTypeId);
throw new Exception(string.Format("Referenced content type {0} not available in site or in template", ct.ContentTypeId));
}
}
}
// check if the List exists by url or by title
var index = existingLists.FindIndex(x => x.Title.Equals(templateList.Title, StringComparison.OrdinalIgnoreCase) || x.RootFolder.ServerRelativeUrl.Equals(UrlUtility.Combine(serverRelativeUrl, templateList.Url), StringComparison.OrdinalIgnoreCase));
if (index == -1)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0_, templateList.Title);
var returnTuple = CreateList(web, templateList, parser, scope, isNoScriptSite);
var createdList = returnTuple.Item1;
parser = returnTuple.Item2;
processedLists.Add(new ListInfo { SiteList = createdList, TemplateList = templateList });
parser.AddToken(new ListIdToken(web, templateList.Title, createdList.Id));
parser.AddToken(new ListUrlToken(web, templateList.Title, createdList.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length + 1)));
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Creating_list__0__failed___1_____2_, templateList.Title, ex.Message, ex.StackTrace);
throw;
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Updating_list__0_, templateList.Title);
var existingList = web.Lists[index];
var returnTuple = UpdateList(web, existingList, templateList, parser, scope, isNoScriptSite);
var updatedList = returnTuple.Item1;
parser = returnTuple.Item2;
if (updatedList != null)
{
processedLists.Add(new ListInfo { SiteList = updatedList, TemplateList = templateList });
}
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Updating_list__0__failed___1_____2_, templateList.Title, ex.Message, ex.StackTrace);
throw;
}
}
}
#endregion
#region FieldRefs
foreach (var listInfo in processedLists)
{
if (listInfo.TemplateList.FieldRefs.Any())
{
foreach (var fieldRef in listInfo.TemplateList.FieldRefs)
{
//.........这里部分代码省略.........
示例10: ValidateCustomActions
public static bool ValidateCustomActions(CustomActionCollection source, CustomActionCollection target, TokenParser tokenParser, Web web = null)
{
int sCount = 0;
int tCount = 0;
if (web != null && web.IsNoScriptSite())
{
Console.WriteLine("Skipping validation of custom actions due to noscript site.");
return true;
}
foreach (CustomAction srcSCA in source)
{
//Only count the enabled ones
if (srcSCA.Enabled && !srcSCA.Remove)
{
// ensure token in source are parsed before comparing with target
srcSCA.Title = tokenParser.ParseString(srcSCA.Title);
srcSCA.ImageUrl = tokenParser.ParseString(srcSCA.ImageUrl);
srcSCA.ScriptBlock = tokenParser.ParseString(srcSCA.ScriptBlock);
srcSCA.ScriptSrc = tokenParser.ParseString(srcSCA.ScriptSrc, "~site", "~sitecollection");
srcSCA.Title = tokenParser.ParseString(srcSCA.Title);
srcSCA.Url = tokenParser.ParseString(srcSCA.Url);
if (srcSCA.CommandUIExtension != null)
{
srcSCA.CommandUIExtension = XElement.Parse(tokenParser.ParseString(srcSCA.CommandUIExtension.ToString()));
}
sCount++;
foreach (CustomAction tgtSCA in target)
{
if (tgtSCA.CommandUIExtension != null)
{
// Drop the namespace attribute before comparing (xmlns="http://schemas.microsoft.com/sharepoint").
// SharePoint injects this namespace when we extract a custom action that has a commandUIExtension
tgtSCA.CommandUIExtension = RemoveAllNamespaces(tgtSCA.CommandUIExtension);
}
// Use our custom action "Equals" implementation
if (srcSCA.Equals(tgtSCA))
{
tCount++;
break;
}
else
{
Console.WriteLine("{0} is not matching", tgtSCA.Name);
}
}
}
}
if (sCount != tCount)
{
return false;
}
// cross check that enabled false custom actions do not exist anymore
foreach (CustomAction srcSCA in source)
{
if (!srcSCA.Enabled || srcSCA.Remove)
{
var ca = target.Where(w => w.Name == srcSCA.Name).FirstOrDefault();
if (ca != null)
{
return false;
}
}
}
return true;
}
示例11: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.ComposedLook != null &&
!template.ComposedLook.Equals(ComposedLook.Empty))
{
// Check if this is not a noscript site as themes and composed looks are not supported
if (web.IsNoScriptSite())
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ComposedLooks_NoSiteCheck);
return parser;
}
bool executeQueryNeeded = false;
if (executeQueryNeeded)
{
web.Context.ExecuteQueryRetry();
}
if (String.IsNullOrEmpty(template.ComposedLook.ColorFile) &&
String.IsNullOrEmpty(template.ComposedLook.FontFile) &&
String.IsNullOrEmpty(template.ComposedLook.BackgroundFile))
{
// Apply OOB theme
web.SetComposedLookByUrl(template.ComposedLook.Name, "", "", "");
}
else
{
// Apply custom theme
string colorFile = null;
if (!string.IsNullOrEmpty(template.ComposedLook.ColorFile))
{
colorFile = parser.ParseString(template.ComposedLook.ColorFile);
}
string backgroundFile = null;
if (!string.IsNullOrEmpty(template.ComposedLook.BackgroundFile))
{
backgroundFile = parser.ParseString(template.ComposedLook.BackgroundFile);
}
string fontFile = null;
if (!string.IsNullOrEmpty(template.ComposedLook.FontFile))
{
fontFile = parser.ParseString(template.ComposedLook.FontFile);
}
string masterUrl = null;
if (template.WebSettings != null && !string.IsNullOrEmpty(template.WebSettings.MasterPageUrl))
{
masterUrl = parser.ParseString(template.WebSettings.MasterPageUrl);
}
web.CreateComposedLookByUrl(template.ComposedLook.Name, colorFile, fontFile, backgroundFile, masterUrl);
web.SetComposedLookByUrl(template.ComposedLook.Name, colorFile, fontFile, backgroundFile, masterUrl);
}
// Persist composed look info in property bag
var composedLookJson = JsonConvert.SerializeObject(template.ComposedLook);
web.SetPropertyBagValue("_PnP_ProvisioningTemplateComposedLookInfo", composedLookJson);
}
}
return parser;
}
示例12: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.RootFolder.WelcomePage);
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
foreach (var page in template.Pages)
{
var url = parser.ParseString(page.Url);
if (!url.ToLower().StartsWith(web.ServerRelativeUrl.ToLower()))
{
url = UrlUtility.Combine(web.ServerRelativeUrl, url);
}
var exists = true;
Microsoft.SharePoint.Client.File file = null;
try
{
file = web.GetFileByServerRelativeUrl(url);
web.Context.Load(file);
web.Context.ExecuteQueryRetry();
}
catch (ServerException ex)
{
if (ex.ServerErrorTypeName == "System.IO.FileNotFoundException")
{
exists = false;
}
}
if (exists)
{
if (page.Overwrite)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0_, url);
if (page.WelcomePage && url.Contains(web.RootFolder.WelcomePage))
web.SetHomePage(string.Empty);
file.DeleteObject();
web.Context.ExecuteQueryRetry();
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else {
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Overwriting_existing_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
}
else
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0_, url);
web.AddWikiPageByUrl(url);
if (page.Layout == WikiPageLayout.Custom)
{
web.AddLayoutToWikiPage(WikiPageLayout.OneColumn, url);
}
else {
web.AddLayoutToWikiPage(page.Layout, url);
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Pages_Creating_new_page__0__failed___1_____2_, url, ex.Message, ex.StackTrace);
}
}
if (page.WelcomePage)
{
web.RootFolder.EnsureProperty(p => p.ServerRelativeUrl);
var rootFolderRelativeUrl = url.Substring(web.RootFolder.ServerRelativeUrl.Length);
web.SetHomePage(rootFolderRelativeUrl);
}
if (page.WebParts != null & page.WebParts.Any())
{
if (!isNoScriptSite)
{
var existingWebParts = web.GetWebParts(url);
foreach (var webpart in page.WebParts)
{
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
//.........这里部分代码省略.........
示例13: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var site = (web.Context as ClientContext).Site;
// Check if this is not a noscript site as publishing features are not supported
if (web.IsNoScriptSite())
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Publishing_SkipProvisioning);
return parser;
}
var webFeatureActive = web.IsFeatureActive(PUBLISHING_FEATURE_WEB);
var siteFeatureActive = site.IsFeatureActive(PUBLISHING_FEATURE_SITE);
if (template.Publishing.AutoCheckRequirements == AutoCheckRequirementsOptions.SkipIfNotCompliant && !webFeatureActive)
{
scope.LogDebug("Publishing Feature (Web Scoped) not active. Skipping provisioning of Publishing settings");
return parser;
}
else if (template.Publishing.AutoCheckRequirements == AutoCheckRequirementsOptions.MakeCompliant)
{
if (!siteFeatureActive)
{
scope.LogDebug("Making site compliant for publishing");
site.ActivateFeature(PUBLISHING_FEATURE_SITE);
web.ActivateFeature(PUBLISHING_FEATURE_WEB);
}
else
{
if (!web.IsFeatureActive(PUBLISHING_FEATURE_WEB))
{
scope.LogDebug("Making site compliant for publishing");
web.ActivateFeature(PUBLISHING_FEATURE_WEB);
}
}
}
else
{
throw new Exception("Publishing Feature not active. Provisioning failed");
}
// Set allowed web templates
var availableWebTemplates = template.Publishing.AvailableWebTemplates.Select(t => new WebTemplateEntity() { LanguageCode = t.LanguageCode.ToString(), TemplateName = t.TemplateName }).ToList();
if (availableWebTemplates.Any())
{
web.SetAvailableWebTemplates(availableWebTemplates);
}
if (template.Publishing.DesignPackage != null)
{
var package = template.Publishing.DesignPackage;
var tempFileName = Path.Combine(Path.GetTempPath(), template.Connector.GetFilenamePart(package.DesignPackagePath));
scope.LogDebug("Saving {0} to temporary file: {1}", package.DesignPackagePath, tempFileName);
using (var stream = template.Connector.GetFileStream(package.DesignPackagePath))
{
using (var outstream = System.IO.File.Create(tempFileName))
{
stream.CopyTo(outstream);
}
}
scope.LogDebug("Installing design package");
site.InstallSolution(package.PackageGuid, tempFileName, package.MajorVersion, package.MinorVersion);
System.IO.File.Delete(tempFileName);
}
// Set allowed page layouts
var availablePageLayouts = template.Publishing.PageLayouts.Select(p => p.Path);
if (availablePageLayouts.Any())
{
web.SetAvailablePageLayouts(site.RootWeb, availablePageLayouts);
}
// Set default page layout, if any
var defaultPageLayout = template.Publishing.PageLayouts.FirstOrDefault(p => p.IsDefault);
if (defaultPageLayout != null)
{
web.SetDefaultPageLayoutForSite(site.RootWeb, defaultPageLayout.Path);
}
return parser;
}
}
示例14: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// 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 = web.IsNoScriptSite();
var context = web.Context as ClientContext;
web.EnsureProperties(w => w.ServerRelativeUrl, w => w.Url);
// Build on the fly the list of additional files coming from the Directories
var directoryFiles = new List<Model.File>();
foreach (var directory in template.Directories)
{
var metadataProperties = directory.GetMetadataProperties();
directoryFiles.AddRange(directory.GetDirectoryFiles(metadataProperties));
}
foreach (var file in template.Files.Union(directoryFiles))
{
var folderName = parser.ParseString(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
if (SkipFile(isNoScriptSite, file.Src, folderName))
{
// add log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Files_SkipFileUpload, file.Src, folderName);
continue;
}
var folder = web.EnsureFolderPath(folderName);
var checkedOut = false;
var targetFile = folder.GetFile(template.Connector.GetFilenamePart(file.Src));
if (targetFile != null)
{
if (file.Overwrite)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_and_overwriting_existing_file__0_, file.Src);
checkedOut = CheckOutIfNeeded(web, targetFile);
using (var stream = GetFileStream(template, file))
{
targetFile = UploadFile(template, file, folder, stream);
}
}
else
{
checkedOut = CheckOutIfNeeded(web, targetFile);
}
}
else
{
using (var stream = GetFileStream(template, file))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Uploading_file__0_, file.Src);
targetFile = UploadFile(template, file, folder, stream);
}
checkedOut = CheckOutIfNeeded(web, targetFile);
}
if (targetFile != null)
{
if (file.Properties != null && file.Properties.Any())
{
Dictionary<string, string> transformedProperties = file.Properties.ToDictionary(property => property.Key, property => parser.ParseString(property.Value));
SetFileProperties(targetFile, transformedProperties, false);
}
#if !SP2013
bool webPartsNeedLocalization = false;
#endif
if (file.WebParts != null && file.WebParts.Any())
{
targetFile.EnsureProperties(f => f.ServerRelativeUrl);
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl).ToList();
foreach (var webPart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == parser.ParseString(webPart.Title)) == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Adding_webpart___0___to_page, webPart.Title);
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = parser.ParseString(webPart.Title);
wpEntity.WebPartXml = parser.ParseString(webPart.Contents).Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webPart.Zone;
wpEntity.WebPartIndex = (int)webPart.Order;
var wpd = web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
#if !SP2013
if (webPart.Title.ContainsResourceToken())
{
//.........这里部分代码省略.........
示例15: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.WebSettings != null)
{
// Check if this is not a noscript site as we're not allowed to update some properties
bool isNoScriptSite = web.IsNoScriptSite();
web.EnsureProperty(w => w.HasUniqueRoleAssignments);
var webSettings = template.WebSettings;
#if !ONPREMISES
if (!isNoScriptSite)
{
web.NoCrawl = webSettings.NoCrawl;
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipNoCrawlUpdate);
}
if (!web.IsSubSite() || (web.IsSubSite() && web.HasUniqueRoleAssignments))
{
String requestAccessEmailValue = parser.ParseString(webSettings.RequestAccessEmail);
if (!String.IsNullOrEmpty(requestAccessEmailValue) && requestAccessEmailValue.Length >= 255)
{
requestAccessEmailValue = requestAccessEmailValue.Substring(0, 255);
}
if (!String.IsNullOrEmpty(requestAccessEmailValue))
{
web.RequestAccessEmail = requestAccessEmailValue;
web.Update();
web.Context.ExecuteQueryRetry();
}
}
#endif
var masterUrl = parser.ParseString(webSettings.MasterPageUrl);
if (!string.IsNullOrEmpty(masterUrl))
{
if (!isNoScriptSite)
{
web.MasterUrl = masterUrl;
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipMasterPageUpdate);
}
}
var customMasterUrl = parser.ParseString(webSettings.CustomMasterPageUrl);
if (!string.IsNullOrEmpty(customMasterUrl))
{
if (!isNoScriptSite)
{
web.CustomMasterUrl = customMasterUrl;
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_WebSettings_SkipCustomMasterPageUpdate);
}
}
if (webSettings.Title != null)
{
web.Title = parser.ParseString(webSettings.Title);
}
if (webSettings.Description != null)
{
web.Description = parser.ParseString(webSettings.Description);
}
if (webSettings.SiteLogo != null)
{
web.SiteLogoUrl = parser.ParseString(webSettings.SiteLogo);
}
var welcomePage = parser.ParseString(webSettings.WelcomePage);
if (!string.IsNullOrEmpty(welcomePage))
{
web.RootFolder.WelcomePage = welcomePage;
web.RootFolder.Update();
}
if (webSettings.AlternateCSS != null)
{
web.AlternateCssUrl = parser.ParseString(webSettings.AlternateCSS);
}
web.Update();
web.Context.ExecuteQueryRetry();
}
}
return parser;
}