Пример #1
0
        /// <summary>
        /// Add counterpayload to payloads
        /// InvalidFormatException will be catched and logged on warn level
        /// </summary>
        /// <param name="payloads"></param>
        /// <param name="nbr"></param>
        /// <param name="value"></param>
        /// <param name="balancedParentheses">check on number of '(' is equal to number of ')'</param>
        protected void AddCounterPayload(IList <BasePayload> payloads, int nbr, string value, bool balancedParentheses)
        {
            try
            {
                if (balancedParentheses && value != null && (value.Count('('.Equals) != value.Count(')'.Equals)))
                {
                    Log.LogWarning("Parentheses not in balance for counter {nbr}: {value}", nbr, value);
                }
                else
                {
                    var payload = new CounterPayload
                    {
                        InternalNr = nbr,
                        Value      = Parser.ReadSmartMeterCounterValue(value, nbr)
                    };

                    if (payload.Value < ulong.MaxValue)
                    {
                        payloads.Add(payload);
                    }
                }
            }
            catch (InvalidFormatException)
            {
                Log.LogWarning("Invalid syntax of value for counter {nbr}: {value} not in format XXXXX.XXX", nbr, value);
            }
        }
Пример #2
0
        /// <summary>
        /// Add counterpayload consisting of multiple values to payloads
        /// InvalidFormatException will be catched and logged on warn level
        /// </summary>
        /// <param name="payloads"></param>
        /// <param name="nbr"></param>
        /// <param name="values"></param>
        /// <param name="balancedParentheses">check on number of '(' is equal to number of ')'</param>
        protected void AddCounterPayload(IList <BasePayload> payloads, int nbr, List <string> values, bool balancedParentheses)
        {
            if (!values.Any())
            {
                return;
            }

            var payload = new CounterPayload
            {
                InternalNr = nbr
            };

            foreach (var value in values)
            {
                if (balancedParentheses && value != null && (value.Count('('.Equals) != value.Count(')'.Equals)))
                {
                    Log.LogWarning("Parentheses not in balance for counter {nrb}: {value}", nbr, value);
                    return;
                }

                try
                {
                    payload.Value += Parser.ReadSmartMeterCounterValue(value, nbr);
                }
                catch (InvalidFormatException)
                {
                    Log.LogWarning("Invalid syntax of value for counter {nrb}: {value} not in format XXXXX.XXX", nbr, value);
                    return;
                }
            }

            if (payload.Value < ulong.MaxValue)
            {
                payloads.Add(payload);
            }
        }