diff --git a/AyaNovaQBI/Timestamp.cs b/AyaNovaQBI/Timestamp.cs
index 7b7b79a..8a7a1dd 100644
--- a/AyaNovaQBI/Timestamp.cs
+++ b/AyaNovaQBI/Timestamp.cs
@@ -22,7 +22,7 @@ namespace AyaNovaQBI
///
/// Do not modify the definition of BuildAt as your changes will be discarded.
///
- public static DateTime BuildAt { get { return new DateTime(637915984703608685); } } //--**
+ public static DateTime BuildAt { get { return new DateTime(637916008895872612); } } //--**
///
/// The program that time stamped it.
///
diff --git a/AyaNovaQBI/util.cs b/AyaNovaQBI/util.cs
index f48c129..d66027b 100644
--- a/AyaNovaQBI/util.cs
+++ b/AyaNovaQBI/util.cs
@@ -76,13 +76,13 @@ namespace AyaNovaQBI
if (response.IsSuccessStatusCode)
return "OK";
else
- return "Failed: " + response.StatusCode.ToString();
+ return $"Failed: {response.StatusCode.ToString()}";
}
catch (Exception ex)
{
while (ex.InnerException != null)
ex = ex.InnerException;
- return "Failed exception: \r\n" + ex.Message;
+ return $"Failed exception: \r\n{ex.Message}";
}
}
@@ -111,7 +111,7 @@ namespace AyaNovaQBI
if (ex.InnerException != null)
InnerErr = ex.InnerException.Message;
- throw new Exception("Authentication error, route: AUTH\r\nError:" + Err + "\r\nInner error:" + InnerErr);
+ throw new Exception($"Authentication error, route: AUTH\r\nError:{Err}\r\nInner error:{InnerErr}");
}
var a = new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(await response.Content.ReadAsStringAsync()) };
@@ -217,7 +217,7 @@ namespace AyaNovaQBI
}
//no luck re-throw the exception
- throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException);
+ throw new Exception($"API call failed after {MAX_TRIES.ToString()} attempts", FirstException);
}
private async static Task TryGetAsync(string route)
@@ -238,14 +238,14 @@ namespace AyaNovaQBI
var InnerErr = "";
if (ex.InnerException != null)
InnerErr = ex.InnerException.Message;
- throw new Exception("GET error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace);
+ throw new Exception($"GET error, route: {route}\r\nError:{Err}\r\nInner error:{InnerErr}\r\nStack:{ex.StackTrace}");
}
var responseAsString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
- throw new Exception("GET error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase);
+ throw new Exception($"GET error, code: {(int)response.StatusCode}, route: {route}\r\n{responseAsString}\r\n{response.ReasonPhrase}");
}
else
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
@@ -273,7 +273,7 @@ namespace AyaNovaQBI
}
//no luck re-throw the exception
- throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException);
+ throw new Exception($"API call failed after {MAX_TRIES.ToString()} attempts", FirstException);
}
public async static Task PostAsync(string route, string s = null)
@@ -295,7 +295,7 @@ namespace AyaNovaQBI
}
//no luck re-throw the exception
- throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException);
+ throw new Exception($"API call failed after {MAX_TRIES.ToString()} attempts", FirstException);
}
@@ -320,14 +320,14 @@ namespace AyaNovaQBI
var InnerErr = "";
if (ex.InnerException != null)
InnerErr = ex.InnerException.Message;
- throw new Exception("POST error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace + "\r\nPOSTED OBJECT:\r\n" + postJson);
+ throw new Exception($"POST error, route: {route}\r\nError:{Err}\r\nInner error:{InnerErr}\r\nStack:{ex.StackTrace}\r\nPOSTED OBJECT:\r\n{postJson}");
}
var responseAsString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
if (string.IsNullOrWhiteSpace(postJson))
postJson = "n/a";
- throw new Exception("POST error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPOSTED OBJECT:\r\n" + postJson);
+ throw new Exception($"POST error, code: {(int)response.StatusCode}, route: {route}\r\n{responseAsString}\r\n{response.ReasonPhrase}\r\nPOSTED OBJECT:\r\n{postJson}");
}
else
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
@@ -382,7 +382,7 @@ namespace AyaNovaQBI
}
//no luck re-throw the exception
- throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException);
+ throw new Exception($"API call failed after {MAX_TRIES.ToString()} attempts", FirstException);
}
public async static Task PutAsync(string route)
@@ -404,7 +404,7 @@ namespace AyaNovaQBI
}
//no luck re-throw the exception
- throw new Exception("API call failed after " + MAX_TRIES.ToString() + " attempts", FirstException);
+ throw new Exception($"API call failed after {MAX_TRIES.ToString()} attempts", FirstException);
}
public async static Task TryPutAsync(string route, string putJson = null)
@@ -427,14 +427,14 @@ namespace AyaNovaQBI
var InnerErr = "";
if (ex.InnerException != null)
InnerErr = ex.InnerException.Message;
- throw new Exception("PUT error, route: " + route + "\r\nError:" + Err + "\r\nInner error:" + InnerErr + "\r\nStack:" + ex.StackTrace + "\r\nPOSTED OBJECT:\r\n" + putJson);
+ throw new Exception($"PUT error, route: {route}\r\nError:{Err}\r\nInner error:{InnerErr}\r\nStack:{ex.StackTrace}\r\nPOSTED OBJECT:\r\n{putJson}");
}
var responseAsString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
if (string.IsNullOrWhiteSpace(putJson))
putJson = "n/a";
- throw new Exception("PUT error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPUT OBJECT:\r\n" + putJson);
+ throw new Exception($"PUT error, code: {(int)response.StatusCode}, route: {route}\r\n{responseAsString}\r\n{response.ReasonPhrase}\r\nPUT OBJECT:\r\n{putJson}");
}
else
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
@@ -528,11 +528,7 @@ namespace AyaNovaQBI
//BUILD DATE VERSION ALLOWED?
if (ALicense.maintenanceExpiration < Timestamp.BuildAt)
{
- initErrors.AppendLine("NOT LICENSED!\r\n\r\nThis QBI plugin was built " +
- Timestamp.BuildAt.ToString("g") + "\r\n" +
- "but the licensed support and updates subscription has ended on " +
- ALicense.maintenanceExpiration.ToLocalTime().ToString("g") + "\r\n" +
- "\r\nDowngrade back to your previous licensed QBI version or\r\npurchase a support and updates subscription to continue using this version of QBI.");
+ initErrors.AppendLine($"NOT LICENSED!\r\n\r\nThis QBI plugin was built {Timestamp.BuildAt.ToString("g")}\r\nbut the licensed support and updates subscription has ended on {ALicense.maintenanceExpiration.ToLocalTime().ToString("g")}\r\n\r\nDowngrade back to your previous licensed QBI version or\r\npurchase a support and updates subscription to continue using this version of QBI.");
return false;
}
@@ -543,11 +539,32 @@ namespace AyaNovaQBI
LOG_AVAILABLE = true;
- //Validate QB connection can be made and open connection and start session with QB (see Util.QBValidate in v7
+ await IntegrationLog($"PFC: AyaNova user \"{AyaNovaUserName}\" starting QBI, pre-flight check (PFC) commencing");
+
+ //QB CONNECTION validation and setup
try
- {
-
- var pfstatus = await QBValidate();
+ {
+ if(await QBValidate() == pfstat.Cancel)
+ {
+ await IntegrationLog("PFC: Unable to validate QuickBooks connection, user selected cancel");
+ return false;
+ }
+ else
+ {
+ await IntegrationLog($"PFC: QB Company name= {QCompanyName}, QB Country version={QCountry}, QBVersion={QVersion}, Companyfile={QCompanyFile}");
+ //once connected collect the country, version we are dealing with (Util.qbValidate)
+ //confirm qb is 2008 or newer and bail if not (util.qbvalidate)
+ //cache company name and other qb info
+ //PFC - PopulateQBListCache()
+ //PFC - PopulateAyaListCache()
+
+
+ //PFC - Validate settings, create if necessary (Util.ValidateSettings()) and save
+ //TODO: if QBIntegration.IntegrationData==null then nothing is set yet and it's fresh so trigger the setup stuff
+
+ //PFC - verify integration mapped objects still exist at each end (Util.PreFlightCheck() line 199)
+ //DONE
+ }
}
catch(Exception ex)
{
@@ -555,18 +572,7 @@ namespace AyaNovaQBI
return false;
}
- //once connected collect the country, version we are dealing with (Util.qbValidate)
- //confirm qb is 2008 or newer and bail if not (util.qbvalidate)
- //cache company name and other qb info
- //PFC - PopulateQBListCache()
- //PFC - PopulateAyaListCache()
-
-
- //PFC - Validate settings, create if necessary (Util.ValidateSettings()) and save
- //TODO: if QBIntegration.IntegrationData==null then nothing is set yet and it's fresh so trigger the setup stuff
-
- //PFC - verify integration mapped objects still exist at each end (Util.PreFlightCheck() line 199)
- //DONE
+
return true;
@@ -594,7 +600,8 @@ namespace AyaNovaQBI
QBIntegration.Active = true;
QBIntegration.Name = "QBI - QuickBooks Desktop integration";
r = await PostAsync("integration", Newtonsoft.Json.JsonConvert.SerializeObject(QBIntegration));
- var id = IdFromResponse(r);
+ QBIntegration.Id = IdFromResponse(r);
+ await IntegrationLog("AyaNova QBI Integration installed to AyaNova");
}
else
{
@@ -661,17 +668,28 @@ namespace AyaNovaQBI
sessionManager.CloseConnection();
if (ex.ErrorCode == -2147220458 || ex.ErrorCode == -2147220472 || ex.Message.Contains("Could not start"))
{
+ var msg = "QuickBooks doesn't appear to be running on this computer.\r\n" +
+ "Start QuickBooks and open your company file now before proceeding.";
+
+ await IntegrationLog($"PFC: {msg}");
if (MessageBox.Show(
- "QuickBooks doesn't appear to be running on this computer.\r\n" +
- "Start QuickBooks and open your company file now before proceeding.",
+ msg,
"AyaNova QBI: Pre flight check",
- MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Cancel) return pfstat.Cancel;
+ MessageBoxButtons.RetryCancel, MessageBoxIcon.Information) == DialogResult.Cancel)
+ {
+ await IntegrationLog($"PFC: User opted to cancel");
+ return pfstat.Cancel;
+ }
+
+ await IntegrationLog($"PFC: User opted to retry");
+
+
}
else
{
- await IntegrationLog("PFC: QBValidate connect unanticipated exception: " + ex.Message + "\r\nError code:" + ex.ErrorCode.ToString());
- MessageBox.Show(ex.Message + "\r\nError code:" + string.Format("(HRESULT:0x{0:X8})", ex.ErrorCode));
+ await IntegrationLog($"PFC: QBValidate connect unanticipated exception: {ex.Message}\r\nError code:{ex.ErrorCode.ToString()}");
+ MessageBox.Show($"{ex.Message}\r\nError code:{string.Format("(HRESULT:0x{0:X8})", ex.ErrorCode)}");
return pfstat.Cancel;
}
@@ -718,18 +736,10 @@ namespace AyaNovaQBI
if (QVersion < 6.0)
{
- await IntegrationLog("PFC: Failed, QuickBooks found is too old, 2008 or higher is required, prompted user to run QB update utility to be able to proceed");
- CopyableMessageBox cp = new CopyableMessageBox(
-
- "You seem to be running QuickBooks older than 2008\r\n" +
- "You must update to 2008 or higher before you can use AyaNova QBI.\r\n\r\n" +
- "(If you are running QuickBooks 2008 or higher and still getting this error, ensure that you are also using QBFC7 or higher)\r\n\r\n" +
- "VERSION FOUND = " + QVersion
-
- );
-
+ var msg = $"You seem to be running QuickBooks older than 2008\r\nYou must update to 2008 or higher before you can use AyaNova QBI.\r\n\r\n(If you are running QuickBooks 2008 or higher and still getting this error, ensure that you are also using QBFC15 or higher)\r\n\r\nVERSION FOUND = {QVersion}";
+ await IntegrationLog($"PFC: Failed - {msg}");
+ CopyableMessageBox cp = new CopyableMessageBox(msg);
cp.ShowDialog();
-
return pfstat.Failed;
}
@@ -753,8 +763,8 @@ namespace AyaNovaQBI
IResponse response = responseSet.ResponseList.GetAt(0);
if (response.StatusCode != 0)
{
- await IntegrationLog("PFC: Failed Company query:" + response.StatusMessage + ", " + response.StatusCode.ToString());
- throw new ApplicationException("PFC: Failed Company query:" + response.StatusMessage + ", " + response.StatusCode.ToString());
+ await IntegrationLog($"PFC: Failed Company query:{response.StatusMessage}, {response.StatusCode.ToString()}");
+ throw new ApplicationException($"PFC: Failed Company query:{response.StatusMessage}, {response.StatusCode.ToString()}");
}
@@ -762,9 +772,7 @@ namespace AyaNovaQBI
QCompanyName = ProcessQBString(cl.CompanyName);
requestSet.ClearRequests();
//----------------
- // }
- // else
- // QCompanyName=QCompanyFile;
+
// Close the session and connection with QuickBooks
sessionManager.EndSession();
@@ -776,7 +784,7 @@ namespace AyaNovaQBI
{
//MessageBox.Show(ex.Message.ToString() + "\nStack Trace: \n" + ex.StackTrace + "\nExiting the application");
- await IntegrationLog("PFC: Failed with exception:" + ex.Message);
+ await IntegrationLog($"PFC: Failed with exception:{ex.Message}");
if (booSessionBegun)
{
sessionManager.EndSession();
@@ -880,11 +888,9 @@ namespace AyaNovaQBI
}
catch (System.FormatException)
{
- CopyableMessageBox cp = new CopyableMessageBox("SafeToDouble: Can't parse QB string double version number:\r\n[" +
- s +
- "]\r\nPlease copy and send this message to AyaNova tech support at support@ayanova.com");
+ CopyableMessageBox cp = new CopyableMessageBox($"SafeToDouble: Can't parse QB string double version number:\r\n[{s}]\r\nPlease copy and send this message to AyaNova tech support at support@ayanova.com");
cp.ShowDialog();
- throw new System.ApplicationException("SafeToDouble: Can't parse QB string double value number: \"" + s + "\"");
+ throw new System.ApplicationException($"SafeToDouble: Can't parse QB string double value number: \"{s}\"");
}
}
return retvalue;