Ejemplo n.º 1
0
        public void SetFileProperties(CspDunsPortModel model, string ldcCode, string tradingPartnerId, string tdspDuns, string suffix)
        {
            var partnerId = tradingPartnerId
                            .Replace("{DUNS}", tdspDuns);

            LdcCode          = ldcCode;
            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 Export810Model(false)
            {
                LdcId            = model.LdcId ?? 0,
                CspDunsId        = model.CspDunsId,
                CspDuns          = string.Empty,
                LdcDuns          = string.Empty,
                LdcShortName     = LdcCode,
                TradingPartnerId = TradingPartnerId,
            };

            models.Add(currentModel);
        }
Ejemplo n.º 2
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 Export810Model
                {
                    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}\". 810 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 810 Xml records found to export for TDSP Duns \"{0}\" and CR Duns \"{1}\".",
                                       xmlPort.LdcDuns, xmlPort.Duns);
                    continue;
                }

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

                XNamespace marketNamespace = "http://CIS.Integration.Schema.Market.Common.Market810";
                var        document        = new XDocument(
                    new XElement(marketNamespace + "Market810",
                                 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 810 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());
        }