public void ParseSingleLine_ParsesTestData()
        {
            // ASSERT:
            // Processor can parse individual line.

            Assert.IsNotNull(sourceBytes);
            Assert.IsTrue(sourceBytes.Any());

            processor = new EbcdicParser();

            int count    = 0;
            int position = 0;

            while (position < sourceBytes.Length)
            {
                byte[] lineBytes = ParserUtilities.ReadBytesRange(
                    sourceBytes,
                    length: lineTemplate.LineSize,
                    startPosition: position);

                position += lineTemplate.LineSize;

                var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

                if (count == 0)
                {
                    AssertDataForTheFirstRecord(parsedLine);
                }

                Debug.WriteLine(parsedLine.ToXmlString());
                count++;
            }

            Assert.IsTrue(count > 1);
        }
        public void Parse(string filePath, KickstartLineTemplate parentLayout, List <MultiFileTypeMeta> MetaData)
        {
            //Get File Information
            FileInfo info     = new FileInfo(filePath);
            string   fileName = info.FullName.Replace(info.Extension, "");

            //Create a collection of parsers
            EbcdicParser parentParser = new EbcdicParser();

            //Open File and Action
            using (FileStream reader = File.OpenRead(filePath))
            {
                ParsedLine        p;
                MultiFileTypeMeta meta;
                long   fsBytes   = (long)reader.Length;
                long   bytesRead = 0;
                byte[] bHeader   = new byte[parentLayout.LineSize];
                byte[] child;
                int    recordLength;
                string recordType;

                while (bytesRead < fsBytes)
                {
                    reader.Read(bHeader, 0, parentLayout.LineSize);
                    reader.Position = -parentLayout.LineSize;
                    p = parentParser.ParseSingleLine(parentLayout, bHeader);

                    recordType = p.ParsedFields.Where(f => f.Key == "RecordType").Select(f => f.Value.Text).First();

                    meta = MetaData.Where(md => md.DefinitionTemplate.LayoutName == recordType).First();

                    if (meta.DefinitionTemplate.VariableWidth)
                    {
                        recordLength = int.Parse(p.ParsedFields.Where(f => f.Key == "RecordLength").Select(f => f.Value.Text).First());
                        meta.DefinitionTemplate.ChangeLineSize(recordLength + meta.DefinitionTemplate.Offset);
                        child = new byte[recordLength + meta.DefinitionTemplate.Offset];
                    }
                    else
                    {
                        child = new byte[meta.DefinitionTemplate.LineSize];
                    }

                    bytesRead += reader.Read(child, 0, meta.DefinitionTemplate.LineSize);

                    if (meta.DefinitionTemplate.Import == true)
                    {
                        if (meta.DefinitionTemplate.FieldsCount > 0)
                        {
                            meta.Parser.ParseAndAddSingleLine(meta.DefinitionTemplate, child, meta.DefinitionTemplate.ChunkSize);
                            if (meta.Parser.ParsedLines.Length >= meta.DefinitionTemplate.ChunkSize)
                            {
                                meta.Parser.SaveParsedLinesAsTxtFile($"{fileName}_{recordType}.txt", "|", true, true, "¬", meta.AppendToFile);
                                meta.AppendToFile = true;
                            }
                        }
                    }
                }
                MetaData.ForEach(m => m.Parser.SaveParsedLinesAsTxtFile($"{fileName}_{m.DefinitionTemplate.LayoutName}.txt", "|", true, true, "¬", m.AppendToFile));
            }
        }
        public void ParseSingleLine_ParsesTestData()
        {
            // ASSERT:
            // Processor can parse individual line.

            var sourceBytes  = TestData.GetSampleEbcidicDataWithFixedRecordLength();
            var lineTemplate = TestData.GetLineTemplateToParseEbcidicDataWithFixedRecordLength();

            Assert.IsNotNull(sourceBytes);
            Assert.IsTrue(sourceBytes.Any());

            var processor = new EbcdicParser();

            int count    = 0;
            int position = 0;

            while (position < sourceBytes.Length)
            {
                byte[] lineBytes = ParserUtilities.ReadBytesRange(
                    sourceBytes,
                    length: lineTemplate.LineSize,
                    startPosition: position);

                position += lineTemplate.LineSize;

                var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

                if (count == 0)
                {
                    Assert.IsTrue(parsedLine[TestData.FieldReservationNumber].Equals("04416365US2"));
                    Assert.IsTrue(parsedLine[TestData.FieldCheckInDate].Equals("2015-01-23"));
                    Assert.IsTrue(parsedLine[TestData.FieldCalcNetAmount].Equals("437.39"));
                    Assert.IsTrue(parsedLine[TestData.FieldCustomerName].Equals("KAY KENG,LOW"));
                    Assert.IsTrue(parsedLine[TestData.FieldRunDate].Equals("2015-01-28"));
                    Assert.IsTrue(parsedLine[TestData.FieldCurrencyConvRate].Equals("0.762728"));
                    Assert.IsTrue(parsedLine[TestData.FieldUsDollarAmountDue].Equals("220.26"));
                    Assert.IsTrue(parsedLine[TestData.FieldDateOfBirth].Equals("1972-08-09"));
                }

                Debug.WriteLine(parsedLine.ToXmlString());
                count++;
            }

            Assert.IsTrue(count > 1);
        }
        public void Used_For_Manual_Testing()
        {
            var lineBytes    = ParserUtilities.ConvertHexStringToByteArray("F1-F5-F0-F1-F2-F3");
            var lineTemplate = new LineTemplate(lineBytes.Length);
            var fieldName    = "TEST_ITEM";

            lineTemplate.AddFieldTemplate(
                new FieldTemplate(
                    fieldName: fieldName,
                    fieldType: FieldType.DateString,
                    startPosition: 0,
                    fieldSize: lineBytes.Length,
                    decimalPlaces: 0));

            var processor = new EbcdicParser();

            var parsedLine = processor.ParseSingleLine(lineTemplate, lineBytes);

            var testOutput = parsedLine[fieldName];

            Debug.WriteLine(parsedLine.ToXmlString());
        }