From 25cbfacc8e8ad8867223b8cdc9db511dc292d4dd Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Wed, 27 May 2020 10:57:23 -0700 Subject: [PATCH] Added QB dependencies + simple http server. --- BodyshopUploader/BodyshopPartner.csproj | 30 +++++++++++++++- BodyshopUploader/Utils/GraphQL.cs | 2 +- BodyshopUploader/Utils/HTTPServer.cs | 38 ++++++++++++++++++++ BodyshopUploader/Utils/QuickBooksInterop.cs | 31 ++++++++++++++++ BodyshopUploader/ViewModels/MainViewModel.cs | 2 ++ BodyshopUploader/packages.config | 2 ++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 BodyshopUploader/Utils/HTTPServer.cs create mode 100644 BodyshopUploader/Utils/QuickBooksInterop.cs diff --git a/BodyshopUploader/BodyshopPartner.csproj b/BodyshopUploader/BodyshopPartner.csproj index 9f3d97a..0ace047 100644 --- a/BodyshopUploader/BodyshopPartner.csproj +++ b/BodyshopUploader/BodyshopPartner.csproj @@ -80,6 +80,16 @@ ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll + + False + True + ..\..\..\Program Files (x86)\Common Files\Intuit\QuickBooks\Interop.QBFC13.dll + + + False + False + ..\..\..\Program Files (x86)\Common Files\Intuit\QuickBooks\Interop.QBXMLRP2.dll + ..\packages\MaterialDesignColors.1.2.2\lib\net45\MaterialDesignColors.dll @@ -91,6 +101,9 @@ True True + + ..\packages\MimeTypesMap.1.0.2\lib\net45\MimeTypesMap.dll + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll @@ -118,6 +131,9 @@ ..\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll + + ..\packages\Simple-HTTP.1.0.6\lib\net47\SimpleHTTP.dll + ..\packages\Splat.1.6.2\lib\Net45\Splat.dll @@ -313,12 +329,14 @@ GrowlNotification.xaml + + @@ -395,7 +413,17 @@ - + + + {0CB030A6-7B72-42CE-B92A-849B4A4A2CFB} + 1 + 0 + 0 + tlbimp + False + True + + False diff --git a/BodyshopUploader/Utils/GraphQL.cs b/BodyshopUploader/Utils/GraphQL.cs index 4156cdb..8803ab8 100644 --- a/BodyshopUploader/Utils/GraphQL.cs +++ b/BodyshopUploader/Utils/GraphQL.cs @@ -28,7 +28,7 @@ namespace BodyshopPartner.Utils var graphQLResponse = await g.PostAsync(r); if (graphQLResponse.Errors == null) { - logger.Trace("GQL Response: {0}", graphQLResponse.Data); + //logger.Trace("GQL Response: {0}", graphQLResponse.Data); return graphQLResponse.Data; } else diff --git a/BodyshopUploader/Utils/HTTPServer.cs b/BodyshopUploader/Utils/HTTPServer.cs new file mode 100644 index 0000000..5f21a57 --- /dev/null +++ b/BodyshopUploader/Utils/HTTPServer.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using SimpleHttp; + +namespace BodyshopPartner.Utils +{ + public static class HTTPServer + { + private static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger(); + + public static void InitHttpServer() + { + Route.Add("/qb/receivables", (req, res, props) => + { + res.WithCORS(); + //res.AddHeader("Access-Control-Allow-Origin", "http://localhost:3000 https://localhost:3000 http://localhost:5000 https://localhost:5000 https://*.imex.online,imex.online"); + res.Close() ; + }, "OPTIONS"); + + Route.Add("/qb/receivables", (req, res, props) => + { + Console.WriteLine("Got a hit."); + //res.WithCORS(); + Utils.QuickBooksInterop.connectToQuickBooks(); + + res.WithCORS().AsText("Hello."); + }, "POST"); + + logger.Trace("Starting HTTP server..."); + + //TODO As a part of the installer, add netsh http add urlacl url=http://+:1337/ user="Everyone + HttpServer.ListenAsync(1337, System.Threading.CancellationToken.None, Route.OnHttpRequestAsync).Wait(); + } + } +} diff --git a/BodyshopUploader/Utils/QuickBooksInterop.cs b/BodyshopUploader/Utils/QuickBooksInterop.cs new file mode 100644 index 0000000..2d7ca9e --- /dev/null +++ b/BodyshopUploader/Utils/QuickBooksInterop.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Interop.QBFC13; +using Interop.QBXMLRP2; + +namespace BodyshopPartner.Utils +{ + public static class QuickBooksInterop + { + private static string ticket; + private static RequestProcessor2 rp; + private static string maxVersion; + private static string companyFile = ""; + private static QBFileMode mode = QBFileMode.qbFileOpenDoNotCare; + private static string appID = "IDN123"; + private static string appName = "BodyshopPartner"; + + public static void connectToQuickBooks() + { + + rp = new RequestProcessor2Class(); + rp.OpenConnection(appID, appName); + ticket = rp.BeginSession(companyFile, mode); + string[] versions = rp.get_QBXMLVersionsForSession(ticket); + maxVersion = versions[versions.Length - 1]; + } + } +} diff --git a/BodyshopUploader/ViewModels/MainViewModel.cs b/BodyshopUploader/ViewModels/MainViewModel.cs index 9965bea..6b8cf60 100644 --- a/BodyshopUploader/ViewModels/MainViewModel.cs +++ b/BodyshopUploader/ViewModels/MainViewModel.cs @@ -76,6 +76,8 @@ namespace BodyshopPartner.ViewModels _callingThread.ReportProgress(80); + Utils.HTTPServer.InitHttpServer(); + logger.Debug("VM Init Complete"); _callingThread.ReportProgress(100); } diff --git a/BodyshopUploader/packages.config b/BodyshopUploader/packages.config index d1c9bf3..31a0cc5 100644 --- a/BodyshopUploader/packages.config +++ b/BodyshopUploader/packages.config @@ -11,6 +11,7 @@ + @@ -19,6 +20,7 @@ +