Moving Rules remainings from Core

This commit is contained in:
Sebastien Ros 2013-09-05 18:05:27 -07:00
parent 0ea0077fa3
commit 5add094502
4 changed files with 39 additions and 45 deletions

View File

@ -112,7 +112,6 @@
<Compile Include="Containers\ViewModels\ContainerWidgetViewModel.cs" />
<Compile Include="Containers\ViewModels\ContainerViewModel.cs" />
<Compile Include="Contents\ControlWrapper.cs" />
<Compile Include="Contents\Handlers\RulesHandler.cs" />
<Compile Include="Contents\Security\AuthorizationEventHandler.cs" />
<Compile Include="Common\Services\BbcodeFilter.cs" />
<Compile Include="Common\Services\ICommonService.cs" />

View File

@ -1,39 +1,33 @@
using System;
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Environment.Extensions;
using Orchard.Events;
namespace Orchard.Core.Contents.Handlers {
public interface IRulesManager : IEventHandler {
void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext);
}
public class RulePartHandler : ContentHandler {
public RulePartHandler(IRulesManager rulesManager) {
OnPublished<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Published",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
OnRemoved<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Removed",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
OnVersioned<ContentPart>(
(context, part1, part2) =>
rulesManager.TriggerEvent("Content", "Versioned",
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
OnCreated<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Created",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
}
}
using System.Collections.Generic;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.Rules.Services;
namespace Orchard.Rules.Handlers {
public class RulePartHandler : ContentHandler {
public RulePartHandler(IRulesManager rulesManager) {
OnPublished<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Published",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
OnRemoved<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Removed",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
OnVersioned<ContentPart>(
(context, part1, part2) =>
rulesManager.TriggerEvent("Content", "Versioned",
() => new Dictionary<string, object> { { "Content", part1.ContentItem } }));
OnCreated<ContentPart>(
(context, part) =>
rulesManager.TriggerEvent("Content", "Created",
() => new Dictionary<string, object> { { "Content", context.ContentItem } }));
}
}
}

View File

@ -82,6 +82,7 @@
<Content Include="Views\Web.config" />
<Content Include="Scripts\Web.config" />
<Content Include="Styles\Web.config" />
<Compile Include="Handlers\ContentHandler.cs" />
<Compile Include="ImportExport\RulesExportEventHandler.cs" />
<Compile Include="ImportExport\RulesCustomExportStep.cs" />
<Compile Include="ImportExport\RulesRecipeHandler.cs" />

View File

@ -17,14 +17,14 @@ namespace Orchard.Rules.Providers {
Func<dynamic, bool> contentHasPart = ContentHasPart;
describe.For("Content", T("Content Items"), T("Content Items"))
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is created.", FormatPartsList(context))), "SelectContentTypes")
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is versioned.", FormatPartsList(context))), "SelectContentTypes")
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is published.", FormatPartsList(context))), "SelectContentTypes")
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, (Func<dynamic, LocalizedString>)(context => T("When content with types ({0}) is removed.", FormatPartsList(context))), "SelectContentTypes");
.Element("Created", T("Content Created"), T("Content is actually created."), contentHasPart, context => T("When content with types ({0}) is created.", FormatPartsList(context)), "SelectContentTypes")
.Element("Versioned", T("Content Versioned"), T("Content is actually versioned."), contentHasPart, context => T("When content with types ({0}) is versioned.", FormatPartsList(context)), "SelectContentTypes")
.Element("Published", T("Content Published"), T("Content is actually published."), contentHasPart, context => T("When content with types ({0}) is published.", FormatPartsList(context)), "SelectContentTypes")
.Element("Removed", T("Content Removed"), T("Content is actually removed."), contentHasPart, context => T("When content with types ({0}) is removed.", FormatPartsList(context)), "SelectContentTypes");
}
private string FormatPartsList(dynamic context) {
var contenttypes = context.Properties["ContentTypes"];
private string FormatPartsList(EventContext context) {
var contenttypes = context.Properties.ContainsKey("ContentTypes") ? context.Properties["ContentTypes"] : context.Properties["contenttypes"];
if (String.IsNullOrEmpty(contenttypes)) {
return T("Any").Text;