public IMarketFileExportResult[] Export(CancellationToken token) { var cspDunsPorts = clientDataAccess.ListCspDunsPort(); var prismPorts = cspDunsPorts .Where(x => x.ProviderId == 1) .ToArray(); var context = new Prism814Context(); foreach (var prismPort in prismPorts) { if (token.IsCancellationRequested) { break; } var headers = exportDataAccess.ListUnprocessed(prismPort.LdcDuns, prismPort.Duns, 1); if (headers.Length == 0) { logger.TraceFormat("Zero 814 Prism records found to export for TDSP Duns \"{0}\" and CR Duns \"{1}\".", prismPort.LdcDuns, prismPort.Duns); continue; } logger.DebugFormat("Exporting {0} unprocessed 814 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(); context.ActionCode = header.ActionCode; var identifiedMarket = clientDataAccess.IdentifyMarket(header.TdspDuns); if (identifiedMarket.HasValue) { context.SetMarket(identifiedMarket.Value); } if (context.ActionCode.Equals("PC", StringComparison.Ordinal) || context.ActionCode.Equals("PD", StringComparison.Ordinal) || context.Market != MarketOptions.Texas) { context.SetFileProperties(prismPort, header.TdspDuns, "ENR"); } else { context.SetFileProperties(prismPort, "183529049", "ENR"); } context.SetHeaderId(headerKey); var services = exportDataAccess.ListServices(headerKey); WriteHeader(context, header, services); WriteAccount(context, header); WriteName(context, header); WriteService(context, header, services); } } return(context.Models); }