VersionRecord() public static méthode

Gets a specific version based on the version record identifier.
public static VersionRecord ( int id ) : VersionOptions
id int
Résultat VersionOptions
 public virtual IEnumerable <ContentItem> GetAllVersions(int id)
 {
     return(_contentItemVersionRepository
            .Fetch(x => x.ContentItemRecord.Id == id)
            .OrderBy(x => x.Number)
            .Select(x => Get(x.Id, VersionOptions.VersionRecord(x.Id))));
 }
Exemple #2
0
        public IEnumerable <T> GetMany <T>(IEnumerable <int> ids, VersionOptions options, QueryHints hints) where T : class, IContent
        {
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) => {
                contentItemCriteria.Add(Restrictions.In("Id", ids.ToArray()));
                if (options.IsPublished)
                {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Published", true));
                }
                else if (options.IsLatest)
                {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
                }
                else if (options.IsDraft)
                {
                    contentItemVersionCriteria.Add(
                        Restrictions.And(Restrictions.Eq("Published", false),
                                         Restrictions.Eq("Latest", true)));
                }
            });
            var itemsById = contentItemVersionRecords
                            .Select(r => Get(r.ContentItemRecord.Id, VersionOptions.VersionRecord(r.Id)))
                            .GroupBy(ci => ci.Id)
                            .ToDictionary(g => g.Key);

            return(ids.SelectMany(id => {
                IGrouping <int, ContentItem> values;
                return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty <ContentItem>();
            }).AsPart <T>().ToArray());
        }
        public IEnumerable <ContentItem> GetManyByVersionId(IEnumerable <int> versionRecordIds, QueryHints hints)
        {
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) =>
                                                                  contentItemVersionCriteria.Add(Restrictions.In("Id", versionRecordIds.ToArray())));

            var itemsById = contentItemVersionRecords
                            .Select(r => Get(r.ContentItemRecord.Id, VersionOptions.VersionRecord(r.Id)))
                            .GroupBy(ci => ci.VersionRecord.Id)
                            .ToDictionary(g => g.Key);

            return(versionRecordIds.SelectMany(id => {
                IGrouping <int, ContentItem> values;
                return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty <ContentItem>();
            }).ToArray());
        }
        public IEnumerable <ContentItem> Slice(int skip, int count)
        {
            ApplyHqlVersionOptionsRestrictions(_versionOptions);
            var hql   = ToHql(false);
            var query = _session.CreateQuery(hql);

            if (skip != 0)
            {
                query.SetFirstResult(skip);
            }
            if (count != 0)
            {
                query.SetMaxResults(count);
            }

            return(query.List <ContentItemVersionRecord>()
                   .Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
                   .ToReadOnlyCollection());
        }
        public IEnumerable<ContentItem> GetManyByVersionId(IEnumerable<int> versionRecordIds, QueryHints hints) {
            if (!versionRecordIds.Any()) {
                // since there are no ids, I have to get no item, so it makes
                // sense to not do anything at all
                return Enumerable.Empty<ContentItem>();
            }
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) =>
                contentItemVersionCriteria.Add(Restrictions.In("Id", versionRecordIds.ToArray())));

            var itemsById = contentItemVersionRecords
                .Select(r => Get(r.ContentItemRecord.Id, VersionOptions.VersionRecord(r.Id)))
                .Where(ci => ci != null)
                .GroupBy(ci => ci.VersionRecord.Id)
                .ToDictionary(g => g.Key);

            return versionRecordIds.SelectMany(id => {
                IGrouping<int, ContentItem> values;
                return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty<ContentItem>();
            }).ToArray();
        }
        public IEnumerable <ContentItem> Slice(int skip, int count)
        {
            ApplyHqlVersionOptionsRestrictions(_versionOptions);
            var hql   = ToHql(false);
            var query = _session
                        .CreateQuery(hql)
                        .SetCacheable(true)
                        .SetResultTransformer(new DistinctRootEntityResultTransformer());

            if (skip != 0)
            {
                query.SetFirstResult(skip);
            }
            if (count != 0 && count != Int32.MaxValue)
            {
                query.SetMaxResults(count);
            }

            return(query.List <ContentItemVersionRecord>()
                   .Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
                   .ToReadOnlyCollection());
        }
