当前位置: 首页>>代码示例>>C#>>正文


C# ContentManagement.ContentItem类代码示例

本文整理汇总了C#中Orchard.ContentManagement.ContentItem的典型用法代码示例。如果您正苦于以下问题:C# ContentItem类的具体用法?C# ContentItem怎么用?C# ContentItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ContentItem类属于Orchard.ContentManagement命名空间,在下文中一共展示了ContentItem类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NullCheckingCanBeDoneOnProperties

        public void NullCheckingCanBeDoneOnProperties() {
            var contentItem = new ContentItem();
            var contentPart = new ContentPart { TypePartDefinition = new ContentTypePartDefinition(new ContentPartDefinition("FooPart"), new SettingsDictionary()) };
            var contentField = new ContentField { PartFieldDefinition = new ContentPartFieldDefinition(new ContentFieldDefinition("FooType"), "FooField", new SettingsDictionary()) };

            dynamic item = contentItem;
            dynamic part = contentPart;

            Assert.That(item.FooPart == null, Is.True);
            Assert.That(item.FooPart != null, Is.False);

            contentItem.Weld(contentPart);

            Assert.That(item.FooPart == null, Is.False);
            Assert.That(item.FooPart != null, Is.True);
            Assert.That(item.FooPart, Is.SameAs(contentPart));

            Assert.That(part.FooField == null, Is.True);
            Assert.That(part.FooField != null, Is.False);
            Assert.That(item.FooPart.FooField == null, Is.True);
            Assert.That(item.FooPart.FooField != null, Is.False);

            contentPart.Weld(contentField);

            Assert.That(part.FooField == null, Is.False);
            Assert.That(part.FooField != null, Is.True);
            Assert.That(item.FooPart.FooField == null, Is.False);
            Assert.That(item.FooPart.FooField != null, Is.True);
            Assert.That(part.FooField, Is.SameAs(contentField));
            Assert.That(item.FooPart.FooField, Is.SameAs(contentField));
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:31,代码来源:DynamicContentItemTests.cs

示例2: tryGetBodyText

 public static string tryGetBodyText(ContentItem item)
 {
     BodyPart bodyPart = item.Parts.FirstOrDefault(x => x.PartDefinition.Name == "BodyPart") as BodyPart;
     if (bodyPart != null)
         return bodyPart.Text;
     return null;
 }
开发者ID:prakasha,项目名称:Orchard1.4,代码行数:7,代码来源:ContentHelper.cs

示例3: EmailAsync

 public static void EmailAsync(this IScheduledTaskManager _taskManager, ContentItem contentItem)
 {
    
     var tasks = _taskManager.GetTasks(Services.EmailScheduledTaskHandler.TASK_TYPE_EMAIL);
     if (tasks == null || tasks.Count() < 100)
         _taskManager.CreateTask(Services.EmailScheduledTaskHandler.TASK_TYPE_EMAIL, DateTime.UtcNow, contentItem);
 }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:7,代码来源:TaskHelper.cs

示例4: TestInit

        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);
        }
开发者ID:SunRobin2015,项目名称:RobinWithOrchard,代码行数:26,代码来源:ImportContentSessionTests.cs

示例5: IsValid

        private bool IsValid(int itemId, out ContentItem item, out ActionResult invalidResult)
        {
            if (_orchardServices.WorkContext.CurrentUser == null || !_orchardServices.Authorizer.Authorize(Permissions.WatchItems))
            {
                invalidResult = new HttpUnauthorizedResult();
                item = null;
                return false;
            }

            item = _orchardServices.ContentManager.Get(itemId);

            if (item == null)
            {
                invalidResult = HttpNotFound();
                return false;
            }

            if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent))
            {
                invalidResult = new HttpUnauthorizedResult();
                return false;
            }

            if (!item.Has<WatchablePart>())
            {
                invalidResult = HttpNotFound();
                return false;
            }

            invalidResult = null;
            return true;
        }
开发者ID:Lombiq,项目名称:Orchard-Watcher,代码行数:32,代码来源:WatchController.cs

示例6: RemoveArchiveLaterTasks

        void IArchiveLaterService.ArchiveLater(ContentItem contentItem, DateTime scheduledArchiveUtc) {
            if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't archive selected content.")))
                return;

            RemoveArchiveLaterTasks(contentItem);
            _scheduledTaskManager.CreateTask(UnpublishTaskType, scheduledArchiveUtc, contentItem);
        }
开发者ID:RasterImage,项目名称:Orchard,代码行数:7,代码来源:ArchiveLaterService.cs

