public TransmitResult PostFileHttp(string fileName, CspDunsPortModel port) { var cspDuns = clientDataAccess.LoadDunsByCspDunsId(port.CspDunsId); if (string.IsNullOrWhiteSpace(cspDuns)) { var message = string.Format("CspDuns not found for CSPDUNSID \"{0}\".", port.CspDunsId); logger.Error(message); return(new TransmitResult { Message = message, Transmitted = false, }); } switch (port.Protocol.ToUpper()) { case "GISB1.4": var gisbProtocol = new ProtocolGisbHttp(); return(gisbProtocol.TransmitFile(fileName, port.FtpRemoteServer, port.FtpUserId, port.FtpPassword, cspDuns, port.GisbCommonCode)); case "NAESB1.6": var naesbProtocol = new ProtocolNaesbHttp(); return(naesbProtocol.TransmitFile(fileName, port.FtpRemoteServer, port.FtpUserId, port.FtpPassword, cspDuns, port.GisbCommonCode)); } return(new TransmitResult { Message = string.Empty, Transmitted = false, }); }
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 Export650Model(false) { LdcId = model.LdcId ?? 0, CspDunsId = model.CspDunsId, CspDuns = string.Empty, LdcDuns = string.Empty, LdcShortName = LdcCode, TradingPartnerId = TradingPartnerId, }; models.Add(currentModel); }
private StringBuilder BuildFileContent(List <Type814Header> headers, CspDunsPortModel cspDunsPort) { var ldcModel = clientDataAccess.LoadLdcById(cspDunsPort.LdcId.HasValue ? cspDunsPort.LdcId.Value: 0); var contentBuilder = new StringBuilder(); var rootLevelColumns = string.Format("{0},{1},{2}", "LdcDuns", "LdcName", "CspDuns"); var rootLevelData = string.Format("{0},{1},{2}", cspDunsPort.LdcDuns, ldcModel.LdcName, cspDunsPort.Duns); var headerLines = GetHeaderLines(headers); for (var i = 0; i < headerLines.Count; i++) { //header row if (i == 0) { //add header row contentBuilder.AppendLine(string.Format("{0},{1}", rootLevelColumns, headerLines[i])); } else { //add data rows contentBuilder.AppendLine(string.Format("{0},{1}", rootLevelData, headerLines[i])); } } return(contentBuilder); }
public TransmitResult TransmitFile(FileInfo targetFile, CspDunsPortModel port) { switch (port.Protocol) { case "FTP": return(PostFileFtp(targetFile.FullName, port)); case "GISB1.4": case "NAESB1.6": return(PostFileHttp(targetFile.FullName, port)); case "SOAP": return(PostFileSoap(targetFile.FullName, port)); } var message = string.Format("Unsupported protocol \"{0}\" found for Port \"{1}\".", port.Protocol, port.PortId); logger.Error(message); return(new TransmitResult { Message = message, Transmitted = false, }); }
public TransmitResult PostFileFtp(string fileName, CspDunsPortModel port) { var ftpRemoteDirectory = fileName.Contains("_MTCR") ? "custbill" : string.Empty; var ftpProtocol = new ProtocolFtp(); return(ftpProtocol.TransmitFile(fileName, port.FtpRemoteServer, ftpRemoteDirectory, port.FtpUserId, port.FtpPassword)); }
public void EncryptFiles(ErcotFileContext context, CspDunsPortModel port, MarketFileModel[] models, CancellationToken token) { var pgpEncryption = InfrastructureFactory.CreatePgpEncryptor(port.PgpEncryptionKey, port.PgpSignatureKey, port.PgpPassphrase); var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; foreach (var marketFile in models) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var sourcePath = Path.Combine(context.DirectoryDecrypted, marketFile.FileName); var sourceInfo = new FileInfo(sourcePath); if (!sourceInfo.Exists) { logger.WarnFormat("Unable to encrypt file \"{0}\". File does not exist or has been deleted.", marketFile.FileName); continue; } try { using (var scope = new TransactionScope(TransactionScopeOption.Required, options)) { var archivePath = Path.Combine(context.DirectoryArchive, DateTime.Now.ToString("yyyyMM"), marketFile.FileName); sourceInfo.CopyTo(archivePath, true); var targetPath = Path.Combine(context.DirectoryEncrypted, marketFile.FileName); var targetName = string.Concat(targetPath, ".pgp"); pgpEncryption.EncryptFile(sourceInfo.FullName, targetName); marketFile.Status = MarketFileStatusOptions.Encrypted; marketFile.ProcessDate = DateTime.Now; marketDataAccess.UpdateMarketFile(marketFile); scope.Complete(); } } catch (Exception ex) { logger.ErrorFormat(ex, "Unknown error occurred while encrypting file \"{0}\".", marketFile.FileName); } } }
public void TransportFiles(ErcotFileContext context, CspDunsPortModel port, MarketFileModel[] models, CancellationToken token) { var configuration = new SecureBlackboxFtpConfiguration { FtpRemoteServer = port.FtpRemoteServer, FtpRemoteDirectory = string.Empty, FtpUsername = port.FtpUserId, FtpPassword = port.FtpPassword, FtpPort = 21, FtpSsl = false, }; var ftpHandler = new SecureBlackboxFtpHandler(configuration); var options = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; foreach (var marketFile in models) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } var fileName = string.Concat(marketFile.FileName, ".pgp"); var targetPath = Path.Combine(context.DirectoryEncrypted, fileName); var targetInfo = new FileInfo(targetPath); if (!targetInfo.Exists) { logger.WarnFormat("Unable to FTP file \"{0}\". File does not exist or has been deleted.", fileName); continue; } try { var ftpOutPath = Path.Combine(port.DirectoryOut, fileName); targetInfo.CopyTo(ftpOutPath, true); var ftpOutInfo = new FileInfo(ftpOutPath); if (!ftpOutInfo.Exists) { logger.WarnFormat("Unable to FTP file \"{0}\". File could not be copied to output directory.", fileName); continue; } logger.InfoFormat("Trasmitting file \"{0}\" to FTP Server \"{1}\".", ftpOutPath, port.FtpRemoteServer); using (var scope = new TransactionScope(TransactionScopeOption.Required, options)) { ftpHandler.SendFiles("/custbill", port.DirectoryOut, name => name.Equals(fileName, StringComparison.OrdinalIgnoreCase)); var completedPath = Path.Combine(port.DirectoryOut, @"\Complete\", ftpOutInfo.Name); var completedInfo = new FileInfo(completedPath); if (completedInfo.Exists) { completedInfo.Delete(); } ftpOutInfo.MoveTo(completedPath); var encryptedArchivePath = Path.Combine(context.DirectoryArchive, @"\Encrypted\", targetInfo.Name); targetInfo.MoveTo(encryptedArchivePath); marketFile.Status = MarketFileStatusOptions.Transmitted; marketFile.ProcessDate = DateTime.Now; marketDataAccess.UpdateMarketFile(marketFile); scope.Complete(); } } catch (Exception ex) { logger.ErrorFormat(ex, "Unknown error occurred while transmitting file \"{0}\".", fileName); } } }
public void Should_Produce_The_Same_Content_As_A_Sample_File() { const string expectedContent = @"SH|SELTX183529049ENR|2276133|D|O| 01|SELTX183529049ENR|TX|Q|2276133||957877905|CENTERPOINT ENERGY|148055531|STARTEX POWER||20130309|||||24|ERCOT|183529049| 05|SELTX183529049ENR|8R|COTTONWOOD CAPITAL PROPERTY MANAGEMENT II LLC AS AGENT FOR T||||12700 STAFFORD RD BS2||STAFFORD|TX|77477|||2815648277|2815648277|FRANK MILLER|||||| 10|SELTX183529049ENR|EL|CE|MVO|1|D|||||||||||||||||||||||||||||||||||||1008901023817063480105|||||||||||||||| 11|SELTX183529049ENR|||||||||||||||20130312|||| TL|1"; // arrange var port = new CspDunsPortModel { CspDunsId = 1, CspDunsPortId = 1, Duns = "148055531", LdcDuns = string.Empty, LdcShortName = string.Empty, TradingPartnerId = "SELTX{DUNS}", ProviderId = 1, FileType = string.Empty, }; var header = new Type814Header { HeaderKey = 3893482, TransactionSetPurposeCode = "Q", TransactionNbr = "2276133", TransactionDate = "20130309", ActionCode = "24", TdspDuns = "957877905", TdspName = "Centerpoint Energy", CrDuns = "148055531", CrName = "StarTex Power", TransactionTypeId = 13, MarketId = 1, ProviderId = 1, TransactionQueueTypeId = 1, ReferenceNbr = string.Empty, }; var name = new Type814Name { HeaderKey = 3893482, NameKey = 2470182, EntityIdType = "8R", EntityName = "COTTONWOOD CAPITAL PROPERTY MANAGEMENT II LLC AS AGENT FOR T", EntityName2 = string.Empty, EntityName3 = string.Empty, Address1 = "12700 STAFFORD RD BS2", Address2 = string.Empty, City = "STAFFORD", State = "TX", PostalCode = "77477", ContactName = "FRANK MILLER", ContactPhoneNbr1 = "281-564-8277", ContactPhoneNbr2 = string.Empty, EntityFirstName = string.Empty, EntityLastName = "Cottonwood Capital Property Management II LLC as ", EntityEmail = string.Empty, }; var service = new Type814Service { HeaderKey = 3893482, ServiceKey = 3892992, ServiceTypeCode1 = "SH", ServiceType1 = "EL", ServiceTypeCode2 = "SH", ServiceType2 = "CE", ServiceTypeCode3 = "SH", ServiceType3 = "MVO", MaintenanceTypeCode = "002", EsiId = "1008901023817063480105", SpecialNeedsIndicator = "N", SpecialReadSwitchDate = "20130312", EspAccountNumber = "291920", PaymentOption = "N", }; clientDataAccess.Expect(x => x.ListCspDunsPort()) .Return(new[] { port }); clientDataAccess.Expect(x => x.IdentifyMarket(Arg <string> .Is.Anything)) .Return(1); exportDataAccess.Expect(x => x.ListUnprocessed(Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg.Is(1))) .Return(new[] { header }); exportDataAccess.Expect(x => x.ListNames(Arg <int> .Is.Anything)) .Return(new[] { name }); exportDataAccess.Expect(x => x.ListServices(Arg <int> .Is.Anything)) .Return(new[] { service }); exportDataAccess.Stub(x => x.ListServiceStatuses(Arg <int> .Is.Anything)) .Return(new Type814ServiceStatus[0]); exportDataAccess.Stub(x => x.ListServiceRejects(Arg <int> .Is.Anything)) .Return(new Type814ServiceReject[0]); exportDataAccess.Stub(x => x.ListServiceMeters(Arg <int> .Is.Anything)) .Return(new Type814ServiceMeter[0]); // act var results = concern.Export(CancellationToken.None); // assert Assert.IsNotNull(results); Assert.AreEqual(1, results.Length); var result = results[0]; Assert.IsNotNull(result); Assert.AreEqual(1, result.HeaderCount); CollectionAssert.Contains(result.HeaderKeys, 3893482); result.FinalizeDocument(1); Assert.AreEqual(expectedContent, result.Content); }
public void Should_Produce_The_Same_Content_As_A_Sample_File() { const string expectedContent = @"SH|ACTTX957877905MTR|8842008|O| 01|ACTTX957877905MTR|TX|13|20130319|8842008|8841948|79|IT|TYRA BROWN|||1800 EL PASEO ST|APT 205|HOUSTON|TX|77054|BROWN TYRA|6824338859|6824338859|CENTERPOINT ENERGY|957877905|ACCENT ENERGY TEXAS|133305370|201303191003| 10|ACTTX957877905MTR|RC001|01|1008901018191437145100|N|20130319||N|||||||||||||||||||||||||||||| TL|1"; // arrange var port = new CspDunsPortModel { CspDunsId = 1, CspDunsPortId = 1, Duns = "133305370", LdcDuns = string.Empty, LdcShortName = string.Empty, TradingPartnerId = "ACTTX{DUNS}", ProviderId = 1, FileType = string.Empty, }; var header = new Type650Header { HeaderKey = 275531, TransactionNbr = "8842008", TransactionSetPurposeCode = "13", TransactionDate = "20130319", TransactionType = "79", ReferenceNbr = "8841948", ActionCode = "IT", TdspName = "Centerpoint Energy", TdspDuns = "957877905", CrName = "Accent Energy Texas", CrDuns = "133305370", ProcessedReceivedDateTime = "201303191003", TransactionTypeId = 18, MarketId = 1, ProviderId = 1, }; var name = new Type650Name { HeaderKey = 275531, NameKey = 122923, EntityName = "Tyra Brown", EntityName2 = string.Empty, EntityName3 = string.Empty, EntityIdType = "8R", Address1 = "1800 EL PASEO ST", Address2 = "APT 205", City = "HOUSTON", State = "TX", PostalCode = "77054", ContactName = "Brown Tyra", ContactPhoneNbr1 = "682-433-8859", ContactPhoneNbr2 = "682-433-8859" }; var service = new Type650Service { HeaderKey = 275531, ServiceKey = 275393, PurposeCode = "RC001", PriorityCode = "01", EsiId = "1008901018191437145100", SpecialProcessCode = "N", ServiceReqDate = "20130319", CallAhead = "N", NotBeforeDate = string.Empty, PremLocation = string.Empty, ReportRemarks = string.Empty, Directions = string.Empty, MeterNbr = string.Empty, Membership = string.Empty, RemarksPermanentSuspend = string.Empty, DisconnectAuthorization = string.Empty }; clientDataAccess.Expect(x => x.ListCspDunsPort()) .Return(new[] { port }); clientDataAccess.Expect(x => x.IdentifyMarket(Arg <string> .Is.Anything)) .Return(1); exportDataAccess.Expect(x => x.ListUnprocessed(Arg <string> .Is.Anything, Arg <string> .Is.Anything, Arg.Is(1))) .Return(new[] { header }); exportDataAccess.Expect(x => x.ListNames(Arg <int> .Is.Anything)) .Return(new[] { name }); exportDataAccess.Expect(x => x.ListServices(Arg <int> .Is.Anything)) .Return(new[] { service }); exportDataAccess.Stub(x => x.ListServiceRejects(Arg <int> .Is.Anything)) .Return(new Type650ServiceReject[0]); exportDataAccess.Stub(x => x.ListServiceMeters(Arg <int> .Is.Anything)) .Return(new Type650ServiceMeter[0]); // act var results = concern.Export(CancellationToken.None); // assert Assert.IsNotNull(results); Assert.AreEqual(1, results.Length); var result = results[0]; Assert.IsNotNull(result); Assert.AreEqual(1, result.HeaderCount); CollectionAssert.Contains(result.HeaderKeys, 275531); result.FinalizeDocument(1); Assert.AreEqual(expectedContent, result.Content); }
public void SetFileProperties(CspDunsPortModel model, string tdspDuns, string suffix) { SetFileProperties(model, model.LdcShortName, model.TradingPartnerId, tdspDuns, suffix); }
public CspDunsPortModel[] ListCspDunsPort(string fileType) { var dunsList = ListCspDuns(); if (dunsList.Length == 0) { return(new CspDunsPortModel[0]); } var collection = new List <CspDunsPortModel>(); using (var connection = new SqlConnection(connectionString)) { for (int index = 0, count = dunsList.Length; index < count; index++) { var model = dunsList[index]; using (var command = connection.CreateCommand("csp_CSPDUNSPortList")) { command.AddWithValue("@CSPDUNSID", model.CspDunsId); if (connection.State != ConnectionState.Open) { connection.Open(); } using (var reader = command.ExecuteReader()) { while (reader.Read()) { var item = new CspDunsPortModel { CspDunsId = model.CspDunsId, Duns = model.Duns, CspDunsPortId = reader.GetInt32("CSPDUNSPortID"), ProviderId = reader.GetInt32("ProviderID"), TradingPartnerId = reader.GetString("TradingPartnerIdentifier"), DirectoryIn = reader.GetString("DirectoryIn"), DirectoryOut = reader.GetString("DirectoryOut"), PgpEncryptionKey = reader.GetString("PgpEncryptionKey"), PgpSignatureKey = reader.GetString("PgpSignatureKey"), PgpPassphrase = reader.GetString("PgpPassPhrase"), Protocol = reader.GetString("Protocol"), PortId = reader.GetInt32("PortID"), FtpRemoteServer = reader.GetString("RemoteServer"), FtpUserId = reader.GetString("UserId"), FtpPassword = reader.GetString("Password"), }; reader.TryGetInt32("LDCID", x => item.LdcId = x); reader.TryGetString("LDCDUNS", x => item.LdcDuns = x); reader.TryGetString("LDCShortName", x => item.LdcShortName = x); reader.TryGetBoolean("TransportEnabledFlag", x => item.TransportEnabledFlag = x); reader.TryGetBoolean("DecryptionEnabledFlag", x => item.DecryptionEnabledFlag = x); reader.TryGetBoolean("EncryptionEnabledFlag", x => item.EncryptionEnabledFlag = x); reader.TryGetString("FileType", x => item.FileType = x); reader.TryGetString("GISBCommonCode", x => item.GisbCommonCode = x); collection.Add(item); } } } } } if (collection.Count == 0) { return(new CspDunsPortModel[0]); } if (!string.IsNullOrWhiteSpace(fileType)) { collection.RemoveAll(x => !string.IsNullOrEmpty(x.FileType) && !x.FileType.Equals(fileType)); var matches = collection .Where(x => !string.IsNullOrEmpty(x.FileType) && x.FileType.Equals(fileType)) .ToArray(); if (matches.Any()) { foreach (var match in matches) { collection.RemoveAll( x => x.CspDunsId.Equals(match.CspDunsId) && x.LdcId.Equals(match.LdcId) && string.IsNullOrWhiteSpace(x.FileType) && !x.CspDunsPortId.Equals(match.CspDunsPortId)); } } return(collection.ToArray()); } return(collection .Where(x => string.IsNullOrEmpty(x.FileType)) .ToArray()); }
public TransmitResult PostFileSoap(string fileName, CspDunsPortModel port) { var soapProtocol = new ProtocolSoap(); return(soapProtocol.TransmitFile(fileName, port.FtpRemoteServer, port.FtpUserId, port.FtpPassword)); }
public void TransmitMarketFile(TransmitFileContext context, MarketFileModel marketFile, CspDunsPortModel port) { var fileName = string.Concat(marketFile.FileName, ".pgp"); var encryptedFilePath = Path.Combine(context.DirectoryArchive, "Encrypted", fileName); var sourceFilePath = Path.Combine(port.DirectoryOut, fileName); var targetFilePath = Path.Combine(port.DirectoryOut, "Complete", fileName); var encryptedFile = new FileInfo(encryptedFilePath); if (encryptedFile.Exists) { encryptedFile.CopyTo(sourceFilePath, true); } var sourceFile = new FileInfo(sourceFilePath); try { var result = TransmitFile(sourceFile, port); marketFile.Status = (result.Transmitted) ? MarketFileStatusOptions.Transmitted : MarketFileStatusOptions.Error; marketFile.ProcessError = result.Message; marketFile.ProcessDate = DateTime.Now; marketDataAccess.UpdateMarketFile(marketFile); if (result.Transmitted) { MoveFile(sourceFile, targetFilePath); } } catch (Exception ex) { logger.ErrorFormat(ex, "Unknown error occurred while transmitting file \"{0}\".", marketFile.FileName); marketFile.Status = MarketFileStatusOptions.Error; marketFile.ProcessError = ex.Message; marketFile.ProcessDate = DateTime.Now; marketDataAccess.UpdateMarketFile(marketFile); } }