Exemple #7
0
        private IEnumerable <ContentItem> Slice(int skip, int count)
        {
            var criteria = BindItemVersionCriteria();

            criteria.ApplyVersionOptionsRestrictions(_versionOptions);

            criteria.SetFetchMode("ContentItemRecord", FetchMode.Eager);
            criteria.SetFetchMode("ContentItemRecord.ContentType", FetchMode.Eager);

            // TODO: put 'removed false' filter in place
            if (skip != 0)
            {
                criteria = criteria.SetFirstResult(skip);
            }
            if (count != 0)
            {
                criteria = criteria.SetMaxResults(count);
            }
            return(criteria
                   .List <ContentItemVersionRecord>()
                   .Select(x => ContentManager.Get(x.Id, VersionOptions.VersionRecord(x.Id)))
                   .ToReadOnlyCollection());
        }
        public IEnumerable<T> GetMany<T>(IEnumerable<int> ids, VersionOptions options, QueryHints hints) where T : class, IContent {
            if (!ids.Any()) {
                // since there are no ids, I have to get no item, so it makes
                // sense to not do anything at all
                return Enumerable.Empty<T>();
            }
            var contentItemVersionRecords = GetManyImplementation(hints, (contentItemCriteria, contentItemVersionCriteria) => {
                contentItemCriteria.Add(Restrictions.In("Id", ids.ToArray()));
                if (options.IsPublished) {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Published", true));
                }
                else if (options.IsLatest) {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
                }
                else if (options.IsDraft && !options.IsDraftRequired) {
                    contentItemVersionCriteria.Add(
                        Restrictions.And(Restrictions.Eq("Published", false),
                                        Restrictions.Eq("Latest", true)));
                }
                else if (options.IsDraft || options.IsDraftRequired) {
                    contentItemVersionCriteria.Add(Restrictions.Eq("Latest", true));
                }
            });

            var itemsById = contentItemVersionRecords
                .Select(r => Get(r.ContentItemRecord.Id, options.IsDraftRequired ? options : VersionOptions.VersionRecord(r.Id)))
                .Where(ci => ci != null)
                .GroupBy(ci => ci.Id)
                .ToDictionary(g => g.Key);

            return ids.SelectMany(id => {
                    IGrouping<int, ContentItem> values;
                    return itemsById.TryGetValue(id, out values) ? values : Enumerable.Empty<ContentItem>();
                }).AsPart<T>().ToArray();
        }
Exemple #9
0
        public ContentItem Get(string id, VersionOptions versionOptions, string contentTypeHint = null)
        {
            var contentIdentity = new ContentIdentity(id);

            // lookup in local cache
            if (_identities.ContainsKey(contentIdentity))
            {
                if (_draftVersionRecordIds.ContainsKey(_identities[contentIdentity]))
                {
                    //draft was previously created. Recall.
                    versionOptions = VersionOptions.VersionRecord(_draftVersionRecordIds[_identities[contentIdentity]]);
                }
                var result = _contentManager.Get(_identities[contentIdentity], versionOptions);

                // if two identities are conflicting, then ensure that there types are the same
                // e.g., importing a blog as home page (alias=) and the current home page is a page, the blog
                // won't be imported, and blog posts will be attached to the page
                if (contentTypeHint == null || result.ContentType == contentTypeHint)
                {
                    return(result);
                }
            }

            ContentItem existingItem = _contentManager.ResolveIdentity(contentIdentity);

            //ensure we have the correct version
            if (existingItem != null)
            {
                existingItem = _contentManager.Get(existingItem.Id, versionOptions);
            }

            if (existingItem == null && _identities.ContainsKey(contentIdentity))
            {
                existingItem = _contentManager.Get(_identities[contentIdentity], versionOptions);
            }

            if (existingItem != null)
            {
                _identities[contentIdentity] = existingItem.Id;
                if (versionOptions.IsDraftRequired)
                {
                    _draftVersionRecordIds[existingItem.Id] = existingItem.VersionRecord.Id;
                }
                return(existingItem);
            }

            //create item if not found and draft was requested, or it is found later in the import queue
            if (versionOptions.IsDraftRequired || _allIdentitiesForImportStatus.ContainsKey(contentIdentity))
            {
                var contentType = _contentTypes.ContainsKey(contentIdentity) ? _contentTypes[contentIdentity] : contentTypeHint;

                if (!_contentTypes.ContainsKey(contentIdentity))
                {
                    throw new ArgumentException("Unknown content type for " + id);
                }

                var contentItem = _contentManager.Create(contentType, VersionOptions.Draft);

                _identities[contentIdentity] = contentItem.Id;

                //store versionrecordid in case a draft is requested again
                _draftVersionRecordIds[contentItem.Id] = contentItem.VersionRecord.Id;

                //add the requested item as a dependency if it is not the currently running item
                if (_allIdentitiesForImportStatus.ContainsKey(contentIdentity) &&
                    !_allIdentitiesForImportStatus[contentIdentity])
                {
                    _dependencyIdentities.Enqueue(contentIdentity);
                }

                return(contentItem);
            }

            return(null);
        }