本文整理汇总了C#中OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser.GetLeftOverTokens方法的典型用法代码示例。如果您正苦于以下问题:C# TokenParser.GetLeftOverTokens方法的具体用法?C# TokenParser.GetLeftOverTokens怎么用?C# TokenParser.GetLeftOverTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OfficeDevPnP.Core.Framework.Provisioning.ObjectHandlers.TokenParser
的用法示例。
在下文中一共展示了TokenParser.GetLeftOverTokens方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsFieldXmlValid
/// <summary>
/// Check if all tokens where replaced. If the field is a taxonomy field then we will check for the values of the referenced termstore and termset.
/// </summary>
/// <param name="fieldXml">The xml to parse</param>
/// <param name="parser"></param>
/// <param name="context"></param>
/// <returns></returns>
protected static bool IsFieldXmlValid(string fieldXml, TokenParser parser, ClientRuntimeContext context)
{
var isValid = true;
var leftOverTokens = parser.GetLeftOverTokens(fieldXml);
if (!leftOverTokens.Any())
{
var fieldElement = XElement.Parse(fieldXml);
if (fieldElement.Attribute("Type").Value == "TaxonomyFieldType")
{
var termStoreIdElement = fieldElement.XPathSelectElement("//ArrayOfProperty/Property[Name='SspId']/Value");
if (termStoreIdElement != null)
{
var termStoreId = Guid.Parse(termStoreIdElement.Value);
TaxonomySession taxSession = TaxonomySession.GetTaxonomySession(context);
try
{
taxSession.EnsureProperty(t => t.TermStores);
var store = taxSession.TermStores.GetById(termStoreId);
context.Load(store);
context.ExecuteQueryRetry();
if (store.ServerObjectIsNull.HasValue && !store.ServerObjectIsNull.Value)
{
var termSetIdElement = fieldElement.XPathSelectElement("//ArrayOfProperty/Property[Name='TermSetId']/Value");
if (termSetIdElement != null)
{
var termSetId = Guid.Parse(termSetIdElement.Value);
try
{
var termSet = store.GetTermSet(termSetId);
context.Load(termSet);
context.ExecuteQueryRetry();
isValid = termSet.ServerObjectIsNull.HasValue && !termSet.ServerObjectIsNull.Value;
}
catch (Exception)
{
isValid = false;
}
}
}
}
catch (Exception)
{
isValid = false;
}
}
else
{
isValid = false;
}
}
}
else
{
//Some tokens where not replaced
isValid = false;
}
return isValid;
}
示例2: CreateField
private static Field CreateField(XElement fieldElement, ListInfo listInfo, TokenParser parser, string originalFieldXml, ClientRuntimeContext context, PnPMonitoredScope scope)
{
Field field = null;
fieldElement = PrepareField(fieldElement);
var fieldXml = parser.ParseString(fieldElement.ToString(), "~sitecollection", "~site");
if (IsFieldXmlValid(parser.ParseString(originalFieldXml), parser, context))
{
field = listInfo.SiteList.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.AddFieldInternalNameHint);
listInfo.SiteList.Context.Load(field);
listInfo.SiteList.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 (field.TitleResource.SetUserResourceValue(nameAttributeValue, parser))
{
isDirty = true;
}
}
var descriptionAttributeValue = originalFieldElement.Attribute("Description") != null ? originalFieldElement.Attribute("Description").Value : "";
if (descriptionAttributeValue.ContainsResourceToken())
{
if (field.DescriptionResource.SetUserResourceValue(descriptionAttributeValue, parser))
{
isDirty = true;
}
}
}
#endif
if (isDirty)
{
field.Update();
listInfo.SiteList.Context.ExecuteQueryRetry();
}
}
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));
}
return field;
}
示例3: 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;
}
示例4: UpdateField
private void UpdateField(Web web, string fieldId, XElement templateFieldElement, PnPMonitoredScope scope, TokenParser parser, string originalFieldXml)
{
var existingField = web.Fields.GetById(Guid.Parse(fieldId));
web.Context.Load(existingField, f => f.SchemaXml);
web.Context.ExecuteQueryRetry();
XElement existingFieldElement = XElement.Parse(existingField.SchemaXml);
XNodeEqualityComparer equalityComparer = new XNodeEqualityComparer();
if (equalityComparer.GetHashCode(existingFieldElement) != equalityComparer.GetHashCode(templateFieldElement)) // Is field different in template?
{
if (existingFieldElement.Attribute("Type").Value == templateFieldElement.Attribute("Type").Value) // Is existing field of the same type?
{
if (IsFieldXmlValid(parser.ParseString(originalFieldXml), parser, web.Context))
{
var listIdentifier = templateFieldElement.Attribute("List") != null ? templateFieldElement.Attribute("List").Value : null;
if (listIdentifier != null)
{
// Temporary remove list attribute from list
templateFieldElement.Attribute("List").Remove();
}
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.Load(existingField, f => f.TypeAsString, f => f.DefaultValue);
web.Context.ExecuteQueryRetry();
bool isDirty = false;
#if !CLIENTSDKV15
if (originalFieldXml.ContainsResourceToken())
{
var originalFieldElement = XElement.Parse(originalFieldXml);
var nameAttributeValue = originalFieldElement.Attribute("Title") != null ? originalFieldElement.Attribute("Title").Value : "";
if (nameAttributeValue.ContainsResourceToken())
{
existingField.TitleResource.SetUserResourceValue(nameAttributeValue, parser);
isDirty = true;
}
var descriptionAttributeValue = originalFieldElement.Attribute("Description") != null ? originalFieldElement.Attribute("Description").Value : "";
if (descriptionAttributeValue.ContainsResourceToken())
{
existingField.DescriptionResource.SetUserResourceValue(descriptionAttributeValue, parser);
isDirty = true;
}
}
#endif
if (isDirty)
{
existingField.Update();
web.Context.ExecuteQuery();
}
if ((existingField.TypeAsString == "TaxonomyFieldType" || existingField.TypeAsString == "TaxonomyFieldTypeMulti") && !string.IsNullOrEmpty(existingField.DefaultValue))
{
var taxField = web.Context.CastTo<TaxonomyField>(existingField);
ValidateTaxonomyFieldDefaultValue(taxField);
}
}
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;
WriteWarning(string.Format(CoreResources.Provisioning_ObjectHandlers_Fields_Field__0____1___exists_but_is_of_different_type__Skipping_field_, fieldName, fieldId), ProvisioningMessageType.Warning);
scope.LogWarning(CoreResources.Provisioning_ObjectHandlers_Fields_Field__0____1___exists_but_is_of_different_type__Skipping_field_, fieldName, fieldId);
}
}
}
示例5: CreateField
private static void CreateField(Web web, XElement templateFieldElement, PnPMonitoredScope scope, TokenParser parser, string originalFieldXml)
{
var listIdentifier = templateFieldElement.Attribute("List") != null ? templateFieldElement.Attribute("List").Value : null;
if (listIdentifier != null)
{
// Temporary remove list attribute from list
templateFieldElement.Attribute("List").Remove();
}
var fieldXml = parser.ParseString(templateFieldElement.ToString(), "~sitecollection", "~site");
if (IsFieldXmlValid(fieldXml, parser, web.Context))
{
var field = web.Fields.AddFieldAsXml(fieldXml, false, AddFieldOptions.AddFieldInternalNameHint);
web.Context.Load(field, f => f.TypeAsString, f => f.DefaultValue);
web.Context.ExecuteQueryRetry();
bool isDirty = false;
#if !CLIENTSDKV15
if (originalFieldXml.ContainsResourceToken())
{
var originalFieldElement = XElement.Parse(originalFieldXml);
var nameAttributeValue = originalFieldElement.Attribute("Name") != null ? originalFieldElement.Attribute("Name").Value : "";
if (nameAttributeValue.ContainsResourceToken())
{
field.TitleResource.SetUserResourceValue(nameAttributeValue, parser);
isDirty = true;
}
var descriptionAttributeValue = originalFieldElement.Attribute("Description") != null ? originalFieldElement.Attribute("Description").Value : "";
if (descriptionAttributeValue.ContainsResourceToken())
{
field.DescriptionResource.SetUserResourceValue(descriptionAttributeValue, parser);
isDirty = true;
}
}
#endif
if (isDirty)
{
field.Update();
web.Context.ExecuteQuery();
}
if ((field.TypeAsString == "TaxonomyFieldType" || field.TypeAsString == "TaxonomyFieldTypeMulti") && !string.IsNullOrEmpty(field.DefaultValue))
{
var taxField = web.Context.CastTo<TaxonomyField>(field);
ValidateTaxonomyFieldDefaultValue(taxField);
}
}
else
{
// The field Xml was found invalid
var tokenString = parser.GetLeftOverTokens(fieldXml).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));
}
}