public void Store(ContentItem item)
        {
            _itemByVersionRecordId.Add(item.VersionRecord.Id, item);

            // is it the Published version ?
            if (item.VersionRecord.Latest && item.VersionRecord.Published) {
                _publishedItemsByContentRecordId[item.Id] = item;
            }
        }
        public void ContentItemProjectsPartNamesAsProperties()
        {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;

            Assert.That((object)testingPartDynamic, Is.SameAs(testingPart));
        }
        public void ActualPropertiesTakePriority()
        {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("Parts"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.Parts;

            Assert.That((object)testingPartDynamic, Is.AssignableTo<IEnumerable<ContentPart>>());
        }
        public void ContentItemPropertyOnPartRootsYou()
        {
            var contentItem = new ContentItem();
            var testingPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("TestingPart"), new SettingsDictionary()) };
            var anotherPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("AnotherPart"), new SettingsDictionary()) };
            contentItem.Weld(testingPart);
            contentItem.Weld(anotherPart);

            dynamic contentItemDynamic = contentItem;
            dynamic testingPartDynamic  = contentItemDynamic.TestingPart;
            dynamic anotherPartDynamic  = contentItemDynamic.AnotherPart;

            dynamic contentItemDynamic1  = testingPartDynamic.ContentItem;
            dynamic contentItemDynamic2  = anotherPartDynamic.ContentItem;

            Assert.That((object)contentItemDynamic1, Is.SameAs(contentItem));
            Assert.That((object)contentItemDynamic2, Is.SameAs(contentItem));
        }
        public void TestInit()
        {
            _testItemIdentity1 = new ContentIdentity("/ItemId=1");
            _testItemIdentity2 = new ContentIdentity("/ItemId=2");
            _testItemIdentity3 = new ContentIdentity("/ItemId=3");
            _testItemIdentity4 = new ContentIdentity("/ItemId=4");
            _testItemIdentity5 = new ContentIdentity("/ItemId=5");
            var draftItem = new ContentItem { VersionRecord = new ContentItemVersionRecord { Id = 1234, Published = false, Latest = true, ContentItemRecord = new ContentItemRecord { Id = 1 } } };
            var publishedItem = new ContentItem { VersionRecord = new ContentItemVersionRecord { Id = 1234, Published = true, Latest = true, ContentItemRecord = new ContentItemRecord { Id = 1 } } };

            var draftItem5 = new ContentItem { VersionRecord = new ContentItemVersionRecord { Id = 1234, Published = false, Latest = true, ContentItemRecord = new ContentItemRecord { Id = 5 } } };
            var publishedItem5 = new ContentItem { VersionRecord = new ContentItemVersionRecord { Id = 1234, Published = true, Latest = true, ContentItemRecord = new ContentItemRecord { Id = 5 } } };

            _contentManager = new Mock<IContentManager>();
            _contentManager.Setup(m => m.Get(It.Is<int>(v => v == 1), It.Is<VersionOptions>(v => v.IsDraftRequired))).Returns(draftItem);
            _contentManager.Setup(m => m.Get(It.Is<int>(v => v == 1), It.Is<VersionOptions>(v => !v.IsDraftRequired))).Returns(publishedItem);

            _contentManager.Setup(m => m.Get(It.Is<int>(v => v == 5), It.Is<VersionOptions>(v => v.IsDraftRequired))).Returns(draftItem5);
            _contentManager.Setup(m => m.Get(It.Is<int>(v => v == 5), It.Is<VersionOptions>(v => !v.IsDraftRequired))).Returns(publishedItem5);

            _contentManager.Setup(m => m.GetItemMetadata(It.Is<IContent>(c => c.Id == 1))).Returns(new ContentItemMetadata { Identity = _testItemIdentity1 });
            _contentManager.Setup(m => m.GetItemMetadata(It.Is<IContent>(c => c.Id == 5))).Returns(new ContentItemMetadata { Identity = _testItemIdentity5 });

            _contentManager.Setup(m => m.New(It.IsAny<string>())).Returns(draftItem5);

            _contentManager.Setup(m => m.ResolveIdentity(It.Is<ContentIdentity>(id => id.Get("ItemId") == "1"))).Returns(publishedItem);
        }
 private ContentPart CreateContentItemPart()
 {
     var partDefinition = FooPartDefinition();
     var typeDefinition = new ContentTypeDefinitionBuilder()
         .WithPart(partDefinition, part => { })
         .Build();
     var contentItem = new ContentItem {
         VersionRecord = new ContentItemVersionRecord {
             ContentItemRecord = new ContentItemRecord()
         }
     };
     var contentPart = new ContentPart {
         TypePartDefinition = typeDefinition.Parts.Single()
     };
     contentItem.Weld(contentPart);
     contentItem.Weld(new InfosetPart {
         Infoset = contentItem.Record.Infoset,
         VersionInfoset = contentItem.VersionRecord.Infoset
     });
     return contentPart;
 }
 public bool RecallVersionRecordId(int id, out ContentItem item)
 {
     return _itemByVersionRecordId.TryGetValue(id, out item);
 }
 public bool RecallContentRecordId(int id, out ContentItem item)
 {
     return _publishedItemsByContentRecordId.TryGetValue(id, out item);
 }
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);
        }