Skip to content

Commit

Permalink
add neuter for track data, up minor version
Browse files Browse the repository at this point in the history
  • Loading branch information
brianarnold789 committed May 10, 2017
1 parent d55e6f5 commit 81d9366
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 63 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
114 changes: 55 additions & 59 deletions LitleSdkForNet/LitleSdkForNet/Communications.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -41,51 +35,53 @@ public static bool ValidateServerCertificate(

public void neuterXML(ref string inputXml)
{
const string pattern1 = "(?i)<number>.*?</number>";
const string pattern2 = "(?i)<accNum>.*?</accNum>";
const string pattern3 = "(?i)<track>.*?</<track>";

string pattern1 = "(?i)<number>.*?</number>";
string pattern2 = "(?i)<accNum>.*?</accNum>";

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, "<number>xxxxxxxxxxxxxxxx</number>");
inputXml = rgx2.Replace(inputXml, "<accNum>xxxxxxxxxx</accNum>");
inputXml = rgx3.Replace(inputXml, "<track>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</track>");
}

public void log(String logMessage, String logFile, bool neuter)
public void log(string logMessage, string logFile, bool neuter)
{
lock (_synLock)
{
if (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<String, String> config)
public virtual string HttpPost(string xmlRequest, Dictionary<string, string> config)
{
string logFile = null;
if (config.ContainsKey("logFile"))
{
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"])) {
Expand All @@ -110,7 +106,7 @@ virtual public string HttpPost(string xmlRequest, Dictionary<String, String> 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;
}
Expand All @@ -124,13 +120,13 @@ virtual public string HttpPost(string xmlRequest, Dictionary<String, String> 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();
}
Expand All @@ -148,14 +144,14 @@ virtual public string HttpPost(string xmlRequest, Dictionary<String, String> con
return xmlResponse;
}

public bool isProxyOn(Dictionary<String,String> config) {
public bool isProxyOn(Dictionary<string,string> 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<String, String> config)
public virtual string socketStream(string xmlRequestFilePath, string xmlResponseDestinationDirectory, Dictionary<string, string> 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;

Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
{
Expand All @@ -234,18 +230,18 @@ virtual public string socketStream(string xmlRequestFilePath, string xmlResponse
return xmlResponseDestinationDirectory + batchName;
}

virtual public void FtpDropOff(string fileDirectory, string fileName, Dictionary<String, String> config)
public virtual void FtpDropOff(string fileDirectory, string fileName, Dictionary<string, string> 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);
Expand All @@ -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
Expand Down Expand Up @@ -300,26 +296,26 @@ virtual public void FtpDropOff(string fileDirectory, string fileName, Dictionary
session.disconnect();
}

virtual public void FtpPoll(string fileName, int timeout, Dictionary<string, string> config)
public virtual void FtpPoll(string fileName, int timeout, Dictionary<string, string> 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);
}
ChannelSftp channelSftp = null;
Channel channel;

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
Expand All @@ -337,7 +333,7 @@ virtual public void FtpPoll(string fileName, int timeout, Dictionary<string, str

//check if file exists
SftpATTRS sftpATTRS = null;
Stopwatch stopWatch = new Stopwatch();
var stopWatch = new Stopwatch();
stopWatch.Start();
do
{
Expand All @@ -364,22 +360,22 @@ virtual public void FtpPoll(string fileName, int timeout, Dictionary<string, str
} while (sftpATTRS == null && stopWatch.Elapsed.TotalMilliseconds <= timeout);
}

virtual public void FtpPickUp(string destinationFilePath, Dictionary<String, String> config, string fileName)
public virtual void FtpPickUp(string destinationFilePath, Dictionary<string, string> 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
Expand Down
2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNet/LitleBatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion LitleSdkForNet/LitleSdkForNetTest/Unit/TestBatchRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void testBatchRequestContainsMerchantSdkAttribute()
String actual = batchRequest.generateXmlHeader();
String expected = @"
<batchRequest id=""""
merchantSdk=""DotNet;8.29.2""
merchantSdk=""DotNet;8.29.3""
merchantId=""01234"">
";
Assert.AreEqual(expected, actual);
Expand Down

0 comments on commit 81d9366

Please sign in to comment.