说实话,写的太粗糙,真有点不好意思拿出来示人,可是又一想,写都写了,还怕给人看?!俗话有说,“丑媳妇早晚还是要见公婆”, 不是吗?!
主要功能:通过自定义Razor(C#)表达式,对Orchard中Content的Handler添加处理程序,说白了,就是在内容有新建,发布等时,可以自已干点啥,比如:通过输入的内容创建另外类型的内容。
支持IContentHandler 定义的全部事件:
namespace Orchard.ContentManagement.Handlers { public interface IContentHandler : IDependency { void Activating(ActivatingContentContext context); void Activated(ActivatedContentContext context); void Initializing(InitializingContentContext context); void Creating(CreateContentContext context); void Created(CreateContentContext context); void Loading(LoadContentContext context); void Loaded(LoadContentContext context); void Versioning(VersionContentContext context); void Versioned(VersionContentContext context); void Publishing(PublishContentContext context); void Published(PublishContentContext context); void Unpublishing(PublishContentContext context); void Unpublished(PublishContentContext context); void Removing(RemoveContentContext context); void Removed(RemoveContentContext context); void Indexing(IndexContentContext context); void Indexed(IndexContentContext context); void Importing(ImportContentContext context); void Imported(ImportContentContext context); void Exporting(ExportContentContext context); void Exported(ExportContentContext context); void GetContentItemMetadata(GetContentItemMetadataContext context); void BuildDisplay(BuildDisplayContext context); void BuildEditor(BuildEditorContext context); void UpdateEditor(UpdateEditorContext context); } }
如图:
示例代码:
Condition:
@if (Model.Content.ContentType == "Page") { @: true } else { @: false }
@using Orchard; @using Orchard.Security; @using Orchard.Settings; @using Orchard.ContentManagement; @using Orchard.ContentManagement.Handlers; @using Orchard.ContentManagement.Aspects; @using Orchard.Core.Common.Models; @using RaisingStudio.Trigger.Services; @using RaisingStudio.Razor.Services; @using RaisingStudio.Trigger.Models; @using RaisingStudio.Razor.Models; @{ IContentManager contentManager = Model.ContentManager; var bodyText = Model.As<BodyPart>().Text; var razorPage = contentManager.Create<RazorContentPart>("RazorPage", VersionOptions.Draft); razorPage.Template = bodyText; contentManager.Publish(razorPage.ContentItem); @: true }
项目地址:http://trigger4orchard.codeplex.com/
Orchard Gallery下载: http://orchardproject.net/gallery/server/Package/Download/Orchard.Module.RaisingStudio.Trigger/1.0