mirror of
https://github.com/stokebob/bnhtrade.git
synced 2026-05-19 03:58:19 +00:00
Compare commits
4 Commits
db8eafe571
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 89ec6476fc | |||
| db9a2b9ccc | |||
| 8e8c4138e3 | |||
| f921e79671 |
@@ -12,7 +12,21 @@ namespace bnhtrade.Core
|
|||||||
{
|
{
|
||||||
public string GetAppDataPath()
|
public string GetAppDataPath()
|
||||||
{
|
{
|
||||||
string path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\bnhtrade\";
|
string path = null;
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
||||||
|
+ @"\bnhtrade\";
|
||||||
|
}
|
||||||
|
else if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS())
|
||||||
|
{
|
||||||
|
path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
|
||||||
|
+ "/.bnhtrade/";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new PlatformNotSupportedException("Unsupported operating system");
|
||||||
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,97 +1,78 @@
|
|||||||
using System;
|
using FikaAmazonAPI.AmazonSpApiSDK.Models.Services;
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Data.Database
|
namespace bnhtrade.Core.Data.Database
|
||||||
{
|
{
|
||||||
|
/// this class needs a sort out. Ideally it shoud be called what it is, a connection string builder, and
|
||||||
|
/// it should expose a method to serve the connection string--rather than class inheritance and using a property setter
|
||||||
|
/// something to do once there aren't so many open git branches
|
||||||
|
///
|
||||||
public class Connection
|
public class Connection
|
||||||
{
|
{
|
||||||
//protected readonly string SqlConnectionString;
|
private string _server;
|
||||||
private Model.Credentials.bnhtradeDB _dbCredentials;
|
private string _user;
|
||||||
|
private string _userPassword;
|
||||||
|
private string _database = "e2A";
|
||||||
|
private bool _persistSecurityInfo = true;
|
||||||
|
private bool _multipleActiveResultSets = true;
|
||||||
|
private bool _encrypt = true;
|
||||||
|
private uint _connectRetryInterval;
|
||||||
|
private uint _connectRetryCount;
|
||||||
|
private uint _connectTimeout;
|
||||||
|
|
||||||
protected string SqlConnectionString
|
internal string SqlConnectionString { get; private set; }
|
||||||
{
|
|
||||||
get { return _dbCredentials.ConnectionString; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection()
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="connectRetryInterval">Retry interval in seconds, must be 5-60</param>
|
||||||
|
/// <param name="connectTimeout">Timeout length in seconds (0 is indefinitely)</param>
|
||||||
|
/// <exception cref="ArgumentOutOfRangeException"></exception>
|
||||||
|
/// <exception cref="Exception"></exception>
|
||||||
|
public Connection(uint connectRetryInterval = 10, uint connectRetryCount = 6, uint connectionTimeout = 60)
|
||||||
{
|
{
|
||||||
var config = new Config().GetConfiguration();
|
if (connectRetryInterval < 5 || connectRetryInterval > 60)
|
||||||
|
{
|
||||||
|
// these are limits set by the sql server
|
||||||
|
throw new ArgumentOutOfRangeException("ConnectRetryInterval must be from 5 to 60 seconds");
|
||||||
|
}
|
||||||
|
_connectRetryInterval = connectRetryInterval;
|
||||||
|
_connectRetryCount = connectRetryCount;
|
||||||
|
_connectTimeout = connectionTimeout;
|
||||||
|
|
||||||
// attempt to retrive credentials from app.local.config
|
// retrive credentials from app.local.config
|
||||||
|
var config = new Config().GetConfiguration();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string dataSource = config.AppSettings.Settings["DbDataSource"].Value;
|
_server = config.AppSettings.Settings["DbDataSource"].Value;
|
||||||
string userId = config.AppSettings.Settings["DbUserId"].Value;
|
_user = config.AppSettings.Settings["DbUserId"].Value;
|
||||||
string pass = config.AppSettings.Settings["DbUserPassword"].Value;
|
_userPassword = config.AppSettings.Settings["DbUserPassword"].Value;
|
||||||
|
|
||||||
// check
|
// check
|
||||||
if (string.IsNullOrEmpty(dataSource))
|
if (string.IsNullOrEmpty(_server))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Could not retrive 'DbDataSource' from config file");
|
throw new ArgumentException("Could not retrive 'DbDataSource' from config file");
|
||||||
}
|
}
|
||||||
else if (string.IsNullOrEmpty(userId))
|
else if (string.IsNullOrEmpty(_user))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Could not retrive 'DbUserId' from config file");
|
throw new ArgumentException("Could not retrive 'DbUserId' from config file");
|
||||||
}
|
}
|
||||||
else if (string.IsNullOrEmpty(pass))
|
else if (string.IsNullOrEmpty(_userPassword))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Could not retrive 'DbUserPassword' from config file");
|
throw new ArgumentException("Could not retrive 'DbUserPassword' from config file");
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbCredentials = new bnhtrade.Core.Model.Credentials.bnhtradeDB(dataSource, userId, pass);
|
|
||||||
this._dbCredentials = dbCredentials;
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new Exception("Unable to retirve DB credentials: " + ex.Message);
|
throw new Exception("Unable to retirve DB credentials: " + ex.Message);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private void ConnectionOld()
|
// build connection string
|
||||||
{
|
SqlConnectionString = "Server=" + _server + ";Database=" + _database + ";PersistSecurityInfo=" + _persistSecurityInfo.ToString()
|
||||||
// attempt to retrive credentials from app.local.config
|
+ ";User=" + _user + ";Password=" + _userPassword + ";MultipleActiveResultSets=" + _multipleActiveResultSets.ToString()
|
||||||
try
|
+ ";ConnectRetryInterval=" + _connectRetryInterval + ";ConnectRetryCount=" + _connectRetryCount + ";Timeout=" + _connectTimeout
|
||||||
{
|
+ ";Encrypt=" + _encrypt.ToString() +";";
|
||||||
string dataSource = ConfigurationManager.AppSettings["DbDataSource"];
|
|
||||||
string userId = ConfigurationManager.AppSettings["DbUserId"];
|
|
||||||
string pass = ConfigurationManager.AppSettings["DbUserPassword"];
|
|
||||||
|
|
||||||
// check
|
|
||||||
if (string.IsNullOrEmpty(dataSource))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbDataSource' from config file");
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrEmpty(userId))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbUserId' from config file");
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrEmpty(pass))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbUserPassword' from config file");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dbCredentials = new bnhtrade.Core.Model.Credentials.bnhtradeDB(dataSource, userId, pass);
|
|
||||||
this._dbCredentials = dbCredentials;
|
|
||||||
}
|
|
||||||
catch(Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unable to retirve DB credentials: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection(Model.Credentials.bnhtradeDB dbCredentials)
|
|
||||||
{
|
|
||||||
// setup sql parameters
|
|
||||||
if (dbCredentials == null)
|
|
||||||
{
|
|
||||||
throw new Exception("DB credentials object is null");
|
|
||||||
}
|
|
||||||
this._dbCredentials = dbCredentials;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Data.Database.Import
|
namespace bnhtrade.Core.Data.Database.Import
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using bnhtrade.Core.Logic.Amazon.Fba;
|
using bnhtrade.Core.Logic.Amazon.Fba;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics.Eventing.Reader;
|
using System.Diagnostics.Eventing.Reader;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using FikaAmazonAPI.ConstructFeed.Messages;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.ConstrainedExecution;
|
using System.Runtime.ConstrainedExecution;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Dapper;
|
using Dapper;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
+95
-94
@@ -2,7 +2,6 @@
|
|||||||
using bnhtrade.Core.Data.Database.Repository.Interface;
|
using bnhtrade.Core.Data.Database.Repository.Interface;
|
||||||
using bnhtrade.Core.Model.Amazon;
|
using bnhtrade.Core.Model.Amazon;
|
||||||
using Microsoft.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.VisualBasic.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
@@ -369,7 +368,7 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
//
|
//
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Update the settlement report marketplace name by settlement Id (not table id)
|
/// Update the settlement report marketplace name by settlement Id (not row id)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="settlementId">Settlement id (not table/record id) of the settlement to update</param>
|
/// <param name="settlementId">Settlement id (not table/record id) of the settlement to update</param>
|
||||||
/// <param name="marketPlaceName">marketplace name</param>
|
/// <param name="marketPlaceName">marketplace name</param>
|
||||||
@@ -433,13 +432,13 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
/// Takes a Settlement Report flat file from Amazon and imports it into the database.
|
/// Takes a Settlement Report flat file from Amazon and imports it into the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="filePath">path to the Amazon report flat file</param>
|
/// <param name="filePath">path to the Amazon report flat file</param>
|
||||||
/// <param name="reportId">The unique Amazon SP-API report id (not settlement id)</param>
|
/// <param name="spapiReportId">The unique Amazon SP-API report id (not settlement id)</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool CreateAmazonSettlements(string filePath, string reportId)
|
public bool CreateAmazonSettlements(string filePath, string spapiReportId)
|
||||||
{
|
{
|
||||||
int settlementReportId = 0;
|
int settlementReportId = 0;
|
||||||
string settlementRef = "";
|
string settlementRef = null;
|
||||||
bool marketPlaceUpdated = false;
|
string marketplaceName = null;
|
||||||
decimal settlementAmount = 0m;
|
decimal settlementAmount = 0m;
|
||||||
int lineNumber = 2;
|
int lineNumber = 2;
|
||||||
int lineSkip = 0;
|
int lineSkip = 0;
|
||||||
@@ -479,17 +478,17 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
int indexQuantityPurchased = Array.IndexOf(headers, "quantity-purchased");
|
int indexQuantityPurchased = Array.IndexOf(headers, "quantity-purchased");
|
||||||
int indexPromotionId = Array.IndexOf(headers, "promotion-id");
|
int indexPromotionId = Array.IndexOf(headers, "promotion-id");
|
||||||
|
|
||||||
string currency = "";
|
string currency = null;
|
||||||
|
|
||||||
string fileRow;
|
string fileRow;
|
||||||
while ((fileRow = reader.ReadLine()) != null)
|
while ((fileRow = reader.ReadLine()) != null)
|
||||||
{
|
{
|
||||||
Console.Write("\rParsing record: " + lineNumber);
|
Console.Write("\rParsing record: " + lineNumber);
|
||||||
//split line into array
|
//split line into array
|
||||||
string[] items = fileRow.Split('\t');
|
string[] rowArray = fileRow.Split('\t');
|
||||||
if (items.Length != columnCount)
|
if (rowArray.Length != columnCount)
|
||||||
{
|
{
|
||||||
// skip line
|
// skip line, check settlement total at the end
|
||||||
lineSkip = lineSkip + 1;
|
lineSkip = lineSkip + 1;
|
||||||
_log.LogWarning(
|
_log.LogWarning(
|
||||||
"Line #" + lineNumber + " skipped due to no enough element in row.",
|
"Line #" + lineNumber + " skipped due to no enough element in row.",
|
||||||
@@ -498,28 +497,25 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
}
|
}
|
||||||
else if (lineNumber == 2)
|
else if (lineNumber == 2)
|
||||||
{
|
{
|
||||||
// check if settlement has already been imported
|
settlementRef = rowArray[indexSettlementId];
|
||||||
|
currency = rowArray[indexCurrency];
|
||||||
|
settlementAmount = decimal.Parse(rowArray[indexTotalAmount].Replace(",", "."));
|
||||||
|
|
||||||
|
// check if settlement has already been imported
|
||||||
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
||||||
{
|
{
|
||||||
cmd.CommandText = "SELECT COUNT(*) FROM tblImportAmazonSettlementReport WHERE [settlement-id]=@settlementId;";
|
cmd.CommandText = "SELECT COUNT(*) FROM tblImportAmazonSettlementReport WHERE [settlement-id]=@settlementId;";
|
||||||
cmd.Transaction = _transaction as SqlTransaction;
|
cmd.Transaction = _transaction as SqlTransaction;
|
||||||
cmd.Parameters.AddWithValue("@settlementId", items[indexSettlementId]);
|
cmd.Parameters.AddWithValue("@settlementId", rowArray[indexSettlementId]);
|
||||||
|
|
||||||
int recordCount = (int)cmd.ExecuteScalar();
|
int recordCount = (int)cmd.ExecuteScalar();
|
||||||
if (recordCount > 0)
|
if (recordCount > 0)
|
||||||
{
|
{
|
||||||
SetSpapiReportId(items[indexSettlementId], reportId);
|
SetSpapiReportId(rowArray[indexSettlementId], spapiReportId);
|
||||||
_log.LogInformation("Settlement report already imported, skipping...");
|
_log.LogInformation("Settlement report already imported, skipping...");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//set currencyId
|
|
||||||
//currencyId = GeneralQueries.GetCurrencyId(items[5]);
|
|
||||||
|
|
||||||
//set currency
|
|
||||||
currency = items[indexCurrency];
|
|
||||||
settlementAmount = decimal.Parse(items[indexTotalAmount].Replace(",", "."));
|
|
||||||
|
|
||||||
// insert
|
// insert
|
||||||
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
||||||
@@ -543,61 +539,38 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
,@depositDate
|
,@depositDate
|
||||||
,@settlementotalAmounttId
|
,@settlementotalAmounttId
|
||||||
,@currency
|
,@currency
|
||||||
,@reportId
|
,@spapiReportId
|
||||||
);";
|
);";
|
||||||
|
|
||||||
// add parameters
|
|
||||||
if (indexSettlementId == -1 || items[indexSettlementId].Length == 0) { cmd.Parameters.AddWithValue("@settlementId", DBNull.Value); }
|
|
||||||
else
|
|
||||||
{
|
|
||||||
settlementRef = items[indexSettlementId];
|
|
||||||
cmd.Parameters.AddWithValue("@settlementId", settlementRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
var parseDateTime = new Core.Logic.Utilities.DateTime();
|
var parseDateTime = new Core.Logic.Utilities.DateTime();
|
||||||
|
|
||||||
if (indexSettlementStartDate == -1 || items[indexSettlementStartDate].Length == 0) { cmd.Parameters.AddWithValue("@settlementStartDate", DBNull.Value); }
|
// add parameters
|
||||||
else { cmd.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementStartDate])); }
|
cmd.Parameters.AddWithValue("@settlementId", rowArray[indexSettlementId]);
|
||||||
|
cmd.Parameters.AddWithValue("@settlementStartDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexSettlementStartDate]));
|
||||||
if (indexSettlementEndDate == -1 || items[indexSettlementEndDate].Length == 0) { cmd.Parameters.AddWithValue("@settlementEndDate", DBNull.Value); }
|
cmd.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexSettlementEndDate]));
|
||||||
else { cmd.Parameters.AddWithValue("@settlementEndDate", parseDateTime.ParseIsoDateTimeString(items[indexSettlementEndDate])); }
|
cmd.Parameters.AddWithValue("@depositDate", parseDateTime.ParseIsoDateTimeString(rowArray[indexDepositDate]));
|
||||||
|
cmd.Parameters.AddWithValue("@settlementotalAmounttId", settlementAmount);
|
||||||
if (indexDepositDate == -1 || items[indexDepositDate].Length == 0) { cmd.Parameters.AddWithValue("@depositDate", DBNull.Value); }
|
if (string.IsNullOrWhiteSpace(spapiReportId)) { cmd.Parameters.AddWithValue("@spapiReportId", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@depositDate", parseDateTime.ParseIsoDateTimeString(items[indexDepositDate])); }
|
else { cmd.Parameters.AddWithValue("@spapiReportId", spapiReportId); }
|
||||||
|
|
||||||
if (indexTotalAmount == -1 || items[indexTotalAmount].Length == 0) { cmd.Parameters.AddWithValue("@totalAmount", DBNull.Value); }
|
|
||||||
else { cmd.Parameters.AddWithValue("@settlementotalAmounttId", settlementAmount); }
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(reportId)) { cmd.Parameters.AddWithValue("@reportId", DBNull.Value); }
|
|
||||||
else { cmd.Parameters.AddWithValue("@reportId", reportId); }
|
|
||||||
|
|
||||||
cmd.Parameters.AddWithValue("@currency", currency);
|
cmd.Parameters.AddWithValue("@currency", currency);
|
||||||
|
|
||||||
//if (currencyId == -1) { sqlCommand.Parameters.AddWithValue("@currencyId", DBNull.Value); }
|
|
||||||
//else { sqlCommand.Parameters.AddWithValue("@currencyId", currencyId); }
|
|
||||||
|
|
||||||
//execute and retrive id
|
//execute and retrive id
|
||||||
settlementReportId = (int)cmd.ExecuteScalar();
|
settlementReportId = (int)cmd.ExecuteScalar();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//update market place name in main table, if required
|
// attempt to retrieve marketplace name for header table
|
||||||
if (marketPlaceUpdated == false && settlementReportId > 0 && items[indexMarketplaceName].Length > 1)
|
if (rowArray[indexMarketplaceName].Length > 1 && settlementReportId > 0)
|
||||||
{
|
{
|
||||||
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
if (marketplaceName == null)
|
||||||
{
|
{
|
||||||
cmd.Transaction = _transaction as SqlTransaction;
|
marketplaceName = rowArray[indexMarketplaceName];
|
||||||
cmd.CommandText = @"
|
}
|
||||||
UPDATE tblImportAmazonSettlementReport
|
else if (marketplaceName != rowArray[indexMarketplaceName])
|
||||||
SET [marketplace-name]=@MarketplaceName
|
{
|
||||||
WHERE ImportAmazonSettlementReportID=@ImportAmazonSettlementReportID;";
|
_log.LogError("Marketplace name '" + rowArray[indexMarketplaceName] + "' on line " + lineNumber +
|
||||||
cmd.Parameters.AddWithValue("@MarketplaceName", items[indexMarketplaceName]);
|
" is different from marketplace name '" + marketplaceName + "' on previous line. This shouldn't be possible!");
|
||||||
cmd.Parameters.AddWithValue("@ImportAmazonSettlementReportID", settlementReportId);
|
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
|
||||||
marketPlaceUpdated = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -620,67 +593,95 @@ namespace bnhtrade.Core.Data.Database.Repository.Implementation
|
|||||||
|
|
||||||
cmd.Parameters.AddWithValue("@currency", currency);
|
cmd.Parameters.AddWithValue("@currency", currency);
|
||||||
|
|
||||||
if (indexTransactionType == -1 || items[indexTransactionType].Length == 0) { cmd.Parameters.AddWithValue("@TransactionType", DBNull.Value); }
|
if (indexTransactionType == -1 || rowArray[indexTransactionType].Length == 0) { cmd.Parameters.AddWithValue("@TransactionType", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@TransactionType", items[indexTransactionType]); }
|
else { cmd.Parameters.AddWithValue("@TransactionType", rowArray[indexTransactionType]); }
|
||||||
|
|
||||||
if (indexOrderId == -1 || items[indexOrderId].Length == 0) { cmd.Parameters.AddWithValue("@orderRef", DBNull.Value); }
|
if (indexOrderId == -1 || rowArray[indexOrderId].Length == 0) { cmd.Parameters.AddWithValue("@orderRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@orderRef", items[indexOrderId]); }
|
else { cmd.Parameters.AddWithValue("@orderRef", rowArray[indexOrderId]); }
|
||||||
|
|
||||||
if (indexMerchantOrderId == -1 || items[indexMerchantOrderId].Length == 0) { cmd.Parameters.AddWithValue("@merchantOrderRef", DBNull.Value); }
|
if (indexMerchantOrderId == -1 || rowArray[indexMerchantOrderId].Length == 0) { cmd.Parameters.AddWithValue("@merchantOrderRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@merchantOrderRef", items[indexMerchantOrderId]); }
|
else { cmd.Parameters.AddWithValue("@merchantOrderRef", rowArray[indexMerchantOrderId]); }
|
||||||
|
|
||||||
if (indexAdjustmentId == -1 || items[indexAdjustmentId].Length == 0) { cmd.Parameters.AddWithValue("@AdjustmentRef", DBNull.Value); }
|
if (indexAdjustmentId == -1 || rowArray[indexAdjustmentId].Length == 0) { cmd.Parameters.AddWithValue("@AdjustmentRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@AdjustmentRef", items[indexAdjustmentId]); }
|
else { cmd.Parameters.AddWithValue("@AdjustmentRef", rowArray[indexAdjustmentId]); }
|
||||||
|
|
||||||
if (indexShipmentId == -1 || items[indexShipmentId].Length == 0) { cmd.Parameters.AddWithValue("@ShipmentRef", DBNull.Value); }
|
if (indexShipmentId == -1 || rowArray[indexShipmentId].Length == 0) { cmd.Parameters.AddWithValue("@ShipmentRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@ShipmentRef", items[indexShipmentId]); }
|
else { cmd.Parameters.AddWithValue("@ShipmentRef", rowArray[indexShipmentId]); }
|
||||||
|
|
||||||
if (indexMarketplaceName == -1 || items[indexMarketplaceName].Length == 0) { cmd.Parameters.AddWithValue("@MarketplaceName", DBNull.Value); }
|
if (indexMarketplaceName == -1 || rowArray[indexMarketplaceName].Length == 0) { cmd.Parameters.AddWithValue("@MarketplaceName", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@MarketplaceName", items[indexMarketplaceName]); }
|
else { cmd.Parameters.AddWithValue("@MarketplaceName", rowArray[indexMarketplaceName]); }
|
||||||
|
|
||||||
if (indexAmountType == -1 || items[indexAmountType].Length == 0) { cmd.Parameters.AddWithValue("@AmountType", DBNull.Value); }
|
if (indexAmountType == -1 || rowArray[indexAmountType].Length == 0) { cmd.Parameters.AddWithValue("@AmountType", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@AmountType", items[indexAmountType]); }
|
else { cmd.Parameters.AddWithValue("@AmountType", rowArray[indexAmountType]); }
|
||||||
|
|
||||||
if (indexAmountDescription == -1 || items[indexAmountDescription].Length == 0) { cmd.Parameters.AddWithValue("@AmountDescription", DBNull.Value); }
|
if (indexAmountDescription == -1 || rowArray[indexAmountDescription].Length == 0) { cmd.Parameters.AddWithValue("@AmountDescription", DBNull.Value); }
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string amountDescription = items[indexAmountDescription];
|
string amountDescription = rowArray[indexAmountDescription];
|
||||||
if (amountDescription.Length > 100) { amountDescription = amountDescription.Substring(0, 100); }
|
if (amountDescription.Length > 100) { amountDescription = amountDescription.Substring(0, 100); }
|
||||||
cmd.Parameters.AddWithValue("@AmountDescription", amountDescription);
|
cmd.Parameters.AddWithValue("@AmountDescription", amountDescription);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexAmount == -1 || items[indexAmount].Length == 0) { cmd.Parameters.AddWithValue("@Amount", DBNull.Value); }
|
if (indexAmount == -1 || rowArray[indexAmount].Length == 0) { cmd.Parameters.AddWithValue("@Amount", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@Amount", decimal.Parse(items[indexAmount].Replace(",", "."))); }
|
else { cmd.Parameters.AddWithValue("@Amount", decimal.Parse(rowArray[indexAmount].Replace(",", "."))); }
|
||||||
|
|
||||||
if (indexFulfillmentId == -1 || items[indexFulfillmentId].Length == 0) { cmd.Parameters.AddWithValue("@FulfillmentRef", DBNull.Value); }
|
if (indexFulfillmentId == -1 || rowArray[indexFulfillmentId].Length == 0) { cmd.Parameters.AddWithValue("@FulfillmentRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@FulfillmentRef", items[indexFulfillmentId]); }
|
else { cmd.Parameters.AddWithValue("@FulfillmentRef", rowArray[indexFulfillmentId]); }
|
||||||
|
|
||||||
if (indexPostedDateTime == -1 || items[indexPostedDateTime].Length == 0) { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", DBNull.Value); }
|
if (indexPostedDateTime == -1 || rowArray[indexPostedDateTime].Length == 0) { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTime().ParseIsoDateTimeString(items[indexPostedDateTime])); }
|
else { cmd.Parameters.AddWithValue("@PostedDateTimeUTC", new Logic.Utilities.DateTime().ParseIsoDateTimeString(rowArray[indexPostedDateTime])); }
|
||||||
|
|
||||||
if (indexOrderItemCode == -1 || items[indexOrderItemCode].Length == 0) { cmd.Parameters.AddWithValue("@OrderItemCode", DBNull.Value); }
|
if (indexOrderItemCode == -1 || rowArray[indexOrderItemCode].Length == 0) { cmd.Parameters.AddWithValue("@OrderItemCode", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@OrderItemCode", long.Parse(items[indexOrderItemCode])); }
|
else { cmd.Parameters.AddWithValue("@OrderItemCode", long.Parse(rowArray[indexOrderItemCode])); }
|
||||||
|
|
||||||
if (indexMerchantOrderItemId == -1 || items[indexMerchantOrderItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", DBNull.Value); }
|
if (indexMerchantOrderItemId == -1 || rowArray[indexMerchantOrderItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", long.Parse(items[indexMerchantOrderItemId])); }
|
else { cmd.Parameters.AddWithValue("@MerchantOrderItemRef", long.Parse(rowArray[indexMerchantOrderItemId])); }
|
||||||
|
|
||||||
if (indexMerchantAdjustmentItemId == -1 || items[indexMerchantAdjustmentItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", DBNull.Value); }
|
if (indexMerchantAdjustmentItemId == -1 || rowArray[indexMerchantAdjustmentItemId].Length == 0) { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", items[indexMerchantAdjustmentItemId]); }
|
else { cmd.Parameters.AddWithValue("@MerchantAdjustmentItemRef", rowArray[indexMerchantAdjustmentItemId]); }
|
||||||
|
|
||||||
if (indexSku == -1 || items[indexSku].Length == 0) { cmd.Parameters.AddWithValue("@SkuNumber", DBNull.Value); }
|
if (indexSku == -1 || rowArray[indexSku].Length == 0) { cmd.Parameters.AddWithValue("@SkuNumber", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@SkuNumber", items[indexSku]); }
|
else { cmd.Parameters.AddWithValue("@SkuNumber", rowArray[indexSku]); }
|
||||||
|
|
||||||
if (indexQuantityPurchased == -1 || items[indexQuantityPurchased].Length == 0) { cmd.Parameters.AddWithValue("@QuantityPurchased", DBNull.Value); }
|
if (indexQuantityPurchased == -1 || rowArray[indexQuantityPurchased].Length == 0) { cmd.Parameters.AddWithValue("@QuantityPurchased", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@QuantityPurchased", int.Parse(items[indexQuantityPurchased])); }
|
else { cmd.Parameters.AddWithValue("@QuantityPurchased", int.Parse(rowArray[indexQuantityPurchased])); }
|
||||||
|
|
||||||
if (indexPromotionId == -1 || items[indexPromotionId].Length == 0) { cmd.Parameters.AddWithValue("@PromotionRef", DBNull.Value); }
|
if (indexPromotionId == -1 || rowArray[indexPromotionId].Length == 0) { cmd.Parameters.AddWithValue("@PromotionRef", DBNull.Value); }
|
||||||
else { cmd.Parameters.AddWithValue("@PromotionRef", items[indexPromotionId]); }
|
else { cmd.Parameters.AddWithValue("@PromotionRef", rowArray[indexPromotionId]); }
|
||||||
|
|
||||||
cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lineNumber = lineNumber + 1;
|
lineNumber = lineNumber + 1;
|
||||||
}
|
}
|
||||||
|
// end of filestream reading
|
||||||
|
|
||||||
|
// if we haven't gotten the marketplace name from the line items, attempt to infer from currency
|
||||||
|
if (marketplaceName == null && settlementReportId > 0)
|
||||||
|
{
|
||||||
|
if (currency == "GBP")
|
||||||
|
{
|
||||||
|
marketplaceName = MarketPlaceEnum.AmazonUK.GetMarketplaceUrl();
|
||||||
|
marketplaceName = char.ToUpper(marketplaceName[0]) + marketplaceName.Substring(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// finally, if we have it, add marketplace name to main table
|
||||||
|
if (marketplaceName != null && settlementReportId > 0)
|
||||||
|
{
|
||||||
|
using (SqlCommand cmd = _connection.CreateCommand() as SqlCommand)
|
||||||
|
{
|
||||||
|
cmd.Transaction = _transaction as SqlTransaction;
|
||||||
|
cmd.CommandText = @"
|
||||||
|
UPDATE tblImportAmazonSettlementReport
|
||||||
|
SET [marketplace-name]=@MarketplaceName
|
||||||
|
WHERE ImportAmazonSettlementReportID=@ImportAmazonSettlementReportID;";
|
||||||
|
cmd.Parameters.AddWithValue("@MarketplaceName", marketplaceName);
|
||||||
|
cmd.Parameters.AddWithValue("@ImportAmazonSettlementReportID", settlementReportId);
|
||||||
|
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//final check - settlement amount matches sum of inserted settlement lines
|
//final check - settlement amount matches sum of inserted settlement lines
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Data.Database.Sku.Price
|
namespace bnhtrade.Core.Data.Database.Sku.Price
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -10,11 +10,6 @@ namespace bnhtrade.Core.Data.Database.Sku.Price
|
|||||||
{
|
{
|
||||||
public class ReadParameter : Connection
|
public class ReadParameter : Connection
|
||||||
{
|
{
|
||||||
public ReadParameter() : base()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<Model.Sku.Price.SkuRepriceInfo> Execute()
|
public List<Model.Sku.Price.SkuRepriceInfo> Execute()
|
||||||
{
|
{
|
||||||
string stringSql = @"
|
string stringSql = @"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -0,0 +1,87 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Data.SqlClient;
|
||||||
|
|
||||||
|
namespace bnhtrade.Core.Data.Database
|
||||||
|
{
|
||||||
|
internal class ServerPing
|
||||||
|
{
|
||||||
|
internal ServerPing()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Logic.Log.LogEvent log = new Logic.Log.LogEvent();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Polls SQL Server until it comes online, max attempts are reached, or the cancellation token is triggered.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout">Seconds each connection attempt waits before failing.</param>
|
||||||
|
/// <param name="maxAttempts">Maximum number of poll attempts. 0 = retry indefinitely.</param>
|
||||||
|
/// <param name="cancellationToken">Token to cancel the polling loop.</param>
|
||||||
|
/// <returns>True when the server responds, false if max attempts reached or cancelled.</returns>
|
||||||
|
internal async Task<bool> WaitForServerAsync(uint timeout = 10, uint maxAttempts = 6, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
var connection = new Connection(connectionTimeout: timeout);
|
||||||
|
|
||||||
|
int attempt = 0;
|
||||||
|
DateTime firstAttempt = DateTime.UtcNow;
|
||||||
|
int lineWidth = Console.WindowWidth - 1;
|
||||||
|
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] Starting to poll SQL Server for availability...");
|
||||||
|
|
||||||
|
while (!cancellationToken.IsCancellationRequested)
|
||||||
|
{
|
||||||
|
attempt++;
|
||||||
|
bool isFinalAttempt = maxAttempts > 0 && attempt >= maxAttempts;
|
||||||
|
|
||||||
|
Console.WriteLine($"\r[{DateTime.Now:HH:mm:ss}] Attempt {attempt} of {maxAttempts} ");
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using SqlConnection conn = new SqlConnection(connection.SqlConnectionString);
|
||||||
|
if (attempt == 1)
|
||||||
|
firstAttempt = DateTime.UtcNow;
|
||||||
|
await conn.OpenAsync(cancellationToken);
|
||||||
|
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] SQL Server is online, attempt {attempt} succeeded!");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\n[{DateTime.Now:HH:mm:ss}] Polling cancelled.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (SqlException ex)
|
||||||
|
{
|
||||||
|
if (isFinalAttempt)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] SQL Server not available (error {ex.Number}): {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFinalAttempt)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"[{DateTime.Now:HH:mm:ss}] Max attempts ({maxAttempts}) reached, could not connect to SQL Server.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// countdown overwrites the same line as the attempt message
|
||||||
|
int retrySeconds = (firstAttempt.AddSeconds(timeout * attempt) - DateTime.UtcNow).Seconds ;
|
||||||
|
for (int i = retrySeconds; i > 0; i--)
|
||||||
|
{
|
||||||
|
Console.Write($"\r[--------] Retrying in {i}s...");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await Task.Delay(TimeSpan.FromSeconds(1), cancellationToken);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"\n[{DateTime.Now:HH:mm:ss}] Polling cancelled.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using bnhtrade.Core.Data.Database._BoilerPlate;
|
using bnhtrade.Core.Data.Database._BoilerPlate;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
|
||||||
using Microsoft.Data.SqlClient;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Data.Database.Stock
|
namespace bnhtrade.Core.Data.Database.Stock
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Configuration;
|
|
||||||
|
|
||||||
namespace bnhtrade.Core.Data.Database.UnitOfWork
|
|
||||||
{
|
|
||||||
public class Connection
|
|
||||||
{
|
|
||||||
//protected readonly string SqlConnectionString;
|
|
||||||
private Model.Credentials.bnhtradeDB _dbCredentials;
|
|
||||||
|
|
||||||
protected string SqlConnectionString
|
|
||||||
{
|
|
||||||
get { return _dbCredentials.ConnectionString; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public Connection()
|
|
||||||
{
|
|
||||||
var config = new Config().GetConfiguration();
|
|
||||||
|
|
||||||
// attempt to retrive credentials from app.local.config
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string dataSource = config.AppSettings.Settings["DbDataSource"].Value;
|
|
||||||
string userId = config.AppSettings.Settings["DbUserId"].Value;
|
|
||||||
string pass = config.AppSettings.Settings["DbUserPassword"].Value;
|
|
||||||
|
|
||||||
// check
|
|
||||||
if (string.IsNullOrEmpty(dataSource))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbDataSource' from config file");
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrEmpty(userId))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbUserId' from config file");
|
|
||||||
}
|
|
||||||
else if (string.IsNullOrEmpty(pass))
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Could not retrive 'DbUserPassword' from config file");
|
|
||||||
}
|
|
||||||
|
|
||||||
var dbCredentials = new bnhtrade.Core.Model.Credentials.bnhtradeDB(dataSource, userId, pass);
|
|
||||||
this._dbCredentials = dbCredentials;
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
throw new Exception("Unable to retirve DB credentials: " + ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
using bnhtrade.Core.Test.Amazon.SP_API;
|
using bnhtrade.Core.Test.Amazon.SP_API;
|
||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using CsvHelper.Configuration.Attributes;
|
using CsvHelper.Configuration.Attributes;
|
||||||
using Microsoft.VisualBasic.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ using FikaAmazonAPI.ConstructFeed.Messages;
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Account
|
namespace bnhtrade.Core.Logic.Account
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using CsvHelper;
|
using CsvHelper;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Sku.Price
|
namespace bnhtrade.Core.Logic.Sku.Price
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Sku
|
namespace bnhtrade.Core.Logic.Sku
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using bnhtrade.Core.Data.Database;
|
using bnhtrade.Core.Data.Database;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ using bnhtrade.Core.Model.Stock;
|
|||||||
using FikaAmazonAPI.AmazonSpApiSDK.Models.Restrictions;
|
using FikaAmazonAPI.AmazonSpApiSDK.Models.Restrictions;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using bnhtrade.Core.Data.Database;
|
using bnhtrade.Core.Data.Database;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.SqlClient;
|
using Microsoft.Data.SqlClient;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -9,7 +9,7 @@ using System.Transactions;
|
|||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Stock
|
namespace bnhtrade.Core.Logic.Stock
|
||||||
{
|
{
|
||||||
public class SkuTransactionTypeCrud : Connection // this inheritance can be removed when old code is removed below
|
public class SkuTransactionTypeCrud
|
||||||
{
|
{
|
||||||
private Data.Database.Stock.ReadSkuTransactionType dbRead;
|
private Data.Database.Stock.ReadSkuTransactionType dbRead;
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace bnhtrade.Core.Logic.Utilities
|
namespace bnhtrade.Core.Logic.Utilities
|
||||||
@@ -14,8 +15,23 @@ namespace bnhtrade.Core.Logic.Utilities
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<bool> IsServerOnlineAsync()
|
||||||
|
{
|
||||||
|
using var cts = new CancellationTokenSource();
|
||||||
|
Console.CancelKeyPress += (sender, e) => { e.Cancel = true; cts.Cancel(); };
|
||||||
|
|
||||||
|
return await new bnhtrade.Core.Logic.Utilities.SqlServerPing()
|
||||||
|
.WaitForServerAsync(timeout: 15, maxAttempts: 60, cts.Token);
|
||||||
|
}
|
||||||
|
|
||||||
public void DownloadAll()
|
public void DownloadAll()
|
||||||
{
|
{
|
||||||
|
if (!IsServerOnlineAsync().GetAwaiter().GetResult())
|
||||||
|
{
|
||||||
|
Console.WriteLine("Server is not online, skipping nightly scheduled tasks.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
log.LogInformation("Nightly scheduled tasks started.");
|
log.LogInformation("Nightly scheduled tasks started.");
|
||||||
|
|
||||||
bool stockUpdate = false;
|
bool stockUpdate = false;
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
using System;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace bnhtrade.Core.Logic.Utilities
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Polls SQL Server until it comes online, max attempts are reached, or the operation is cancelled.
|
||||||
|
/// Intended for use on application startup when the remote SQL Server machine may still be booting.
|
||||||
|
/// </summary>
|
||||||
|
public class SqlServerPing
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Polls SQL Server until it comes online, max attempts are reached, or the cancellation token is triggered.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="timeout">Seconds each connection attempt waits before failing (1–300).</param>
|
||||||
|
/// <param name="maxAttempts">Maximum number of poll attempts. 0 = retry indefinitely.</param>
|
||||||
|
/// <param name="cancellationToken">Token to cancel the polling loop.</param>
|
||||||
|
/// <returns>True when the server responds, false if max attempts reached or cancelled.</returns>
|
||||||
|
public async Task<bool> WaitForServerAsync(uint timeout = 10, uint maxAttempts = 6, CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
return await new Data.Database.ServerPing().WaitForServerAsync(timeout, maxAttempts, cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
using Microsoft.VisualBasic;
|
using System;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace bnhtrade.Core.Model.Credentials
|
|
||||||
{
|
|
||||||
public class AmazonSPAPI
|
|
||||||
{
|
|
||||||
public string AccessKey { get; private set; }
|
|
||||||
public string SecretKey { get; private set; }
|
|
||||||
public string RoleArn { get; private set; }
|
|
||||||
public string ClientId { get; private set; }
|
|
||||||
public string ClientSecret { get; private set; }
|
|
||||||
public string RefreshToken { get; private set; }
|
|
||||||
|
|
||||||
public AmazonSPAPI(string accessKey, string secretKey, string roleArn, string clientId, string clientSecret, string refreshToken)
|
|
||||||
{
|
|
||||||
this.AccessKey = accessKey;
|
|
||||||
this.SecretKey = secretKey;
|
|
||||||
this.RoleArn = roleArn;
|
|
||||||
this.ClientId = clientId;
|
|
||||||
this.ClientSecret = clientSecret;
|
|
||||||
this.RefreshToken = refreshToken;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace bnhtrade.Core.Model.Credentials
|
|
||||||
{
|
|
||||||
public class bnhtradeDB
|
|
||||||
{
|
|
||||||
public string DataSource { get; private set; }
|
|
||||||
|
|
||||||
public string UserId { get; private set; }
|
|
||||||
|
|
||||||
public string UserPassword { get; private set; }
|
|
||||||
|
|
||||||
public string InitialCatalog { get; private set; } = "e2A";
|
|
||||||
|
|
||||||
public bool PersistSecurityInfo { get; private set; } = true;
|
|
||||||
|
|
||||||
public bool MultipleActiveResultSets { get; private set; } = true;
|
|
||||||
|
|
||||||
public uint ConnectionTimeout { get; private set; }
|
|
||||||
|
|
||||||
public string ConnectionString
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return "Data Source=" + DataSource + ";Initial Catalog=" + InitialCatalog + ";Persist Security Info=" + PersistSecurityInfo.ToString()
|
|
||||||
+ ";User ID=" + UserId + ";Password=" + UserPassword + ";MultipleActiveResultSets=" + MultipleActiveResultSets.ToString()
|
|
||||||
+ ";Connect Timeout=" + ConnectionTimeout + ";Encrypt=True;TrustServerCertificate=True";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public bnhtradeDB (string source, string userId, string userPassword, uint connectionTimeout = 30)
|
|
||||||
{
|
|
||||||
this.DataSource = source;
|
|
||||||
this.UserId = userId;
|
|
||||||
this.UserPassword = userPassword;
|
|
||||||
this.ConnectionTimeout = connectionTimeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms.Design;
|
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||||
<UseWindowsForms>true</UseWindowsForms>
|
|
||||||
<ImportWindowsDesktopTargets>true</ImportWindowsDesktopTargets>
|
|
||||||
<!--Added the line below to copy all dll from .nuget folder to build output folder-->
|
<!--Added the line below to copy all dll from .nuget folder to build output folder-->
|
||||||
<!--CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies-->
|
<!--CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies-->
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -40,6 +38,7 @@
|
|||||||
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
|
<PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" />
|
||||||
<PackageReference Include="RestSharp" Version="112.1.0" />
|
<PackageReference Include="RestSharp" Version="112.1.0" />
|
||||||
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
|
<PackageReference Include="RestSharp.Serializers.NewtonsoftJson" Version="112.1.0" />
|
||||||
|
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.4" />
|
||||||
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
<PackageReference Include="System.Data.SqlClient" Version="4.9.0" />
|
||||||
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Configuration;
|
using System.Configuration;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using System.Transactions;
|
using System.Transactions;
|
||||||
|
|
||||||
namespace bnhtradeScheduledTasks
|
namespace bnhtradeScheduledTasks
|
||||||
@@ -12,7 +13,7 @@ namespace bnhtradeScheduledTasks
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Main(string[] args)
|
static async Task Main(string[] args)
|
||||||
{
|
{
|
||||||
if (OperatingSystem.IsWindows())
|
if (OperatingSystem.IsWindows())
|
||||||
{
|
{
|
||||||
@@ -310,7 +311,7 @@ namespace bnhtradeScheduledTasks
|
|||||||
Console.WriteLine(consoleHeader);
|
Console.WriteLine(consoleHeader);
|
||||||
Console.WriteLine("Main Menu > Dev Funcions");
|
Console.WriteLine("Main Menu > Dev Funcions");
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
Console.WriteLine("<1> Test some randon function I've set here");
|
Console.WriteLine("<1> Ping SQL Server");
|
||||||
Console.WriteLine("<2> Test Account");
|
Console.WriteLine("<2> Test Account");
|
||||||
Console.WriteLine("<3> Test Export");
|
Console.WriteLine("<3> Test Export");
|
||||||
Console.WriteLine("<4> Test Import");
|
Console.WriteLine("<4> Test Import");
|
||||||
@@ -334,7 +335,16 @@ namespace bnhtradeScheduledTasks
|
|||||||
{
|
{
|
||||||
Console.Clear();
|
Console.Clear();
|
||||||
|
|
||||||
var obj = new bnhtrade.Core.Test.Amazon.SP_API.VariousCalls();
|
using var cts = new CancellationTokenSource();
|
||||||
|
Console.CancelKeyPress += (sender, e) => { e.Cancel = true; cts.Cancel(); };
|
||||||
|
|
||||||
|
bool online = await new bnhtrade.Core.Logic.Utilities.SqlServerPing()
|
||||||
|
.WaitForServerAsync(timeout: 10, maxAttempts: 10, cts.Token);
|
||||||
|
|
||||||
|
if (!online)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Could not connect to SQL Server.");
|
||||||
|
}
|
||||||
|
|
||||||
Console.WriteLine("Complete, press any key to continue...");
|
Console.WriteLine("Complete, press any key to continue...");
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- https://go.microsoft.com/fwlink/?LinkID=208121. -->
|
||||||
|
<Project>
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration>Release</Configuration>
|
||||||
|
<Platform>Any CPU</Platform>
|
||||||
|
<PublishDir>C:\Users\Bobbie\Desktop\bnhtrade</PublishDir>
|
||||||
|
<PublishProtocol>FileSystem</PublishProtocol>
|
||||||
|
<_TargetId>Folder</_TargetId>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RuntimeIdentifier>linux-x64</RuntimeIdentifier>
|
||||||
|
<SelfContained>false</SelfContained>
|
||||||
|
<PublishSingleFile>true</PublishSingleFile>
|
||||||
|
</PropertyGroup>
|
||||||
|
</Project>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net8.0-windows</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>bnhtrade_Scheduled_Tasks</RootNamespace>
|
<RootNamespace>bnhtrade_Scheduled_Tasks</RootNamespace>
|
||||||
<AssemblyName>bnhtradeScheduledTasks</AssemblyName>
|
<AssemblyName>bnhtradeScheduledTasks</AssemblyName>
|
||||||
|
|||||||
Reference in New Issue
Block a user