/// <summary>
        /// Map fields group object
        /// </summary>
        /// <param name="value"></param>
        /// <param name="fieldsGroup"></param>
        /// <param name="writtenNumbers"></param>
        /// <returns></returns>
        private List <object> MapFieldsGroup(object value, FieldsGroup fieldsGroup, IDictionary <string, decimal> writtenNumbers)
        {
            List <object> result = new List <object>();

            if (fieldsGroup.HasDependencies() || fieldsGroup.Occurs > 1)
            {
                MapCollection(result, fieldsGroup, writtenNumbers, (dynamic)value);
            }
            else
            {
                result = MapFieldsList(value, fieldsGroup, writtenNumbers);
            }
            return(result);
        }
Example #2
0
        /// <summary>
        /// Compute the fields group size
        /// </summary>
        /// <param name="field"></param>
        /// <param name="fieldsGroup"></param>
        /// <returns></returns>
        private int GetFieldsGroupSize(object field, FieldsGroup fieldsGroup)
        {
            int size = 0;

            if (fieldsGroup.HasDependencies() || fieldsGroup.Occurs > 1)
            {
                //linq converted
                size += ((List <object>)field).Sum(item => GetFieldsListSize((List <object>)item, fieldsGroup));
            }
            else
            {
                size = GetFieldsListSize((List <object>)field, fieldsGroup);
            }
            return(size);
        }
Example #3
0
 /// <summary>
 /// Write field groups
 /// </summary>
 /// <param name="field"></param>
 /// <param name="fieldsGroup"></param>
 /// <exception cref="IOException">&nbsp;</exception>
 /// <exception cref="EbcdicException">&nbsp;</exception>
 private void WriteFieldsGroup(object field, FieldsGroup fieldsGroup)
 {
     if (fieldsGroup.HasDependencies() || fieldsGroup.Occurs > 1)
     {
         // if occurs is more than one or variable, we have a list of lists
         foreach (object item in (List <object>)field)
         {
             WriteFields((List <object>)item, fieldsGroup);
         }
     }
     else
     {
         WriteFields((List <object>)field, fieldsGroup);
     }
 }
Example #4
0
        /// <summary>
        /// read a fields group
        /// </summary>
        /// <param name="fieldsGroup"></param>
        /// <param name="readNumericValues"></param>
        /// <returns></returns>
        /// <exception cref="IOException"></exception>
        /// <exception cref="EbcdicException"></exception>
        private List <object> ReadFieldsGroup(FieldsGroup fieldsGroup, IDictionary <string, decimal> readNumericValues)
        {
            List <object> values = new List <object>();
            int           occurs;

            if (fieldsGroup.HasDependencies())
            {
                if (readNumericValues.ContainsKey(fieldsGroup.DependingOn))
                {
                    occurs = Decimal.ToInt32(readNumericValues[fieldsGroup.DependingOn]);
                }
                else
                {
                    throw new System.Exception(
                              string.Format("Check your copybook :[{0}] is not present, but field format says it has dependencies ...",
                                            fieldsGroup.DependingOn));
                }
            }
            else
            {
                occurs = fieldsGroup.Occurs;
            }

            for (int i = 0; i < occurs; i++)
            {
                values.Add(ReadFields(fieldsGroup));
            }

            if (fieldsGroup.HasDependencies() || occurs > 1)
            {
                // if occurs is more than one or variable, return results in a list
                return(values);
            }
            else
            {
                // otherwise, just return the single item
                return((List <object>)values[0]);
            }
        }
 /// <summary>
 /// dynamic types handling
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="result"></param>
 /// <param name="fieldsGroup"></param>
 /// <param name="writtenNumbers"></param>
 /// <param name="value"></param>
 private void MapCollection <T>(List <object> result, FieldsGroup fieldsGroup, IDictionary <string, decimal> writtenNumbers, List <T> value)
 {
     result.AddRange(value.Select(item => MapFieldsList(item, fieldsGroup, writtenNumbers)));
 }