本文整理汇总了C#中OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser类的典型用法代码示例。如果您正苦于以下问题:C# TokenParser类的具体用法?C# TokenParser怎么用?C# TokenParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TokenParser类属于OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers命名空间,在下文中一共展示了TokenParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
web.Context.Load(web.RegionalSettings);
web.Context.Load(web.RegionalSettings.TimeZone, tz => tz.Id);
web.Context.ExecuteQueryRetry();
Model.RegionalSettings settings = new Model.RegionalSettings();
settings.AdjustHijriDays = web.RegionalSettings.AdjustHijriDays;
settings.AlternateCalendarType = (CalendarType)web.RegionalSettings.AlternateCalendarType;
settings.Collation = web.RegionalSettings.Collation;
settings.FirstDayOfWeek = (DayOfWeek)web.RegionalSettings.FirstDayOfWeek;
settings.FirstWeekOfYear = web.RegionalSettings.FirstWeekOfYear;
settings.LocaleId = (int)web.RegionalSettings.LocaleId;
settings.ShowWeeks = web.RegionalSettings.ShowWeeks;
settings.Time24 = web.RegionalSettings.Time24;
settings.TimeZone = web.RegionalSettings.TimeZone.Id;
settings.WorkDayEndHour = (WorkHour)web.RegionalSettings.WorkDayEndHour;
settings.WorkDays = web.RegionalSettings.WorkDays;
settings.WorkDayStartHour = (WorkHour)web.RegionalSettings.WorkDayStartHour;
template.RegionalSettings = settings;
// 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;
}
示例2: 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;
}
示例3: Validate
public bool Validate(ContentTypeCollection sourceCollection, ContentTypeCollection targetCollection, TokenParser tokenParser)
{
// Convert object collections to XML
List<SerializedContentType> sourceContentTypes = new List<SerializedContentType>();
List<SerializedContentType> targetContentTypes = new List<SerializedContentType>();
foreach (ContentType ct in sourceCollection)
{
ProvisioningTemplate pt = new ProvisioningTemplate();
pt.ContentTypes.Add(ct);
sourceContentTypes.Add(new SerializedContentType() { SchemaXml = ExtractElementXml(pt) });
}
foreach (ContentType ct in targetCollection)
{
ProvisioningTemplate pt = new ProvisioningTemplate();
pt.ContentTypes.Add(ct);
targetContentTypes.Add(new SerializedContentType() { SchemaXml = ExtractElementXml(pt) });
}
// Use XML validation logic to compare source and target
Dictionary<string, string[]> parserSettings = new Dictionary<string, string[]>();
parserSettings.Add("SchemaXml", null);
bool isContentTypeMatch = ValidateObjectsXML(sourceContentTypes, targetContentTypes, "SchemaXml", new List<string> { "ID" }, tokenParser, parserSettings);
Console.WriteLine("-- Content type validation " + isContentTypeMatch);
return isContentTypeMatch;
}
示例4: CanProvisionObjects
public void CanProvisionObjects()
{
var template = new ProvisioningTemplate();
FileSystemConnector connector = new FileSystemConnector(resourceFolder, "");
template.Connector = connector;
template.Files.Add(new Core.Framework.Provisioning.Model.File() { Overwrite = true, Src = fileName, Folder = folder });
using (var ctx = TestCommon.CreateClientContext())
{
var parser = new TokenParser(ctx.Web, template);
new ObjectFiles().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
ctx.Web.EnsureProperties(w => w.ServerRelativeUrl);
var file = ctx.Web.GetFileByServerRelativeUrl(
UrlUtility.Combine(ctx.Web.ServerRelativeUrl,
UrlUtility.Combine(folder, fileName)));
ctx.Load(file, f => f.Exists);
ctx.ExecuteQueryRetry();
Assert.IsTrue(file.Exists);
}
}
示例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;
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;
}
示例6: CanProvisionSupportedUILanguages
public void CanProvisionSupportedUILanguages()
{
using (var scope = new Core.Diagnostics.PnPMonitoredScope("CanProvisionSupportedUILanguages"))
{
using (var ctx = TestCommon.CreateClientContext())
{
// Load the base template which will be used for the comparison work
var template = new ProvisioningTemplate();
template.SupportedUILanguages.Add(new SupportedUILanguage() { LCID = 1033 }); // English
template.SupportedUILanguages.Add(new SupportedUILanguage() { LCID = 1032 }); // Greek
var parser = new TokenParser(ctx.Web, template);
new ObjectSupportedUILanguages().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
ctx.Load(ctx.Web, w => w.SupportedUILanguageIds);
ctx.ExecuteQueryRetry();
Assert.IsTrue(ctx.Web.SupportedUILanguageIds.Count() == 2);
Assert.IsTrue(ctx.Web.SupportedUILanguageIds.Any(i => i == 1033));
Assert.IsTrue(ctx.Web.SupportedUILanguageIds.Any(i => i == 1032));
}
}
}
示例7: CanProvisionAuditSettings
public void CanProvisionAuditSettings()
{
using (var scope = new Core.Diagnostics.PnPMonitoredScope("CanProvisionAuditSettings"))
{
using (var ctx = TestCommon.CreateClientContext())
{
// Load the base template which will be used for the comparison work
var template = new ProvisioningTemplate();
template.AuditSettings = new AuditSettings();
template.AuditSettings.AuditFlags = AuditMaskType.CheckIn;
template.AuditSettings.AuditLogTrimmingRetention = 5;
template.AuditSettings.TrimAuditLog = true;
var parser = new TokenParser(ctx.Web, template);
new ObjectAuditSettings().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
var site = ctx.Site;
var auditSettings = site.Audit;
ctx.Load(auditSettings, af => af.AuditFlags);
ctx.Load(site, s => s.AuditLogTrimmingRetention, s => s.TrimAuditLog);
ctx.ExecuteQueryRetry();
Assert.IsTrue(auditSettings.AuditFlags == AuditMaskType.CheckIn);
Assert.IsTrue(site.AuditLogTrimmingRetention == 5);
Assert.IsTrue(site.TrimAuditLog = true);
}
}
}
示例8: CanProvisionObjects
public void CanProvisionObjects()
{
var template = new ProvisioningTemplate();
template.SiteFields.Add(new Core.Framework.Provisioning.Model.Field() { SchemaXml = ElementSchema });
using (var ctx = TestCommon.CreateClientContext())
{
var parser = new TokenParser(ctx.Web, template);
new ObjectField().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
new ObjectLookupFields().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
var f = ctx.Web.GetFieldById<FieldLookup>(fieldId);
Assert.IsNotNull(f);
Assert.IsInstanceOfType(f, typeof(FieldLookup));
var schemaXml = f.SchemaXml;
// so listId MUST have braces
Assert.IsTrue(schemaXml.Contains("List=\""+_listIdWithBraces+"\""));
// web id should NOT have braces
Assert.IsTrue(schemaXml.Contains("WebId=\"" + ctx.Web.Id.ToString()+ "\""));
// Source ID MUST have braces
Assert.IsTrue(schemaXml.Contains("SourceID=\"" + ctx.Web.Id.ToString("B") + "\""));
}
}
示例9: CanProvisionObjects
public void CanProvisionObjects()
{
var template = new ProvisioningTemplate();
foreach (var user in admins)
{
template.Security.AdditionalMembers.Add(new User() { Name = user.LoginName });
}
using (var ctx = TestCommon.CreateClientContext())
{
var parser = new TokenParser(ctx.Web, template);
new ObjectSiteSecurity().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
var memberGroup = ctx.Web.AssociatedMemberGroup;
ctx.Load(memberGroup, g => g.Users);
ctx.ExecuteQueryRetry();
foreach (var user in admins)
{
var existingUser = memberGroup.Users.GetByLoginName(user.LoginName);
ctx.Load(existingUser);
ctx.ExecuteQueryRetry();
Assert.IsNotNull(existingUser);
}
}
}
示例10: Validate
public static bool Validate(CustomActions sourceCustomActions, CustomActions targetCustomActions, TokenParser tokenParser)
{
Console.WriteLine("Custom Action validation started...");
bool isSiteCustomActionsMatch = false;
bool isWebCustomActionsMatch = false;
if (sourceCustomActions.SiteCustomActions.Count > 0)
{
isSiteCustomActionsMatch = ValidateCustomActions(sourceCustomActions.SiteCustomActions, targetCustomActions.SiteCustomActions, tokenParser);
Console.WriteLine("Site Custom Actions validation " + isSiteCustomActionsMatch);
}
if (sourceCustomActions.WebCustomActions.Count > 0)
{
isWebCustomActionsMatch = ValidateCustomActions(sourceCustomActions.WebCustomActions, targetCustomActions.WebCustomActions, tokenParser);
Console.WriteLine("Web Custom Actions validation " + isWebCustomActionsMatch);
}
if (!isSiteCustomActionsMatch || !isWebCustomActionsMatch)
{
return false;
}
else
{
return true;
}
}
示例11: 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;
}
示例12: 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;
}
}
示例13: CanProvisionRegionalSettings
public void CanProvisionRegionalSettings()
{
using (var scope = new Core.Diagnostics.PnPMonitoredScope("CanProvisionRegionalSettings"))
{
using (var ctx = TestCommon.CreateClientContext())
{
// Load the base template which will be used for the comparison work
var template = new ProvisioningTemplate();
template.RegionalSettings = new Core.Framework.Provisioning.Model.RegionalSettings();
template.RegionalSettings.FirstDayOfWeek = System.DayOfWeek.Monday;
template.RegionalSettings.WorkDayEndHour = WorkHour.PM0700;
template.RegionalSettings.TimeZone = 5;
template.RegionalSettings.Time24 = true;
var parser = new TokenParser(ctx.Web, template);
new ObjectRegionalSettings().ProvisionObjects(ctx.Web, template, parser, new ProvisioningTemplateApplyingInformation());
ctx.Load(ctx.Web.RegionalSettings);
ctx.Load(ctx.Web.RegionalSettings.TimeZone, tz => tz.Id);
ctx.ExecuteQueryRetry();
Assert.IsTrue(ctx.Web.RegionalSettings.Time24);
Assert.IsTrue(ctx.Web.RegionalSettings.WorkDayEndHour == (short)WorkHour.PM0700);
Assert.IsTrue(ctx.Web.RegionalSettings.FirstDayOfWeek == (uint)System.DayOfWeek.Monday);
Assert.IsTrue(ctx.Web.RegionalSettings.TimeZone.Id == 5);
}
}
}
示例14: 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;
}
}
示例15: Validate
public bool Validate(ProvisioningTemplate ptSource, ProvisioningTemplate ptTarget, TokenParser sParser, TokenParser tParser)
{
bool isValid = false;
#region SiteFields
if (ptTarget.SiteFields.Count > 0)
{
isValid = ValidateSiteFields(ptSource.SiteFields, ptTarget.SiteFields, sParser, tParser);
if (!isValid) { return false; }
}
#endregion
#region ContentTypes
if (ptTarget.ContentTypes.Count > 0)
{
isValid = ValidateContentTypes(ptSource.ContentTypes, ptTarget.ContentTypes, sParser, tParser);
if (!isValid) { return false; }
}
#endregion
#region ListInstances
isValid = ValidateListInstances(ptSource.Lists, ptTarget.Lists, sParser, tParser);
if (!isValid) { return false; }
#endregion
#if !ONPREMISES
#region Custom Action
isValid = ValidateCustomActions(ptSource.CustomActions, ptTarget.CustomActions, sParser, tParser, ptTarget.SiteFields.Count > 0);
if (!isValid) { return false; }
#endregion
#endif
return isValid;
}