Пример #1
0
        public void WriteHeader(Prism824Context context, Type824Header header)
        {
            var line = string.Format("SH|{0}|{1}|O|", context.TradingPartnerId, header.TransactionNbr);

            context.AppendLine(line);
            logger.TraceFormat("Wrote 824 \"SH\" PRISM line for Header {0}", header.HeaderKey);
        }
Пример #2
0
        public void ParseTransaction(Prism824Context context, string[] marketFields)
        {
            var model = new Type824Header
            {
                TransactionDate   = context.TransactionDate,
                TransactionNbr    = context.TransactionNumber,
                ActionCode        = context.TransactionTypeCode,
                CrDuns            = context.CrDuns,
                CrName            = context.CrName,
                TdspDuns          = context.TdspDuns,
                TdspName          = context.TdspName,
                AppAckCode        = marketFields.AtIndex(2),
                TransactionSetNbr = marketFields.AtIndex(4),
                ReferenceNbr      = marketFields.AtIndex(3),
            };

            var identifiedMarket = clientDataAccess.IdentifyMarket(model.TdspDuns);

            if (identifiedMarket.HasValue)
            {
                context.SetMarket(identifiedMarket.Value);
            }

            model.MarketId   = context.MarketId;
            model.ProviderId = 1;

            model.EsiId = context.PremiseNumber;
            if (context.Market == MarketOptions.Texas)
            {
                model.EsiId = marketFields.AtIndex(9);
            }

            context.PushModel(model);
        }
Пример #3
0
        public string IdentifyEsiId(Prism824Context context, Type824Header header)
        {
            if (context.Market == MarketOptions.Maryland)
            {
                return(string.Empty);
            }

            return(header.EsiId);
        }
Пример #4
0
        public void WriteTransactionInfo(Prism824Context context, Type824Header header)
        {
            var esiId = IdentifyEsiId(context, header);

            var line = string.Format("10|{0}|{1}|{2}|{3}|||||{4}||", context.TradingPartnerId, header.AppAckCode,
                                     header.ReferenceNbr, header.TransactionSetNbr, esiId);

            context.AppendLine(line);
            logger.TraceFormat("Wrote 824 \"10\" PRISM line for Header {0}", header.HeaderKey);
        }
Пример #5
0
 public void ParseHeader(Prism824Context context, string[] marketFields)
 {
     context.TransactionTypeCode = marketFields.AtIndex(5);
     context.TransactionDate     = marketFields.AtIndex(3);
     context.TransactionNumber   = marketFields.AtIndex(4);
     context.TdspName            = marketFields.AtIndex(6);
     context.TdspDuns            = marketFields.AtIndex(7);
     context.CrName        = marketFields.AtIndex(12);
     context.CrDuns        = marketFields.AtIndex(13);
     context.PremiseNumber = marketFields.AtIndex(20);
 }
Пример #6
0
        public void WriteReason(Prism824Context context, Type824Header header)
        {
            if (!header.HeaderKey.HasValue)
            {
                return;
            }

            var headerKey = header.HeaderKey.Value;
            var reasons   = marketDataAccess.ListReasons(headerKey);

            foreach (var reason in reasons)
            {
                var line = string.Format("20|{0}|{1}|{2}|", context.TradingPartnerId, reason.ReasonCode,
                                         reason.ReasonText);

                context.AppendLine(line);
                logger.TraceFormat("Wrote 824 \"20\" PRISM line for Header {0}", header.HeaderKey);
            }
        }
Пример #7
0
        public void ParseLine(Prism824Context context, string line)
        {
            if (string.IsNullOrWhiteSpace(line))
            {
                return;
            }

            if (line.Length < 2)
            {
                return;
            }

            var indicator    = line.Substring(0, 2);
            var marketFields = line.Split('|');

            switch (indicator)
            {
            case "SH":
                context.ResolveToHeader();
                context.Initialize();
                context.TransactionActualCount++;
                marketFields.TryAtIndex(3, x => context.Alias = x);
                break;

            case "01":
                ParseHeader(context, marketFields);
                break;

            case "10":
                ParseTransaction(context, marketFields);
                break;

            case "20":
                ParseReason(context, marketFields);
                break;

            case "TL":
                context.ResolveToHeader();
                marketFields.TryAtIndexInt(1, x => context.TransactionAuditCount = x);
                break;
            }
        }
