private ExtendedContentInfo CreateExtendedContextData(ContentItem item, bool resolveVersions = false)
        {
            if (item == null)
            {
                return(null);
            }

            var data = new ExtendedContentInfo
            {
                Created       = item.Created.ToString("o"),
                Expires       = item.Expires.HasValue ? item.Expires.Value.ToString("o") : null,
                IsPage        = item.IsPage,
                Published     = item.Published.HasValue ? item.Published.Value.ToString("o") : null,
                SavedBy       = item.SavedBy,
                Updated       = item.Updated.ToString("o"),
                Visible       = item.Visible,
                ZoneName      = item.ZoneName,
                VersionIndex  = item.VersionIndex,
                Url           = item.Url,
                ReadProtected = !engine.SecurityManager.IsAuthorized(item, new GenericPrincipal(new GenericIdentity(""), null)),
                TypeName      = item.GetContentType().Name
            };

            if (resolveVersions)
            {
                var draftInfo = engine.Resolve <DraftRepository>().GetDraftInfo(item);
                data.Draft = CreateExtendedContextData(draftInfo != null ? engine.Resolve <IVersionManager>().GetVersion(item, draftInfo.VersionIndex) : null);
                if (data.Draft != null)
                {
                    data.Draft.SavedBy = draftInfo.SavedBy;
                    data.Draft.Updated = draftInfo.Saved.ToString("o");
                }
                data.VersionOf = CreateExtendedContextData(item.VersionOf);
            }
            ;
            if (item.State == ContentState.Waiting)
            {
                DateTime?futurePublishDate = (DateTime?)item["FuturePublishDate"];
                if (futurePublishDate.HasValue)
                {
                    data.FuturePublishDate = futurePublishDate.Value.ToString("o");
                }
            }
            return(data);
        }
Esempio n. 2
0
        private ExtendedContentInfo CreateExtendedContextData(ContentItem item, bool resolveVersions = false)
        {
            if (item == null)
                return null;

            var data = new ExtendedContentInfo
            {
                Created = item.Created.ToString("o"),
                Expires = item.Expires.HasValue ? item.Expires.Value.ToString("o") : null,
                IsPage = item.IsPage,
                Published = item.Published.HasValue ? item.Published.Value.ToString("o") : null,
                SavedBy = item.SavedBy,
                Updated = item.Updated.ToString("o"),
                Visible = item.Visible,
                ZoneName = item.ZoneName,
                VersionIndex = item.VersionIndex,
                Url = item.Url,
                ReadProtected = !engine.SecurityManager.IsAuthorized(item, new GenericPrincipal(new GenericIdentity(""), null)),
                TypeName = item.GetContentType().Name
            };
            if (resolveVersions)
            {
                var draftInfo = engine.Resolve<DraftRepository>().GetDraftInfo(item);
                data.Draft = CreateExtendedContextData(draftInfo != null ? engine.Resolve<IVersionManager>().GetVersion(item, draftInfo.VersionIndex) : null);
                if (data.Draft != null)
                {
                    data.Draft.SavedBy = draftInfo.SavedBy;
                    data.Draft.Updated = draftInfo.Saved.ToString("o");
                }
                data.VersionOf = CreateExtendedContextData(item.VersionOf);
            };
            if (item.State == ContentState.Waiting)
            {
                DateTime? futurePublishDate = (DateTime?)item["FuturePublishDate"];
                if (futurePublishDate.HasValue)
                    data.FuturePublishDate = futurePublishDate.Value.ToString("o");
            }
            return data;
        }