本文整理汇总了C#中SPMeta2.Definitions.WebPartDefinition.WithAssertAndCast方法的典型用法代码示例。如果您正苦于以下问题:C# WebPartDefinition.WithAssertAndCast方法的具体用法?C# WebPartDefinition.WithAssertAndCast怎么用?C# WebPartDefinition.WithAssertAndCast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SPMeta2.Definitions.WebPartDefinition
的用法示例。
在下文中一共展示了WebPartDefinition.WithAssertAndCast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<PageViewerWebPart>("webpartInstance", value => value.RequireNotNull());
var definition = webpartModel.WithAssertAndCast<PageViewerWebPartDefinition>("webpartModel", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(definition.ContentLink))
{
var contentLinkValue = definition.ContentLink ?? string.Empty;
TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original contentLinkValue: [{0}]", contentLinkValue);
contentLinkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
{
Value = contentLinkValue,
Context = CurrentHost.HostFile.Web
}).Value;
TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced contentLinkValue: [{0}]", contentLinkValue);
typedWebpart.ContentLink = contentLinkValue;
}
if (!string.IsNullOrEmpty(definition.SourceType))
{
typedWebpart.SourceType = (PathPattern)Enum.Parse(typeof(PathPattern), definition.SourceType);
}
}
示例2: OnBeforeDeployModel
protected override void OnBeforeDeployModel(WebpartPageModelHost host, WebPartDefinition webpartModel)
{
_host = host;
var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());
typedModel.WebpartType = typeof(ClientWebPart).AssemblyQualifiedName;
}
示例3: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());
// TODO
typedWebpart.SolutionId = typedModel.SolutionId;
typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
typedWebpart.TypeFullName = typedModel.TypeFullName;
foreach (var prop in typedModel.UserCodeProperties)
{
var currentProperty = typedWebpart.Properties
.OfType<SPUserCodeProperty>()
.FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());
if (currentProperty == null)
{
currentProperty = new SPUserCodeProperty();
currentProperty.Name = prop.Name;
typedWebpart.Properties.Add(currentProperty);
}
currentProperty.Value = prop.Value;
}
}
示例4: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<SilverlightWebPart>("webpartInstance", value => value.RequireNotNull());
var typedDefinition = webpartModel.WithAssertAndCast<SilverlightWebPartDefinition>("webpartModel", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(typedDefinition.Url))
{
var linkValue = typedDefinition.Url;
TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Original Url: [{0}]", linkValue);
linkValue = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
{
Value = linkValue,
Context = CurrentHost.HostFile.Web
}).Value;
TraceService.VerboseFormat((int)LogEventId.ModelProvisionCoreCall, "Token replaced Url: [{0}]", linkValue);
typedWebpart.Url = linkValue;
}
if (!string.IsNullOrEmpty(typedDefinition.CustomInitParameters))
{
typedWebpart.CustomInitParameters = typedDefinition.CustomInitParameters;
}
}
示例5: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ContactFieldControl>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<ContactFieldControlDefinition>("webpartModel", value => value.RequireNotNull());
}
示例6: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<UserDocsWebPart>("webpartInstance", value => value.RequireNotNull());
var definition = webpartModel.WithAssertAndCast<UserDocsWebPartDefinition>("webpartModel", value => value.RequireNotNull());
// TODO, specific provision
}
示例7: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ScriptEditorWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<ScriptEditorWebPartDefinition>("webpartModel", value => value.RequireNotNull());
typedWebpart.Content = typedModel.Content ?? string.Empty;
}
示例8: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());
typedWebpart.FeatureId = typedModel.FeatureId;
typedWebpart.ProductId = typedModel.ProductId;
typedWebpart.WebPartName = typedModel.WebPartName;
typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
}
示例9: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
{
base.ProcessWebpartProperties(webpartInstance, definition);
var typedWebpart = webpartInstance.WithAssertAndCast<RefinementScriptWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = definition.WithAssertAndCast<RefinementScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(typedModel.SelectedRefinementControlsJson))
typedWebpart.SelectedRefinementControlsJson = typedModel.SelectedRefinementControlsJson;
if (!string.IsNullOrEmpty(typedModel.EmptyMessage))
typedWebpart.EmptyMessage = typedModel.EmptyMessage;
}
示例10: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<SiteFeedWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<SiteFeedWebPartDefinition>("webpartModel", value => value.RequireNotNull());
//typedWebpart.ContentLink = typedModel.ContentLink ?? string.Empty;
//var xmlDoc = new XmlDocument();
//var xmlElement = xmlDoc.CreateElement("ContentElement");
//xmlElement.InnerText = typedModel.Content ?? string.Empty;
//typedWebpart.Content = xmlElement;
}
示例11: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<SPUserCodeWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<UserCodeWebPartDefinition>("webpartModel", value => value.RequireNotNull());
// TODO
typedWebpart.SolutionId = typedModel.SolutionId;
typedWebpart.AssemblyFullName = typedModel.AssemblyFullName;
typedWebpart.TypeFullName = typedModel.TypeFullName;
foreach (var prop in typedModel.UserCodeProperties)
{
var currentProperty = typedWebpart.Properties
.OfType<SPUserCodeProperty>()
.FirstOrDefault(p => p.Name.ToUpper() == prop.Name.ToUpper());
if (currentProperty == null)
{
currentProperty = new SPUserCodeProperty
{
Name = prop.Name
};
typedWebpart.Properties.Add(currentProperty);
}
if (prop.IsTokenisable.HasValue && prop.IsTokenisable.Value)
{
// Enhance 'UserCodeWebPartDefinition'
// UserCodeProperty should support ~sitecollection/~site tokens #485
var value = TokenReplacementService.ReplaceTokens(new TokenReplacementContext
{
Value = prop.Value,
Context = CurrentHost.HostFile.Web
}).Value;
currentProperty.Value = value;
}
else
{
currentProperty.Value = prop.Value;
}
}
}
示例12: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition definition)
{
base.ProcessWebpartProperties(webpartInstance, definition);
var typedWebpart = webpartInstance.WithAssertAndCast<ContentBySearchWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = definition.WithAssertAndCast<ContentBySearchWebPartDefinition>("webpartModel", value => value.RequireNotNull());
// templates
if (!string.IsNullOrEmpty(typedModel.GroupTemplateId))
typedWebpart.GroupTemplateId = typedModel.GroupTemplateId;
if (!string.IsNullOrEmpty(typedModel.ItemTemplateId))
typedWebpart.ItemTemplateId = typedModel.ItemTemplateId;
if (!string.IsNullOrEmpty(typedModel.RenderTemplateId))
typedWebpart.RenderTemplateId = typedModel.RenderTemplateId;
if (!string.IsNullOrEmpty(typedModel.DataProviderJSON))
typedWebpart.DataProviderJSON = typedModel.DataProviderJSON;
if (!string.IsNullOrEmpty(typedModel.PropertyMappings))
typedWebpart.PropertyMappings = typedModel.PropertyMappings;
if (typedModel.OverwriteResultPath.HasValue)
typedWebpart.OverwriteResultPath = typedModel.OverwriteResultPath.Value;
if (typedModel.ShouldHideControlWhenEmpty.HasValue)
typedWebpart.ShouldHideControlWhenEmpty = typedModel.ShouldHideControlWhenEmpty.Value;
if (typedModel.LogAnalyticsViewEvent.HasValue)
typedWebpart.LogAnalyticsViewEvent = typedModel.LogAnalyticsViewEvent.Value;
if (typedModel.AddSEOPropertiesFromSearch.HasValue)
typedWebpart.AddSEOPropertiesFromSearch = typedModel.AddSEOPropertiesFromSearch.Value;
if (typedModel.StartingItemIndex.HasValue)
typedWebpart.StartingItemIndex = typedModel.StartingItemIndex.Value;
// misc
if (typedModel.NumberOfItems.HasValue)
typedWebpart.NumberOfItems = typedModel.NumberOfItems.Value;
if (typedModel.ResultsPerPage.HasValue)
typedWebpart.ResultsPerPage = typedModel.ResultsPerPage.Value;
}
示例13: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ResultScriptWebPart>("webpartInstance", value => value.RequireNotNull());
var definition = webpartModel.WithAssertAndCast<ResultScriptWebPartDefinition>("webpartModel", value => value.RequireNotNull());
if (!string.IsNullOrEmpty(definition.DataProviderJSON))
typedWebpart.DataProviderJSON = definition.DataProviderJSON;
if (!string.IsNullOrEmpty(definition.EmptyMessage))
typedWebpart.EmptyMessage = definition.EmptyMessage;
if (definition.ResultsPerPage.HasValue)
typedWebpart.ResultsPerPage = definition.ResultsPerPage.Value;
if (definition.ShowResultCount.HasValue)
typedWebpart.ShowResultCount = definition.ShowResultCount.Value;
}
示例14: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ClientWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<ClientWebPartDefinition>("webpartModel", value => value.RequireNotNull());
// Enhance 'ClientWebPart' provision - ProductWebId should be current web by default #623
// https://github.com/SubPointSolutions/spmeta2/issues/623
var productId = typedModel.ProductId;
if (!productId.HasGuidValue())
productId = _host.SPLimitedWebPartManager.Web.ID;
typedWebpart.FeatureId = typedModel.FeatureId;
typedWebpart.ProductId = productId.Value;
typedWebpart.WebPartName = typedModel.WebPartName;
typedWebpart.ProductWebId = _host.SPLimitedWebPartManager.Web.ID;
}
示例15: ProcessWebpartProperties
protected override void ProcessWebpartProperties(WebPart webpartInstance, WebPartDefinition webpartModel)
{
base.ProcessWebpartProperties(webpartInstance, webpartModel);
var typedWebpart = webpartInstance.WithAssertAndCast<ListViewWebPart>("webpartInstance", value => value.RequireNotNull());
var typedModel = webpartModel.WithAssertAndCast<ListViewWebPartDefinition>("webpartModel", value => value.RequireNotNull());
var web = _host.SPLimitedWebPartManager.Web;
SPList list = null;
if (typedModel.ListId.HasGuidValue())
list = web.Lists[typedModel.ListId.Value];
else if (!string.IsNullOrEmpty(typedModel.ListUrl))
list = web.GetList(SPUrlUtility.CombineUrl(web.ServerRelativeUrl, typedModel.ListUrl));
else if (!string.IsNullOrEmpty(typedModel.ListTitle))
list = web.Lists.TryGetList(typedModel.ListTitle);
typedWebpart.ListName = list.ID.ToString();
typedWebpart.ListId = list.ID;
// view check
if (list != null)
{
SPView view = null;
if (typedModel.ViewId.HasGuidValue())
view = list.Views[typedModel.ViewId.Value];
else if (!string.IsNullOrEmpty(typedModel.ViewName))
view = list.Views[typedModel.ViewName];
if (view != null)
{
typedWebpart.ViewGuid = view.ID.ToString("B").ToUpperInvariant();
typedWebpart.TitleUrl = view.ServerRelativeUrl;
}
}
// able to 'reset', if NULL or use list-view based URLs
if (!string.IsNullOrEmpty(typedModel.TitleUrl))
typedWebpart.TitleUrl = typedModel.TitleUrl;
}