2016-05-27 14:26:28 +02:00
using System ;
using System.Collections.Generic ;
2017-11-21 14:19:16 +01:00
using System.Diagnostics ;
2016-05-27 14:26:28 +02:00
using System.Linq ;
using Newtonsoft.Json ;
using NPoco ;
using Umbraco.Core ;
using Umbraco.Core.Logging ;
2017-11-21 14:19:16 +01:00
using Umbraco.Core.Models.Rdbms ;
using Umbraco.Core.Persistence ;
2016-05-27 14:26:28 +02:00
using Umbraco.Core.Persistence.UnitOfWork ;
using Umbraco.Core.Serialization ;
2017-05-30 18:13:11 +02:00
using Umbraco.Web.Composing ;
2017-11-21 14:19:16 +01:00
using static Umbraco . Core . Persistence . NPocoSqlExtensions . Statics ;
2016-05-27 14:26:28 +02:00
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
2017-11-21 14:19:16 +01:00
// fixme - use SqlTemplate for these queries else it's going to be horribly slow!
2016-05-27 14:26:28 +02:00
// provides efficient database access for NuCache
2017-07-12 14:09:31 +02:00
internal class Database
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
private Sql < ISqlContext > SelectContentSources ( IScopeUnitOfWork uow )
{
return uow . SqlContext . Sql ( )
. Select < NodeDto > ( x = > Alias ( x . NodeId , "Id" ) , x = > Alias ( x . UniqueId , "Uid" ) ,
x = > Alias ( x . Level , "Level" ) , x = > Alias ( x . Path , "Path" ) , x = > Alias ( x . SortOrder , "SortOrder" ) , x = > Alias ( x . ParentId , "ParentId" ) ,
x = > Alias ( x . CreateDate , "CreateDate" ) , x = > Alias ( x . UserId , "CreatorId" ) )
. AndSelect < ContentDto > ( x = > Alias ( x . ContentTypeId , "ContentTypeId" ) )
. AndSelect < DocumentDto > ( x = > Alias ( x . Published , "Published" ) , x = > Alias ( x . Edited , "Edited" ) )
. AndSelect < ContentVersionDto > ( x = > Alias ( x . Text , "DraftName" ) , x = > Alias ( x . VersionDate , "DraftVersionDate" ) , x = > Alias ( x . UserId , "DraftWriterId" ) )
. AndSelect < DocumentVersionDto > ( x = > Alias ( x . TemplateId , "DraftTemplateId" ) )
. AndSelect < ContentVersionDto > ( "pcver" , x = > Alias ( x . Text , "PubName" ) , x = > Alias ( x . VersionDate , "PubVersionDate" ) , x = > Alias ( x . UserId , "PubWriterId" ) )
. AndSelect < DocumentVersionDto > ( "pdver" , x = > Alias ( x . TemplateId , "PubTemplateId" ) )
. AndSelect < ContentNuDto > ( "nuDraft" , x = > Alias ( x . Data , "DraftData" ) )
. AndSelect < ContentNuDto > ( "nuPub" , x = > Alias ( x . Data , "PubData" ) ) ;
}
private Sql < ISqlContext > SelectMediaSources ( IScopeUnitOfWork uow )
{
return uow . SqlContext . Sql ( )
. Select < NodeDto > ( x = > Alias ( x . NodeId , "Id" ) , x = > Alias ( x . UniqueId , "Uid" ) ,
x = > Alias ( x . Level , "Level" ) , x = > Alias ( x . Path , "Path" ) , x = > Alias ( x . SortOrder , "SortOrder" ) , x = > Alias ( x . ParentId , "ParentId" ) ,
x = > Alias ( x . CreateDate , "CreateDate" ) , x = > Alias ( x . UserId , "CreatorId" ) )
. AndSelect < ContentDto > ( x = > Alias ( x . ContentTypeId , "ContentTypeId" ) )
//.AndSelect<DocumentDto>(x => Alias(x.Published, "Published"), x => Alias(x.Edited, "Edited"))
. AndSelect < ContentVersionDto > ( x = > Alias ( x . Text , "PubName" ) , x = > Alias ( x . VersionDate , "PubVersionDate" ) , x = > Alias ( x . UserId , "PubWriterId" ) )
. AndSelect < DocumentVersionDto > ( x = > Alias ( x . TemplateId , "PubTemplateId" ) )
//.AndSelect<ContentVersionDto>("pcver", x => Alias(x.Text, "PubName"), x => Alias(x.VersionDate, "PubVersionDate"), x => Alias(x.UserId, "PubWriterId"))
//.AndSelect<DocumentVersionDto>("pdver", x => Alias(x.TemplateId, "PubTemplateId"))
. AndSelect < ContentNuDto > ( "nuDraft" , x = > Alias ( x . Data , "PubData" ) ) ;
//.AndSelect<ContentNuDto>("nuPub", x => Alias(x.Data, "PubData"));
}
2017-07-11 16:29:44 +02:00
public ContentNodeKit GetContentSource ( IScopeUnitOfWork uow , int id )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectContentSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
. LeftJoin < ContentVersionDto > ( j = >
j . InnerJoin < DocumentVersionDto > ( "pdver" ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id & & right . Published , "pcver" , "pdver" ) , "pcver" )
. On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
. LeftJoin < ContentNuDto > ( "nuPub" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Published , aliasRight : "nuPub" )
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document & & x . NodeId = = id )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
var dto = uow . Database . Fetch < ContentSourceDto > ( sql ) . FirstOrDefault ( ) ;
2016-05-27 14:26:28 +02:00
return dto = = null ? new ContentNodeKit ( ) : CreateContentNodeKit ( dto ) ;
}
2017-07-11 16:29:44 +02:00
public ContentNodeKit GetMediaSource ( IScopeUnitOfWork uow , int id )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectMediaSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
//.LeftJoin<ContentVersionDto>(j =>
// j.InnerJoin<DocumentVersionDto>("pdver").On<ContentVersionDto, DocumentVersionDto>((left, right) => left.Id == right.Id, "pcver", "pdver"), "pcver")
//.On<NodeDto, ContentVersionDto>((left, right) => left.NodeId == right.NodeId)
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
//.LeftJoin<ContentNuDto>("nuPub").On<NodeDto, ContentNuDto>((left, right) => left.NodeId == right.NodeId && right.Published, aliasRight: "nuPub")
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document & & x . NodeId = = id )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
var dto = uow . Database . Fetch < ContentSourceDto > ( sql ) . FirstOrDefault ( ) ;
return dto = = null ? new ContentNodeKit ( ) : CreateContentNodeKit ( dto ) ;
2016-05-27 14:26:28 +02:00
}
// we want arrays, we want them all loaded, not an enumerable
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetAllContentSources ( IScopeUnitOfWork uow )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectContentSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
. LeftJoin < ContentVersionDto > ( j = >
j . InnerJoin < DocumentVersionDto > ( "pdver" ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id & & right . Published , "pcver" , "pdver" ) , "pcver" )
. On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
. LeftJoin < ContentNuDto > ( "nuPub" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Published , aliasRight : "nuPub" )
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateContentNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetAllMediaSources ( IScopeUnitOfWork uow )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectMediaSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
//.LeftJoin<ContentVersionDto>(j =>
// j.InnerJoin<DocumentVersionDto>("pdver").On<ContentVersionDto, DocumentVersionDto>((left, right) => left.Id == right.Id, "pcver", "pdver"), "pcver")
//.On<NodeDto, ContentVersionDto>((left, right) => left.NodeId == right.NodeId)
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
//.LeftJoin<ContentNuDto>("nuPub").On<NodeDto, ContentNuDto>((left, right) => left.NodeId == right.NodeId && right.Published, aliasRight: "nuPub")
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateMediaNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetBranchContentSources ( IScopeUnitOfWork uow , int id )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var syntax = uow . SqlContext . SqlSyntax ;
var sql = SelectContentSources ( uow )
. From < NodeDto > ( )
. InnerJoin < NodeDto > ( "x" ) . On < NodeDto , NodeDto > ( ( left , right ) = > left . NodeId = = right . NodeId | | SqlText < bool > ( left . Path , right . Path , ( lp , rp ) = > $"({lp} LIKE {syntax.GetConcat(rp, " ' , % ' ")})" ) , aliasRight : "x" )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
. LeftJoin < ContentVersionDto > ( j = >
j . InnerJoin < DocumentVersionDto > ( "pdver" ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id & & right . Published , "pcver" , "pdver" ) , "pcver" )
. On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
. LeftJoin < ContentNuDto > ( "nuPub" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Published , aliasRight : "nuPub" )
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. Where < NodeDto > ( x = > x . NodeId = = id , "x" )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateContentNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetBranchMediaSources ( IScopeUnitOfWork uow , int id )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var syntax = uow . SqlContext . SqlSyntax ;
var sql = SelectMediaSources ( uow )
. From < NodeDto > ( )
. InnerJoin < NodeDto > ( "x" ) . On < NodeDto , NodeDto > ( ( left , right ) = > left . NodeId = = right . NodeId | | SqlText < bool > ( left . Path , right . Path , ( lp , rp ) = > $"({lp} LIKE {syntax.GetConcat(rp, " ' , % ' ")})" ) , aliasRight : "x" )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
//.LeftJoin<ContentVersionDto>(j =>
// j.InnerJoin<DocumentVersionDto>("pdver").On<ContentVersionDto, DocumentVersionDto>((left, right) => left.Id == right.Id, "pcver", "pdver"), "pcver")
//.On<NodeDto, ContentVersionDto>((left, right) => left.NodeId == right.NodeId)
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
//.LeftJoin<ContentNuDto>("nuPub").On<NodeDto, ContentNuDto>((left, right) => left.NodeId == right.NodeId && right.Published, aliasRight: "nuPub")
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. Where < NodeDto > ( x = > x . NodeId = = id , "x" )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateMediaNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetTypeContentSources ( IScopeUnitOfWork uow , IEnumerable < int > ids )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectContentSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
. LeftJoin < ContentVersionDto > ( j = >
j . InnerJoin < DocumentVersionDto > ( "pdver" ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id & & right . Published , "pcver" , "pdver" ) , "pcver" )
. On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
. LeftJoin < ContentNuDto > ( "nuPub" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Published , aliasRight : "nuPub" )
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. WhereIn < ContentDto > ( x = > x . ContentTypeId , ids )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateContentNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
2017-07-11 16:29:44 +02:00
public IEnumerable < ContentNodeKit > GetTypeMediaSources ( IScopeUnitOfWork uow , IEnumerable < int > ids )
2016-05-27 14:26:28 +02:00
{
2017-11-21 14:19:16 +01:00
var sql = SelectMediaSources ( uow )
. From < NodeDto > ( )
. InnerJoin < ContentDto > ( ) . On < NodeDto , ContentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < DocumentDto > ( ) . On < NodeDto , DocumentDto > ( ( left , right ) = > left . NodeId = = right . NodeId )
. InnerJoin < ContentVersionDto > ( ) . On < NodeDto , ContentVersionDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & right . Current )
. InnerJoin < DocumentVersionDto > ( ) . On < ContentVersionDto , DocumentVersionDto > ( ( left , right ) = > left . Id = = right . Id )
//.LeftJoin<ContentVersionDto>(j =>
// j.InnerJoin<DocumentVersionDto>("pdver").On<ContentVersionDto, DocumentVersionDto>((left, right) => left.Id == right.Id, "pcver", "pdver"), "pcver")
//.On<NodeDto, ContentVersionDto>((left, right) => left.NodeId == right.NodeId)
. LeftJoin < ContentNuDto > ( "nuDraft" ) . On < NodeDto , ContentNuDto > ( ( left , right ) = > left . NodeId = = right . NodeId & & ! right . Published , aliasRight : "nuDraft" )
//.LeftJoin<ContentNuDto>("nuPub").On<NodeDto, ContentNuDto>((left, right) => left.NodeId == right.NodeId && right.Published, aliasRight: "nuPub")
. Where < NodeDto > ( x = > x . NodeObjectType = = Constants . ObjectTypes . Document )
. WhereIn < ContentDto > ( x = > x . ContentTypeId , ids )
. OrderBy < NodeDto > ( x = > x . Level , x = > x . SortOrder )
;
return uow . Database . Query < ContentSourceDto > ( sql ) . Select ( CreateMediaNodeKit ) ;
2016-05-27 14:26:28 +02:00
}
private static ContentNodeKit CreateContentNodeKit ( ContentSourceDto dto )
{
ContentData d = null ;
ContentData p = null ;
2017-11-15 08:53:20 +01:00
if ( dto . Edited )
2016-05-27 14:26:28 +02:00
{
if ( dto . DraftData = = null )
{
2017-11-21 14:19:16 +01:00
if ( Debugger . IsAttached )
throw new Exception ( "Missing cmsContentNu edited content for node " + dto . Id + ", consider rebuilding." ) ;
Current . Logger . Warn < Database > ( "Missing cmsContentNu edited content for node " + dto . Id + ", consider rebuilding." ) ;
2016-05-27 14:26:28 +02:00
}
else
{
d = new ContentData
{
Name = dto . DraftName ,
Published = false ,
TemplateId = dto . DraftTemplateId ,
2017-11-15 08:53:20 +01:00
Version = dto . Version ,
2016-05-27 14:26:28 +02:00
VersionDate = dto . DraftVersionDate ,
WriterId = dto . DraftWriterId ,
Properties = DeserializeData ( dto . DraftData )
} ;
}
}
2017-11-15 08:53:20 +01:00
if ( dto . Published )
2016-05-27 14:26:28 +02:00
{
if ( dto . PubData = = null )
{
2017-11-21 14:19:16 +01:00
if ( Debugger . IsAttached )
throw new Exception ( "Missing cmsContentNu published content for node " + dto . Id + ", consider rebuilding." ) ;
Current . Logger . Warn < Database > ( "Missing cmsContentNu published content for node " + dto . Id + ", consider rebuilding." ) ;
2016-05-27 14:26:28 +02:00
}
else
{
p = new ContentData
{
Name = dto . PubName ,
Published = true ,
TemplateId = dto . PubTemplateId ,
2017-11-15 08:53:20 +01:00
Version = dto . Version ,
2016-05-27 14:26:28 +02:00
VersionDate = dto . PubVersionDate ,
WriterId = dto . PubWriterId ,
Properties = DeserializeData ( dto . PubData )
} ;
}
}
var n = new ContentNode ( dto . Id , dto . Uid ,
dto . Level , dto . Path , dto . SortOrder , dto . ParentId , dto . CreateDate , dto . CreatorId ) ;
var s = new ContentNodeKit
{
Node = n ,
ContentTypeId = dto . ContentTypeId ,
DraftData = d ,
PublishedData = p
} ;
return s ;
}
private static ContentNodeKit CreateMediaNodeKit ( ContentSourceDto dto )
{
if ( dto . PubData = = null )
throw new Exception ( "No data for media " + dto . Id ) ;
var p = new ContentData
{
Name = dto . PubName ,
Published = true ,
TemplateId = - 1 ,
2017-11-15 08:53:20 +01:00
Version = dto . Version ,
2016-05-27 14:26:28 +02:00
VersionDate = dto . PubVersionDate ,
WriterId = dto . CreatorId , // what-else?
Properties = DeserializeData ( dto . PubData )
} ;
var n = new ContentNode ( dto . Id , dto . Uid ,
dto . Level , dto . Path , dto . SortOrder , dto . ParentId , dto . CreateDate , dto . CreatorId ) ;
var s = new ContentNodeKit
{
Node = n ,
ContentTypeId = dto . ContentTypeId ,
PublishedData = p
} ;
return s ;
}
private static Dictionary < string , object > DeserializeData ( string data )
{
// by default JsonConvert will deserialize our numeric values as Int64
// which is bad, because they were Int32 in the database - take care
var settings = new JsonSerializerSettings
{
Converters = new List < JsonConverter > { new ForceInt32Converter ( ) }
} ;
return JsonConvert . DeserializeObject < Dictionary < string , object > > ( data , settings ) ;
}
}
}