Exemplo n.º 1
0
        /// <summary>
        /// from Orchard.Recipes.Providers.Builders.ContentStep
        /// </summary>
        /// <param name="contentTypes"></param>
        /// <param name="contentItems"></param>
        /// <returns></returns>
        private XElement ExportData(IEnumerable <string> contentTypes, IEnumerable <ContentItem> contentItems)
        {
            var data = new XElement("Content");

            var orderedContentItemsQuery =
                from contentItem in contentItems
                let identity = _contentManager.GetItemMetadata(contentItem).Identity.ToString()
                               orderby identity
                               select contentItem;

            var orderedContentItems = orderedContentItemsQuery.ToList();

            foreach (var contentType in contentTypes.OrderBy(x => x))
            {
                var type  = contentType;
                var items = orderedContentItems.Where(i => i.ContentType == type);
                foreach (var contentItem in items)
                {
                    var contentItemElement = _contentManager.Export(contentItem);
                    if (contentItemElement != null)
                    {
                        data.Add(contentItemElement);
                    }
                }
            }

            return(data);
        }
        protected override void Updating(UpdateContentContext context)
        {
            var contentItem = context.ContentItem;

            _ignoreExportHandlerFor = contentItem;
            _previousVersionXml     = _contentItemCreated
                ? default(XElement) // No need to do a diff on a newly created content item.
                : _contentManager.Export(contentItem);
            _ignoreExportHandlerFor = null;
        }
Exemplo n.º 3
0
        public void ImportingDraftShouldUpdateExistingDraft()
        {
            // Create a draft and an export of it.
            var contentItem = _contentManager.New(ContentTypeName);

            contentItem.As <TitlePart>().Title = "Dummy";
            _contentManager.Create(contentItem, VersionOptions.Draft);
            var element = _contentManager.Export(contentItem);

            // Change the title and then import the element.
            element.Element("TitlePart").Attr("Title", "Smarty");
            Import(element);

            // Assert that we still have the one draft.
            var allContentItems = _contentManager.Query(VersionOptions.Latest).List().ToList();

            Assert.That(allContentItems.Count, Is.EqualTo(1));
            var updatedContentItem = allContentItems[0];

            Assert.That(updatedContentItem.As <IdentityPart>().Identifier, Is.EqualTo(contentItem.As <IdentityPart>().Identifier));

            // Assert that the draft has been updated with the imported change.
            Assert.That(updatedContentItem.As <TitlePart>().Title, Is.EqualTo("Smarty"));
        }