Example #1
0
        public CaseAlert[] GetCaseAlerts(ICaseAlertEvaluationContext context)
		{
			return _evaluator.Evaluate(context);
		}
        public CaseAlert[] Evaluate(ICaseAlertEvaluationContext context)
        {
            CaseAlert[] retVal = null;

            //if (!(context.ContextObject is Dictionary<string, object>))
            //	throw new ArgumentException("context.ContextObject must be a Dictionary");

            var contextCase = context.CurrentCase;

            if (contextCase != null)
            {
                var query = GetCaseRules();

                if (query != null)
                {
                    query = query.Where(rule => rule.Status == (int)CaseRuleStatus.Active);

                    // sort content by type and priority
                    query = query.OrderByDescending(rule => rule.Priority);

                    //Evaluate query
                    var current = query.ToArray();

                    //Evaluate condition expression
                    Func <CaseRule, bool> conditionPredicate = (x) =>
                    {
                        var condition = DeserializeExpression <Func <IEvaluationContext, bool> >(x.PredicateSerialized);
                        return(condition(context));
                    };

                    current = current.Where(x => string.IsNullOrEmpty(x.PredicateSerialized) || conditionPredicate(x)).ToArray();

                    var list = new List <CaseAlert>();

                    var serializedCase = SerializeCase(contextCase);

                    current.ToList().ForEach(x =>
                    {
                        x.Alerts.ToList().ForEach(alert =>
                        {
                            if (!String.IsNullOrEmpty(alert.XslTemplate))
                            {
                                alert.HtmlBody = TransformXML.TransformXml(serializedCase, alert.XslTemplate);
                            }
                            if (!string.IsNullOrEmpty(alert.RedirectUrl))
                            {
                                alert.HtmlBody = alert.RedirectUrl.
                                                 Replace(ContextRedirectVariables.CaseId, contextCase.CaseId).
                                                 Replace(ContextRedirectVariables.ContactId, contextCase.ContactId);
                            }
                            list.Add(alert);
                        });
                    });

                    if (list.Count > 0)
                    {
                        retVal = list.ToArray();
                    }
                }
            }

            return(retVal);
        }
Example #3
0
 public CaseAlert[] GetCaseAlerts(ICaseAlertEvaluationContext context)
 {
     return(_evaluator.Evaluate(context));
 }