Пример #8
0
        public void WriteHeaderData(Prism824Context context, Type824Header header)
        {
            var clearingHouseName = string.Empty;
            var clearingHouseDuns = string.Empty;

            if (context.Market == MarketOptions.Texas)
            {
                clearingHouseName = "ERCOT";
                clearingHouseDuns = "183529049";
            }

            var partnerId = context.TradingPartnerId;
            var stateId   = partnerId.Substring(3, 2);

            var line = string.Format("01|{0}|{1}|{2}|{3}|{4}|{5}|{6}|||||{7}|{8}|||||||||||{9}|{10}|", partnerId,
                                     stateId, header.TransactionDate, header.TransactionNbr, header.ActionCode, header.TdspName,
                                     header.TdspDuns, header.CrName, header.CrDuns, clearingHouseName, clearingHouseDuns);

            context.AppendLine(line);
            logger.TraceFormat("Wrote 824 \"01\" PRISM line for Header {0}", header.HeaderKey);
        }
Пример #9
0
        public IMarketFileParseResult Parse(Stream stream)
        {
            var context = new Prism824Context();

            using (var reader = new StreamReader(stream))
            {
                string marketFileLine;
                while ((marketFileLine = reader.ReadLine()) != null)
                {
                    ParseLine(context, marketFileLine);
                }
            }

            if (context.ShouldResolve)
            {
                logger.Warn("Unresolved data identified after parsing 824. Transactions may not be completed.");
                context.ResolveToHeader();
            }

            return(context.Results);
        }
Пример #10
0
        public void ParseReason(Prism824Context context, string[] marketFields)
        {
            var current = context.Current;

            if (current == null || current.ModelType != Type824Types.Header)
            {
                throw new InvalidOperationException();
            }

            var header = current as Type824Header;

            if (header == null)
            {
                throw new InvalidOperationException();
            }

            var model = new Type824Reason
            {
                ReasonCode = marketFields.AtIndex(2),
                ReasonText = marketFields.AtIndex(3),
            };

            header.AddReason(model);
        }
Пример #11
0
        public IMarketFileExportResult[] Export(CancellationToken token)
        {
            var cspDunsPorts = clientDataAccess.ListCspDunsPort();
            var prismPorts   = cspDunsPorts
                               .Where(x => x.ProviderId == 1)
                               .ToArray();

            var context = new Prism824Context();

            foreach (var prismPort in prismPorts)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }

                var headers = marketDataAccess.ListUnprocessed(prismPort.LdcDuns, prismPort.Duns, 1);
                if (headers.Length == 0)
                {
                    logger.TraceFormat("Zero 824 Prism records found to export for TDSP Duns \"{0}\" and CR Duns \"{1}\".",
                                       prismPort.LdcDuns, prismPort.Duns);
                    continue;
                }

                logger.DebugFormat("Exporting {0} unprocessed 824 record(s) for TDSP Duns \"{1}\" and CR Duns \"{2}\".",
                                   headers.Length, prismPort.LdcDuns, prismPort.Duns);

                foreach (var header in headers)
                {
                    if (!header.HeaderKey.HasValue)
                    {
                        continue;
                    }

                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    var headerKey = header.HeaderKey.Value;

                    context.Initialize();

                    var identifiedMarket = clientDataAccess.IdentifyMarket(header.TdspDuns);
                    if (identifiedMarket.HasValue)
                    {
                        context.SetMarket(identifiedMarket.Value);
                    }

                    context.SetFileProperties(prismPort, header.TdspDuns, "ADV");
                    context.SetHeaderId(headerKey);

                    WriteHeader(context, header);
                    WriteHeaderData(context, header);
                    WriteTransactionInfo(context, header);
                    WriteReason(context, header);
                }
            }

            return(context.Models);
        }