public static ItemAcknowledgement FromString(StreamReader reader)
        {
            var result = new ItemAcknowledgement();

            // first line should be header record
            var line = reader.ReadLine();

            if (line == null || line.Substring(0, 2) != ItemRecordTypes.FileHeaderRecord)
            {
                throw new ArgumentException("stream bad format");
            }

            result.Header = FileHeaderRecord.FromString(line);

            while ((line = reader.ReadLine()) != null)
            {
                var type = line.Substring(0, 2);

                if (type == ItemRecordTypes.CashLetterHeaderRecord)
                {
                    result.CashLetters.Add(new CashLetterRecord());

                    var header = CashLetterHeaderRecord.FromString(line);
                    result.CashLetters.Last().Header = header;
                }
                else if (type == ItemRecordTypes.ItemDetailRecord)
                {
                    var item = ItemDetailRecord.FromString(line);
                    result.CashLetters.Last().Details.Add(item);
                }
                else if (type == ItemRecordTypes.ItemDetailAddendumRecord)
                {
                    var addendum = ItemDetailAddendumRecord.FromString(line);
                    result.CashLetters.Last().Details.Last().Addendums.Add(addendum);
                }
                else if (type == ItemRecordTypes.CashLetterControlRecord)
                {
                    var control = CashLetterControlRecord.FromString(line);
                    result.CashLetters.Last().Control = control;
                }
                else if (type == ItemRecordTypes.FileControlRecord)
                {
                    result.Control = FileControlRecord.FromString(line);
                }
            }

            return(result);
        }
Example #2
0
        public static ReceiptAcknowledgement FromString(StreamReader reader)
        {
            var result = new ReceiptAcknowledgement();

            // first line should be header record
            var line = reader.ReadLine();

            if (line == null || line.Substring(0, 2) != ReceiptRecordTypes.FileHeaderRecord)
            {
                throw new ArgumentException("stream bad format");
            }

            result.Header = FileHeaderRecord.FromString(line);

            while ((line = reader.ReadLine()) != null)
            {
                var type = line.Substring(0, 2);

                if (type == ReceiptRecordTypes.FileDetailRecord)
                {
                    var detail = FileDetailRecord.FromString(line);
                    result.Details.Add(detail);
                }
                else if (type == ReceiptRecordTypes.FileDetailAddendumRecord)
                {
                    var addendum = FileDetailAddendumRecord.FromString(line);
                    // reference last added detail record
                    result.Details.Last().Addendums.Add(addendum);
                }
                else if (type == ReceiptRecordTypes.FileControlRecord)
                {
                    result.Control = FileControlRecord.FromString(line);
                }
            }

            return(result);
        }