Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
0
    public static IMessage ParserFrom(short id, byte[] buffer)
    {
        ParserDelegate d = null;

        if (m_parsers.TryGetValue(id, out d))
        {
            return(d.Invoke(buffer));
        }
        return(null);
    }
Ejemplo n.º 3
0
        protected static T Read <T> (Stream stream, ParserDelegate parser, int millisecondsTimeout)
            where T : HttpBase
        {
            var timeout = false;
            var timer   = new Timer(
                state => {
                timeout = true;
                stream.Close();
            },
                null,
                millisecondsTimeout,
                -1);

            T         http      = null;
            Exception exception = null;

            try {
                http = (T)parser(readHeaders(stream, _headersMaxLength));
                var contentLen = http.Headers["Content-Length"];
                if (contentLen != null && contentLen.Length > 0)
                {
                    http.EntityBodyData = readEntityBody(stream, contentLen);
                }
            }
            catch (Exception ex) {
                exception = ex;
            }
            finally {
                timer.Change(-1, -1);
                timer.Dispose();
            }

            var msg = timeout
                ? "A timeout has occurred while reading an HTTP request/response."
                : exception != null
                  ? "An exception has occurred while reading an HTTP request/response."
                  : null;

            if (msg != null)
            {
                throw new WebSocketException(msg, exception);
            }

            return(http);
        }
Ejemplo n.º 4
0
 // Generic parsing function to re-use error handling
 private static object TryParse(ParserDelegate del, string typeName, string inputString)
 {
     try
     {
         return(del(inputString));
     }
     catch (ArgumentException e) // Will also catch ArgumentNullException
     {
         var msg = BuildParsingErrorMessage(typeName, inputString);
         throw new ArgumentException(msg, e);
     }
     catch (FormatException e)
     {
         var msg = BuildParsingErrorMessage(typeName, inputString);
         throw new ArgumentException(msg, e);
     }
     catch (OverflowException e)
     {
         var msg = BuildParsingErrorMessage(typeName, inputString);
         throw new ArgumentException(msg, e);
     }
 }
Ejemplo n.º 5
0
 // Generic parser function
 private object TryParse(ParserDelegate del, string dataType, string input)
 {
     try
     {
         return(del(RawQuantityString));
     }
     catch (ArgumentException e) // Will also catch ArgumentNullException
     {
         var msg = GetParsingErrorMsg(dataType, input);
         throw new InvalidOperationException(msg, e);
     }
     catch (FormatException e)
     {
         var msg = GetParsingErrorMsg(dataType, input);
         throw new InvalidOperationException(msg, e);
     }
     catch (OverflowException e)
     {
         var msg = GetParsingErrorMsg(dataType, input);
         throw new InvalidOperationException(msg, e);
     }
 }
Ejemplo n.º 6
0
        public static void ReadObject(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
        {
            System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ObjectStart);

            if (begin != null)
            {
                begin(context);
            }

            // parse the properties
            reader.Read();
            while (reader.Token != JsonToken.ObjectEnd)
            {
                parser(reader, context);
                reader.Read();
            }

            if (end != null)
            {
                end(context);
            }
        }
Ejemplo n.º 7
0
        private object HttpGet(string url, NameValueCollection parameters, ParserDelegate parser)
        {
            //create web request with params
            WebClient webClient = new WebClient();

            webClient.QueryString.Add(parameters);

            //add basic auth token
            string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(Username + ":" + Password));

            webClient.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;

            //call REST API and return result
            while (true)
            {
                //retry if there is any timeout etc
                try
                {
                    Stream    replyStream = webClient.OpenRead(API_BASE + url);
                    XDocument replyDoc    = XDocument.Load(replyStream);

                    return(parser(replyDoc));
                }
                catch (WebException e)
                {
                    if (e.HResult == -2146233079)
                    {
                        Thread.Sleep(1000); //retry on timeout
                    }
                    else
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 8
0
        public static void ReadArray(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
        {
            System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ArrayStart);

            // parse the elements
            reader.Read();
            while (reader.Token != JsonToken.ArrayEnd)
            {
                if (reader.Token == JsonToken.ObjectStart)
                {
                    ReadObject(reader, context, begin, parser, end);
                }
                else if (reader.Token == JsonToken.ArrayStart)
                {
                    ReadArray(reader, context, parser);
                }
                else
                {
                    parser(reader, context);
                }

                reader.Read();
            }
        }
Ejemplo n.º 9
0
 public PrimitiveParser(ParserDelegate <T> parser)
 {
     _parser = parser;
 }
Ejemplo n.º 10
0
 public Tag(ParserDelegate <T> parser) : base(typeof(T))
 {
     _parser = parser;
 }
Ejemplo n.º 11
0
 public StatementParser(ParserDelegate parse)
 {
     _parse = parse;
 }
Ejemplo n.º 12
0
        public static void ReadObject(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
        {
            System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ObjectStart);

            if (begin != null)
            {
                begin(context);
            }

            // parse the properties
            reader.Read();
            while (reader.Token != JsonToken.ObjectEnd)
            {
                parser(reader, context);
                reader.Read();
            }

            if (end != null)
            {
                end(context);
            }
        }
Ejemplo n.º 13
0
 public static void ReadArray(JsonReader reader, object context, ParserDelegate parser)
 {
     ReadArray(reader, context, null, parser, null);
 }
Ejemplo n.º 14
0
        public static void ReadArray(JsonReader reader, object context, BeginObjectDelegate begin, ParserDelegate parser, EndObjectDelegate end)
        {
            System.Diagnostics.Debug.Assert(reader.Token == JsonToken.ArrayStart);

            // parse the elements
            reader.Read();
            while (reader.Token != JsonToken.ArrayEnd)
            {
                if (reader.Token == JsonToken.ObjectStart)
                {
                    ReadObject(reader, context, begin, parser, end);
                }
                else if (reader.Token == JsonToken.ArrayStart)
                {
                    ReadArray(reader, context, parser);
                }
                else
                {
                    parser(reader, context);
                }

                reader.Read();
            }
        }
Ejemplo n.º 15
0
 public static IOption <T> TryParse <T>(string str, ParserDelegate <T> parser) =>
 parser(str, out var perhapsResult) ? Some.Of(perhapsResult) : new None <T>();
Ejemplo n.º 16
0
 public static void ReadArray(JsonReader reader, object context, ParserDelegate parser)
 {
     ReadArray(reader, context, null, parser, null);
 }