本文整理汇总了C#中PnPMonitoredScope类的典型用法代码示例。如果您正苦于以下问题:C# PnPMonitoredScope类的具体用法?C# PnPMonitoredScope怎么用?C# PnPMonitoredScope使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PnPMonitoredScope类属于命名空间,在下文中一共展示了PnPMonitoredScope类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var site = (web.Context as ClientContext).Site;
try
{
var siteSearchSettings = site.GetSearchConfiguration();
if (!String.IsNullOrEmpty(siteSearchSettings))
{
template.SiteSearchSettings = siteSearchSettings;
}
var webSearchSettings = web.GetSearchConfiguration();
if (!String.IsNullOrEmpty(webSearchSettings))
{
template.WebSearchSettings = webSearchSettings;
}
}
catch (ServerException)
{
// The search service is not necessarily configured
// Swallow the exception
}
}
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: LocalizeParts
private static void LocalizeParts(Web web, TokenParser parser, string url, WebPartCollection webParts, PnPMonitoredScope scope)
{
if (CanUseAcceptLanguageHeaderForLocalization(web))
{
var context = web.Context;
var allParts = web.GetWebParts(parser.ParseString(url)).ToList();
foreach (var webPart in webParts)
{
#if !SP2016
var partOnPage = allParts.FirstOrDefault(w => w.ZoneId == webPart.Zone && w.WebPart.ZoneIndex == webPart.Order);
#else
var partOnPage = allParts.FirstOrDefault(w => w.WebPart.ZoneIndex == webPart.Order);
#endif
if (webPart.Title.ContainsResourceToken() && partOnPage != null)
{
var resourceValues = parser.GetResourceTokenResourceValues(webPart.Title);
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;
partOnPage.WebPart.Properties["Title"] = resourceValue.Item2;
partOnPage.SaveWebPartChanges();
context.ExecuteQueryRetry();
}
}
}
context.PendingRequest.RequestExecutor.WebRequest.Headers.Remove("Accept-Language");
}
else
{
// warning
scope.LogWarning(CoreResources.Provisioning_Extensions_WebPartLocalization_Skip);
}
}
示例4: PersistFile
internal void PersistFile(Web web, ProvisioningTemplateCreationInformation creationInfo, PnPMonitoredScope scope, string folderPath, string fileName, Boolean decodeFileName = false)
{
if (creationInfo.FileConnector != null)
{
SharePointConnector connector = new SharePointConnector(web.Context, web.Url, "dummy");
Uri u = new Uri(web.Url);
if (folderPath.IndexOf(u.PathAndQuery, StringComparison.InvariantCultureIgnoreCase) > -1)
{
folderPath = folderPath.Replace(u.PathAndQuery, "");
}
using (Stream s = connector.GetFileStream(fileName, folderPath))
{
if (s != null)
{
creationInfo.FileConnector.SaveFileStream(decodeFileName ? HttpUtility.UrlDecode(fileName) : fileName, s);
}
}
}
else
{
WriteWarning("No connector present to persist homepage.", ProvisioningMessageType.Error);
scope.LogError("No connector present to persist homepage");
}
}
示例5: 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;
}
示例6: 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;
}
示例7: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, 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.CalendarType = (CalendarType)web.RegionalSettings.CalendarType;
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;
// We're not comparing regional settings with the value stored in the base template as base templates are always for the US locale (1033)
}
return template;
}
示例8: 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;
}
示例9: 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;
}
}
示例10: 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;
}
示例11: 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;
}
示例12: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, TokenParser parser, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
var lists = this.GetListsWithPages(template);
template.Pages = new PageCollection(template);
var homePageUrl = web.GetHomePageRelativeUrl();
foreach (var list in lists)
{
try
{
List splist = web.Lists.GetById(list.ID);
web.Context.Load(splist);
web.Context.ExecuteQueryRetry();
if (!creationInfo.ExecutePreProvisionEvent<ListInstance, List>(Handlers.Pages, template, list, null))
{
continue;
}
var listItems = GetListPages(web, splist);
var fileItems = listItems.AsEnumerable().Where(x => x.IsFile());
foreach (ListItem item in fileItems)
{
try
{
IPageModelProvider provider = GetProvider(item, homePageUrl, web, parser);
if (null != provider)
{
provider.AddPage(item, template);
}
}
catch (Exception ex)
{
var message = string.Format("Error in export page for list: {0}", list.ServerRelativeUrl);
scope.LogError(ex, message);
}
}
creationInfo.ExecutePostProvisionEvent<ListInstance, List>(Handlers.Pages, template, list, splist);
}
catch (Exception exception)
{
var message = string.Format("Error in export publishing page for list: {0}", list.ServerRelativeUrl);
scope.LogError(exception, message);
}
}
// Impossible to return all files in the site currently
// 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;
}
示例13: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// Set default values for Template ID and Version
template.Id = String.Format("TEMPLATE-{0:N}", Guid.NewGuid()).ToUpper();
template.Version = 1;
template.BaseSiteTemplate = web.GetBaseTemplateId();
// Retrieve original Template ID and remove it from Property Bag Entries
int provisioningTemplateIdIndex = template.PropertyBagEntries.FindIndex(f => f.Key.Equals("_PnP_ProvisioningTemplateId"));
if (provisioningTemplateIdIndex > -1)
{
var templateId = template.PropertyBagEntries[provisioningTemplateIdIndex].Value;
if (!String.IsNullOrEmpty(templateId))
{
template.Id = templateId;
}
template.PropertyBagEntries.RemoveAt(provisioningTemplateIdIndex);
}
// Retrieve original Template Info and remove it from Property Bag Entries
int provisioningTemplateInfoIndex = template.PropertyBagEntries.FindIndex(f => f.Key.Equals("_PnP_ProvisioningTemplateInfo"));
if (provisioningTemplateInfoIndex > -1)
{
var jsonInfo = template.PropertyBagEntries[provisioningTemplateInfoIndex].Value;
if (jsonInfo != null)
{
ProvisioningTemplateInfo info = JsonConvert.DeserializeObject<ProvisioningTemplateInfo>(jsonInfo);
// Override any previously defined Template ID, Version, and SitePolicy
// with the one stored in the Template Info, if any
if (info != null)
{
if (!String.IsNullOrEmpty(info.TemplateId))
{
template.Id = info.TemplateId;
}
if (!String.IsNullOrEmpty(info.TemplateSitePolicy))
{
template.SitePolicy = info.TemplateSitePolicy;
}
if (info.TemplateVersion > 0)
{
template.Version = info.TemplateVersion;
}
}
}
template.PropertyBagEntries.RemoveAt(provisioningTemplateInfoIndex);
}
}
return template;
}
示例14: 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");
}
示例15: ExtractObjects
public override ProvisioningTemplate ExtractObjects(Web web, ProvisioningTemplate template, ProvisioningTemplateCreationInformation creationInfo)
{
using (var scope = new PnPMonitoredScope(this.Name))
{
// 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;
}