本文整理汇总了C#中OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.ProvisioningTemplateApplyingInformation类的典型用法代码示例。如果您正苦于以下问题:C# ProvisioningTemplateApplyingInformation类的具体用法?C# ProvisioningTemplateApplyingInformation怎么用?C# ProvisioningTemplateApplyingInformation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProvisioningTemplateApplyingInformation类属于OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers命名空间,在下文中一共展示了ProvisioningTemplateApplyingInformation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_Fields);
// 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())
{
return;
}
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(field.SchemaXml.ToParsedString("~sitecollection", "~site"));
var fieldId = templateFieldElement.Attribute("ID").Value;
if (!existingFieldIds.Contains(Guid.Parse(fieldId)))
{
CreateField(web, templateFieldElement);
}
else
{
UpdateField(web, fieldId, templateFieldElement);
}
}
}
示例4: ExecuteCmdlet
protected override void ExecuteCmdlet()
{
if (!SelectedWeb.IsPropertyAvailable("Url"))
{
ClientContext.Load(SelectedWeb, w => w.Url);
ClientContext.ExecuteQueryRetry();
}
if (!System.IO.Path.IsPathRooted(Path))
{
Path = System.IO.Path.Combine(SessionState.Path.CurrentFileSystemLocation.Path, Path);
}
FileInfo fileInfo = new FileInfo(Path);
XMLTemplateProvider provider =
new XMLFileSystemTemplateProvider(fileInfo.DirectoryName, "");
var provisioningTemplate = provider.GetTemplate(fileInfo.Name);
if (provisioningTemplate != null)
{
var fileSystemConnector = new FileSystemConnector(fileInfo.DirectoryName, "");
provisioningTemplate.Connector = fileSystemConnector;
var applyingInformation = new ProvisioningTemplateApplyingInformation();
applyingInformation.ProgressDelegate = (message, step, total) =>
{
WriteProgress(new ProgressRecord(0, string.Format("Applying template to {0}", SelectedWeb.Url), message) { PercentComplete = (100 / total) * step });
};
SelectedWeb.ApplyProvisioningTemplate(provisioningTemplate, applyingInformation);
}
}
示例5: 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;
}
示例6: 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;
}
}
示例7: 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;
}
示例8: 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))
{
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);
var composedLookJson = JsonConvert.SerializeObject(template.ComposedLook);
web.SetPropertyBagValue("_PnP_ProvisioningTemplateComposedLookInfo", composedLookJson);
}
// Persist composed look info in property bag
}
}
return parser;
}
示例9: Provision
public void Provision(ClientContext ctx, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation, TokenParser tokenParser, PnPMonitoredScope scope, string configurationData)
{
bool _urlCheck = ctx.Url.Equals(ExtensibilityTestConstants.MOCK_URL, StringComparison.OrdinalIgnoreCase);
if (!_urlCheck) throw new Exception("CTXURLNOTTHESAME");
bool _templateCheck = template.Id.Equals(ExtensibilityTestConstants.PROVISIONINGTEMPLATE_ID, StringComparison.OrdinalIgnoreCase);
if (!_templateCheck) throw new Exception("TEMPLATEIDNOTTHESAME");
bool _configDataCheck = configurationData.Equals(ExtensibilityTestConstants.PROVIDER_MOCK_DATA, StringComparison.OrdinalIgnoreCase);
if (!_configDataCheck) throw new Exception("CONFIGDATANOTTHESAME");
}
示例10: ProvisionObjects
public override void ProvisionObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateApplyingInformation applyingInformation)
{
Log.Info(Constants.LOGGING_SOURCE_FRAMEWORK_PROVISIONING, CoreResources.Provisioning_ObjectHandlers_SitePolicy);
if (template.SitePolicy != null)
{
if (web.GetSitePolicyByName(template.SitePolicy) != null) // Site Policy Available?
{
web.ApplySitePolicy(template.SitePolicy);
}
}
}
示例11: 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;
if (!String.IsNullOrEmpty(template.SearchSettings))
{
site.SetSearchConfiguration(template.SearchSettings);
}
}
return parser;
}
示例12: 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;
}
示例13: ProvisionObjects
public override TokenParser ProvisionObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateApplyingInformation applyingInformation)
{
using (var scope = new PnPMonitoredScope(CoreResources.Provisioning_ObjectHandlers_SitePolicy))
{
if (template.SitePolicy != null)
{
if (web.GetSitePolicyByName(template.SitePolicy) != null) // Site Policy Available?
{
web.ApplySitePolicy(template.SitePolicy);
}
}
}
return parser;
}
示例14: ApplyCustomTemplateToSite
public void ApplyCustomTemplateToSite()
{
var provisioningTemplate = _siteTemplate.PnpTemplate;
var applyingInfo = new ProvisioningTemplateApplyingInformation
{
ProgressDelegate =
(message, step, total) =>
{
Updatehelper.UpdateProgressView($"{step}/{total} Provisioning {message}", _actionRequest);
}
};
_ctx.Web.ApplyProvisioningTemplate(provisioningTemplate, applyingInfo);
}
示例15: 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;
}