本文整理汇总了C#中Page.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# Page.Clone方法的具体用法?C# Page.Clone怎么用?C# Page.Clone使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page.Clone方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldCopyPages
public void ShouldCopyPages()
{
var children = new List<Page> { new Page() };
var parent = new Page { Pages = children };
var result = parent.Clone() as Page;
Assert.IsNotEmpty( result.Pages );
}
示例2: ShouldCopyPageContexts
public void ShouldCopyPageContexts()
{
var page = new Page { PageContexts = new List<PageContext>() };
page.PageContexts.Add( new PageContext() );
var result = page.Clone() as Page;
Assert.NotNull( result.PageContexts );
Assert.IsNotEmpty( result.PageContexts );
}
示例3: ShouldCopyBlocks
public void ShouldCopyBlocks()
{
var page = new Page { Blocks = new List<Block>() };
page.Blocks.Add( new Block() );
var result = page.Clone() as Page;
Assert.NotNull( result.Blocks );
Assert.IsNotEmpty( result.Blocks );
}
示例4: ShouldCopyPagesRecursively
public void ShouldCopyPagesRecursively()
{
var parent = new Page();
var child = new Page();
var grandchild = new Page();
parent.Pages = new List<Page> { child };
child.Pages = new List<Page> { grandchild };
var result = parent.Clone() as Page;
Assert.IsNotEmpty( result.Pages );
Assert.IsNotEmpty( result.Pages.FirstOrDefault().Pages );
}
示例5: ShouldCopyEntity
public void ShouldCopyEntity()
{
var page = new Page { InternalName = "SomePage" };
var result = page.Clone( false );
Assert.AreEqual( result.InternalName, page.InternalName );
}
示例6: Save
/// <summary>
/// Saves the current edit model.
/// </summary>
/// <returns>Whether the entity was updated or not</returns>
public bool Save() {
using (var db = new DataContext()) {
InternalId = (!String.IsNullOrEmpty(InternalId) ? InternalId.Replace(" ", "") : Name.Replace(" ", "")).ToUpper() ;
var site = db.SiteTrees.Where(s => s.Id == Id).SingleOrDefault() ;
if (site == null) {
// Create new dedicated namespace
var name = new Namespace() {
Id = Guid.NewGuid(),
Name = "Site namespace",
InternalId = InternalId,
Description = "Namespace for the site " + InternalId,
} ;
db.Namespaces.Add(name) ;
// Create site
site = new SiteTree() ;
site.Id = Id ;
site.NamespaceId = NamespaceId = name.Id ;
db.SiteTrees.Add(site) ;
}
// If we've changed namespace, update all related permalinks.
if (site.NamespaceId != NamespaceId)
ChangeNamespace(db, Id, NamespaceId) ;
// Update the site tree
site.NamespaceId = NamespaceId ;
site.InternalId = InternalId ;
site.Name = Name ;
site.HostNames = HostNames ;
site.Description = Description ;
// Update the site template
var template = db.PageTemplates.Include(pt => pt.RegionTemplates).Where(pt => pt.Id == Id && pt.IsSiteTemplate).SingleOrDefault() ;
if (template == null) {
template = new PageTemplate() ;
db.PageTemplates.Add(template) ;
template.Id = Id ;
template.Name = Id.ToString() ;
template.IsSiteTemplate = true ;
}
template.Preview = Template.Preview ;
template.Properties = Template.Properties ;
// Update the regions
var currentRegions = new List<Guid>() ;
foreach (var reg in Regions) {
var region = template.RegionTemplates.Where(r => r.Id == reg.Id).SingleOrDefault() ;
if (region == null) {
region = new RegionTemplate() ;
db.RegionTemplates.Add(region) ;
template.RegionTemplates.Add(region) ;
region.Id = Guid.NewGuid() ;
region.TemplateId = template.Id ;
region.Type = reg.Type ;
}
region.Name = reg.Name ;
region.InternalId = reg.InternalId ;
region.Seqno = reg.Seqno ;
region.Description = reg.Description ;
currentRegions.Add(region.Id) ;
}
// Delete removed regions
foreach (var reg in template.RegionTemplates.Where(r => !currentRegions.Contains(r.Id)).ToList()) {
db.RegionTemplates.Remove(reg) ;
}
// Check that we have a site page, if not, create it
var page = db.Pages.Where(p => p.SiteTreeId == site.Id && p.TemplateId == site.Id).SingleOrDefault() ;
if (page == null) {
// Create page
page = new Page() {
Id = Guid.NewGuid(),
SiteTreeId = site.Id,
TemplateId = site.Id,
ParentId = site.Id,
Title = site.Id.ToString(),
PermalinkId = Guid.NewGuid()
} ;
// Create published version
var published = page.Clone() ;
published.IsDraft = false ;
// Create permalink
var permalink = new Permalink() {
Id = page.PermalinkId,
NamespaceId = site.NamespaceId,
Name = site.Id.ToString(),
Type = "SITE"
} ;
//.........这里部分代码省略.........
示例7: SavePages
/// <summary>
/// Recursively saves Pages and associated Blocks, PageRoutes and PageContexts.
/// </summary>
/// <param name="page">The current Page to save</param>
/// <param name="newBlockTypes">List of BlockTypes not currently installed</param>
/// <param name="personId">Id of the Person performing the "Import" operation</param>
/// <param name="parentPageId">Id of the the current Page's parent</param>
/// <param name="siteId">Id of the site the current Page is being imported into</param>
private void SavePages( Page page, IEnumerable<BlockType> newBlockTypes, int personId, int parentPageId, int siteId )
{
// find layout
var layoutService = new LayoutService();
var layout = layoutService.GetBySiteId(siteId).Where( l => l.Name == page.Layout.Name && l.FileName == page.Layout.FileName ).FirstOrDefault();
if ( layout == null )
{
layout = new Layout();
layout.FileName = page.Layout.FileName;
layout.Name = page.Layout.Name;
layout.SiteId = siteId;
layoutService.Add( layout, null );
layoutService.Save( layout, null );
}
int layoutId = layout.Id;
// Force shallow copies on entities so save operations are more atomic and don't get hosed
// by nested object references.
var pg = page.Clone(deepCopy: false);
var blockTypes = newBlockTypes.ToList();
pg.ParentPageId = parentPageId;
pg.LayoutId = layoutId;
var pageService = new PageService();
pageService.Add( pg, personId );
pageService.Save( pg, personId );
var blockService = new BlockService();
foreach ( var block in page.Blocks ?? new List<Block>() )
{
var blockType = blockTypes.FirstOrDefault( bt => block.BlockType.Path == bt.Path );
var b = block.Clone( deepCopy: false );
b.PageId = pg.Id;
if ( blockType != null )
{
b.BlockTypeId = blockType.Id;
}
blockService.Add( b, personId );
blockService.Save( b, personId );
}
var pageRouteService = new PageRouteService();
foreach ( var pageRoute in page.PageRoutes ?? new List<PageRoute>() )
{
var pr = pageRoute.Clone(deepCopy: false);
pr.PageId = pg.Id;
pageRouteService.Add( pr, personId );
pageRouteService.Save( pr, personId );
}
var pageContextService = new PageContextService();
foreach ( var pageContext in page.PageContexts ?? new List<PageContext>() )
{
var pc = pageContext.Clone(deepCopy: false);
pc.PageId = pg.Id;
pageContextService.Add( pc, personId );
pageContextService.Save( pc, personId );
}
foreach ( var p in page.Pages ?? new List<Page>() )
{
SavePages( p, blockTypes, personId, pg.Id, siteId );
}
}
示例8: GetJson
/// <summary>
/// Gets the json for this page.
/// </summary>
/// <param name="page">The page.</param>
/// <param name="isRecursive">if set to <c>true</c> [is recursive].</param>
/// <returns></returns>
private string GetJson( Page page, bool isRecursive )
{
string json;
if ( isRecursive )
{
json = page.ToJson();
}
else
{
// make a deep copy, remove it's child pages, and ToJson that...
var pageCopy = page.Clone() as Page ?? new Page();
pageCopy.Pages = new List<Page>();
json = pageCopy.ToJson();
}
return json;
}