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);
        }
Exemplo n.º 2
0
        private XmlElement siganatureXML(XmlDocument doc, Parametros parametro)
        {
            if (doc == null)
            {
                throw new ArgumentException("xmlDoc");
            }

            var xmlDocumentSignature = new XmlDocument();


            SignatureXML signatureXML = new SignatureXML();

            XmlElement Signature = signatureXML.XmlElement(xmlDocumentSignature);



            //SignedInfo
            SignedInfoXMl SignedInfoXMl = new SignedInfoXMl();
            XmlElement    SignedInfoxml = SignedInfoXMl.XmlElement(xmlDocumentSignature);


            CanonicalizationMethodXML CanonicalizationMethodXML = new CanonicalizationMethodXML();
            XmlElement CanonicalizationMethodxml = CanonicalizationMethodXML.XmlElement(xmlDocumentSignature);

            CanonicalizationMethodXML.XMlAttributeAlgorithm(CanonicalizationMethodxml);


            SignatureMethodXML SignatureMethodXML = new SignatureMethodXML();
            XmlElement         SignatureMethodxml = SignatureMethodXML.XmlElement(xmlDocumentSignature);

            SignatureMethodXML.XMlAttributeAlgorithm(SignatureMethodxml);


            ReferenceXML ReferenceXML = new ReferenceXML();
            XmlElement   Referencexml = ReferenceXML.XmlElement(xmlDocumentSignature);

            ReferenceXML.XMlAttributeURI(Referencexml);



            TransformsXML TransformsXML = new TransformsXML();
            XmlElement    Transformsxml = TransformsXML.XmlElement(xmlDocumentSignature);

            TransformXML TransformXML = new TransformXML();
            XmlElement   Transformxml = TransformXML.XmlElement(xmlDocumentSignature);

            TransformXML.XMlAttributeAlgorithm(Transformxml);


            Transformsxml.AppendChild(Transformxml);


            Referencexml.AppendChild(Transformsxml);


            string digest = DigestUtils.CreateDigest(doc.OuterXml);

            DigestMethodXML DigestMethodXML = new DigestMethodXML();
            XmlElement      DigestMethodxml = DigestMethodXML.XmlElement(xmlDocumentSignature);

            DigestMethodXML.XMlAttributeAlgorithm(DigestMethodxml);
            Referencexml.AppendChild(DigestMethodxml);


            DigestValueXML DigestValueXML = new DigestValueXML();
            XmlElement     DigestValuexml = DigestValueXML.XmlElement(xmlDocumentSignature);;

            DigestValuexml.InnerText = digest;


            Referencexml.AppendChild(DigestValuexml);

            SignedInfoxml.AppendChild(CanonicalizationMethodxml);
            SignedInfoxml.AppendChild(SignatureMethodxml);
            SignedInfoxml.AppendChild(Referencexml);


            //SignedInfo



            string signature = DigestUtils.Sign(SignedInfoxml.OuterXml, parametro.certificado.getX509Certificate2());


            //SignatureValue
            SignatureValueXML SignatureValueXML = new SignatureValueXML();
            XmlElement        SignatureValuexml = SignatureValueXML.XmlElement(xmlDocumentSignature);

            SignatureValuexml.InnerText = signature;
            //SignatureValue



            //KeyInfo
            KeyInfoXML KeyInfoXML = new KeyInfoXML();
            XmlElement KeyInfoXMl = KeyInfoXML.XmlElement(xmlDocumentSignature);

            X509DataXML X509Data    = new X509DataXML();
            XmlElement  X509DataXML = X509Data.XmlElement(xmlDocumentSignature);

            X509IssuerSerialXML X509IssuerSerialXML = new X509IssuerSerialXML();
            XmlElement          x5019Issuer         = X509IssuerSerialXML.XmlElement(xmlDocumentSignature);

            X509IssuerNameXML X509IssuerNameXML = new X509IssuerNameXML();
            XmlElement        X509IssuerName    = X509IssuerNameXML.XmlElement(xmlDocumentSignature);

            X509IssuerName.InnerText = parametro.certificado.getX509Certificate2().IssuerName.Name;
            x5019Issuer.AppendChild(X509IssuerName);

            X509SerialNumberXML X509SerialNumberXML = new X509SerialNumberXML();
            XmlElement          X509SerialNumber    = X509SerialNumberXML.XmlElement(xmlDocumentSignature);

            X509SerialNumber.InnerText = parametro.certificado.getX509Certificate2().GetSerialNumberString();
            x5019Issuer.AppendChild(X509SerialNumber);

            X509DataXML.AppendChild(x5019Issuer);



            X509CertificateXML X509Certificate = new X509CertificateXML();


            XmlElement X509CertificateXML = X509Certificate.XmlElement(xmlDocumentSignature);



            X509CertificateXML.InnerText = DigestUtils.convertToBase64X509Certificate(parametro.certificado.getX509Certificate2());
            X509DataXML.AppendChild(X509CertificateXML);

            KeyInfoXMl.AppendChild(X509DataXML);

            //KeyInfo



            Signature.AppendChild(SignedInfoxml);

            Signature.AppendChild(SignatureValuexml);

            Signature.AppendChild(KeyInfoXMl);



            xmlDocumentSignature.AppendChild(Signature);



            return(Signature);
        }