private LocalizedString Display(EventContext context) { if (!context.Properties.ContainsKey("Name")) { return T("No Schedule selected"); } return T("Rule will be triggered when the '{0}' schedule occurrs", context.Properties["Name"]); }
private bool Condition(EventContext context) { if (!context.Properties.ContainsKey("Name") || !context.Tokens.ContainsKey("Name")) { return false; } return context.Properties["Name"] == (string)context.Tokens["Name"]; }
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; } return contenttypes; }
public void TriggerEvent(string category, string type, Func<Dictionary<string, object>> tokensContext) { var tokens = tokensContext(); // load corresponding events, as on one Rule several events of the same type could be configured // with different parameters var events = _eventRepository.Table .Where(x => x.Category == category && x.Type == type && x.RuleRecord.Enabled) .ToList(); var eventDescriptors = DescribeEvents().SelectMany(x => x.Descriptors); // take the first event which has a valid condition if (!events.Any(e => { var eventCategory = e.Category; var eventType = e.Type; // look for the specified Event target/type var descriptor = eventDescriptors .Where(x => eventCategory == x.Category && eventType == x.Type) .FirstOrDefault(); if (descriptor == null) { return false; } var properties = FormParametersHelper.FromString(e.Parameters); var context = new EventContext { Tokens = tokens, Properties = properties }; // check the condition return descriptor.Condition(context); })) { return; } // load rules too for eager loading var rules = _ruleRepository.Table .Where(x => x.Enabled && x.Events.Any(e => e.Category == category && e.Type == type)); // evaluate their conditions foreach (var e in events) { var rule = e.RuleRecord; ExecuteActions(rule.Actions, tokens); } }