예제 #1
0
        public decimal EvalFunctionalCcyAmt(CashFlow cf, FinActivity activityMap, List <GenLedgerFinActivityJoin> genLedgerFinActivityJoin)
        {
            // get maps that have been computed for each bank statement item
            var            fp = new FunctionParser();
            ParserDelegate TokenFAmountHandler = delegate(FunctionParseDelegateArgs e)
            {
                // e.FunctionArgs[0] will have value like, for example, 'A'
                var result = from j in genLedgerFinActivityJoin
                             where j.FinActivity.Token == e.FunctionArgs[0]
                             select j.GenLedgerKey.FunctionalCcyAmt;
                return(result.Sum());
            };

            fp.Add("FA", TokenFAmountHandler);
            var parsed = fp.ParseToCriteria(activityMap.FunctionalCcyAmtExpr.Replace("{FA}", "FunctionalCcyAmt"));

            try
            {
                object  exprResult = cf.Evaluate(CriteriaOperator.Parse(parsed.Criteria, parsed.Parameters));
                decimal famt       = 0.00M;
                if (exprResult != null && Decimal.TryParse(exprResult.ToString(), out famt))
                {
                    return(famt);
                }
                return(0.00M);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(string.Format(
                                                        "Error parsing map expression = '{1}', at FinActivity.Oid = '{0}', CashFlow.Oid = '{2}'.\r\n{3}",
                                                        activityMap.Oid, activityMap.FunctionalCcyAmtExpr, cf.Oid, ex.Message),
                                                    ex);
            }
        }