Exemple #1
0
        public void SetFileProperties(CspDunsPortModel model, string tdspDuns, string suffix)
        {
            var partnerId = model.TradingPartnerId
                            .Replace("{DUNS}", tdspDuns);

            LdcCode          = model.LdcShortName;
            TradingPartnerId = string.Concat(partnerId, suffix);

            var existingModel = models.FirstOrDefault(x =>
                                                      x.LdcShortName.Equals(LdcCode) &&
                                                      x.TradingPartnerId.Equals(TradingPartnerId));

            if (existingModel != null)
            {
                currentModel = existingModel;
                return;
            }

            currentModel = new Export814Model(false)
            {
                LdcId            = model.LdcId ?? 0,
                CspDunsId        = model.CspDunsId,
                CspDuns          = string.Empty,
                LdcDuns          = string.Empty,
                LdcShortName     = LdcCode,
                TradingPartnerId = TradingPartnerId,
            };

            models.Add(currentModel);
        }
Exemple #2
0
        public IMarketFileExportResult[] Export(CancellationToken token)
        {
            var cspDunsPorts = clientDataAccess.ListCspDunsPort();
            var cspDunsPort  = cspDunsPorts
                               .Where(x => x.ProviderId == 3)
                               .ToArray();

            var collection = new List <IMarketFileExportResult>();

            foreach (var port in cspDunsPort)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }


                var partner = marketDataAccess.LoadCspDunsTradingPartner(port.Duns, port.LdcDuns);
                if (partner == null)
                {
                    logger.ErrorFormat(
                        "No CSP DUNS Trading Partner record exists between CR DUNS \"{0}\" and LDC DUNS \"{1}\". 814 Transactions will not be exported.",
                        port.Duns, port.LdcDuns);

                    continue;
                }

                marketDataAccess.LoadCspDunsTradingPartnerConfig(partner);

                var headers = exportDataAccess.ListUnprocessed(port.LdcDuns, port.Duns, 3);
                if (headers.Length == 0)
                {
                    logger.TraceFormat("Zero 814 records found to export for TDSP Duns \"{0}\" and CR Duns \"{1}\".",
                                       port.LdcDuns, port.Duns);
                    continue;
                }



                var distinctActionCodes = headers.Select(x => new { x.ActionCode }).Distinct().ToList();


                //we need to loop for each action code and based on that generate a file
                foreach (var uniqueValue in distinctActionCodes)
                {
                    var value = uniqueValue;

                    var headerList = new List <Type814Header>();

                    foreach (var header in headers)
                    {
                        if (header.ActionCode.Trim().ToUpper() == value.ActionCode.Trim().ToUpper())
                        {
                            headerList.Add(header);
                        }
                    }

                    if (headerList.Count <= 0)
                    {
                        continue;
                    }

                    var model = new Export814Model
                    {
                        CspDuns              = port.Duns,
                        LdcDuns              = port.LdcDuns,
                        LdcShortName         = port.LdcShortName,
                        TradingPartnerId     = port.TradingPartnerId,
                        ForSsxContent        = true,
                        UniqueFileNameFiller = string.Format("{0}_SSX", value.ActionCode.Trim())
                    };

                    model.CspDunsTradingPartnerId = partner.CspDunsTradingPartnerId;

                    var fileContentBuilder = BuildFileContent(headerList, port);

                    model.Content = fileContentBuilder.ToString();
                    model.AddHeaderKeys(headerList.Where(x => x.HeaderKey.HasValue).Select(x => x.HeaderKey.Value).ToList().ToArray());

                    collection.Add(model);
                }//loop for each Action Code combination
            }

            return(collection.ToArray());
        }