示例7: AreEqual

        private static bool AreEqual(ContentItem item1, ContentItem item2, XElement item1Export, XElement item2Export)
        {
            //todo: this is a little too generous
            if (!item1.SharesIdentifierWith(item2))
                return false;

            if (item1.Has<TitlePart>() && item2.Has<TitlePart>())
            {
                if (!item1.As<TitlePart>().Title.Equals(item2.As<TitlePart>().Title, StringComparison.CurrentCulture))
                {
                    return false;
                }
            }

            if (item1.Has<BodyPart>() && item2.Has<BodyPart>())
            {
                var text1 = item1.As<BodyPart>().Text;
                var text2 = item2.As<BodyPart>().Text;

                if (text1 == null || text2 == null)
                    return false;

                if (!item1.As<BodyPart>().Text.Equals(item2.As<BodyPart>().Text, StringComparison.CurrentCulture))
                {
                    return false;
                }
            }

            // compare xml elements
            return Differences(item1Export, item2Export) == 0;
        }
开发者ID:JustGiving,项目名称:Tad.ContentSync,代码行数:31,代码来源:ContentItemExtensions.cs

示例8: Render

        public dynamic Render(PropertyContext context, ContentItem contentItem, IFieldTypeEditor fieldTypeEditor, string storageName, Type storageType, ContentPartDefinition part, ContentPartFieldDefinition field) {
            var p = contentItem.Parts.FirstOrDefault( x => x.PartDefinition.Name == part.Name);

            if(p == null) {
                return String.Empty;
            }

            var f = p.Fields.FirstOrDefault(x => x.Name == field.Name);

            if(f == null) {
                return String.Empty;
            }

            object value = null;

            _contentFieldValueProviders.Invoke(provider => {
                var result = provider.GetValue(contentItem, f);
                if (result != null) {
                    value = result;
                }
            }, Logger);

            if (value == null) {
                value = f.Storage.Get<object>(storageName);
            }

            if (value == null) {
                return null;
            }

            // call specific formatter rendering
            return _propertyFormater.Format(storageType, value, context.State);
        }
开发者ID:wezmag,项目名称:Coevery,代码行数:33,代码来源:ContentFieldProperties.cs

示例9: Store

 public void Store(string id, ContentItem item) {
     var contentIdentity = new ContentIdentity(id);
     if (_dictionary.ContainsKey(contentIdentity)) {
         _dictionary.Remove(contentIdentity);
     }
     _dictionary.Add(contentIdentity, item);
 }
开发者ID:rupertwhitlock,项目名称:IncreasinglyAbsorbing,代码行数:7,代码来源:ImportContentSession.cs

示例10: Vote

 private void Vote(ContentItem content, IUser currentUser, int rating, VoteRecord currentVote) {
     if (currentVote != null)
         _votingService.ChangeVote(currentVote, rating);
     else {
         _votingService.Vote(content, currentUser.UserName, HttpContext.Request.UserHostAddress, rating);
     }
 }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:7,代码来源:RateController.cs

示例11: CompareContent

 public bool CompareContent(ContentItem preContentItem, ContentItem newContentItem)
 {
     _defferences.Clear();
     var part = newContentItem.Parts.FirstOrDefault(p => p.PartDefinition.Name.Contains(preContentItem.ContentType));
     if (part == null) return false;
     var fieldContext = new PropertyContext
     {
         State = FormParametersHelper.ToDynamic(string.Empty)
     };
     string category = newContentItem.ContentType + "ContentFields";
     var allFielDescriptors = _projectionManager.DescribeProperties().Where(p => p.Category == category).SelectMany(x => x.Descriptors).ToList();
     foreach (var field in part.Fields) {
         if (!field.PartFieldDefinition.Settings.ContainsKey(isAuditKey)) continue;
         bool isAudit = bool.Parse(field.PartFieldDefinition.Settings[isAuditKey]);
         if (!isAudit) continue;
         if (_defferences.Keys.Contains(field.Name)) continue;
         var descriptor = allFielDescriptors.FirstOrDefault(d => d.Name.Text == field.Name + ":Value");
         if (descriptor == null) continue;
         var preValue = descriptor.Property(fieldContext, preContentItem);
         var newValue = descriptor.Property(fieldContext, newContentItem);
         if (preValue != null && !string.IsNullOrEmpty(preValue.ToString())
             && (newValue == null || string.IsNullOrEmpty(newValue.ToString())))
         {
             _defferences.Add(field.Name, string.Format("Deleted {1} in {0}.", field.Name, preValue));
         }
         else if (preValue != null && newValue.ToString() != preValue.ToString() ||
             preValue == null && newValue != null && !string.IsNullOrEmpty(newValue.ToString()))
         {
             _defferences.Add(field.Name, string.Format("Changed {0} from {1} to {2}.", field.Name, preValue, newValue));
         }
     }
     return _defferences.Count == 1;
 }
开发者ID:wezmag,项目名称:Coevery,代码行数:33,代码来源:CompareContentService.cs

