本文整理汇总了C#中PnPMonitoredScope.LogDebug方法的典型用法代码示例。如果您正苦于以下问题:C# PnPMonitoredScope.LogDebug方法的具体用法?C# PnPMonitoredScope.LogDebug怎么用?C# PnPMonitoredScope.LogDebug使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PnPMonitoredScope
的用法示例。
在下文中一共展示了PnPMonitoredScope.LogDebug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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 fields. Technically this can be done but it's not a recommended practice
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns);
return parser;
}
var existingFields = web.Fields;
web.Context.Load(existingFields, fs => fs.Include(f => f.Id));
web.Context.ExecuteQueryRetry();
var existingFieldIds = existingFields.AsEnumerable<SPField>().Select(l => l.Id).ToList();
var fields = template.SiteFields;
foreach (var field in fields)
{
XElement templateFieldElement = XElement.Parse(parser.ParseString(field.SchemaXml, "~sitecollection", "~site"));
var fieldId = templateFieldElement.Attribute("ID").Value;
if (!existingFieldIds.Contains(Guid.Parse(fieldId)))
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Adding_field__0__to_site, fieldId);
CreateField(web, templateFieldElement, scope, parser, field.SchemaXml);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Fields_Adding_field__0__failed___1_____2_, fieldId, ex.Message, ex.StackTrace);
throw;
}
}
else
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Updating_field__0__in_site, fieldId);
UpdateField(web, fieldId, templateFieldElement, scope, parser, field.SchemaXml);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_Fields_Updating_field__0__failed___1_____2_, fieldId, ex.Message, ex.StackTrace);
throw;
}
}
}
return parser;
}
示例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;
foreach (var handler in template.ExtensibilityHandlers
.Union(template.Providers)
.Union(applyingInformation.ExtensibilityHandlers))
{
if (handler.Enabled)
{
try
{
if (!string.IsNullOrEmpty(handler.Configuration))
{
//replace tokens in configuration data
handler.Configuration = parser.ParseString(handler.Configuration);
}
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_extensibility_callout__0_, handler.Assembly);
_extManager.ExecuteExtensibilityProvisionCallOut(context, handler, template, applyingInformation, parser, scope);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_callout_failed___0_____1_, ex.Message, ex.StackTrace);
throw;
}
}
}
}
return parser;
}
示例4: AddExtendedTokens
public TokenParser AddExtendedTokens(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
foreach (var provider in template.Providers)
{
if (provider.Enabled)
{
try
{
if (!string.IsNullOrEmpty(provider.Configuration))
{
provider.Configuration = parser.ParseString(provider.Configuration);
}
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_tokenprovider_extensibility_callout__0_, provider.Assembly);
var _providedTokens = _extManager.ExecuteTokenProviderCallOut(context, provider, template);
if (_providedTokens != null)
{
foreach (var token in _providedTokens)
{
parser.AddToken(token);
}
}
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_tokenprovider_callout_failed___0_____1_, ex.Message, ex.StackTrace);
throw;
}
}
}
return parser;
}
}
示例5: 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;
foreach (var provider in template.Providers)
{
if (provider.Enabled)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_extensibility_callout__0_, provider.Assembly);
_extManager.ExecuteExtensibilityCallOut(context, provider, template);
}
catch (Exception ex)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_callout_failed___0_____1_, ex.Message, ex.StackTrace);
}
}
}
}
return parser;
}
示例6: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_CustomActions))
{
var context = web.Context as ClientContext;
bool isSubSite = web.IsSubSite();
var webCustomActions = web.GetCustomActions();
var siteCustomActions = context.Site.GetCustomActions();
var customActions = new CustomActions();
foreach (var customAction in webCustomActions)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_web_scoped_custom_action___0___to_template, customAction.Name);
customActions.WebCustomActions.Add(CopyUserCustomAction(customAction));
}
// if this is a sub site then we're not creating entities for site collection scoped custom actions
if (!isSubSite)
{
foreach (var customAction in siteCustomActions)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_CustomActions_Adding_site_scoped_custom_action___0___to_template, customAction.Name);
customActions.SiteCustomActions.Add(CopyUserCustomAction(customAction));
}
}
template.CustomActions = customActions;
// 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, scope);
}
}
return template;
}
示例7: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_ContentTypes))
{
// if this is a sub site then we're not creating content type entities.
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ContentTypes_Context_web_is_subweb__Skipping_content_types_);
return template;
}
template.ContentTypes.AddRange(GetEntities(web, scope));
// 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, scope);
}
}
return template;
}
示例8: 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;
#region DataRows
foreach (var listInstance in template.Lists)
{
if (listInstance.DataRows != null && listInstance.DataRows.Any())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ListInstancesDataRows_Processing_data_rows_for__0_, listInstance.Title);
// Retrieve the target list
var list = web.Lists.GetByTitle(listInstance.Title);
web.Context.Load(list);
web.Context.ExecuteQueryRetry();
ListItemsProvider provider = new ListItemsProvider(list, web, template);
provider.AddListItems(listInstance.DataRows, template, parser, scope);
if (null == m_listContentProviders)
{
m_listContentProviders = new Dictionary<Guid, ListItemsProvider>();
}
m_listContentProviders[list.Id] = provider;
}
}
UpdateLookupValues(web, scope);
#endregion
}
}
return parser;
}
示例9: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var context = web.Context as ClientContext;
foreach (var handler in creationInfo.ExtensibilityHandlers)
{
if (handler.Enabled)
{
try
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_Calling_extensibility_callout__0_, handler.Assembly);
template = _extManager.ExecuteExtensibilityExtractionCallOut(context, handler, template, creationInfo, scope);
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_ExtensibilityProviders_callout_failed___0_____1_, ex.Message, ex.StackTrace);
throw;
}
}
}
}
return template;
}
示例10: 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.Url);
foreach (var file in template.Files)
{
var folderName = parser.ParseString(file.Folder);
if (folderName.ToLower().StartsWith((web.ServerRelativeUrl.ToLower())))
{
folderName = folderName.Substring(web.ServerRelativeUrl.Length);
}
var folder = web.EnsureFolderPath(folderName);
File targetFile = null;
var checkedOut = false;
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 (file.WebParts != null && file.WebParts.Any())
{
targetFile.EnsureProperties(f => f.ServerRelativeUrl);
var existingWebParts = web.GetWebParts(targetFile.ServerRelativeUrl);
foreach (var webpart in file.WebParts)
{
// check if the webpart is already set on the page
if (existingWebParts.FirstOrDefault(w => w.WebPart.Title == webpart.Title) == null)
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Files_Adding_webpart___0___to_page, webpart.Title);
var wpEntity = new WebPartEntity();
wpEntity.WebPartTitle = webpart.Title;
wpEntity.WebPartXml = parser.ParseString(webpart.Contents).Trim(new[] { '\n', ' ' });
wpEntity.WebPartZone = webpart.Zone;
wpEntity.WebPartIndex = (int)webpart.Order;
web.AddWebPartToWebPartPage(targetFile.ServerRelativeUrl, wpEntity);
}
}
}
if (checkedOut)
{
targetFile.CheckIn("", CheckinType.MajorCheckIn);
web.Context.ExecuteQueryRetry();
}
// Don't set security when nothing is defined. This otherwise breaks on files set outside of a list
if (file.Security != null &&
(file.Security.ClearSubscopes == true || file.Security.CopyRoleAssignments == true || file.Security.RoleAssignments.Count > 0))
{
targetFile.ListItemAllFields.SetSecurity(parser, file.Security);
}
}
}
}
return parser;
}
示例11: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// if this is a sub site then we're not creating field entities.
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_Fields_Context_web_is_subweb__skipping_site_columns);
return template;
}
var existingFields = web.Fields;
web.Context.Load(web, w => w.ServerRelativeUrl);
web.Context.Load(existingFields, fs => fs.Include(f => f.Id, f => f.SchemaXml, f => f.TypeAsString));
web.Context.ExecuteQueryRetry();
var taxTextFieldsToRemove = new List<Guid>();
foreach (var field in existingFields)
{
if (!BuiltInFieldId.Contains(field.Id))
{
var fieldXml = field.SchemaXml;
XElement element = XElement.Parse(fieldXml);
// Check if the field contains a reference to a list. If by Guid, rewrite the value of the attribute to use web relative paths
var listIdentifier = element.Attribute("List") != null ? element.Attribute("List").Value : null;
if (!string.IsNullOrEmpty(listIdentifier))
{
var listGuid = Guid.Empty;
if (Guid.TryParse(listIdentifier, out listGuid))
{
var list = web.Lists.GetById(listGuid);
web.Context.Load(list, l => l.RootFolder.ServerRelativeUrl);
web.Context.ExecuteQueryRetry();
var listUrl = list.RootFolder.ServerRelativeUrl.Substring(web.ServerRelativeUrl.Length).TrimStart('/');
element.Attribute("List").SetValue(listUrl);
fieldXml = element.ToString();
}
}
// Check if the field is of type TaxonomyField
if (field.TypeAsString.StartsWith("TaxonomyField"))
{
var taxField = (TaxonomyField)field;
web.Context.Load(taxField, tf => tf.TextField, tf => tf.Id);
web.Context.ExecuteQueryRetry();
taxTextFieldsToRemove.Add(taxField.TextField);
}
// Check if we have version attribute. Remove if exists
if (element.Attribute("Version") != null)
{
element.Attributes("Version").Remove();
fieldXml = element.ToString();
}
template.SiteFields.Add(new Field() { SchemaXml = fieldXml });
}
}
// Remove hidden taxonomy text fields
foreach (var textFieldId in taxTextFieldsToRemove)
{
template.SiteFields.RemoveAll(f => Guid.Parse(f.SchemaXml.ElementAttributeValue("ID")).Equals(textFieldId));
}
// 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);
}
}
return template;
}
示例12: AddUserToGroup
private static void AddUserToGroup(Web web, Group group, List<User> members, PnPMonitoredScope scope)
{
if (members.Any())
{
scope.LogDebug("Adding users to group {0}", group.Title);
try
{
foreach (var user in members)
{
scope.LogDebug("Adding user {0}", user.Name);
var existingUser = web.EnsureUser(user.Name);
group.Users.AddUser(existingUser);
}
web.Context.ExecuteQueryRetry();
}
catch (Exception ex)
{
scope.LogError(CoreResources.Provisioning_ObjectHandlers_SiteSecurity_Add_users_failed_for_group___0_____1_____2_, group.Title, ex.Message, ex.StackTrace);
throw;
}
}
}
示例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;
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);
}
// 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);
}
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);
}
return parser;
}
}
示例14: 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 security as by default security is inherited from the root site
if (web.IsSubSite())
{
scope.LogDebug(CoreResources.Provisioning_ObjectHandlers_SiteSecurity_Context_web_is_subweb__skipping_site_security_provisioning);
return parser;
}
var siteSecurity = template.Security;
var ownerGroup = web.AssociatedOwnerGroup;
var memberGroup = web.AssociatedMemberGroup;
var visitorGroup = web.AssociatedVisitorGroup;
web.Context.Load(ownerGroup, o => o.Title, o => o.Users);
web.Context.Load(memberGroup, o => o.Title, o => o.Users);
web.Context.Load(visitorGroup, o => o.Title, o => o.Users);
web.Context.ExecuteQueryRetry();
if (!ownerGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, ownerGroup, siteSecurity.AdditionalOwners, scope);
}
if (!memberGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, memberGroup, siteSecurity.AdditionalMembers, scope);
}
if (!visitorGroup.ServerObjectIsNull.Value)
{
AddUserToGroup(web, visitorGroup, siteSecurity.AdditionalVisitors, scope);
}
foreach (var siteGroup in siteSecurity.SiteGroups)
{
Group group = null;
var allGroups = web.Context.LoadQuery(web.SiteGroups.Include(gr => gr.LoginName));
web.Context.ExecuteQueryRetry();
if (!web.GroupExists(siteGroup.Title))
{
scope.LogDebug("Creating group {0}", siteGroup.Title);
group = web.AddGroup(
parser.ParseString(siteGroup.Title),
parser.ParseString(siteGroup.Description),
parser.ParseString(siteGroup.Title) == parser.ParseString(siteGroup.Owner));
group.AllowMembersEditMembership = siteGroup.AllowMembersEditMembership;
group.AllowRequestToJoinLeave = siteGroup.AllowRequestToJoinLeave;
group.AutoAcceptRequestToJoinLeave = siteGroup.AutoAcceptRequestToJoinLeave;
if (parser.ParseString(siteGroup.Title) != parser.ParseString(siteGroup.Owner))
{
Principal ownerPrincipal = allGroups.FirstOrDefault(gr => gr.LoginName == parser.ParseString(siteGroup.Owner));
if (ownerPrincipal == null)
{
ownerPrincipal = web.EnsureUser(parser.ParseString(siteGroup.Owner));
}
group.Owner = ownerPrincipal;
}
group.Update();
web.Context.ExecuteQueryRetry();
}
else
{
group = web.SiteGroups.GetByName(parser.ParseString(siteGroup.Title));
web.Context.Load(group,
g => g.Title,
g => g.Description,
g => g.AllowMembersEditMembership,
g => g.AllowRequestToJoinLeave,
g => g.AutoAcceptRequestToJoinLeave,
g => g.Owner.LoginName);
web.Context.ExecuteQueryRetry();
var isDirty = false;
if (group.Description != parser.ParseString(siteGroup.Description))
{
group.Description = parser.ParseString(siteGroup.Description);
isDirty = true;
}
if (group.AllowMembersEditMembership != siteGroup.AllowMembersEditMembership)
{
group.AllowMembersEditMembership = siteGroup.AllowMembersEditMembership;
isDirty = true;
}
if (group.AllowRequestToJoinLeave != siteGroup.AllowRequestToJoinLeave)
{
group.AllowRequestToJoinLeave = siteGroup.AllowRequestToJoinLeave;
isDirty = true;
}
if (group.AutoAcceptRequestToJoinLeave != siteGroup.AutoAcceptRequestToJoinLeave)
{
group.AutoAcceptRequestToJoinLeave = siteGroup.AutoAcceptRequestToJoinLeave;
isDirty = true;
}
if (group.Owner.LoginName != parser.ParseString(siteGroup.Owner))
//.........这里部分代码省略.........
示例15: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// if this is a sub site then we're not creating security entities as by default security is inherited from the root site
if (web.IsSubSite())
{
return template;
}
web.Context.Load(web, w => w.HasUniqueRoleAssignments, w => w.Title);
var ownerGroup = web.AssociatedOwnerGroup;
var memberGroup = web.AssociatedMemberGroup;
var visitorGroup = web.AssociatedVisitorGroup;
web.Context.ExecuteQueryRetry();
if (!ownerGroup.ServerObjectIsNull.Value)
{
web.Context.Load(ownerGroup, o => o.Id, o => o.Users, o => o.Title);
}
if (!memberGroup.ServerObjectIsNull.Value)
{
web.Context.Load(memberGroup, o => o.Id, o => o.Users, o => o.Title);
}
if (!visitorGroup.ServerObjectIsNull.Value)
{
web.Context.Load(visitorGroup, o => o.Id, o => o.Users, o => o.Title);
}
web.Context.ExecuteQueryRetry();
List<int> associatedGroupIds = new List<int>();
var owners = new List<User>();
var members = new List<User>();
var visitors = new List<User>();
if (!ownerGroup.ServerObjectIsNull.Value)
{
associatedGroupIds.Add(ownerGroup.Id);
foreach (var member in ownerGroup.Users)
{
owners.Add(new User() { Name = member.LoginName });
}
}
if (!memberGroup.ServerObjectIsNull.Value)
{
associatedGroupIds.Add(memberGroup.Id);
foreach (var member in memberGroup.Users)
{
members.Add(new User() { Name = member.LoginName });
}
}
if (!visitorGroup.ServerObjectIsNull.Value)
{
associatedGroupIds.Add(visitorGroup.Id);
foreach (var member in visitorGroup.Users)
{
visitors.Add(new User() { Name = member.LoginName });
}
}
var siteSecurity = new SiteSecurity();
siteSecurity.AdditionalOwners.AddRange(owners);
siteSecurity.AdditionalMembers.AddRange(members);
siteSecurity.AdditionalVisitors.AddRange(visitors);
var query = from user in web.SiteUsers
where user.IsSiteAdmin
select user;
var allUsers = web.Context.LoadQuery(query);
web.Context.ExecuteQueryRetry();
var admins = new List<User>();
foreach (var member in allUsers)
{
admins.Add(new User() { Name = member.LoginName });
}
siteSecurity.AdditionalAdministrators.AddRange(admins);
if (creationInfo.IncludeSiteGroups)
{
web.Context.Load(web.SiteGroups,
o => o.IncludeWithDefaultProperties(
gr => gr.Title,
gr => gr.AllowMembersEditMembership,
gr => gr.AutoAcceptRequestToJoinLeave,
gr => gr.AllowRequestToJoinLeave,
gr => gr.Description,
gr => gr.Users.Include(u => u.LoginName),
gr => gr.OnlyAllowMembersViewMembership,
gr => gr.Owner.LoginName,
gr => gr.RequestToJoinLeaveEmailSetting
));
web.Context.ExecuteQueryRetry();
foreach (var group in web.SiteGroups.AsEnumerable().Where(o => !associatedGroupIds.Contains(o.Id)))
{
scope.LogDebug("Processing group {0}", group.Title);
var siteGroup = new SiteGroup()
{
//.........这里部分代码省略.........