本文整理汇总了C#中PnPMonitoredScope.LogWarning方法的典型用法代码示例。如果您正苦于以下问题:C# PnPMonitoredScope.LogWarning方法的具体用法?C# PnPMonitoredScope.LogWarning怎么用?C# PnPMonitoredScope.LogWarning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PnPMonitoredScope
的用法示例。
在下文中一共展示了PnPMonitoredScope.LogWarning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
if (template.SitePolicy != null)
{
if (web.GetSitePolicyByName(template.SitePolicy) != null) // Site Policy Available?
{
web.ApplySitePolicy(template.SitePolicy);
scope.LogInfo(CoreResources.Provisioning_ObjectHandlers_SitePolicy_PolicyAdded, template.SitePolicy);
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_SitePolicy_PolicyNotFound, template.SitePolicy);
}
}
}
return parser;
}
示例2: LocalizeView
internal static void LocalizeView(this Microsoft.SharePoint.Client.View view, Web web, string token, TokenParser parser, PnPMonitoredScope scope)
{
if (CanUseAcceptLanguageHeaderForLocalization(web))
{
var context = web.Context;
var resourceValues = parser.GetResourceTokenResourceValues(token);
foreach (var resourceValue in resourceValues)
{
// Save property with correct locale on the request to make it stick
// http://sadomovalex.blogspot.no/2015/09/localize-web-part-titles-via-client.html
context.PendingRequest.RequestExecutor.WebRequest.Headers["Accept-Language"] = resourceValue.Item1;
view.Title = resourceValue.Item2;
view.Update();
context.ExecuteQueryRetry();
}
}
else
{
// warning
scope.LogWarning(CoreResources.Provisioning_Extensions_ViewLocalization_Skip);
}
}
示例3: ExtractObjects
//.........这里部分代码省略.........
foreach (var field in siteList.Fields.AsEnumerable().Where(field => !field.Hidden))
{
if (siteColumns.FirstOrDefault(sc => sc.Id == field.Id) != null)
{
var addField = true;
if (siteList.ContentTypesEnabled && contentTypeFields.FirstOrDefault(c => c.Id == field.Id) == null)
{
if (contentTypeFields.FirstOrDefault(c => c.Id == field.Id) == null)
{
addField = false;
}
}
var fieldElement = XElement.Parse(field.SchemaXml);
var sourceId = fieldElement.Attribute("SourceID") != null ? fieldElement.Attribute("SourceID").Value : null;
if (sourceId != null && sourceId == "http://schemas.microsoft.com/sharepoint/v3")
{
if (field.InternalName == "Editor" ||
field.InternalName == "Author" ||
field.InternalName == "Title" ||
field.InternalName == "ID" ||
field.InternalName == "Created" ||
field.InternalName == "Modified" ||
field.InternalName == "Attachments" ||
field.InternalName == "_UIVersionString" ||
field.InternalName == "DocIcon" ||
field.InternalName == "LinkTitleNoMenu" ||
field.InternalName == "LinkTitle" ||
field.InternalName == "Edit" ||
field.InternalName == "AppAuthor" ||
field.InternalName == "AppEditor" ||
field.InternalName == "ContentType" ||
field.InternalName == "ItemChildCount" ||
field.InternalName == "FolderChildCount" ||
field.InternalName == "LinkFilenameNoMenu" ||
field.InternalName == "LinkFilename" ||
field.InternalName == "_CopySource" ||
field.InternalName == "ParentVersionString" ||
field.InternalName == "ParentLeafName" ||
field.InternalName == "_CheckinComment" ||
field.InternalName == "FileLeafRef" ||
field.InternalName == "FileSizeDisplay" ||
field.InternalName == "Preview" ||
field.InternalName == "ThumbnailOnForm")
{
addField = false;
}
}
if (addField)
{
list.FieldRefs.Add(new FieldRef(field.InternalName)
{
Id = field.Id,
DisplayName = field.Title,
Required = field.Required,
Hidden = field.Hidden,
});
}
}
else
{
list.Fields.Add((new Model.Field { SchemaXml = field.SchemaXml }));
}
list.Security = siteList.GetSecurity();
}
var logCTWarning = false;
if (baseTemplateList != null)
{
if (!baseTemplateList.Equals(list))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Adding_list___0_____1_, list.Title, list.Url);
template.Lists.Add(list);
if (list.ContentTypesEnabled && list.ContentTypeBindings.Any() && web.IsSubSite())
{
logCTWarning = true;
}
}
}
else
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Adding_list___0_____1_, list.Title, list.Url);
template.Lists.Add(list);
if (list.ContentTypesEnabled && list.ContentTypeBindings.Any() && web.IsSubSite())
{
logCTWarning = true;
}
}
if (logCTWarning)
{
scope.LogWarning("You are extracting a template from a subweb. List '{0}' refers to content types. Content types are not exported when extracting a template from a subweb", list.Title);
WriteWarning(string.Format("You are extracting a template from a subweb. List '{0}' refers to content types. Content types are not exported when extracting a template from a subweb", list.Title), ProvisioningMessageType.Warning);
}
}
}
return template;
}
示例4: CreateList
private Tuple<List, TokenParser> CreateList(Web web, ListInstance list, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite = false)
{
List createdList;
if (list.Url.Equals("SiteAssets") && list.TemplateType == (int)ListTemplateType.DocumentLibrary)
{
//Ensure that the Site Assets library is created using the out of the box creation mechanism
//Site Assets that are created using the EnsureSiteAssetsLibrary method slightly differ from
//default Document Libraries. See issue 512 (https://github.com/OfficeDev/PnP-Sites-Core/issues/512)
//for details about the issue fixed by this approach.
createdList = web.Lists.EnsureSiteAssetsLibrary();
//Check that Title and Description have the correct values
web.Context.Load(createdList, l => l.Title,
l => l.Description);
web.Context.ExecuteQueryRetry();
var isDirty = false;
if (!string.Equals(createdList.Description, list.Description))
{
createdList.Description = list.Description;
isDirty = true;
}
if (!string.Equals(createdList.Title, list.Title))
{
createdList.Title = list.Title;
isDirty = true;
}
if (isDirty)
{
createdList.Update();
web.Context.ExecuteQueryRetry();
}
}
else
{
var listCreate = new ListCreationInformation();
listCreate.Description = list.Description;
listCreate.TemplateType = list.TemplateType;
listCreate.Title = parser.ParseString(list.Title);
// the line of code below doesn't add the list to QuickLaunch
// the OnQuickLaunch property is re-set on the Created List object
listCreate.QuickLaunchOption = list.OnQuickLaunch ? QuickLaunchOptions.On : QuickLaunchOptions.Off;
listCreate.Url = parser.ParseString(list.Url);
listCreate.TemplateFeatureId = list.TemplateFeatureID;
createdList = web.Lists.Add(listCreate);
createdList.Update();
}
web.Context.Load(createdList, l => l.BaseTemplate);
web.Context.ExecuteQueryRetry();
#if !SP2013
if (list.Title.ContainsResourceToken())
{
createdList.TitleResource.SetUserResourceValue(list.Title, parser);
}
if (list.Description.ContainsResourceToken())
{
createdList.DescriptionResource.SetUserResourceValue(list.Description, parser);
}
#endif
if (!String.IsNullOrEmpty(list.DocumentTemplate))
{
createdList.DocumentTemplateUrl = parser.ParseString(list.DocumentTemplate);
}
// EnableAttachments are not supported for DocumentLibraries, Survey and PictureLibraries
// TODO: the user should be warned
if (createdList.BaseTemplate != (int)ListTemplateType.DocumentLibrary &&
createdList.BaseTemplate != (int)ListTemplateType.Survey &&
createdList.BaseTemplate != (int)ListTemplateType.PictureLibrary)
{
createdList.EnableAttachments = list.EnableAttachments;
}
createdList.EnableModeration = list.EnableModeration;
createdList.ForceCheckout = list.ForceCheckout;
// Done for all other lists than for Survey - With Surveys versioning configuration will cause an exception
if (createdList.BaseTemplate != (int)ListTemplateType.Survey)
{
createdList.EnableVersioning = list.EnableVersioning;
if (list.EnableVersioning)
{
#if !SP2013
createdList.MajorVersionLimit = list.MaxVersionLimit;
#endif
// DraftVisibilityType.Approver is available only when the EnableModeration option of the list is true
if (DraftVisibilityType.Approver ==
(DraftVisibilityType)list.DraftVersionVisibility)
{
if (list.EnableModeration)
{
createdList.DraftVersionVisibility =
(DraftVisibilityType)list.DraftVersionVisibility;
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ListInstances_DraftVersionVisibility_not_applied_because_EnableModeration_is_not_set_to_true);
//.........这里部分代码省略.........
示例5: ExtractObjects
//.........这里部分代码省略.........
// Retrieve all not hidden lists and the Workflow History Lists, just in case there are active workflow subscriptions
foreach (var siteList in lists.AsEnumerable().Where(l => (l.Hidden == false || ((workflowSubscriptions != null && workflowSubscriptions.Length > 0) && l.BaseTemplate == 140))))
{
ListInstance baseTemplateList = null;
if (creationInfo.BaseTemplate != null)
{
// Check if we need to skip this list...if so let's do it before we gather all the other information for this list...improves performance
var index = creationInfo.BaseTemplate.Lists.FindIndex(f => f.Url.Equals(siteList.RootFolder.ServerRelativeUrl.Substring(serverRelativeUrl.Length + 1)) &&
f.TemplateType.Equals(siteList.BaseTemplate));
if (index != -1)
{
baseTemplateList = creationInfo.BaseTemplate.Lists[index];
}
}
var contentTypeFields = new List<FieldRef>();
var list = new ListInstance
{
Description = siteList.Description,
EnableVersioning = siteList.EnableVersioning,
TemplateType = siteList.BaseTemplate,
Title = siteList.Title,
Hidden = siteList.Hidden,
EnableFolderCreation = siteList.EnableFolderCreation,
DocumentTemplate = Tokenize(siteList.DocumentTemplateUrl, web.Url),
ContentTypesEnabled = siteList.ContentTypesEnabled,
Url = siteList.RootFolder.ServerRelativeUrl.Substring(serverRelativeUrl.Length).TrimStart('/'),
TemplateFeatureID = siteList.TemplateFeatureId,
EnableAttachments = siteList.EnableAttachments,
OnQuickLaunch = siteList.OnQuickLaunch,
EnableModeration = siteList.EnableModeration,
MaxVersionLimit =
siteList.IsPropertyAvailable("MajorVersionLimit") ? siteList.MajorVersionLimit : 0,
EnableMinorVersions = siteList.EnableMinorVersions,
MinorVersionLimit =
siteList.IsPropertyAvailable("MajorWithMinorVersionsLimit")
? siteList.MajorWithMinorVersionsLimit
: 0,
ForceCheckout = siteList.IsPropertyAvailable("ForceCheckout") ?
siteList.ForceCheckout : false,
DraftVersionVisibility = siteList.IsPropertyAvailable("DraftVersionVisibility") ? (int)siteList.DraftVersionVisibility : 0,
};
if (creationInfo.PersistMultiLanguageResources)
{
#if !SP2013
if (UserResourceExtensions.PersistResourceValue(siteList.TitleResource, string.Format("List_{0}_Title", siteList.Title.Replace(" ", "_")), template, creationInfo))
{
list.Title = string.Format("{{res:List_{0}_Title}}", siteList.Title.Replace(" ", "_"));
}
if (UserResourceExtensions.PersistResourceValue(siteList.DescriptionResource, string.Format("List_{0}_Description", siteList.Title.Replace(" ", "_")), template, creationInfo))
{
list.Description = string.Format("{{res:List_{0}_Description}}", siteList.Title.Replace(" ", "_"));
}
#endif
}
list = ExtractContentTypes(web, siteList, contentTypeFields, list);
list = ExtractViews(siteList, list);
list = ExtractFields(web, siteList, contentTypeFields, list, allLists, creationInfo, template);
list = ExtractUserCustomActions(web, siteList, list, creationInfo, template);
list.Security = siteList.GetSecurity();
var logCTWarning = false;
if (baseTemplateList != null)
{
if (!baseTemplateList.Equals(list))
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Adding_list___0_____1_, list.Title, list.Url);
template.Lists.Add(list);
if (list.ContentTypesEnabled && list.ContentTypeBindings.Any() && web.IsSubSite())
{
logCTWarning = true;
}
}
}
else
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstances_Adding_list___0_____1_, list.Title, list.Url);
template.Lists.Add(list);
if (list.ContentTypesEnabled && list.ContentTypeBindings.Any() && web.IsSubSite())
{
logCTWarning = true;
}
}
if (logCTWarning)
{
scope.LogWarning("You are extracting a template from a subweb. List '{0}' refers to content types. Content types are not exported when extracting a template from a subweb", siteList.Title);
WriteWarning(string.Format("You are extracting a template from a subweb. List '{0}' refers to content types. Content types are not exported when extracting a template from a subweb", siteList.Title), ProvisioningMessageType.Warning);
}
}
}
return template;
}
示例6: UpdateField
private Field UpdateField(ClientObject web, ListInfo listInfo, Guid fieldId, XElement templateFieldElement, Field existingField, PnPMonitoredScope scope, TokenParser parser, string originalFieldXml)
{
Field field = null;
web.Context.Load(existingField, f => f.SchemaXmlWithResourceTokens);
web.Context.ExecuteQueryRetry();
var existingFieldElement = XElement.Parse(existingField.SchemaXmlWithResourceTokens);
var equalityComparer = new XNodeEqualityComparer();
// Is field different in template?
if (equalityComparer.GetHashCode(existingFieldElement) != equalityComparer.GetHashCode(templateFieldElement))
{
// Is existing field of the same type?
if (existingFieldElement.Attribute("Type").Value == templateFieldElement.Attribute("Type").Value)
{
templateFieldElement = PrepareField(templateFieldElement);
if (IsFieldXmlValid(parser.ParseString(templateFieldElement.ToString()), parser, web.Context))
{
foreach (var attribute in templateFieldElement.Attributes())
{
if (existingFieldElement.Attribute(attribute.Name) != null)
{
existingFieldElement.Attribute(attribute.Name).Value = attribute.Value;
}
else
{
existingFieldElement.Add(attribute);
}
}
foreach (var element in templateFieldElement.Elements())
{
if (existingFieldElement.Element(element.Name) != null)
{
existingFieldElement.Element(element.Name).Remove();
}
existingFieldElement.Add(element);
}
if (existingFieldElement.Attribute("Version") != null)
{
existingFieldElement.Attributes("Version").Remove();
}
existingField.SchemaXml = parser.ParseString(existingFieldElement.ToString(), "~sitecollection", "~site");
existingField.UpdateAndPushChanges(true);
web.Context.ExecuteQueryRetry();
bool isDirty = false;
#if !SP2013
if (originalFieldXml.ContainsResourceToken())
{
var originalFieldElement = XElement.Parse(originalFieldXml);
var nameAttributeValue = originalFieldElement.Attribute("DisplayName") != null ? originalFieldElement.Attribute("DisplayName").Value : "";
if (nameAttributeValue.ContainsResourceToken())
{
if (existingField.TitleResource.SetUserResourceValue(nameAttributeValue, parser))
{
isDirty = true;
}
}
var descriptionAttributeValue = originalFieldElement.Attribute("Description") != null ? originalFieldElement.Attribute("Description").Value : "";
if (descriptionAttributeValue.ContainsResourceToken())
{
if (existingField.DescriptionResource.SetUserResourceValue(descriptionAttributeValue, parser))
{
isDirty = true;
}
}
}
#endif
if (isDirty)
{
existingField.Update();
web.Context.ExecuteQueryRetry();
field = existingField;
}
}
else
{
// The field Xml was found invalid
var tokenString = parser.GetLeftOverTokens(originalFieldXml).Aggregate(String.Empty, (acc, i) => acc + " " + i);
scope.LogError("The field was found invalid: {0}", tokenString);
throw new Exception(string.Format("The field was found invalid: {0}", tokenString));
}
}
else
{
var fieldName = existingFieldElement.Attribute("Name") != null ? existingFieldElement.Attribute("Name").Value : existingFieldElement.Attribute("StaticName").Value;
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ListInstances_Field__0____1___exists_in_list__2____3___but_is_of_different_type__Skipping_field_, fieldName, fieldId, listInfo.TemplateList.Title, listInfo.SiteList.Id);
WriteWarning(string.Format(CoreResources.Provisioning_ObjectHandlers_ListInstances_Field__0____1___exists_in_list__2____3___but_is_of_different_type__Skipping_field_, fieldName, fieldId, listInfo.TemplateList.Title, listInfo.SiteList.Id), ProvisioningMessageType.Warning);
}
}
return field;
}
示例7: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
if (template.Workflows == null)
{
template.Workflows = new Workflows();
}
using (var scope = new PnPMonitoredScope(this.Name))
{
if (creationInfo.FileConnector == null)
{
scope.LogWarning("Cannot export Workflow definitions without a FileConnector.");
}
else
{
// Pre-load useful properties
web.EnsureProperty(w => w.Id);
// Retrieve all the lists and libraries
var lists = web.Lists;
web.Context.Load(lists);
web.Context.ExecuteQuery();
// Retrieve the workflow definitions (including unpublished ones)
Microsoft.SharePoint.Client.WorkflowServices.WorkflowDefinition[] definitions = null;
try
{
definitions = web.GetWorkflowDefinitions(false);
}
catch (ServerException)
{
// If there is no workflow service present in the farm this method will throw an error.
// Swallow the exception
}
if (definitions != null)
{
template.Workflows.WorkflowDefinitions.AddRange(
from d in definitions
select new Model.WorkflowDefinition(d.Properties.TokenizeWorkflowDefinitionProperties(lists))
{
AssociationUrl = d.AssociationUrl,
Description = d.Description,
DisplayName = d.DisplayName,
DraftVersion = d.DraftVersion,
FormField = d.FormField,
Id = d.Id,
InitiationUrl = d.InitiationUrl,
Published = d.Published,
RequiresAssociationForm = d.RequiresAssociationForm,
RequiresInitiationForm = d.RequiresInitiationForm,
RestrictToScope = (!String.IsNullOrEmpty(d.RestrictToScope) && Guid.Parse(d.RestrictToScope) != web.Id) ? WorkflowExtension.TokenizeListIdProperty(d.RestrictToScope, lists) : null,
RestrictToType = !String.IsNullOrEmpty(d.RestrictToType) ? d.RestrictToType : "Universal",
XamlPath = d.Xaml.SaveXamlToFile(d.Id, creationInfo.FileConnector),
}
);
}
// Retrieve the workflow subscriptions
Microsoft.SharePoint.Client.WorkflowServices.WorkflowSubscription[] subscriptions = null;
try
{
subscriptions = web.GetWorkflowSubscriptions();
}
catch (ServerException)
{
// If there is no workflow service present in the farm this method will throw an error.
// Swallow the exception
}
if (subscriptions != null)
{
#if CLIENTSDKV15
template.Workflows.WorkflowSubscriptions.AddRange(
from s in subscriptions
select new Model.WorkflowSubscription(s.PropertyDefinitions.TokenizeWorkflowSubscriptionProperties(lists))
{
DefinitionId = s.DefinitionId,
Enabled = s.Enabled,
EventSourceId = s.EventSourceId != web.Id ? String.Format("{{listid:{0}}}", lists.First(l => l.Id == s.EventSourceId).Title) : null,
EventTypes = s.EventTypes.ToList(),
ManualStartBypassesActivationLimit = s.ManualStartBypassesActivationLimit,
Name = s.Name,
ListId = s.EventSourceId != web.Id ? String.Format("{{listid:{0}}}", lists.First(l => l.Id == s.EventSourceId).Title) : null,
StatusFieldName = s.StatusFieldName,
}
);
#else
template.Workflows.WorkflowSubscriptions.AddRange(
from s in subscriptions
select new Model.WorkflowSubscription(s.PropertyDefinitions.TokenizeWorkflowSubscriptionProperties(lists))
{
DefinitionId = s.DefinitionId,
Enabled = s.Enabled,
EventSourceId = s.EventSourceId != web.Id ? WorkflowExtension.TokenizeListIdProperty(s.EventSourceId.ToString(), lists) : null,
EventTypes = s.EventTypes.ToList(),
ManualStartBypassesActivationLimit = s.ManualStartBypassesActivationLimit,
Name = s.Name,
//.........这里部分代码省略.........
示例8: CreateList
private Tuple<List, TokenParser> CreateList(Web web, ListInstance list, TokenParser parser, PnPMonitoredScope scope)
{
var listCreate = new ListCreationInformation();
listCreate.Description = list.Description;
listCreate.TemplateType = list.TemplateType;
listCreate.Title = parser.ParseString(list.Title);
// the line of code below doesn't add the list to QuickLaunch
// the OnQuickLaunch property is re-set on the Created List object
listCreate.QuickLaunchOption = list.OnQuickLaunch ? QuickLaunchOptions.On : QuickLaunchOptions.Off;
listCreate.Url = parser.ParseString(list.Url);
listCreate.TemplateFeatureId = list.TemplateFeatureID;
var createdList = web.Lists.Add(listCreate);
createdList.Update();
web.Context.Load(createdList, l => l.BaseTemplate);
web.Context.ExecuteQueryRetry();
if (!String.IsNullOrEmpty(list.DocumentTemplate))
{
createdList.DocumentTemplateUrl = parser.ParseString(list.DocumentTemplate);
}
// EnableAttachments are not supported for DocumentLibraries and Surveys
// TODO: the user should be warned
if (createdList.BaseTemplate != (int)ListTemplateType.DocumentLibrary && createdList.BaseTemplate != (int)ListTemplateType.Survey)
{
createdList.EnableAttachments = list.EnableAttachments;
}
createdList.EnableModeration = list.EnableModeration;
// Done for all other lists than for Survey - With Surveys versioning configuration will cause an exception
if (createdList.BaseTemplate != (int)ListTemplateType.Survey)
{
createdList.EnableVersioning = list.EnableVersioning;
if (list.EnableVersioning)
{
#if !CLIENTSDKV15
createdList.MajorVersionLimit = list.MaxVersionLimit;
#endif
if (createdList.BaseTemplate == (int)ListTemplateType.DocumentLibrary)
{
// Only supported on Document Libraries
createdList.EnableMinorVersions = list.EnableMinorVersions;
createdList.DraftVersionVisibility = (DraftVisibilityType)list.DraftVersionVisibility;
if (list.EnableMinorVersions)
{
createdList.MajorWithMinorVersionsLimit = list.MinorVersionLimit; // Set only if enabled, otherwise you'll get exception due setting value to zero.
// DraftVisibilityType.Approver is available only when the EnableModeration option of the list is true
if (DraftVisibilityType.Approver ==
(DraftVisibilityType)list.DraftVersionVisibility)
{
if (list.EnableModeration)
{
createdList.DraftVersionVisibility =
(DraftVisibilityType)list.DraftVersionVisibility;
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ListInstances_DraftVersionVisibility_not_applied_because_EnableModeration_is_not_set_to_true);
WriteWarning(CoreResources.Provisioning_ObjectHandlers_ListInstances_DraftVersionVisibility_not_applied_because_EnableModeration_is_not_set_to_true, ProvisioningMessageType.Warning);
}
}
else
{
createdList.DraftVersionVisibility = (DraftVisibilityType)list.DraftVersionVisibility;
}
}
}
}
}
createdList.OnQuickLaunch = list.OnQuickLaunch;
if (createdList.BaseTemplate != (int)ListTemplateType.DiscussionBoard)
{
createdList.EnableFolderCreation = list.EnableFolderCreation;
}
createdList.Hidden = list.Hidden;
createdList.ContentTypesEnabled = list.ContentTypesEnabled;
createdList.Update();
web.Context.Load(createdList.Views);
web.Context.Load(createdList, l => l.Id);
web.Context.Load(createdList, l => l.RootFolder.ServerRelativeUrl);
web.Context.Load(createdList.ContentTypes);
web.Context.ExecuteQueryRetry();
// Remove existing content types only if there are custom content type bindings
var contentTypesToRemove = new List<ContentType>();
if (list.RemoveExistingContentTypes && list.ContentTypeBindings.Count > 0)
{
contentTypesToRemove.AddRange(createdList.ContentTypes);
}
//.........这里部分代码省略.........
示例9: 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;
}
示例10: 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;
}
示例11: UpdateContentType
private static void UpdateContentType(Web web, Microsoft.SharePoint.Client.ContentType existingContentType, ContentType templateContentType, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite = false)
{
var isDirty = false;
if (existingContentType.Hidden != templateContentType.Hidden)
{
scope.LogPropertyUpdate("Hidden");
existingContentType.Hidden = templateContentType.Hidden;
isDirty = true;
}
if (existingContentType.ReadOnly != templateContentType.ReadOnly)
{
scope.LogPropertyUpdate("ReadOnly");
existingContentType.ReadOnly = templateContentType.ReadOnly;
isDirty = true;
}
if (existingContentType.Sealed != templateContentType.Sealed)
{
scope.LogPropertyUpdate("Sealed");
existingContentType.Sealed = templateContentType.Sealed;
isDirty = true;
}
if (templateContentType.Description != null && existingContentType.Description != parser.ParseString(templateContentType.Description))
{
scope.LogPropertyUpdate("Description");
existingContentType.Description = parser.ParseString(templateContentType.Description);
isDirty = true;
}
if (templateContentType.DocumentTemplate != null && existingContentType.DocumentTemplate != parser.ParseString(templateContentType.DocumentTemplate))
{
scope.LogPropertyUpdate("DocumentTemplate");
existingContentType.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
isDirty = true;
}
if (existingContentType.Name != parser.ParseString(templateContentType.Name))
{
scope.LogPropertyUpdate("Name");
existingContentType.Name = parser.ParseString(templateContentType.Name);
isDirty = true;
// CT is being renamed, add an extra token to the tokenparser
parser.AddToken(new ContentTypeIdToken(web, existingContentType.Name, existingContentType.StringId));
}
if (templateContentType.Group != null && existingContentType.Group != parser.ParseString(templateContentType.Group))
{
scope.LogPropertyUpdate("Group");
existingContentType.Group = parser.ParseString(templateContentType.Group);
isDirty = true;
}
if (!isNoScriptSite)
{
if (templateContentType.DisplayFormUrl != null && existingContentType.DisplayFormUrl != parser.ParseString(templateContentType.DisplayFormUrl))
{
scope.LogPropertyUpdate("DisplayFormUrl");
existingContentType.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
isDirty = true;
}
if (templateContentType.EditFormUrl != null && existingContentType.EditFormUrl != parser.ParseString(templateContentType.EditFormUrl))
{
scope.LogPropertyUpdate("EditFormUrl");
existingContentType.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
isDirty = true;
}
if (templateContentType.NewFormUrl != null && existingContentType.NewFormUrl != parser.ParseString(templateContentType.NewFormUrl))
{
scope.LogPropertyUpdate("NewFormUrl");
existingContentType.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
isDirty = true;
}
}
else
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
// log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, existingContentType.Name);
}
}
#if !SP2013
if (templateContentType.Name.ContainsResourceToken())
{
existingContentType.NameResource.SetUserResourceValue(templateContentType.Name, parser);
isDirty = true;
}
if (templateContentType.Description.ContainsResourceToken())
{
existingContentType.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
isDirty = true;
}
#endif
if (isDirty)
{
existingContentType.Update(true);
web.Context.ExecuteQueryRetry();
}
// Delta handling
existingContentType.EnsureProperty(c => c.FieldLinks);
List<Guid> targetIds = existingContentType.FieldLinks.AsEnumerable().Select(c1 => c1.Id).ToList();
List<Guid> sourceIds = templateContentType.FieldRefs.Select(c1 => c1.Id).ToList();
//.........这里部分代码省略.........
示例12: CreateContentType
private static Microsoft.SharePoint.Client.ContentType CreateContentType(Web web, ContentType templateContentType, TokenParser parser, FileConnectorBase connector, PnPMonitoredScope scope,
List<Microsoft.SharePoint.Client.ContentType> existingCTs = null, List<Microsoft.SharePoint.Client.Field> existingFields = null, bool isNoScriptSite = false)
{
var name = parser.ParseString(templateContentType.Name);
var description = parser.ParseString(templateContentType.Description);
var id = parser.ParseString(templateContentType.Id);
var group = parser.ParseString(templateContentType.Group);
var createdCT = web.CreateContentType(name, description, id, group);
foreach (var fieldRef in templateContentType.FieldRefs)
{
Microsoft.SharePoint.Client.Field field = null;
try
{
// Try to get the field by ID
field = web.Fields.GetById(fieldRef.Id);
}
catch (ArgumentException)
{
// In case of failure, if we have the name
if (!String.IsNullOrEmpty(fieldRef.Name))
{
// Let's try with that one
field = web.Fields.GetByInternalNameOrTitle(fieldRef.Name);
}
}
// Add it to the target content type
// Notice that this code will fail if the field does not exist
web.AddFieldToContentType(createdCT, field, fieldRef.Required, fieldRef.Hidden);
}
// Add new CTs
parser.AddToken(new ContentTypeIdToken(web, name, id));
#if !ONPREMISES
// Set resources
if (templateContentType.Name.ContainsResourceToken())
{
createdCT.NameResource.SetUserResourceValue(templateContentType.Name, parser);
}
if (templateContentType.Description.ContainsResourceToken())
{
createdCT.DescriptionResource.SetUserResourceValue(templateContentType.Description, parser);
}
#endif
//Reorder the elements so that the new created Content Type has the same order as defined in the
//template. The order can be different if the new Content Type inherits from another Content Type.
//In this case the new Content Type has all field of the original Content Type and missing fields
//will be added at the end. To fix this issue we ordering the fields once more.
createdCT.FieldLinks.Reorder(templateContentType.FieldRefs.Select(fld => parser.ParseString(fld.Name)).ToArray());
createdCT.ReadOnly = templateContentType.ReadOnly;
createdCT.Hidden = templateContentType.Hidden;
createdCT.Sealed = templateContentType.Sealed;
if (templateContentType.DocumentSetTemplate == null)
{
// Only apply a document template when the contenttype is not a document set
if (!string.IsNullOrEmpty(parser.ParseString(templateContentType.DocumentTemplate)))
{
createdCT.DocumentTemplate = parser.ParseString(templateContentType.DocumentTemplate);
}
}
// Skipping updates of forms as we can't upload forms to noscript sites
if (!isNoScriptSite)
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
createdCT.NewFormUrl = parser.ParseString(templateContentType.NewFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)))
{
createdCT.EditFormUrl = parser.ParseString(templateContentType.EditFormUrl);
}
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)))
{
createdCT.DisplayFormUrl = parser.ParseString(templateContentType.DisplayFormUrl);
}
}
else
{
if (!String.IsNullOrEmpty(parser.ParseString(templateContentType.DisplayFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.EditFormUrl)) ||
!String.IsNullOrEmpty(parser.ParseString(templateContentType.NewFormUrl)))
{
// log message
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_ContentTypes_SkipCustomFormUrls, name);
}
}
createdCT.Update(true);
web.Context.ExecuteQueryRetry();
// If the CT is a DocumentSet
if (templateContentType.DocumentSetTemplate != null)
{
// Retrieve a reference to the DocumentSet Content Type
//.........这里部分代码省略.........
示例13: ProvisionObjects
//.........这里部分代码省略.........
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)
{
WebPartEntity wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = parser.ParseString(webpart.Contents.Trim(new[] { '\n', ' ' }));
web.AddWebPartToWikiPage(url, wpEntity, (int)webpart.Row, (int)webpart.Column, false);
}
}
var allWebParts = web.GetWebParts(url);
foreach (var webpart in allWebParts)
{
parser.AddToken(new WebPartIdToken(web, webpart.WebPart.Title, webpart.Id));
}
}
else
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Pages_SkipAddingWebParts, page.Url);
}
}
file = web.GetFileByServerRelativeUrl(url);
file.EnsureProperty(f => f.ListItemAllFields);
if (page.Fields.Any())
{
var item = file.ListItemAllFields;
foreach (var fieldValue in page.Fields)
{
item[fieldValue.Key] = parser.ParseString(fieldValue.Value);
}
item.Update();
web.Context.ExecuteQueryRetry();
}
if (page.Security != null && page.Security.RoleAssignments.Count != 0)
{
web.Context.Load(file.ListItemAllFields);
web.Context.ExecuteQueryRetry();
file.ListItemAllFields.SetSecurity(parser, page.Security);
}
}
}
return parser;
}
示例14: ProvisionCustomActionImplementation
private void ProvisionCustomActionImplementation(object parent, CustomActionCollection customActions, TokenParser parser, PnPMonitoredScope scope, bool isNoScriptSite= false)
{
Web web = null;
Site site = null;
if (parent is Site)
{
site = parent as Site;
// Switch parser context;
parser.Rebase(site.RootWeb);
}
else
{
web = parent as Web;
// Switch parser context
parser.Rebase(web);
}
foreach (var customAction in customActions)
{
if (isNoScriptSite)
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_CustomActions_SkippingAddUpdateDueToNoScript, customAction.Name);
continue;
}
var caExists = false;
if (site != null)
{
caExists = site.CustomActionExists(customAction.Name);
}
else
{
caExists = web.CustomActionExists(customAction.Name);
}
// If the CustomAction does not exist, we don't have to remove it, and it is enabled
if (!caExists && !customAction.Remove && customAction.Enabled)
{
// Then we add it to the target
var customActionEntity = new CustomActionEntity()
{
CommandUIExtension = customAction.CommandUIExtension != null ? parser.ParseString(customAction.CommandUIExtension.ToString()) : string.Empty,
Description = parser.ParseString(customAction.Description),
Group = customAction.Group,
ImageUrl = parser.ParseString(customAction.ImageUrl),
Location = customAction.Location,
Name = customAction.Name,
RegistrationId = customAction.RegistrationId,
RegistrationType = customAction.RegistrationType,
Remove = customAction.Remove,
Rights = customAction.Rights,
ScriptBlock = parser.ParseString(customAction.ScriptBlock),
ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"),
Sequence = customAction.Sequence,
Title = parser.ParseString(customAction.Title),
Url = parser.ParseString(customAction.Url)
};
if (site != null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Site, customActionEntity.Name);
site.AddCustomAction(customActionEntity);
#if !ONPREMISES
if ((!string.IsNullOrEmpty(customAction.Title) && customAction.Title.ContainsResourceToken()) ||
(!string.IsNullOrEmpty(customAction.Description) && customAction.Description.ContainsResourceToken()))
{
var uca = site.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
SetCustomActionResourceValues(parser, customAction, uca);
}
#endif
}
else
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_custom_action___0___to_scope_Web, customActionEntity.Name);
web.AddCustomAction(customActionEntity);
#if !ONPREMISES
if (customAction.Title.ContainsResourceToken() || customAction.Description.ContainsResourceToken())
{
var uca = web.GetCustomActions().Where(uc => uc.Name == customAction.Name).FirstOrDefault();
SetCustomActionResourceValues(parser, customAction, uca);
}
#endif
}
}
else
{
UserCustomAction existingCustomAction = null;
if (site != null)
{
existingCustomAction = site.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
}
else
{
existingCustomAction = web.GetCustomActions().FirstOrDefault(c => c.Name == customAction.Name);
}
if (existingCustomAction != null)
{
// If we have to remove the existing CustomAction
//.........这里部分代码省略.........
示例15: UpdateCustomAction
internal static void UpdateCustomAction(TokenParser parser, PnPMonitoredScope scope, CustomAction customAction, UserCustomAction existingCustomAction, bool isNoScriptSite = false)
{
var isDirty = false;
if (isNoScriptSite)
{
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_CustomActions_SkippingAddUpdateDueToNoScript, customAction.Name);
return;
}
// Otherwise we update it
if (customAction.CommandUIExtension != null)
{
if (existingCustomAction.CommandUIExtension != parser.ParseString(customAction.CommandUIExtension.ToString()))
{
scope.LogPropertyUpdate("CommandUIExtension");
existingCustomAction.CommandUIExtension = parser.ParseString(customAction.CommandUIExtension.ToString());
isDirty = true;
}
}
else
{
// Required to allow for a delta action to blank out the CommandUIExtension attribute
if (existingCustomAction.CommandUIExtension != null)
{
scope.LogPropertyUpdate("CommandUIExtension");
existingCustomAction.CommandUIExtension = null;
isDirty = true;
}
}
if (existingCustomAction.Description != customAction.Description)
{
scope.LogPropertyUpdate("Description");
existingCustomAction.Description = customAction.Description;
isDirty = true;
}
#if !ONPREMISES
if (customAction.Description.ContainsResourceToken())
{
if (existingCustomAction.DescriptionResource.SetUserResourceValue(customAction.Description, parser))
{
isDirty = true;
}
}
#endif
if (existingCustomAction.Group != customAction.Group)
{
scope.LogPropertyUpdate("Group");
existingCustomAction.Group = customAction.Group;
isDirty = true;
}
if (existingCustomAction.ImageUrl != parser.ParseString(customAction.ImageUrl))
{
scope.LogPropertyUpdate("ImageUrl");
existingCustomAction.ImageUrl = parser.ParseString(customAction.ImageUrl);
isDirty = true;
}
if (existingCustomAction.Location != customAction.Location)
{
scope.LogPropertyUpdate("Location");
existingCustomAction.Location = customAction.Location;
isDirty = true;
}
if (existingCustomAction.RegistrationId != customAction.RegistrationId)
{
scope.LogPropertyUpdate("RegistrationId");
existingCustomAction.RegistrationId = customAction.RegistrationId;
isDirty = true;
}
if (existingCustomAction.RegistrationType != customAction.RegistrationType)
{
scope.LogPropertyUpdate("RegistrationType");
existingCustomAction.RegistrationType = customAction.RegistrationType;
isDirty = true;
}
if (existingCustomAction.ScriptBlock != parser.ParseString(customAction.ScriptBlock))
{
scope.LogPropertyUpdate("ScriptBlock");
existingCustomAction.ScriptBlock = parser.ParseString(customAction.ScriptBlock);
isDirty = true;
}
if (existingCustomAction.ScriptSrc != parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection"))
{
scope.LogPropertyUpdate("ScriptSrc");
existingCustomAction.ScriptSrc = parser.ParseString(customAction.ScriptSrc, "~site", "~sitecollection");
isDirty = true;
}
if (existingCustomAction.Sequence != customAction.Sequence)
{
scope.LogPropertyUpdate("Sequence");
existingCustomAction.Sequence = customAction.Sequence;
isDirty = true;
}
if (existingCustomAction.Title != parser.ParseString(customAction.Title))
{
scope.LogPropertyUpdate("Title");
existingCustomAction.Title = parser.ParseString(customAction.Title);
isDirty = true;
}
//.........这里部分代码省略.........