Exemple #3
0
        public IMarketFileExportResult[] Export(CancellationToken token)
        {
            var cspDunsPorts = clientDataAccess.ListCspDunsPort();
            var xmlPorts     = cspDunsPorts
                               .Where(x => x.ProviderId == 2)
                               .ToArray();

            var collection = new List <IMarketFileExportResult>();

            foreach (var xmlPort in xmlPorts)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }

                var model = new Export814Model
                {
                    CspDuns          = xmlPort.Duns,
                    LdcDuns          = xmlPort.LdcDuns,
                    LdcShortName     = xmlPort.LdcShortName,
                    TradingPartnerId = xmlPort.TradingPartnerId,
                };

                var partner = marketDataAccess.LoadCspDunsTradingPartner(xmlPort.Duns, xmlPort.LdcDuns);
                if (partner == null)
                {
                    logger.ErrorFormat(
                        "No CSP DUNS Trading Partner record exists between CR DUNS \"{0}\" and LDC DUNS \"{1}\". 814 Transactions will not be exported.",
                        xmlPort.Duns, xmlPort.LdcDuns);

                    continue;
                }

                marketDataAccess.LoadCspDunsTradingPartnerConfig(partner);
                model.CspDunsTradingPartnerId = partner.CspDunsTradingPartnerId;

                var headers = exportDataAccess.ListUnprocessed(xmlPort.LdcDuns, xmlPort.Duns, 2);
                if (headers.Length == 0)
                {
                    logger.TraceFormat("Zero 814 Xml records found to export for TDSP Duns \"{0}\" and CR Duns \"{1}\".",
                                       xmlPort.LdcDuns, xmlPort.Duns);
                    continue;
                }

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

                XNamespace marketNamespace = "http://CIS.Integration.Schema.Market.Common.Market814";
                var        document        = new XDocument(
                    new XElement(marketNamespace + "Market814",
                                 new XAttribute(XNamespace.Xmlns + "ns0", marketNamespace),
                                 new XElement("TransactionCount", model.HeaderCount),
                                 new XElement("LdcIsaQualifier", partner.GetConfig("TradingPartnerISAQualifier")),
                                 new XElement("LdcIsaIdentifier", partner.GetConfig("TradingPartnerISAIdentifier")),
                                 new XElement("LdcDuns", partner.TradingPartnerDuns),
                                 new XElement("CspIsaQualifier", partner.GetConfig("CspISAQualifier")),
                                 new XElement("CspDuns", partner.CspDuns),
                                 new XElement("MarketFileId", string.Empty),
                                 new XElement("LdcGSIdentifier", partner.GetConfig("TradingPartnerGSIdentifier")),
                                 new XElement("LdcN1Qualifier", partner.GetConfig("TradingPartnerN1Qualifier")),
                                 new XElement("CspN1Qualifier", partner.GetConfig("CspN1Qualifier")),
                                 new XElement("AuthInfoQualifier", string.Empty),
                                 new XElement("AuthInfo", string.Empty),
                                 new XElement("SecurityInfoQualifier", string.Empty),
                                 new XElement("SecurityInfo", string.Empty),
                                 new XElement("InterchangeControlNbr", string.Empty),
                                 new XElement("AckRequested", string.Empty),
                                 new XElement("TestIndicator", string.Empty),
                                 new XElement("SubelementSeparator", partner.GetConfig("TradingPartnerSubElementDelimiter")),
                                 new XElement("FunctionalGroup", "GE"),
                                 new XElement("FunctionalGroupControlNbr", string.Empty),
                                 new XElement("CspIsaIdentifier", partner.GetConfig("CspIsaIdentifier")),
                                 new XElement("CspGSIdentifier", partner.GetConfig("CspGSIdentifier"))));

                if (document.Root == null)
                {
                    logger.Error("Unable to create 814 XML document. Root node element is null.");
                    continue;
                }

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

                    if (token.IsCancellationRequested)
                    {
                        break;
                    }

                    var element = new XElement("Transaction",
                                               new XElement("SegmentCount", "0"));

                    WriteHeader(element, header);
                    model.AddHeaderKey(header.HeaderKey.Value);

                    document.Root.Add(element);
                }

                model.Document = document;
                collection.Add(model);
            }

            return(collection.ToArray());
        }