Last active
October 12, 2016 12:57
-
-
Save 5up3rman/419dc66f06607a2c494397b44bd2bc6a to your computer and use it in GitHub Desktop.
Rule Context and Processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Serializable] | |
public class ContentEditorRuleContext : RuleContext, ISerializable | |
{ | |
public List<IMappedItem> MappedItems { get; set; } = new List<IMappedItem>(); | |
public void GetObjectData(SerializationInfo info, StreamingContext context) | |
{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContentEditorRulesProcessor | |
{ | |
private Item item { get; set; } | |
public List<IMappedItem> MappedItems { get; set; } = new List<IMappedItem>(); | |
public ContentEditorRulesProcessor(Item currentItem) | |
{ | |
item = currentItem; | |
if (item == null || !item.Paths.IsContentItem) return; | |
ProcessRules(); | |
} | |
private void ProcessRules() | |
{ | |
var ruleContext = new ContentEditorRuleContext { Item = item }; | |
// Get the Rules Folder | |
var rulesFolder = Factory.GetDatabase(RulesConstants.MasterDb).GetItem(RulesConstants.CeRulesFolder); | |
if (rulesFolder == null) return; | |
var rules = RuleFactory.GetRules<ContentEditorRuleContext>(rulesFolder, "Rule"); | |
rules.Run(ruleContext); | |
// Set the MappedItems to the ruleContext.MappedItems which are a collection of items gathered from the Actions | |
MappedItems = ruleContext.MappedItems; | |
ruleContext.Abort(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct RulesConstants | |
{ | |
public const string MasterDb = "master"; | |
public const string CeRulesFolder = "{55F26A63-D476-498F-817B-2FCDE203DB8A}"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment