/// <summary> /// Parse the Response file /// </summary> /// <param name="fileName"> /// Name of the file being parsed /// </param> /// <param name="stream"> /// Stream of data capturing the contents /// </param> /// <returns> /// Instance of Response File /// </returns> public OfferRegistrationResponseFile Parse(string fileName, Stream stream) { OfferRegistrationResponseFile responseFile = new OfferRegistrationResponseFile(); string recordType; OfferRegistrationResponseHeader header = null; OfferRegistrationResponseTrailer trailer = null; Collection <OfferRegistrationResponseDetail> detailRecords = new Collection <OfferRegistrationResponseDetail>(); if (stream != null) { using (StreamReader reader = new StreamReader(stream)) { string headerStr = reader.ReadLine(); header = new OfferRegistrationResponseHeader(headerStr); while ((Line = reader.ReadLine()) != null) { recordType = Line.Substring(0, 1); if (recordType == "D") { OfferRegistrationResponseDetail details = new OfferRegistrationResponseDetail(Line); detailRecords.Add(details); } if (recordType == "T") { trailer = new OfferRegistrationResponseTrailer(Line); // should be last line break; } } } } // verify integrity if (trailer.TrailerCount != detailRecords.Count) { Log.Warning("Number of Records suggested by trailer Amex Offer Registration Response file \"{0}\" do not match.", (int)ResultCode.FileMissingExpectedRecord, fileName); } responseFile.Header = header; responseFile.Trailer = trailer; foreach (OfferRegistrationResponseDetail detailRecord in detailRecords) { responseFile.ResponseRecords.Add(detailRecord); } return(responseFile); }
/// <summary> /// Parse the Response file /// </summary> /// <param name="fileName"> /// Name of the file being parsed /// </param> /// <param name="stream"> /// Stream of data capturing the contents /// </param> /// <returns> /// Instance of Response File /// </returns> public OfferRegistrationResponseFile Parse(string fileName, Stream stream) { OfferRegistrationResponseFile responseFile = new OfferRegistrationResponseFile(); OfferRegistrationResponseHeader header = null; OfferRegistrationResponseTrailer trailer = null; Collection <OfferRegistrationResponseDetail> detailRecords = new Collection <OfferRegistrationResponseDetail>(); if (stream != null) { using (StreamReader reader = new StreamReader(stream)) { string line; while ((line = reader.ReadLine()) != null) { string recordType = line.Substring(0, 1); switch (recordType) { case "H": header = new OfferRegistrationResponseHeader(line); break; case "D": detailRecords.Add(new OfferRegistrationResponseDetail(line)); break; case "T": trailer = new OfferRegistrationResponseTrailer(line); break; } } } } // verify integrity if (trailer != null && trailer.TrailerCount != detailRecords.Count) { Log.Warning("Number of Records suggested by trailer Amex Offer Registration Response file \"{0}\" do not match.", (int)ResultCode.FileMissingExpectedRecord, fileName); } responseFile.Header = header; responseFile.Trailer = trailer; foreach (OfferRegistrationResponseDetail detailRecord in detailRecords) { responseFile.ResponseRecords.Add(detailRecord); } return(responseFile); }