diff --git a/BodyshopUploader/App.config b/BodyshopUploader/App.config index 9c7497c..2deac30 100644 --- a/BodyshopUploader/App.config +++ b/BodyshopUploader/App.config @@ -46,6 +46,9 @@ True + + + \ No newline at end of file diff --git a/BodyshopUploader/Properties/Resources.Designer.cs b/BodyshopUploader/Properties/Resources.Designer.cs index 794886f..10ad562 100644 --- a/BodyshopUploader/Properties/Resources.Designer.cs +++ b/BodyshopUploader/Properties/Resources.Designer.cs @@ -267,6 +267,60 @@ namespace BodyshopPartner.Properties { } } + /// + /// Looks up a localized string similar to Successfully connected to QuickBooks. Processing requests.... + /// + public static string Msg_QbConnected_Msg { + get { + return ResourceManager.GetString("Msg_QbConnected_Msg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to QuickBooks Connection. + /// + public static string Msg_QbConnected_Title { + get { + return ResourceManager.GetString("Msg_QbConnected_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Please do not close ImEX Online or ImEX Partner during the connection process.. + /// + public static string Msg_QbConnection_Msg { + get { + return ResourceManager.GetString("Msg_QbConnection_Msg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to QuickBooks Connection Request. + /// + public static string Msg_QbConnection_Title { + get { + return ResourceManager.GetString("Msg_QbConnection_Title", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Successfully disconnected from QuickBooks.. + /// + public static string Msg_QbDisconnection_Msg { + get { + return ResourceManager.GetString("Msg_QbDisconnection_Msg", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to QuickBooks Disconnection. + /// + public static string Msg_QbDisconnection_Title { + get { + return ResourceManager.GetString("Msg_QbDisconnection_Title", resourceCulture); + } + } + /// /// Looks up a localized string similar to Password. /// diff --git a/BodyshopUploader/Properties/Resources.resx b/BodyshopUploader/Properties/Resources.resx index 1d758ed..8e51161 100644 --- a/BodyshopUploader/Properties/Resources.resx +++ b/BodyshopUploader/Properties/Resources.resx @@ -186,6 +186,24 @@ Error uploading job. + + Successfully connected to QuickBooks. Processing requests... + + + QuickBooks Connection + + + Please do not close ImEX Online or ImEX Partner during the connection process. + + + QuickBooks Connection Request + + + Successfully disconnected from QuickBooks. + + + QuickBooks Disconnection + Password diff --git a/BodyshopUploader/Properties/Settings.Designer.cs b/BodyshopUploader/Properties/Settings.Designer.cs index 8622a17..5ac176e 100644 --- a/BodyshopUploader/Properties/Settings.Designer.cs +++ b/BodyshopUploader/Properties/Settings.Designer.cs @@ -92,5 +92,17 @@ namespace BodyshopPartner.Properties { this["AutoStartMonitor"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("")] + public string QuickBooksFilePath { + get { + return ((string)(this["QuickBooksFilePath"])); + } + set { + this["QuickBooksFilePath"] = value; + } + } } } diff --git a/BodyshopUploader/Properties/Settings.settings b/BodyshopUploader/Properties/Settings.settings index daa64b3..4bc4dda 100644 --- a/BodyshopUploader/Properties/Settings.settings +++ b/BodyshopUploader/Properties/Settings.settings @@ -20,5 +20,8 @@ True + + + \ No newline at end of file diff --git a/BodyshopUploader/Utils/Growls/GrowlNotification.xaml b/BodyshopUploader/Utils/Growls/GrowlNotification.xaml index 0d72771..d3c288a 100644 --- a/BodyshopUploader/Utils/Growls/GrowlNotification.xaml +++ b/BodyshopUploader/Utils/Growls/GrowlNotification.xaml @@ -127,7 +127,7 @@ To="0" Storyboard.TargetProperty="Opacity" Duration="0:0:1" - BeginTime="0:0:2" /> + BeginTime="0:0:3" /> diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs index 0999aee..e01ea71 100644 --- a/BodyshopUploader/Utils/HTTPServer.cs +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -46,28 +46,48 @@ namespace BodyshopPartner.Utils List AllRequests = ParseRequest(req); List HttpResponse = new List(); - // 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)); } diff --git a/BodyshopUploader/Utils/QuickBooksInterop.cs b/BodyshopUploader/Utils/QuickBooksInterop.cs index 8f7d863..d1ebdf6 100644 --- a/BodyshopUploader/Utils/QuickBooksInterop.cs +++ b/BodyshopUploader/Utils/QuickBooksInterop.cs @@ -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; + } } } diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index d76a12e..455626f 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -33,6 +33,7 @@ namespace BodyshopPartner.ViewModels Growler = new GrowlNotification(this); Utils.JobProcessingQueue.SetGrowler(Growler); + Utils.QuickBooksInterop.SetGrowler(Growler); } private void Bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) @@ -227,7 +228,7 @@ namespace BodyshopPartner.ViewModels { Notification _n = new Notification() { - Id = 123, + Id = new Random().Next(), Title = "This is a title", Subtitle = "Subtitle", Message = "Somethin" diff --git a/BodyshopUploader/Views/Main.xaml b/BodyshopUploader/Views/Main.xaml index c3291b3..0b65311 100644 --- a/BodyshopUploader/Views/Main.xaml +++ b/BodyshopUploader/Views/Main.xaml @@ -21,6 +21,7 @@ FontFamily="{DynamicResource MaterialDesignFont}" Loaded="Window_Loaded" xmlns:util="clr-namespace:BodyshopPartner.Utils" + xmlns:properties="clr-namespace:BodyshopPartner.Properties" Closing="Window_Closing"> @@ -205,13 +206,17 @@ + + + + - diff --git a/BodyshopUploader/Views/Main.xaml.cs b/BodyshopUploader/Views/Main.xaml.cs index a4c5c29..179e941 100644 --- a/BodyshopUploader/Views/Main.xaml.cs +++ b/BodyshopUploader/Views/Main.xaml.cs @@ -35,5 +35,11 @@ namespace BodyshopPartner.Views e.Cancel = true ; this.Hide(); } + + private void TextBox_TextChanged(object sender, TextChangedEventArgs e) + { + Properties.Settings.Default.QuickBooksFilePath = ((System.Windows.Controls.TextBox)sender).Text; + Properties.Settings.Default.Save(); + } } }