本文整理汇总了C#中Page.AddWidget方法的典型用法代码示例。如果您正苦于以下问题:C# Page.AddWidget方法的具体用法?C# Page.AddWidget怎么用?C# Page.AddWidget使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page.AddWidget方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClonePageSettings
/// <summary>
/// Clones the target page settings to source page.
/// </summary>
/// <param name="sourcePage">The source page.</param>
/// <param name="targetPage">The target page.</param>
/// <returns></returns>
public static bool ClonePageSettings(Page sourcePage, Page targetPage)
{
var pageService = ServiceLocator.Current.GetInstance<IPageService>();
var permissionCommonService = ServiceLocator.Current.GetInstance<IPermissionCommonService>();
sourcePage.Widgets.AsParallel().ForAll(widget =>
{
var pageWidget = new PageWidget();
pageWidget.InjectFrom<CloneEntityInjection>(widget);
pageWidget.Page = targetPage;
pageWidget.ParentWidgetId = widget.Id;
//copy widget settings
if (widget.Settings != null)
{
pageWidget.Settings = (PageWidgetSettings)new PageWidgetSettings().InjectFrom<CloneEntityInjection>(widget.Settings);
pageWidget.Settings.LookAndFeelSettings = new LookAndFeelSettings().InjectFrom<CloneEntityInjection>(widget.Settings.LookAndFeelSettings) as LookAndFeelSettings;
pageWidget.Settings.Widget = pageWidget;
}
//clone page widget instance
if (widget.InstanceId != null)
{
pageWidget.InstanceId = CloneWidgetInstance(widget);
}
targetPage.AddWidget(pageWidget);
});
//copy page layout
targetPage.PageLayout = (PageLayout)new PageLayout { Id = targetPage.PageLayout.Id }.InjectFrom<CloneEntityInjection>(sourcePage.PageLayout);
targetPage.PageLayout.Page = targetPage;
sourcePage.PageLayout.ColumnWidths.AsParallel().ForAll(column =>
{
var columnWidth = (PageLayoutColumnWidthValue)new PageLayoutColumnWidthValue().InjectFrom<CloneEntityInjection>(column);
columnWidth.PageLayout = targetPage.PageLayout;
targetPage.PageLayout.AddColumnWidth(columnWidth);
});
//copy page settings)
if (sourcePage.Settings != null)
{
targetPage.Settings = (PageSettings)new PageSettings().InjectFrom<CloneEntityInjection>(sourcePage.Settings);
targetPage.Settings.LookAndFeelSettings = (LookAndFeelSettings)new LookAndFeelSettings().InjectFrom<CloneEntityInjection>(sourcePage.Settings.LookAndFeelSettings);
targetPage.Settings.Page = targetPage;
}
if (pageService.Save(targetPage))
{
//copy permissions and update page styles
foreach (var item in targetPage.Widgets)
{
if (item.ParentWidgetId == null) continue;
var systemWidget = MvcApplication.Widgets.FirstOrDefault(w => w.Identifier == item.Widget.Identifier);
var sourceWidget = sourcePage.Widgets.FirstOrDefault(w => w.Id == item.ParentWidgetId);
if (sourceWidget != null)
{
if (targetPage.Settings != null && !String.IsNullOrEmpty(targetPage.Settings.CustomCSS))
{
targetPage.Settings.CustomCSS = targetPage.Settings.CustomCSS.Replace(String.Format(PageWidgetTemplate, sourceWidget.Id), String.Format(PageWidgetTemplate, item.Id));
}
permissionCommonService.CloneObjectPermisions(systemWidget.GetType(), sourceWidget.Id, item.Id);
}
}
return pageService.Save(targetPage);
}
return false;
}
示例2: ClonePageSettingsFromTemplate
public static bool ClonePageSettingsFromTemplate(Page template, Page targetPage, long? widgetId)
{
var pageService = ServiceLocator.Current.GetInstance<IPageService>();
var permissionCommonService = ServiceLocator.Current.GetInstance<IPermissionCommonService>();
template.Widgets.Where(widget => widget.Widget.IsPlaceHolder).AsParallel().ForAll(widget =>
{
var pageWidget = new PageWidget();
pageWidget.InjectFrom<CloneEntityInjection>(widget);
pageWidget.Page = targetPage;
pageWidget.ParentWidgetId = widget.Id;
//copy widget settings
if (widget.Settings != null)
{
pageWidget.Settings = (PageWidgetSettings)new PageWidgetSettings().InjectFrom<CloneEntityInjection>(widget.Settings);
pageWidget.Settings.LookAndFeelSettings = new LookAndFeelSettings().InjectFrom<CloneEntityInjection>(widget.Settings.LookAndFeelSettings) as LookAndFeelSettings;
pageWidget.Settings.Widget = pageWidget;
}
if (widgetId.HasValue)
{
var widgetService = ServiceLocator.Current.GetInstance<IWidgetService>();
pageWidget.Widget = widgetService.Find(widgetId.Value);
}
pageWidget.TemplateWidgetId = widget.Id;
targetPage.AddWidget(pageWidget);
});
targetPage.Template = template;
if (pageService.Save(targetPage))
{
//copy permissions and update page styles
foreach (var item in targetPage.Widgets)
{
if (item.ParentWidgetId == null) continue;
var systemWidget = MvcApplication.Widgets.FirstOrDefault(w => w.Identifier == item.Widget.Identifier);
var sourceWidget = template.Widgets.FirstOrDefault(w => w.Id == item.ParentWidgetId);
if (sourceWidget != null)
{
if (targetPage.Settings != null && !String.IsNullOrEmpty(targetPage.Settings.CustomCSS))
{
targetPage.Settings.CustomCSS = targetPage.Settings.CustomCSS.Replace(String.Format(PageWidgetTemplate, sourceWidget.Id), String.Format(PageWidgetTemplate, item.Id));
}
permissionCommonService.CloneObjectPermisions(systemWidget.GetType(), sourceWidget.Id, item.Id);
}
}
return pageService.Save(targetPage);
}
return false;
}
示例3: UnlinkPage
/// <summary>
/// Unlinks the page.
/// </summary>
/// <param name="page">The page.</param>
public static void UnlinkPage(Page page)
{
var pageService = ServiceLocator.Current.GetInstance<IPageService>();
var permissionCommonService = ServiceLocator.Current.GetInstance<IPermissionCommonService>();
var pageWidgetService = ServiceLocator.Current.GetInstance<IPageWidgetService>();
if (page.Template != null)
{
page.Template.Widgets.AsEnumerable().Each(widget =>
{
PageWidget pageWidget = null;
if(widget.Widget.IsPlaceHolder)
{
pageWidget =
page.Widgets.FirstOrDefault(
currentPageWidget =>
currentPageWidget.TemplateWidgetId ==
widget.Id);
pageWidget.ColumnNumber = widget.ColumnNumber;
pageWidget.OrderNumber = widget.OrderNumber;
pageWidget.TemplateWidgetId = null;
}
if (pageWidget == null)
{
pageWidget = new PageWidget();
pageWidget.InjectFrom<CloneEntityInjection>(widget);
pageWidget.Page = page;
pageWidget.ParentWidgetId = widget.Id;
//copy widget settings
if (widget.Settings != null)
{
pageWidget.Settings =
(PageWidgetSettings)
new PageWidgetSettings().InjectFrom
<CloneEntityInjection>(widget.Settings);
pageWidget.Settings.LookAndFeelSettings =
new LookAndFeelSettings().InjectFrom
<CloneEntityInjection>(
widget.Settings.
LookAndFeelSettings) as
LookAndFeelSettings;
pageWidget.Settings.Widget = pageWidget;
}
//clone page widget instance
if (widget.InstanceId != null)
{
pageWidget.InstanceId =
CloneWidgetInstance(widget);
}
//TODO: save collection
pageWidgetService.Save(pageWidget);
page.AddWidget(pageWidget);
}
});
//copy page layout
page.PageLayout =
(PageLayout)
new PageLayout().InjectFrom<CloneEntityInjection>(
page.Template.PageLayout);
page.PageLayout.Page = page;
page.Template.PageLayout.ColumnWidths.AsParallel().ForAll(column =>
{
var columnWidth =
(PageLayoutColumnWidthValue)
new PageLayoutColumnWidthValue().
InjectFrom<CloneEntityInjection>(
column);
columnWidth.PageLayout =
page.PageLayout;
page.PageLayout.AddColumnWidth(
columnWidth);
});
//copy page settings)
if (page.Template.Settings != null)
{
page.Settings =
(PageSettings)new PageSettings().InjectFrom<CloneEntityInjection>(page.Template.Settings);
page.Settings.LookAndFeelSettings =
(LookAndFeelSettings)
new LookAndFeelSettings().InjectFrom<CloneEntityInjection>(
page.Template.Settings.LookAndFeelSettings);
page.Settings.Page = page;
}
if (pageService.Save(page))
{
//copy permissions and update page styles
foreach (var item in page.Widgets)
{
if (item.ParentWidgetId == null) continue;
var systemWidget =
MvcApplication.Widgets.FirstOrDefault(w => w.Identifier == item.Widget.Identifier);
var sourceWidget = page.Template.Widgets.FirstOrDefault(w => w.Id == item.ParentWidgetId);
if (sourceWidget != null)
//.........这里部分代码省略.........