示例12: GetDriver

 private IContentItemDriver GetDriver(ContentItem contentItem) {
     return
         _contentItemDrivers
         .Where(cid => cid.GetContentTypes().Any(ct => string.Compare(ct.Name, contentItem.ContentType, true) == 0))
         //TODO: (erikpo) SingleOrDefault should be called here, but for some reason, the amount of drivers registered is doubled sometimes.
         .FirstOrDefault();
 }
开发者ID:mofashi2011,项目名称:orchardcms,代码行数:7,代码来源:RoutableAspectHandler.cs

示例13: Display

        public override IDisplayResult Display(ContentItem contentItem, IUpdateModel updater)
        {
            var testContentPart = contentItem.As<TestContentPartA>();

            if (testContentPart == null)
            {
                return null;
            }

            return Combine(
                // A new shape is created and the properties of the object are bound to it when rendered
                Shape("TestContentPartA", testContentPart).Location("Detail", "Content"),
                // New shape, no initialization, custom location
                Shape("LowerDoll").Location("Detail", "Footer"),
                // New shape 
                Shape("TestContentPartA",
                    ctx => ctx.New.TestContentPartA().Creating(_creating++),
                    shape =>
                    {
                        shape.Processing = _processing++;
                        return Task.CompletedTask;
                    })
                    .Location("Detail", "Content")
                    .Cache("lowerdoll2", cache => cache.During(TimeSpan.FromSeconds(5))),
                // A strongly typed shape model is used and initialized when rendered
                Shape<TestContentPartAShape>(shape => { shape.Line = "Strongly typed shape"; return Task.CompletedTask; })
                    .Location("Detail", "Content:2"),
                // Cached shape
                Shape("LowerDoll")
                    .Location("Detail", "/Footer")
                    .Cache("lowerdoll", cache => cache.During(TimeSpan.FromSeconds(5)))
                );
        }
开发者ID:MichaelPetrinolis,项目名称:Orchard2,代码行数:33,代码来源:TestContentDisplay.cs

示例14: UpdateBundleProducts

        public void UpdateBundleProducts(ContentItem item, IEnumerable<ProductEntry> products) {
            var record = item.As<BundlePart>().Record;
            var oldProducts = _bundleProductsRepository.Fetch(
                r => r.BundlePartRecord == record);
            var lookupNew = products
                .Where(e => e.Quantity > 0)
                .ToDictionary(r => r.ProductId, r => r.Quantity);
            // Delete the products that are no longer there
            // and updtes the ones that should stay
            foreach (var bundleProductRecord in oldProducts) {
                var key = bundleProductRecord.ContentItemRecord.Id;
                if (lookupNew.ContainsKey(key)) {
                    bundleProductRecord.Quantity = lookupNew[key];
                    _bundleProductsRepository.Update(bundleProductRecord);
                    lookupNew.Remove(key);
                }
                else {
                    _bundleProductsRepository.Delete(bundleProductRecord);
                }
            }
            // Add the new products
            foreach (var productQuantity in lookupNew
                .Where(kvp => kvp.Value > 0)
                .Select(kvp => new ProductQuantity {ProductId = kvp.Key, Quantity = kvp.Value})) {

                AddProduct(productQuantity.Quantity, productQuantity.ProductId, record);
            }
        }
开发者ID:richinoz,项目名称:Orchard1.6,代码行数:28,代码来源:BundleService.cs

示例15: TryFindLocalizedRoute

        //Finds localized route part for the specified content and culture
        //Returns true if localized url for content and culture exists; otherwise - false
        public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out AutoroutePart localizedRoute) {
            if (!routableContent.Parts.Any(p => p.Is<ILocalizableAspect>())) {
                localizedRoute = null;
                return false;
            }

            //var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture());
            IEnumerable<LocalizationPart> localizations = _localizationService.GetLocalizations(routableContent, VersionOptions.Published);

            ILocalizableAspect localizationPart = null, siteCultureLocalizationPart = null;
            foreach (LocalizationPart l in localizations) {
                if (l.Culture.Culture == cultureName) {
                    localizationPart = l;
                    break;
                }
                if (l.Culture == null && siteCultureLocalizationPart == null) {
                    siteCultureLocalizationPart = l;
                }
            }

            //try get localization part for default site culture
            if (localizationPart == null) {
                localizationPart = siteCultureLocalizationPart;
            }

            if (localizationPart == null) {
                localizedRoute = null;
                return false;
            }

            ContentItem localizedContentItem = localizationPart.ContentItem;
            localizedRoute = localizedContentItem.Parts.Single(p => p is AutoroutePart).As<AutoroutePart>();
            return true;
        }
开发者ID:wezmag,项目名称:Coevery,代码行数:36,代码来源:LocalizableContentService.cs


注:本文中的Orchard.ContentManagement.ContentItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。