Exemple #1
0
        /// <summary>
        ///     It works as a fully autonomus function regards to reading from EDI file,
        ///     because the real EDI file parsing is possible only after the separator parsing.
        /// </summary>
        /// <param name="inputFileName"></param>
        /// <param name="errors"></param>
        /// <param name="segmentSeparator">
        ///     It can be a magic value 'C'. It means CR+LF line separator. We use CR+LF by default.
        ///     If it is NOT 'C', we use the value of segmentSeparator.
        /// </param>
        /// <param name="dataElementSeparator"></param>
        /// <param name="dataComponentSeparator"></param>
        private static string[] GetLinesAndSeparators(IProvider fileProvider, Errors errors,
            out char segmentSeparator,
            out char dataElementSeparator, out char dataComponentSeparator)
        {
            segmentSeparator = '~';
            dataElementSeparator = '*';
            dataComponentSeparator = ':';

            // Segment separator is placed right after "ISA" tag of the first segment.
            var lines = fileProvider.ReadAllLines().ToArray();
            if (lines.Length == 0)
            {
                errors.NewError(string.Format("No text provided for parsing in the EDI file:'{0}'", fileProvider.InputAddress));
                return null;
            }

            var symbols = lines[0].ToCharArray();
            if (symbols.Length < 105)
            {
                errors.NewError(
                    string.Format("The first line of the text '{0}' is too short to get a sub-element separator",
                        lines[0]));
                return null;
            }

            dataElementSeparator = symbols[103];
            dataComponentSeparator = symbols[104];
            segmentSeparator = lines.Length > 1 ? 'C' : symbols[105];

            return lines;
        }