Added better error handling + added bulk handling of payable import BOD-152

This commit is contained in:
Patrick Fic
2020-06-04 09:52:17 -07:00
parent fe4cb24742
commit b9573b38f0
11 changed files with 202 additions and 27 deletions

View File

@@ -127,7 +127,7 @@
To="0"
Storyboard.TargetProperty="Opacity"
Duration="0:0:1"
BeginTime="0:0:2" />
BeginTime="0:0:3" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>

View File

@@ -46,28 +46,48 @@ namespace BodyshopPartner.Utils
List<QbRequestItem> AllRequests = ParseRequest(req);
List<QbResponseItem> HttpResponse = new List<QbResponseItem>();
// string requestXMLstring = ParseBodyToString(req);
hlog("Connecting to QuickBooks. This may take a moment...");
QuickBooksInterop.ConnectToQuickBooks();
foreach (QbRequestItem request in AllRequests)
{
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequest(request.QbXML));
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
logger.Trace(response.ToString());
logger.Debug(ResponseStatus.ToString());
hlog(ResponseStatus.ToString());
QbResponseItem r = new QbResponseItem()
try
{
Id = request.Id,
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
ErrorMessage = ResponseStatus.StatusMessage
};
hlog("Processing QuickBooks request. ImEX Online Record ID:" + request.Id);
XDocument response = XDocument.Parse(QuickBooksInterop.ProcessQBXmlRequestUnManaged(request.QbXML));
QbXmlResponse ResponseStatus = QuickBooksInterop.ParseResponseXml(response);
logger.Trace(response.ToString());
logger.Debug(ResponseStatus.ToString());
hlog(ResponseStatus.ToString());
QbResponseItem r = new QbResponseItem()
{
Id = request.Id,
Success = ResponseStatus.StatusCode == "0" || request.OkStatusCodes.Contains(ResponseStatus.StatusCode),
ErrorMessage = ResponseStatus.StatusMessage
};
HttpResponse.Add(r);
}
catch (Exception Ex)
{
//Shouldn't really get here unless something is malformed.
logger.Error(Ex, "Error encountered when processing QbXML Request.\n {0}", request.QbXML);
QbResponseItem r = new QbResponseItem()
{
Id = request.Id,
Success = false,
ErrorMessage = Ex.Message
};
HttpResponse.Add(r);
}
HttpResponse.Add(r);
}
QuickBooksInterop.DisconnectFromQuickBooks();
hlog("Completed QuickBooks request.");
hlog("Completed QuickBooks requests.");
res.WithCORS().AsText(JsonConvert.SerializeObject(HttpResponse));
}

View File

@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.Xml.Linq;
using BodyshopPartner.Utils.Growls;
using Interop.QBFC13;
using Interop.QBXMLRP2;
@@ -16,20 +17,43 @@ namespace BodyshopPartner.Utils
private static string ticket;
private static RequestProcessor2 rp;
private static string maxVersion;
private static string companyFile = "";
//public static string companyFile; //= @"C:\Users\pfic\Development\QB Testing\Testing\DANS2014.QBW";
private static QBFileMode mode = QBFileMode.qbFileOpenDoNotCare;
private static string appID = "ImEXBSP";
private static string appName = "BodyshopPartner";
private static GrowlNotification Growler;
public static void ConnectToQuickBooks()
{
try
{
logger.Debug("Attempting to connect to QuickBooks...");
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbConnection_Title,
Message = Properties.Resources.Msg_QbConnection_Msg
});
});
rp = new RequestProcessor2Class();
rp.OpenConnection(appID, appName);
ticket = rp.BeginSession(companyFile, mode);
ticket = rp.BeginSession(Properties.Settings.Default.QuickBooksFilePath, mode);
string[] versions = rp.get_QBXMLVersionsForSession(ticket);
maxVersion = versions[versions.Length - 1];
logger.Debug("Connected to QuickBooks. Ticket: " + ticket.ToString());
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbConnected_Title,
Message = Properties.Resources.Msg_QbConnected_Msg
});
});
}
catch (Exception ex)
{
@@ -47,6 +71,16 @@ namespace BodyshopPartner.Utils
rp.EndSession(ticket);
ticket = null;
rp.CloseConnection();
App.Current.Dispatcher.Invoke(() =>
{
Growler.AddNotification(new Notification()
{
Id = new Random().Next(),
Title = Properties.Resources.Msg_QbDisconnection_Title,
Message = Properties.Resources.Msg_QbDisconnection_Msg
});
});
logger.Debug("Disconnected from QuickBooks successfully.");
}
catch (Exception ex)
{
@@ -70,7 +104,22 @@ namespace BodyshopPartner.Utils
return null;
}
}
public static string ProcessQBXmlRequestUnManaged(string request)
{
try
{
//ConnectToQuickBooks();
var ret = rp.ProcessRequest(ticket, request);
//DisconnectFromQuickBooks();
return ret;
}
catch (Exception e)
{
logger.Error(e.Message);
// DisconnectFromQuickBooks();
return null;
}
}
public static Models.QbXmlResponse ParseResponseXml(XDocument response)
{
XElement QueryResponse = response.Root.Descendants("QBXMLMsgsRs").Descendants().FirstOrDefault();
@@ -87,6 +136,10 @@ namespace BodyshopPartner.Utils
Response = response
};
}
public static void SetGrowler(GrowlNotification g)
{
Growler = g;
}
}
}