diff --git a/Common.cs b/Common.cs new file mode 100644 index 0000000..06208b9 --- /dev/null +++ b/Common.cs @@ -0,0 +1,28 @@ + + +namespace uri_import +{ + public class Common + { + public EmailSettings Email { get; set; } + public AcumaticaSettings Acumatica { get; set; } + } + public class EmailSettings + { + public string Username { get; set; } + public string Password { get; set; } + public int Mailbox { get; set; } + public string Url { get; set; } + public string Filter { get; set; } + + } + public class AcumaticaSettings + { + public string Url { get; set; } + public string Username { get; set; } + public string Password { get; set; } + public string Tenant { get; set; } + public string Branch { get; set; } + public string Locale { get; set; } + } +} \ No newline at end of file diff --git a/EClasses/Ex365.cs b/EClasses/Ex365.cs index 77d1281..ebe3291 100644 --- a/EClasses/Ex365.cs +++ b/EClasses/Ex365.cs @@ -1,4 +1,4 @@ -using System.IO; + using System.Net; using System; using System.Collections.Generic; @@ -22,7 +22,7 @@ namespace uri_import.EClasses public Ex365(string username, string password) { _credential = new NetworkCredential(username, password); - _service = new Service("https://outlook.office365.com/ews/Exchange.asmx", _credential); + _service = new Service(Program.Cmn.Email.Url, _credential); } public Ex365(string username, string password, string url) @@ -42,7 +42,7 @@ namespace uri_import.EClasses int index = 1; List list = new List(); IsEqualTo restriction = new IsEqualTo(MessagePropertyPath.HasAttachments, hasAttachment); - Contains subFilter = new Contains(MessagePropertyPath.Subject, "United Rentals, Inc:", ContainmentMode.Prefixed, ContainmentComparison.IgnoreCase); + Contains subFilter = new Contains(MessagePropertyPath.Subject, Program.Cmn.Email.Filter, ContainmentMode.Prefixed, ContainmentComparison.IgnoreCase); ItemShape itemShape = new ItemShape(ShapeType.Id); FindItemResponse response = _service.FindItem(StandardFolder.Inbox, itemShape, subFilter); for (int i = 0; i < response.Items.Count; i++) @@ -107,8 +107,8 @@ namespace uri_import.EClasses public SalesOrder SalesOrder { get; set; } public string SalesOrderNumber { get; set; } public List ProductionOrders { get { return _productionOrders; } set { _productionOrders = value; } } - public bool Released { get{return _released;} set{_released = value;}} - public bool Linked { get{return _linked;} set{_linked = value;}} + public bool Released { get { return _released; } set { _released = value; } } + public bool Linked { get { return _linked; } set { _linked = value; } } public List Errors { get { return _errors; } set { _errors = value; } } } } \ No newline at end of file diff --git a/FClasses/JSONActions.cs b/FClasses/JSONActions.cs new file mode 100644 index 0000000..74c693f --- /dev/null +++ b/FClasses/JSONActions.cs @@ -0,0 +1,17 @@ + +using Newtonsoft.Json; +using System.IO; + +namespace uri_import +{ + public class JSONActions + { + public static Common ReadSettings(string file) + { + string text = File.ReadAllText(file); + Common c = JsonConvert.DeserializeObject(text); + return c; + } + + } +} \ No newline at end of file diff --git a/Program.cs b/Program.cs index 66662f7..874cf78 100644 --- a/Program.cs +++ b/Program.cs @@ -13,16 +13,26 @@ namespace uri_import { class Program { + public static Common Cmn { get; set; } static void Main(string[] args) { + Cmn = JSONActions.ReadSettings("settings.json"); FileActions.MakeDirectories(); - Ex365 exch = new Ex365("mcarman@prelub.com", "Gr@nt@cc3$$", "https://outlook.office365.com/ews/Exchange.asmx", Independentsoft.Exchange.StandardFolder.Inbox); - List pos = exch.GetPOs("United Rentals, Inc:"); + Ex365 exch = new Ex365(Cmn.Email.Username, + Cmn.Email.Password, + Cmn.Email.Url, + (Independentsoft.Exchange.StandardFolder)Cmn.Email.Mailbox); + List pos = exch.GetPOs(Cmn.Email.Filter); List sos = new List(); WritePOsToDirectory(pos); try { - var config = AcumaticaREST.Config("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); + var config = AcumaticaREST.Config(Cmn.Acumatica.Url, + Cmn.Acumatica.Username, + Cmn.Acumatica.Password, + Cmn.Acumatica.Tenant, + null, + null); foreach (EmailAttachment ea in pos) { @@ -32,7 +42,10 @@ namespace uri_import } catch (Exception lex) { - ea.Errors.Add(string.Format("{0} {1} {2}", DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), lex.Message)); + ea.Errors.Add(string.Format("{0} {1} {2}", + DateTime.Now.ToShortDateString(), + DateTime.Now.ToShortTimeString(), + lex.Message)); } ea.SalesOrder = PDFHelper.PDFBuildSalesOrder(PDFHelper.PDFLinesToText(ea.FilePath)); SalesOrder order = ea.SalesOrder; @@ -49,7 +62,6 @@ namespace uri_import AcumaticaREST.CreateSalesOrder(ref order, config, ea.FileName, ea.Content); ea.SalesOrder.OrderNbr = order.OrderNbr; ea.SalesOrder.ID = order.ID; - //AcumaticaREST.UploadPurchaseOrder(config, ea.SalesOrder, "PurchaseOrder.pdf", ea.Content); int ln = 1; foreach (SalesOrderDetail detail in ea.SalesOrder.Details) { @@ -61,13 +73,27 @@ namespace uri_import prod.SOOrderType = "SO"; prod.SOLineNbr = detail.LineNbr; ln = ln + 1; - AcumaticaREST.CreateProductionOrder(config, ref prod, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); + AcumaticaREST.CreateProductionOrder(config, + ref prod, + Cmn.Acumatica.Url, + Cmn.Acumatica.Username, + Cmn.Acumatica.Password, + Cmn.Acumatica.Tenant, + null, + null); ea.ProductionOrders.Add(prod); } } foreach (EmailAttachment ea in pos) { - AcumaticaREST.ReleaseAndLinkProductionOrders(config, ea, "https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); + AcumaticaREST.ReleaseAndLinkProductionOrders(config, + ea, + Cmn.Acumatica.Url, + Cmn.Acumatica.Username, + Cmn.Acumatica.Password, + Cmn.Acumatica.Tenant, + null, + null); } } catch (Exception exception) @@ -76,15 +102,30 @@ namespace uri_import } finally { - AcumaticaREST.APILogout("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", null, null); + AcumaticaREST.APILogout(Cmn.Acumatica.Url, + Cmn.Acumatica.Username, + Cmn.Acumatica.Password, + Cmn.Acumatica.Tenant, + null, + null); } - using (RestService service = new RestService("https://rpmindustries.acumatica.com", "bryckman", "Washington1", "RPM SANDBOX", "en_US")) + using (RestService service = new RestService(Cmn.Acumatica.Url, + Cmn.Acumatica.Username, + Cmn.Acumatica.Password, + Cmn.Acumatica.Tenant, + Cmn.Acumatica.Locale)) { foreach (EmailAttachment ea in pos) { try { - AcumaticaREST.PutFile(service, ea.SalesOrder, "https://rpmindustries.acumatica.com", "SO", ea.SalesOrder.OrderNbr.Value.ToString(), ea.FileName, ea.Content); + AcumaticaREST.PutFile(service, + ea.SalesOrder, + Cmn.Acumatica.Url, + "SO", + ea.SalesOrder.OrderNbr.Value.ToString(), + ea.FileName, + ea.Content); } catch { } } @@ -95,9 +136,11 @@ namespace uri_import { foreach (EmailAttachment obj in pos) { - string path = Path.Combine(FileActions.Attachments, obj.FileName); + string path = Path.Combine(FileActions.Attachments, + obj.FileName); if (!File.Exists(path)) - File.WriteAllBytes(path, obj.Content); + File.WriteAllBytes(path, + obj.Content); Console.WriteLine(obj.FilePath); } } diff --git a/bin/Debug/net6.0/settings.json b/bin/Debug/net6.0/settings.json new file mode 100644 index 0000000..9376cca --- /dev/null +++ b/bin/Debug/net6.0/settings.json @@ -0,0 +1,17 @@ +{ + "Email": { + "Username": "mcarman", + "Password": "Gr@nt@cc3$$", + "Mailbox": 4, + "Url": "https://outlook.office365.com/ews/Exchange.asmx", + "Filter": "United Rentals, Inc:" + }, + "Acumatica": { + "Url": "https://rpmindustries.acumatica.com", + "Username": "bryckman", + "Password": "Washington1", + "Tenant": "RPM SANDBOX", + "Branch": null, + "Locale": "en_US" + } +} diff --git a/bin/Debug/net6.0/uri_import.deps.json b/bin/Debug/net6.0/uri_import.deps.json index 71bd394..0e72109 100644 --- a/bin/Debug/net6.0/uri_import.deps.json +++ b/bin/Debug/net6.0/uri_import.deps.json @@ -14,6 +14,7 @@ "Acumatica.SOAPLikeWrapperForREST": "2.2.0", "Independentsoft.Exchange": "3.0.700", "Microsoft.AspNet.WebApi.Client": "5.2.9", + "Newtonsoft.Json": "13.0.1", "iTextSharp": "5.5.13.3" }, "runtime": { diff --git a/bin/Debug/net6.0/uri_import.dll b/bin/Debug/net6.0/uri_import.dll index 09a76cb..2d300a1 100644 Binary files a/bin/Debug/net6.0/uri_import.dll and b/bin/Debug/net6.0/uri_import.dll differ diff --git a/bin/Debug/net6.0/uri_import.pdb b/bin/Debug/net6.0/uri_import.pdb index 738c551..ea661ac 100644 Binary files a/bin/Debug/net6.0/uri_import.pdb and b/bin/Debug/net6.0/uri_import.pdb differ diff --git a/obj/Debug/net6.0/ref/uri_import.dll b/obj/Debug/net6.0/ref/uri_import.dll index 7707657..2b849ab 100644 Binary files a/obj/Debug/net6.0/ref/uri_import.dll and b/obj/Debug/net6.0/ref/uri_import.dll differ diff --git a/obj/Debug/net6.0/refint/uri_import.dll b/obj/Debug/net6.0/refint/uri_import.dll index 7707657..2b849ab 100644 Binary files a/obj/Debug/net6.0/refint/uri_import.dll and b/obj/Debug/net6.0/refint/uri_import.dll differ diff --git a/obj/Debug/net6.0/uri_import.assets.cache b/obj/Debug/net6.0/uri_import.assets.cache index 28aacdb..c2d0896 100644 Binary files a/obj/Debug/net6.0/uri_import.assets.cache and b/obj/Debug/net6.0/uri_import.assets.cache differ diff --git a/obj/Debug/net6.0/uri_import.csproj.CoreCompileInputs.cache b/obj/Debug/net6.0/uri_import.csproj.CoreCompileInputs.cache index c92ad4e..1068f0a 100644 --- a/obj/Debug/net6.0/uri_import.csproj.CoreCompileInputs.cache +++ b/obj/Debug/net6.0/uri_import.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -4e4c11c4c71f46c18965a424b9f9a1438c6d22fe +78d01467e9e3cc497ef927b78a1d505298ac0fad diff --git a/obj/Debug/net6.0/uri_import.csproj.FileListAbsolute.txt b/obj/Debug/net6.0/uri_import.csproj.FileListAbsolute.txt index c6eed4d..20dd8a3 100644 --- a/obj/Debug/net6.0/uri_import.csproj.FileListAbsolute.txt +++ b/obj/Debug/net6.0/uri_import.csproj.FileListAbsolute.txt @@ -56,3 +56,4 @@ /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.pdb /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/uri_import.genruntimeconfig.cache /Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/obj/Debug/net6.0/ref/uri_import.dll +/Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/bin/Debug/net6.0/settings.json diff --git a/obj/Debug/net6.0/uri_import.dll b/obj/Debug/net6.0/uri_import.dll index 09a76cb..2d300a1 100644 Binary files a/obj/Debug/net6.0/uri_import.dll and b/obj/Debug/net6.0/uri_import.dll differ diff --git a/obj/Debug/net6.0/uri_import.pdb b/obj/Debug/net6.0/uri_import.pdb index 738c551..ea661ac 100644 Binary files a/obj/Debug/net6.0/uri_import.pdb and b/obj/Debug/net6.0/uri_import.pdb differ diff --git a/obj/project.assets.json b/obj/project.assets.json index 1acf22d..53cfcde 100644 --- a/obj/project.assets.json +++ b/obj/project.assets.json @@ -16929,6 +16929,7 @@ "Acumatica.SOAPLikeWrapperForREST >= 2.2.0", "Independentsoft.Exchange >= 3.0.700", "Microsoft.AspNet.WebApi.Client >= 5.2.9", + "Newtonsoft.Json >= 13.0.1", "iTextSharp >= 5.5.13.3" ] }, @@ -16997,6 +16998,10 @@ "target": "Package", "version": "[5.2.9, )" }, + "Newtonsoft.Json": { + "target": "Package", + "version": "[13.0.1, )" + }, "iTextSharp": { "target": "Package", "version": "[5.5.13.3, )" diff --git a/obj/project.nuget.cache b/obj/project.nuget.cache index c0a65fb..f762b10 100644 --- a/obj/project.nuget.cache +++ b/obj/project.nuget.cache @@ -1,6 +1,6 @@ { "version": 2, - "dgSpecHash": "B4b8ZmD30OLjaqk4Q6OPh7+OqtVFjvXbHsidJuIJoVxkqWHyCbX6HwI1svFaWxIyFFyRcegok5GCYMGmnGfDCg==", + "dgSpecHash": "7WpKbFkHS/s7tOD5MbhBm5xnUQv3bAyqqClFUIT5edY5sOGg/XhzW7kt2OeNB6fPvlsbV7mnaXN0z+1a7bMP0g==", "success": true, "projectFilePath": "/Volumes/New2TBDrive/apps/acumatica/console/ac_uri_import/Acumatica_Import_URI/uri_import.csproj", "expectedPackageFiles": [ diff --git a/obj/uri_import.csproj.nuget.dgspec.json b/obj/uri_import.csproj.nuget.dgspec.json index 0a313b8..e9e5398 100644 --- a/obj/uri_import.csproj.nuget.dgspec.json +++ b/obj/uri_import.csproj.nuget.dgspec.json @@ -65,6 +65,10 @@ "target": "Package", "version": "[5.2.9, )" }, + "Newtonsoft.Json": { + "target": "Package", + "version": "[13.0.1, )" + }, "iTextSharp": { "target": "Package", "version": "[5.5.13.3, )" diff --git a/settings.json b/settings.json new file mode 100644 index 0000000..9376cca --- /dev/null +++ b/settings.json @@ -0,0 +1,17 @@ +{ + "Email": { + "Username": "mcarman", + "Password": "Gr@nt@cc3$$", + "Mailbox": 4, + "Url": "https://outlook.office365.com/ews/Exchange.asmx", + "Filter": "United Rentals, Inc:" + }, + "Acumatica": { + "Url": "https://rpmindustries.acumatica.com", + "Username": "bryckman", + "Password": "Washington1", + "Tenant": "RPM SANDBOX", + "Branch": null, + "Locale": "en_US" + } +} diff --git a/uri_import.csproj b/uri_import.csproj index 4fd1777..32a61cb 100644 --- a/uri_import.csproj +++ b/uri_import.csproj @@ -13,7 +13,10 @@ - + + + Always +