コード例 #1
0
        /// <summary>
        /// Processes the rebate confirmation file.
        /// </summary>
        private void ProcessRebateConfirmation()
        {
            // Deserialize rebate confirmation file into a RebateConfirmation object.
            RebateConfirmationParser rebateConfirmationParser = new RebateConfirmationParser(Context.Log);
            RebateConfirmation       rebateConfirmation       = rebateConfirmationParser.Parse(FileName, Stream);

            if (rebateConfirmation != null)
            {
                for (int count = 0; count < rebateConfirmation.DataRecords.Count; count++)
                {
                    RebateConfirmationData rebateConfirmationData = rebateConfirmation.DataRecords[count];
                    if (rebateConfirmationData != null)
                    {
                        // Mark the redemption as RejectedByPartner.
                        Context[Key.RebateConfirmationData] = rebateConfirmationData;
                        ResultCode result = RedeemedDealOperations.MarkRejectedByMasterCard();

                        // Log warning if needed.
                        switch (result)
                        {
                        case ResultCode.MatchingRedeemedDealNotFound:
                            Context.Log.Warning("RebateConfirmationData record #{0} could not be marked RejectedByPartner, because " +
                                                "no matching redemption record could be found.", (int)result, count + 1);
                            break;

                        case ResultCode.MultipleMatchingRedeemedDealsFound:
                            Context.Log.Warning("More than one matching redemption record matched RebateConfirmationData record " +
                                                "#{0}. One of these was marked RejectedByPartner, but since the data is " +
                                                "ambiguous, it may not correspond to the correct redemption.", (int)result, count + 1);
                            break;

                        case ResultCode.RedeemedDealFoundIsInexactMatch:
                            Context.Log.Warning("A matching redemption record for RebateConfirmationData record #{0} was marked " +
                                                "RejectedByPartner, but the record was not an exact match.", (int)result, count + 1);
                            break;
                        }
                        ;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses the specified rebate confirmation file into a rebate confirmation object if possible.
        /// </summary>
        /// <param name="rebateConfirmationFileName">
        /// The rebate confirmation file name to parse into a RebateConfirmation object.
        /// </param>
        /// <param name="stream">
        /// File contents as stream of data
        /// </param>
        /// <returns>
        /// * The RebateConfirmation object resulting from the parsing attempt if the specified rebate confirmation file could be found.
        /// * Otherwise returns null.
        /// </returns>
        internal RebateConfirmation Parse(string rebateConfirmationFileName,
                                          Stream stream)
        {
            RebateConfirmation     = new RebateConfirmation();
            LineNumber             = 0;
            NumberOfHeaderRecords  = 0;
            NumberOfDataRecords    = 0;
            NumberOfTrailerRecords = 0;

            if (stream != null)
            {
                FileName = Path.GetFileName(rebateConfirmationFileName);
                RebateConfirmationHeaderParser.FileName  = FileName;
                RebateConfirmationDataParser.FileName    = FileName;
                RebateConfirmationTrailerParser.FileName = FileName;
                bool loggedTrailerOutOfPlace = false;

                // Read the rebate confirmation file one line at a time and parse each line as a record.
                string recordType;
                using (StreamReader streamReader = new StreamReader(stream))
                {
                    while ((Line = streamReader.ReadLine()) != null)
                    {
                        if (Line.Length > RebateConfirmationConstants.RecordTypeLength)
                        {
                            LineNumber++;
                            recordType = Line.Substring(0, RebateConfirmationConstants.RecordTypeLength);

                            // Log a warning if the trailer record has already been parsed and a warning was not already logged.
                            if (TrailerFound == true && loggedTrailerOutOfPlace == false)
                            {
                                Log.Warning("Error parsing record in line #{0} from file \"{1}\". One or more records found  " +
                                            "after trailer record parsed.", (int)ResultCode.RecordOutOfPlace, LineNumber,
                                            FileName);
                                loggedTrailerOutOfPlace = true;
                            }

                            // Parse the record according to its type and add it to the RebateConfirmation object.
                            switch (recordType)
                            {
                            case RebateConfirmationHeaderParser.RecordType:
                                ParseHeaderRecord();
                                break;

                            case RebateConfirmationDataParser.RecordType:
                                ParseDataRecord();
                                break;

                            case RebateConfirmationTrailerParser.RecordType:
                                ParseTrailerRecord();
                                break;

                            default:
                                Log.Warning("Error parsing record in line #{0} from file \"{1}\". Encountered invalid " +
                                            "record type \"{2}\".", (int)ResultCode.ExpectedValueNotFound, LineNumber,
                                            FileName, recordType);
                                break;
                            }
                        }
                        else
                        {
                            Log.Warning("Error parsing record in line #{0} from file \"{1}\". Unexpected end of record detected.",
                                        (int)ResultCode.UnexpectedEndOfRecord, LineNumber, FileName);
                        }
                    }
                }

                // Add entries to the log if the rebate confirmation file did not have the expected number of records.
                if (RebateConfirmation.Header == null)
                {
                    Log.Warning("Header for RebateConfirmation file \"{0}\" missing or corrupted.",
                                (int)ResultCode.FileMissingExpectedRecord, rebateConfirmationFileName);
                }

                if (RebateConfirmation.DataRecords.Count == 0)
                {
                    Log.Information("RebateConfirmation file \"{0}\" contained no data records.", rebateConfirmationFileName);
                }

                if (RebateConfirmation.Trailer == null)
                {
                    Log.Warning("Trailer for rebate confirmation file \"{0}\" missing or corrupted.",
                                (int)ResultCode.FileMissingExpectedRecord, rebateConfirmationFileName);
                }
                else
                {
                    if (NumberOfDataRecords != RebateConfirmation.Trailer.ExceptionRecordCount)
                    {
                        Log.Warning("Exception record count for rebate confirmation file \"{0}\" is {1} but trailer indicated it should be {2}.",
                                    (int)ResultCode.RecordCountMismatch, rebateConfirmationFileName, NumberOfDataRecords, RebateConfirmation.Trailer.ExceptionRecordCount);
                    }
                }
            }
            else
            {
                Log.Error("RebateConfirmation file \"{0}\" could not be found.", null, (int)ResultCode.FileNotFound, rebateConfirmationFileName);
                RebateConfirmation = null;
            }

            return(RebateConfirmation);
        }