2016-05-27 14:26:28 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using NPoco;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Logging;
|
|
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
|
|
|
|
|
using Umbraco.Core.Serialization;
|
2017-05-30 18:13:11 +02:00
|
|
|
|
using Umbraco.Web.Composing;
|
2016-05-27 14:26:28 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.PublishedCache.NuCache.DataSource
|
|
|
|
|
|
{
|
|
|
|
|
|
// 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-07-11 16:29:44 +02:00
|
|
|
|
public ContentNodeKit GetContentSource(IScopeUnitOfWork uow, int id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
{
|
|
|
|
|
|
var dto = uow.Database.Fetch<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docDraft.text DraftName, docDraft.versionId DraftVersion, docDraft.updateDate DraftVersionDate, docDraft.writerUserId DraftWriterId, docDraft.templateId DraftTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuDraft.data DraftData,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docPub.text PubName, docPub.versionId PubVersion, docPub.updateDate PubVersionDate, docPub.writerUserId PubWriterId, docPub.templateId PubTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
LEFT JOIN cmsDocument docDraft ON (docDraft.nodeId=n.id AND docDraft.newest=1 AND docDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsDocument docPub ON (docPub.nodeId=n.id AND docPub.published=1)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuDraft ON (nuDraft.nodeId=n.id AND nuDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType AND n.id=@id
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Document, /*id =*/ id })).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
|
|
|
|
{
|
|
|
|
|
|
// should be only 1 version for medias
|
|
|
|
|
|
|
|
|
|
|
|
var dto = uow.Database.Fetch<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
|
|
|
|
|
n.text PubName, ver.versionId PubVersion, ver.versionDate PubVersionDate,
|
|
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
JOIN cmsContentVersion ver ON (ver.contentId=n.id)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType AND n.id=@id
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Media, /*id =*/ id })).FirstOrDefault();
|
2016-05-27 14:26:28 +02:00
|
|
|
|
return dto == null ? new ContentNodeKit() : CreateMediaNodeKit(dto);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docDraft.text DraftName, docDraft.versionId DraftVersion, docDraft.updateDate DraftVersionDate, docDraft.writerUserId DraftWriterId, docDraft.templateId DraftTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuDraft.data DraftData,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docPub.text PubName, docPub.versionId PubVersion, docPub.updateDate PubVersionDate, docPub.writerUserId PubWriterId, docPub.templateId PubTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
LEFT JOIN cmsDocument docDraft ON (docDraft.nodeId=n.id AND docDraft.newest=1 AND docDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsDocument docPub ON (docPub.nodeId=n.id AND docPub.published=1)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuDraft ON (nuDraft.nodeId=n.id AND nuDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType
|
|
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Document })).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
|
|
|
|
{
|
|
|
|
|
|
// should be only 1 version for medias
|
|
|
|
|
|
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
|
|
|
|
|
n.text PubName, ver.versionId PubVersion, ver.versionDate PubVersionDate,
|
|
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
JOIN cmsContentVersion ver ON (ver.contentId=n.id)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType
|
|
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Media })).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
|
|
|
|
{
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docDraft.text DraftName, docDraft.versionId DraftVersion, docDraft.updateDate DraftVersionDate, docDraft.writerUserId DraftWriterId, docDraft.templateId DraftTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuDraft.data DraftData,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docPub.text PubName, docPub.versionId PubVersion, docPub.updateDate PubVersionDate, docPub.writerUserId PubWriterId, docPub.templateId PubTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-09-22 18:28:21 +02:00
|
|
|
|
JOIN umbracoNode x ON (n.id=x.id OR n.path LIKE " + uow.SqlContext.SqlSyntax.GetConcat("x.path", "',%'") + @")
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
LEFT JOIN cmsDocument docDraft ON (docDraft.nodeId=n.id AND docDraft.newest=1 AND docDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsDocument docPub ON (docPub.nodeId=n.id AND docPub.published=1)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuDraft ON (nuDraft.nodeId=n.id AND nuDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType AND x.id=@id
|
|
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Document, /*id =*/ id })).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
|
|
|
|
{
|
|
|
|
|
|
// should be only 1 version for medias
|
|
|
|
|
|
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
|
|
|
|
|
n.text PubName, ver.versionId PubVersion, ver.versionDate PubVersionDate,
|
|
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-09-22 18:28:21 +02:00
|
|
|
|
JOIN umbracoNode x ON (n.id=x.id OR n.path LIKE " + uow.SqlContext.SqlSyntax.GetConcat("x.path", "',%'") + @")
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
JOIN cmsContentVersion ver ON (ver.contentId=n.id)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
|
|
|
|
|
WHERE n.nodeObjectType=@objType AND x.id=@id
|
|
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Media, /*id =*/ id })).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
|
|
|
|
{
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docDraft.text DraftName, docDraft.versionId DraftVersion, docDraft.updateDate DraftVersionDate, docDraft.writerUserId DraftWriterId, docDraft.templateId DraftTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuDraft.data DraftData,
|
2017-11-07 19:49:14 +01:00
|
|
|
|
docPub.text PubName, docPub.versionId PubVersion, docPub.updateDate PubVersionDate, docPub.writerUserId PubWriterId, docPub.templateId PubTemplateId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
LEFT JOIN cmsDocument docDraft ON (docDraft.nodeId=n.id AND docDraft.newest=1 AND docDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsDocument docPub ON (docPub.nodeId=n.id AND docPub.published=1)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuDraft ON (nuDraft.nodeId=n.id AND nuDraft.published=0)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
2017-11-01 16:27:24 +01:00
|
|
|
|
WHERE n.nodeObjectType=@objType AND uContent.contentTypeId IN (@ids)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Document, /*id =*/ ids })).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
|
|
|
|
{
|
|
|
|
|
|
// should be only 1 version for medias
|
|
|
|
|
|
|
|
|
|
|
|
return uow.Database.Query<ContentSourceDto>(new Sql(@"SELECT
|
|
|
|
|
|
n.id Id, n.uniqueId Uid,
|
2017-11-01 16:27:24 +01:00
|
|
|
|
uContent.contentTypeId ContentTypeId,
|
2016-05-27 14:26:28 +02:00
|
|
|
|
n.level Level, n.path Path, n.sortOrder SortOrder, n.parentId ParentId,
|
|
|
|
|
|
n.createDate CreateDate, n.nodeUser CreatorId,
|
|
|
|
|
|
n.text PubName, ver.versionId PubVersion, ver.versionDate PubVersionDate,
|
|
|
|
|
|
nuPub.data PubData
|
|
|
|
|
|
FROM umbracoNode n
|
2017-11-01 16:27:24 +01:00
|
|
|
|
JOIN uContent ON (uContent.nodeId=n.id)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
JOIN cmsContentVersion ver ON (ver.contentId=n.id)
|
|
|
|
|
|
LEFT JOIN cmsContentNu nuPub ON (nuPub.nodeId=n.id AND nuPub.published=1)
|
2017-11-01 16:27:24 +01:00
|
|
|
|
WHERE n.nodeObjectType=@objType AND uContent.contentTypeId IN (@ids)
|
2016-05-27 14:26:28 +02:00
|
|
|
|
ORDER BY n.level, n.sortOrder
|
2017-09-19 18:19:05 +02:00
|
|
|
|
", new { objType = Constants.ObjectTypes.Media, /*id =*/ ids })).Select(CreateMediaNodeKit);
|
2016-05-27 14:26:28 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static ContentNodeKit CreateContentNodeKit(ContentSourceDto dto)
|
|
|
|
|
|
{
|
|
|
|
|
|
ContentData d = null;
|
|
|
|
|
|
ContentData p = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (dto.DraftVersion != Guid.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dto.DraftData == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//throw new Exception("Missing cmsContentNu content for node " + dto.Id + ", consider rebuilding.");
|
2016-09-11 19:57:33 +02:00
|
|
|
|
Current.Logger.Warn<Database>("Missing cmsContentNu 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,
|
|
|
|
|
|
Version = dto.DraftVersion,
|
|
|
|
|
|
VersionDate = dto.DraftVersionDate,
|
|
|
|
|
|
WriterId = dto.DraftWriterId,
|
|
|
|
|
|
Properties = DeserializeData(dto.DraftData)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dto.PubVersion != Guid.Empty)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (dto.PubData == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
//throw new Exception("Missing cmsContentNu content for node " + dto.Id + ", consider rebuilding.");
|
2016-09-11 19:57:33 +02:00
|
|
|
|
Current.Logger.Warn<Database>("Missing cmsContentNu 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,
|
|
|
|
|
|
Version = dto.PubVersion,
|
|
|
|
|
|
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,
|
|
|
|
|
|
Version = dto.PubVersion,
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|