commit dc373a484a8bcb44c7363e27349f6a7605955d09 Author: rpm-mcarman <65228808+rpm-mcarman@users.noreply.github.com> Date: Wed Feb 8 10:49:56 2023 -0500 First Commit diff --git a/Global.cs b/Global.cs new file mode 100644 index 0000000..8f45860 --- /dev/null +++ b/Global.cs @@ -0,0 +1,396 @@ +using System; +using System.Collections.Generic; +using Newtonsoft.Json; +using System.IO; + +namespace importer +{ + public class Global + { + private static Settings _settings; + private static string _storageDir; + public static string StorageDir { get { return _storageDir; } set { _storageDir = value; } } + public static Settings Settings { get { return _settings; } set { _settings = value; } } + public static string ServiceUrl + { + get + { + if (Program.Args[0] == "brandt") + return JDISImport.ServiceUrl; + else return string.Empty; + } + } + public Global() { } + public Global(string[] settingsFile) + { + if (IsWindows()) + { + Global.StorageDir = string.Format("C:/{0}/store/", settingsFile[0]).Replace("/", "\\"); + } + else if (IsMacOS()) + { + Global.StorageDir = string.Format("/Users/{0}/{1}/store/", settingsFile[1], settingsFile[0]); + } + else if (IsLinux()) + { + Global.StorageDir = string.Format("/home/{0}/{1}/store/", settingsFile[1], settingsFile[0]); + } + else + { + throw new Exception("OS cannot be detected."); + } + Global.Settings = new Settings(); + string path = Path.Combine(Global.StorageDir, string.Format("{0}.json", settingsFile[0])); + + string text = File.ReadAllText(path); + Global.Settings = JsonConvert.DeserializeObject(text); + + } + + public static bool IsWindows() => + System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); + + public static bool IsMacOS() => + System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX); + + public static bool IsLinux() => + System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux); + public static DateTime DateFormatter(string d, bool hastime = true) + { + string month, day, year, time; + + DateTime dt = new DateTime(); + if (d.IndexOf("JAN") != -1) + { + month = "01"; + d = d.Replace("JAN", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("FEB") != -1) + { + month = "02"; + d = d.Replace("FEB", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("MARCH") != -1) + { + month = "03"; + d = d.Replace("MARCH", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("MAR") != -1) + { + month = "03"; + d = d.Replace("MAR", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("APRIL") != -1) + { + month = "04"; + d = d.Replace("APRIL", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("APR") != -1) + { + month = "04"; + d = d.Replace("APR", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + + else if (d.IndexOf("MAY") != -1) + { + month = "05"; + d = d.Replace("MAY", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("JUNE") != -1) + { + month = "06"; + d = d.Replace("JUNE", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("JUN") != -1) + { + month = "06"; + d = d.Replace("JUN", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("JULY") != -1) + { + month = "07"; + d = d.Replace("JULY", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("JUL") != -1) + { + month = "07"; + d = d.Replace("JUL", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("AUG") != -1) + { + month = "08"; + d = d.Replace("AUG", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("SEPT") != -1) + { + month = "09"; + d = d.Replace("SEPT", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("SEP") != -1) + { + month = "09"; + d = d.Replace("SEP", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("OCT") != -1) + { + month = "10"; + d = d.Replace("OCT", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("0CT") != -1) + { + month = "10"; + d = d.Replace("0CT", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else if (d.IndexOf("NOV") != -1) + { + month = "11"; + d = d.Replace("NOV", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + else + { + month = "12"; + d = d.Replace("DEC", "|"); + day = d.Substring(0, d.IndexOf("|")); + year = d.Substring(d.IndexOf("|") + 1, 4); + if (hastime) + time = d.Substring(d.IndexOf(":") - 3 + 2); + else time = "00:00:00.000"; + + string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time); + dt = DateTime.Parse(date); + } + return dt; + } + } + public static class Deserialize + { + public static T FromJson(string json) + { + //Console.WriteLine(json); + return JsonConvert.DeserializeObject(json, Converter.Settings); + + } + } + public static class Serialize + { + public static string ToJson(this T self) + { + return JsonConvert.SerializeObject(self, Converter.Settings); + } + } + internal static class Converter + { + public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings + { + MetadataPropertyHandling = MetadataPropertyHandling.Ignore, + DateParseHandling = DateParseHandling.None, + DateFormatHandling = DateFormatHandling.MicrosoftDateFormat, + }; + } + [JsonObject(MemberSerialization.OptIn)] + public class Settings + { + + [JsonProperty(PropertyName = "Remote")] + public bool Remote { get; set; } + [JsonProperty(PropertyName = "LogFile")] + public string LogFile { get; set; } + [JsonProperty(PropertyName = "MailProperties")] + public MailProperties MailProperties { get; set; } + [JsonProperty(PropertyName = "Prelub")] + public Prelub Prelub { get; set; } + [JsonProperty(PropertyName = "Customer")] + public string Customer { get; set; } + } + [JsonObject(MemberSerialization.OptIn)] + public class MailProperties + { + [JsonProperty(PropertyName = "AppID")] + public string AppID { get; set; } + [JsonProperty(PropertyName = "TenentID")] + public string TenentID { get; set; } + [JsonProperty(PropertyName = "ObjectId")] + public string ObjectId { get; set; } + [JsonProperty(PropertyName = "SecretID")] + public string SecretID { get; set; } + [JsonProperty(PropertyName = "SecretV")] + public string SecretV { get; set; } + [JsonProperty(PropertyName = "Mailbox")] + public string Mailbox { get; set; } + [JsonProperty(PropertyName = "Url")] + public string Url { get; set; } + [JsonProperty(PropertyName = "Password")] + public string Password { get; set; } + [JsonProperty(PropertyName = "Username")] + public string Username { get; set; } + [JsonProperty(PropertyName = "Scope")] + public string Scope { get; set; } + [JsonProperty(PropertyName = "Filter")] + public string Filter { get; set; } + } + [JsonObject(MemberSerialization.OptIn)] + public class Prelub + { + [JsonProperty(PropertyName = "LocalService")] + public string LocalService { get; set; } + [JsonProperty(PropertyName = "RemoteService")] + public string RemoteService { get; set; } + } +} +/* +{ + "MailProperties": { + "Username": "mcarman@prelub.com", + "Password": "Gr@nt@cc3$$", + "Mailbox": 4, + "Url": "https://outlook.office365.com/ews/Exchange.asmx", + "Filter": "Brandt Import, brandt import, Brandt import, brandt Import, BRANDT IMPORT", + "AppID": "489776b1-ee79-4b14-bc44-9f6bf47332db", + "TenentID": "1fd06c96-d3a4-45e9-9ed7-bcecb394d277", + "ObjectId": "c7647074-edb6-4e8e-8a01-a1ed924fdae9", + "SecretID": "cba04a6c-a233-4646-909b-b50921edbe1c", + "SecretV": "up-8Q~y46~JyQZjJlsAJ-zpXpglpmuPIJ1Gx3a2O" + }, + "Remote": false, + "LogFile": "jdis.log", + "Prelub": { + "LocalService": "http://servicesbrandt.rpmindustries.com:8081", + "RemoteService": "https://servicesbrandt.rpmindustries.com" + } +} +*/ \ No newline at end of file diff --git a/ImportObjects/CustomerImport.cs b/ImportObjects/CustomerImport.cs new file mode 100644 index 0000000..2f5d4d5 --- /dev/null +++ b/ImportObjects/CustomerImport.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace importer.ImportObjects +{ + public class CustomerImport + { + public string Number { get; set; } + public string Name { get; set; } + public string Addr1 { get; set; } + public string Addr2 { get; set; } + public string City { get; set; } + public string State { get; set; } + public string Zip { get; set; } + } +} \ No newline at end of file diff --git a/ImportObjects/EquipmentImport.cs b/ImportObjects/EquipmentImport.cs new file mode 100644 index 0000000..8ce0be6 --- /dev/null +++ b/ImportObjects/EquipmentImport.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using importer.RestObjects; + +namespace importer.ImportObjects +{ + public class EquipmentImport + { + public bool IsNew { get; set; } + public int MID { get; set; } + public string Make { get; set; } + public string Model { get; set; } + public string SerialNumber { get; set; } + public string EquipmentNumber { get; set; } + public string MeterReading { get; set; } + public static int MachineExists(string serialNumber) + { + Dictionary search = new Dictionary(); + search.Add("search", serialNumber); + RESTService svc = new RESTService(); + List machines = svc.RestGet("Equipments.svc", search); + if (machines.Count > 0) return machines.LastOrDefault().ID; + else return 0; + } + } +} \ No newline at end of file diff --git a/ImportObjects/PartImport.cs b/ImportObjects/PartImport.cs new file mode 100644 index 0000000..95cd098 --- /dev/null +++ b/ImportObjects/PartImport.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace importer.ImportObjects +{ + public class PartImport + { + + public string Qty { get; set; } + public string Number { get; set; } + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/ImportObjects/WorkOrderImport.cs b/ImportObjects/WorkOrderImport.cs new file mode 100644 index 0000000..f745885 --- /dev/null +++ b/ImportObjects/WorkOrderImport.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace importer.ImportObjects +{ + public class WorkOrderImport + { + public DateTime CreateDate { get; set; } + public DateTime OpnDt { get; set; } + public string Number { get; set; } + public string Segment { get; set; } + public string InspectionLevel { get; set; } + public string TechnicianUserID { get; set; } + public DateTime ScheduledStartDate { get; set; } + public string InspectionInterval { get; set; } + public string InspectionType { get; set; } + public string CodeAndDescriptionOriginal { get; set; } + } +} \ No newline at end of file diff --git a/JDISImport.cs b/JDISImport.cs new file mode 100644 index 0000000..9507ce5 --- /dev/null +++ b/JDISImport.cs @@ -0,0 +1,536 @@ +using System.Security.Principal; +using System; +using System.Text; +using System.Linq; +using System.Collections.Generic; +using importer.RestObjects; +using importer.ImportObjects; +using System.IO; + +namespace importer +{ + public class JDISImport + { + private static string _serviceUrl; + private static RESTService _rservice; + private static List _customers; + private static List _makes; + private static List _products; + private static List _models; + private static List _inspectionTypes; + private static List