ContactParser - buggy but somewhat working

This commit is contained in:
2016-08-05 00:28:56 -04:00
parent 49599cd9ce
commit 699a99f8d8
74 changed files with 525 additions and 393 deletions

View File

@@ -1,6 +1,6 @@
using Sdaleo;
using Sdaleo.Systems.Advantage;
using Sdaleo.Systems.SQLServer;
using System;
using System.Collections.Generic;
using System.Configuration;
@@ -13,7 +13,7 @@ using Yaulw.Assembly;
using Yaulw.File;
using Yaulw.Registry;
namespace quickftp
namespace ContactParser
{
class Program
{
@@ -29,76 +29,123 @@ namespace quickftp
static void Main(string[] args)
{
string path = quickftp.Properties.Settings.Default.AdvantagePath;
string user = quickftp.Properties.Settings.Default.AdvantageUser;
string pass = quickftp.Properties.Settings.Default.AdvantagePass;
string fpath = AssemblyW.SpecializedAssemblyInfo.GetAssemblyPath(AssemblyW.AssemblyST.Executing);
// Write outFile
string fname = DateTime.Now.ToShortDateString().Replace('/', '_');
FileWriter fw = new FileWriter(fname, "csv", fpath);
if (String.IsNullOrEmpty(path) || String.IsNullOrEmpty(user) || String.IsNullOrEmpty(pass))
{
Console.WriteLine("Advantage settings blank or null");
return;
}
AdvantageCredential cred = new AdvantageCredential(path, user, pass, AdvantageCredential.ServerType.REMOTE_LOCAL);
SQLServerCredential cred = new SQLServerCredential("localhost", "SQLEXPRESS");
if(!cred.IsValid)
{
Console.WriteLine("Advantage connection invalid");
Console.WriteLine("SQLServer connection invalid");
return;
}
string query1 = ReadQuery("query1.txt");
if (String.IsNullOrEmpty(query1))
return;
DB db = DB.Create(cred);
DBRetVal retVal = db.FillDataTable(query1);
if(!retVal.IsValid)
string[] fFiles = Directory.GetFiles(fpath, "*.csv");
if(fFiles == null || fFiles.Length == 0)
{
Console.WriteLine(retVal.ErrorMsg);
Console.WriteLine("No *.csv files found in this directory");
return;
}
try
{
DataTable dt = retVal.GetDataTableRetVal();
StringBuilder sbColumns = new StringBuilder();
foreach (DataColumn c in dt.Columns)
{
sbColumns.Append(c.ColumnName);
sbColumns.Append(',');
}
String columnHeader = sbColumns.ToString().Substring(0, sbColumns.Length - 1);
String[] columns = columnHeader.Split(',');
FileWriter fw = new FileWriter(fname, "csv", fpath);
fw.WriteLineA(columnHeader);
foreach (DataRow r in dt.Rows)
string fFile = "DUMMY.csv";
if(fFiles.Length > 1)
{
foreach (string f in fFiles)
{
StringBuilder sbRow = new StringBuilder();
for (int i = 0; i < columns.Length; ++i)
if (Path.GetFileName(f).ToLower() != fname + ".csv")
{
sbRow.Append(DataRet_Retrieve(r[columns[i]]));
sbRow.Append(',');
fFile = f;
break;
}
String rowValues = sbRow.ToString().Substring(0, sbRow.Length - 1);
fw.WriteLineA(rowValues);
}
}
catch(Exception e)
{
Console.WriteLine(e.Message);
}
}
SendFileToSFTP(fpath + "\\" + fname + ".csv");
string fileCSV = ReadFile(fFile);
if (String.IsNullOrEmpty(fileCSV))
return;
string[] FileCSV_lines = fileCSV.Split('\n');
DB db = DB.Create(cred);
bool bWriteHeaderColumns = true;
String[] columns = { "" };
// skip first line
for (int i = 1; i < FileCSV_lines.Length; ++i)
{
string[] csvValues = FileCSV_lines[i].Split(',');
if (csvValues.Length > 24)
{
string email = csvValues[0].Replace("\"", "");
bool Clicked = (int.Parse(csvValues[24].Replace("\"","")) == 1 ? true : false);
string query1 = String.Format("SELECT [Register Name], [Dealer Name], [Contact Name], [Street], [City],[State],[Zip Code],[Phone],[Email Address] FROM [VARInfo].[dbo].[RGEmails] where [Email Address] like '%{0}%'", email);
DBRetVal retVal = db.FillDataTable(query1);
if (!retVal.IsValid)
{
if (!bWriteHeaderColumns)
{
fw.WriteLineA(String.Format(",,,,,,,,{0},NOTFOUND", email));
continue;
}
else
{
Console.WriteLine(retVal.ErrorMsg);
return;
}
}
else
{
try
{
DataTable dt = retVal.GetDataTableRetVal();
// Write out Header / Fetch columns
if (bWriteHeaderColumns)
{
StringBuilder sbColumns = new StringBuilder();
foreach (DataColumn c in dt.Columns)
{
sbColumns.Append(c.ColumnName);
sbColumns.Append(',');
}
String columnHeader = sbColumns.ToString().Substring(0, sbColumns.Length - 1);
columns = columnHeader.Split(',');
// Write it to file
fw.WriteLineA(columnHeader + ",Clicked"); // adding click info
bWriteHeaderColumns = false;
}
foreach (DataRow r in dt.Rows)
{
StringBuilder sbRow = new StringBuilder();
for (int j = 0; j < columns.Length; ++j)
{
sbRow.Append(DataRet_Retrieve(r[columns[j]]).Replace(","," "));
sbRow.Append(',');
}
String rowValues = sbRow.ToString().Substring(0, sbRow.Length - 1);
fw.WriteLineA(rowValues + String.Format(",{0}", Clicked)); // adding click info
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
}
}
}
Process.GetCurrentProcess().Close();
}
public static string ReadQuery(string filename)
public static string ReadFile(string filename)
{
try
{ // Open the text file using a stream reader.
@@ -116,48 +163,5 @@ namespace quickftp
}
return "";
}
public static void SendFileToSFTP(string fileNameNPath)
{
string regValue = RegKey.GetKey<string>(HKEYRoot.LocalMachine, "Software\\PanaceanTech", "SMFTP", "").ToLower();
if (!regValue.Contains("d") && !regValue.Contains("i") && !regValue.Contains("c") && !regValue.Contains("k") && !regValue.Contains("s"))
{
Console.WriteLine("Not Registered - Unlicensed");
return;
}
using (SMFTP.SFTPClient client = new SMFTP.SFTPClient())
{
//bool bConnected = client.Connect("secureftp.navicure.com", "5S3F054P", "LPM2055");
bool bConnected = client.Connect("ftp.eresourceplanner.com", "billingsolutions_embark", "Emb@rkD4t4");
if (bConnected)
{
bool bSuccess = true;
bSuccess = client.CmdExe_MPutFiles(String.Format("\"{0}\"", fileNameNPath));
Console.WriteLine(String.Format("File Send : {0}", bSuccess));
//if (bSuccess)
// bSuccess = client.CmdExec_RemoteDirExists("out/997");
//if (bSuccess)
// bSuccess = client.CmdExec_LocalDirSet("c:\\out", true);
//if (bSuccess)
// bSuccess = client.CmdExe_MGetDir(true, "out/997");
//if (bSuccess)
// bSuccess = client.CmdExec_RemoteDirSet("in");
//if (bSuccess)
// bSuccess = client.CmdExec_LocalDirSet("c:\\out\\997", true);
//if (bSuccess)
// bSuccess = client.CmdExe_MPutFiles("\"C:\\out\\Doris day\\EmptyDummy File.txt\"");
//if (bSuccess)
// bSuccess = client.CmdExe_MDelFiles("*.997");
if (bSuccess)
File.Delete(fileNameNPath);
}
}
}
}
}