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;
        }
Ejemplo n.º 2
0
 public void ForVersion(VersionOptions options)
 {
     _versionOptions = options;
 }
Ejemplo n.º 3
0
 internal static void ApplyVersionOptionsRestrictions(this ICriteria criteria, VersionOptions versionOptions)
 {
     if (versionOptions == null)
     {
         criteria.Add(Restrictions.Eq("Published", true));
     }
     else if (versionOptions.IsPublished)
     {
         criteria.Add(Restrictions.Eq("Published", true));
     }
     else if (versionOptions.IsLatest)
     {
         criteria.Add(Restrictions.Eq("Latest", true));
     }
     else if (versionOptions.IsDraft && !versionOptions.IsDraftRequired)
     {
         criteria.Add(Restrictions.And(
                          Restrictions.Eq("Latest", true),
                          Restrictions.Eq("Published", false)));
     }
     else if (versionOptions.IsDraft || versionOptions.IsDraftRequired)
     {
         criteria.Add(Restrictions.Eq("Latest", true));
     }
     else if (versionOptions.IsAllVersions)
     {
         // no-op... all versions will be returned by default
     }
     else
     {
         throw new ApplicationException("Invalid VersionOptions for content query");
     }
 }
Ejemplo n.º 4
0
 IContentQuery <T> IContentQuery <T> .ForVersion(VersionOptions options)
 {
     _query.ForVersion(options);
     return(this);
 }
Ejemplo n.º 5
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.ContentItemRecord.Id, _versionOptions != null && _versionOptions.IsDraftRequired ? _versionOptions : VersionOptions.VersionRecord(x.Id)))
                   .ToReadOnlyCollection());
        }
Ejemplo n.º 6
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);
        }