From 81d93667c4b860734548cdba4d2bc621b634fc91 Mon Sep 17 00:00:00 2001 From: brianarnold789 Date: Wed, 10 May 2017 16:03:28 -0400 Subject: [PATCH] add neuter for track data, up minor version --- CHANGELOG | 7 +- .../LitleSdkForNet/Communications.cs | 114 +++++++++--------- .../LitleSdkForNet/LitleBatchRequest.cs | 2 +- .../Unit/TestBatchRequest.cs | 2 +- 4 files changed, 62 insertions(+), 63 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index acb6bcfd..28ef1a6f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,11 +1,14 @@ = LitleOnline CHANGELOG +== Version 8.29.3 (May 10, 2017) +* Feature: add neuter for track data in log file + == Version 8.29.2 (Apr 11, 2017) * Bug fix: remove Keep-alive header on HTTP request == Version 8.29.1 -HTTP timeout set to 500ms -Add RecycleEngineActive flag +* Feature: HTTP timeout set to 500ms +* Feature: Add RecycleEngineActive flag == Version 8.29.0 * Bugfix: Load proxy from setting file and adding constructor for accountUpdateFileRequestData and adding test cases diff --git a/LitleSdkForNet/LitleSdkForNet/Communications.cs b/LitleSdkForNet/LitleSdkForNet/Communications.cs index 47962853..0609c208 100644 --- a/LitleSdkForNet/LitleSdkForNet/Communications.cs +++ b/LitleSdkForNet/LitleSdkForNet/Communications.cs @@ -1,20 +1,14 @@ using System; using System.IO; -using System.Xml; -using System.Xml.Serialization; using System.Collections.Generic; using System.Diagnostics; using System.Text; -using System.Xml.XPath; using System.Net; using Tamir.SharpSsh.jsch; -using Tamir.SharpSsh; -using System.Timers; using System.Net.Sockets; using System.Net.Security; using System.Security.Authentication; using System.Security.Cryptography.X509Certificates; -using System.Reflection; using System.Text.RegularExpressions; namespace Litle.Sdk @@ -41,17 +35,19 @@ public static bool ValidateServerCertificate( public void neuterXML(ref string inputXml) { + const string pattern1 = "(?i).*?"; + const string pattern2 = "(?i).*?"; + const string pattern3 = "(?i).*?"; - string pattern1 = "(?i).*?"; - string pattern2 = "(?i).*?"; - - Regex rgx1 = new Regex(pattern1); - Regex rgx2 = new Regex(pattern2); + var rgx1 = new Regex(pattern1); + var rgx2 = new Regex(pattern2); + var rgx3 = new Regex(pattern3); inputXml = rgx1.Replace(inputXml, "xxxxxxxxxxxxxxxx"); inputXml = rgx2.Replace(inputXml, "xxxxxxxxxx"); + inputXml = rgx3.Replace(inputXml, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } - public void log(String logMessage, String logFile, bool neuter) + public void log(string logMessage, string logFile, bool neuter) { lock (_synLock) { @@ -59,15 +55,15 @@ public void log(String logMessage, String logFile, bool neuter) { neuterXML(ref logMessage); } - StreamWriter logWriter = new StreamWriter(logFile, true); - DateTime time = DateTime.Now; + var logWriter = new StreamWriter(logFile, true); + var time = DateTime.Now; logWriter.WriteLine(time.ToString()); logWriter.WriteLine(logMessage + "\r\n"); logWriter.Close(); } } - virtual public string HttpPost(string xmlRequest, Dictionary config) + public virtual string HttpPost(string xmlRequest, Dictionary config) { string logFile = null; if (config.ContainsKey("logFile")) @@ -75,17 +71,17 @@ virtual public string HttpPost(string xmlRequest, Dictionary con logFile = config["logFile"]; } - string uri = config["url"]; - System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; - System.Net.HttpWebRequest req = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); + var uri = config["url"]; + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; + var req = (HttpWebRequest)WebRequest.Create(uri); - bool neuter = false; + var neuter = false; if (config.ContainsKey("neuterAccountNums")) { neuter = ("true".Equals(config["neuterAccountNums"])); } - bool printxml = false; + var printxml = false; if (config.ContainsKey("printxml")) { if("true".Equals(config["printxml"])) { @@ -110,7 +106,7 @@ virtual public string HttpPost(string xmlRequest, Dictionary con req.KeepAlive = false; if (isProxyOn(config)) { - WebProxy myproxy = new WebProxy(config["proxyHost"], int.Parse(config["proxyPort"])); + var myproxy = new WebProxy(config["proxyHost"], int.Parse(config["proxyPort"])); myproxy.BypassProxyOnLocal = true; req.Proxy = myproxy; } @@ -124,13 +120,13 @@ virtual public string HttpPost(string xmlRequest, Dictionary con // read response - System.Net.WebResponse resp = req.GetResponse(); + var resp = req.GetResponse(); if (resp == null) { return null; } string xmlResponse; - using (var reader = new System.IO.StreamReader(resp.GetResponseStream())) + using (var reader = new StreamReader(resp.GetResponseStream())) { xmlResponse = reader.ReadToEnd().Trim(); } @@ -148,14 +144,14 @@ virtual public string HttpPost(string xmlRequest, Dictionary con return xmlResponse; } - public bool isProxyOn(Dictionary config) { + public bool isProxyOn(Dictionary config) { return config.ContainsKey("proxyHost") && config["proxyHost"] != null && config["proxyHost"].Length > 0 && config.ContainsKey("proxyPort") && config["proxyPort"] != null && config["proxyPort"].Length > 0; } - virtual public string socketStream(string xmlRequestFilePath, string xmlResponseDestinationDirectory, Dictionary config) + public virtual string socketStream(string xmlRequestFilePath, string xmlResponseDestinationDirectory, Dictionary config) { - string url = config["onlineBatchUrl"]; - int port = Int32.Parse(config["onlineBatchPort"]); + var url = config["onlineBatchUrl"]; + var port = int.Parse(config["onlineBatchPort"]); TcpClient tcpClient = null; SslStream sslStream = null; @@ -184,9 +180,9 @@ virtual public string socketStream(string xmlRequestFilePath, string xmlResponse Console.WriteLine("Using XML File: " + xmlRequestFilePath); } - using (FileStream readFileStream = new FileStream(xmlRequestFilePath, FileMode.Open)) + using (var readFileStream = new FileStream(xmlRequestFilePath, FileMode.Open)) { - int bytesRead = -1; + var bytesRead = -1; byte[] byteBuffer; do @@ -199,8 +195,8 @@ virtual public string socketStream(string xmlRequestFilePath, string xmlResponse } while (bytesRead != 0); } - string batchName = Path.GetFileName(xmlRequestFilePath); - string destinationDirectory = Path.GetDirectoryName(xmlResponseDestinationDirectory); + var batchName = Path.GetFileName(xmlRequestFilePath); + var destinationDirectory = Path.GetDirectoryName(xmlResponseDestinationDirectory); if (!Directory.Exists(destinationDirectory)) { Directory.CreateDirectory(destinationDirectory); @@ -211,11 +207,11 @@ virtual public string socketStream(string xmlRequestFilePath, string xmlResponse Console.WriteLine("Writing to XML File: " + xmlResponseDestinationDirectory + batchName); } - using (FileStream writeFileStream = new FileStream(xmlResponseDestinationDirectory + batchName, FileMode.Create)) + using (var writeFileStream = new FileStream(xmlResponseDestinationDirectory + batchName, FileMode.Create)) { char[] charBuffer; byte[] byteBuffer; - int bytesRead = 0; + var bytesRead = 0; do { @@ -234,18 +230,18 @@ virtual public string socketStream(string xmlRequestFilePath, string xmlResponse return xmlResponseDestinationDirectory + batchName; } - virtual public void FtpDropOff(string fileDirectory, string fileName, Dictionary config) + public virtual void FtpDropOff(string fileDirectory, string fileName, Dictionary config) { ChannelSftp channelSftp = null; Channel channel; - string url = config["sftpUrl"]; - string username = config["sftpUsername"]; - string password = config["sftpPassword"]; - string knownHostsFile = config["knownHostsFile"]; - string filePath = fileDirectory + fileName; + var url = config["sftpUrl"]; + var username = config["sftpUsername"]; + var password = config["sftpPassword"]; + var knownHostsFile = config["knownHostsFile"]; + var filePath = fileDirectory + fileName; - bool printxml = config["printxml"] == "true"; + var printxml = config["printxml"] == "true"; if (printxml) { Console.WriteLine("Sftp Url: " + url); @@ -254,10 +250,10 @@ virtual public void FtpDropOff(string fileDirectory, string fileName, Dictionary Console.WriteLine("Known hosts file path: " + knownHostsFile); } - JSch jsch = new JSch(); + var jsch = new JSch(); jsch.setKnownHosts(knownHostsFile); - Session session = jsch.getSession(username, url); + var session = jsch.getSession(username, url); session.setPassword(password); try @@ -300,10 +296,10 @@ virtual public void FtpDropOff(string fileDirectory, string fileName, Dictionary session.disconnect(); } - virtual public void FtpPoll(string fileName, int timeout, Dictionary config) + public virtual void FtpPoll(string fileName, int timeout, Dictionary config) { fileName = fileName + ".asc"; - bool printxml = config["printxml"] == "true"; + var printxml = config["printxml"] == "true"; if (printxml) { Console.WriteLine("Polling for outbound result file. Timeout set to " + timeout + "ms. File to wait for is " + fileName); @@ -311,15 +307,15 @@ virtual public void FtpPoll(string fileName, int timeout, Dictionary config, string fileName) + public virtual void FtpPickUp(string destinationFilePath, Dictionary config, string fileName) { ChannelSftp channelSftp = null; Channel channel; - bool printxml = config["printxml"] == "true"; + var printxml = config["printxml"] == "true"; - string url = config["sftpUrl"]; - string username = config["sftpUsername"]; - string password = config["sftpPassword"]; - string knownHostsFile = config["knownHostsFile"]; + var url = config["sftpUrl"]; + var username = config["sftpUsername"]; + var password = config["sftpPassword"]; + var knownHostsFile = config["knownHostsFile"]; - JSch jsch = new JSch(); + var jsch = new JSch(); jsch.setKnownHosts(knownHostsFile); - Session session = jsch.getSession(username, url); + var session = jsch.getSession(username, url); session.setPassword(password); try diff --git a/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs b/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs index 20ce4a13..faaf9b66 100644 --- a/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs +++ b/LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs @@ -817,7 +817,7 @@ public string generateXmlHeader() { xmlHeader += "numBalanceInquirys=\"" + numBalanceInquiries + "\"\r\n"; } - xmlHeader += "merchantSdk=\"DotNet;8.29.2\"\r\n"; + xmlHeader += "merchantSdk=\"DotNet;8.29.3\"\r\n"; xmlHeader += "merchantId=\"" + config["merchantId"] + "\">\r\n"; return xmlHeader; diff --git a/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs b/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs index ed592725..9471c539 100644 --- a/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs +++ b/LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs @@ -55,7 +55,7 @@ public void testBatchRequestContainsMerchantSdkAttribute() String actual = batchRequest.generateXmlHeader(); String expected = @" "; Assert.AreEqual(expected, actual);