Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

3 anni fa
3 anni fa
3 anni fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4. using System.IO;
  5. namespace importer
  6. {
  7. public class Global
  8. {
  9. private static Settings _settings;
  10. private static string _storageDir;
  11. public static string StorageDir { get { return _storageDir; } set { _storageDir = value; } }
  12. public static Settings Settings { get { return _settings; } set { _settings = value; } }
  13. public static string ServiceUrl
  14. {
  15. get
  16. {
  17. if (Program.Args[0] == "brandt")
  18. return JDISImport.ServiceUrl;
  19. else if (Program.Args[0] == "foley")
  20. return PDAImport.ServiceUrl;
  21. else return string.Empty;
  22. }
  23. }
  24. public Global() { }
  25. public Global(string[] settingsFile)
  26. {
  27. if (IsWindows())
  28. {
  29. Global.StorageDir = string.Format("C:/{0}/store/", settingsFile[0]).Replace("/", "\\");
  30. }
  31. else if (IsMacOS())
  32. {
  33. Global.StorageDir = string.Format("/Users/{0}/{1}/store/", settingsFile[1], settingsFile[0]);
  34. }
  35. else if (IsLinux())
  36. {
  37. Global.StorageDir = string.Format("/home/{0}/{1}/store/", settingsFile[1], settingsFile[0]);
  38. }
  39. else
  40. {
  41. throw new Exception("OS cannot be detected.");
  42. }
  43. Global.Settings = new Settings();
  44. string path = Path.Combine(Global.StorageDir, string.Format("{0}.json", settingsFile[0]));
  45. string text = File.ReadAllText(path);
  46. Global.Settings = JsonConvert.DeserializeObject<Settings>(text);
  47. }
  48. public static bool IsWindows() =>
  49. System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
  50. public static bool IsMacOS() =>
  51. System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX);
  52. public static bool IsLinux() =>
  53. System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
  54. public static DateTime DateFormatter(string d, bool hastime = true)
  55. {
  56. string month, day, year, time;
  57. DateTime dt = new DateTime();
  58. if (d.IndexOf("JAN") != -1)
  59. {
  60. month = "01";
  61. d = d.Replace("JAN", "|");
  62. day = d.Substring(0, d.IndexOf("|"));
  63. year = d.Substring(d.IndexOf("|") + 1, 4);
  64. if (hastime)
  65. time = d.Substring(d.IndexOf(":") - 3 + 2);
  66. else time = "00:00:00.000";
  67. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  68. dt = DateTime.Parse(date);
  69. }
  70. else if (d.IndexOf("FEB") != -1)
  71. {
  72. month = "02";
  73. d = d.Replace("FEB", "|");
  74. day = d.Substring(0, d.IndexOf("|"));
  75. year = d.Substring(d.IndexOf("|") + 1, 4);
  76. if (hastime)
  77. time = d.Substring(d.IndexOf(":") - 3 + 2);
  78. else time = "00:00:00.000";
  79. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  80. dt = DateTime.Parse(date);
  81. }
  82. else if (d.IndexOf("MARCH") != -1)
  83. {
  84. month = "03";
  85. d = d.Replace("MARCH", "|");
  86. day = d.Substring(0, d.IndexOf("|"));
  87. year = d.Substring(d.IndexOf("|") + 1, 4);
  88. if (hastime)
  89. time = d.Substring(d.IndexOf(":") - 3 + 2);
  90. else time = "00:00:00.000";
  91. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  92. dt = DateTime.Parse(date);
  93. }
  94. else if (d.IndexOf("MAR") != -1)
  95. {
  96. month = "03";
  97. d = d.Replace("MAR", "|");
  98. day = d.Substring(0, d.IndexOf("|"));
  99. year = d.Substring(d.IndexOf("|") + 1, 4);
  100. if (hastime)
  101. time = d.Substring(d.IndexOf(":") - 3 + 2);
  102. else time = "00:00:00.000";
  103. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  104. dt = DateTime.Parse(date);
  105. }
  106. else if (d.IndexOf("APRIL") != -1)
  107. {
  108. month = "04";
  109. d = d.Replace("APRIL", "|");
  110. day = d.Substring(0, d.IndexOf("|"));
  111. year = d.Substring(d.IndexOf("|") + 1, 4);
  112. if (hastime)
  113. time = d.Substring(d.IndexOf(":") - 3 + 2);
  114. else time = "00:00:00.000";
  115. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  116. dt = DateTime.Parse(date);
  117. }
  118. else if (d.IndexOf("APR") != -1)
  119. {
  120. month = "04";
  121. d = d.Replace("APR", "|");
  122. day = d.Substring(0, d.IndexOf("|"));
  123. year = d.Substring(d.IndexOf("|") + 1, 4);
  124. if (hastime)
  125. time = d.Substring(d.IndexOf(":") - 3 + 2);
  126. else time = "00:00:00.000";
  127. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  128. dt = DateTime.Parse(date);
  129. }
  130. else if (d.IndexOf("MAY") != -1)
  131. {
  132. month = "05";
  133. d = d.Replace("MAY", "|");
  134. day = d.Substring(0, d.IndexOf("|"));
  135. year = d.Substring(d.IndexOf("|") + 1, 4);
  136. if (hastime)
  137. time = d.Substring(d.IndexOf(":") - 3 + 2);
  138. else time = "00:00:00.000";
  139. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  140. dt = DateTime.Parse(date);
  141. }
  142. else if (d.IndexOf("JUNE") != -1)
  143. {
  144. month = "06";
  145. d = d.Replace("JUNE", "|");
  146. day = d.Substring(0, d.IndexOf("|"));
  147. year = d.Substring(d.IndexOf("|") + 1, 4);
  148. if (hastime)
  149. time = d.Substring(d.IndexOf(":") - 3 + 2);
  150. else time = "00:00:00.000";
  151. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  152. dt = DateTime.Parse(date);
  153. }
  154. else if (d.IndexOf("JUN") != -1)
  155. {
  156. month = "06";
  157. d = d.Replace("JUN", "|");
  158. day = d.Substring(0, d.IndexOf("|"));
  159. year = d.Substring(d.IndexOf("|") + 1, 4);
  160. if (hastime)
  161. time = d.Substring(d.IndexOf(":") - 3 + 2);
  162. else time = "00:00:00.000";
  163. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  164. dt = DateTime.Parse(date);
  165. }
  166. else if (d.IndexOf("JULY") != -1)
  167. {
  168. month = "07";
  169. d = d.Replace("JULY", "|");
  170. day = d.Substring(0, d.IndexOf("|"));
  171. year = d.Substring(d.IndexOf("|") + 1, 4);
  172. if (hastime)
  173. time = d.Substring(d.IndexOf(":") - 3 + 2);
  174. else time = "00:00:00.000";
  175. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  176. dt = DateTime.Parse(date);
  177. }
  178. else if (d.IndexOf("JUL") != -1)
  179. {
  180. month = "07";
  181. d = d.Replace("JUL", "|");
  182. day = d.Substring(0, d.IndexOf("|"));
  183. year = d.Substring(d.IndexOf("|") + 1, 4);
  184. if (hastime)
  185. time = d.Substring(d.IndexOf(":") - 3 + 2);
  186. else time = "00:00:00.000";
  187. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  188. dt = DateTime.Parse(date);
  189. }
  190. else if (d.IndexOf("AUG") != -1)
  191. {
  192. month = "08";
  193. d = d.Replace("AUG", "|");
  194. day = d.Substring(0, d.IndexOf("|"));
  195. year = d.Substring(d.IndexOf("|") + 1, 4);
  196. if (hastime)
  197. time = d.Substring(d.IndexOf(":") - 3 + 2);
  198. else time = "00:00:00.000";
  199. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  200. dt = DateTime.Parse(date);
  201. }
  202. else if (d.IndexOf("SEPT") != -1)
  203. {
  204. month = "09";
  205. d = d.Replace("SEPT", "|");
  206. day = d.Substring(0, d.IndexOf("|"));
  207. year = d.Substring(d.IndexOf("|") + 1, 4);
  208. if (hastime)
  209. time = d.Substring(d.IndexOf(":") - 3 + 2);
  210. else time = "00:00:00.000";
  211. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  212. dt = DateTime.Parse(date);
  213. }
  214. else if (d.IndexOf("SEP") != -1)
  215. {
  216. month = "09";
  217. d = d.Replace("SEP", "|");
  218. day = d.Substring(0, d.IndexOf("|"));
  219. year = d.Substring(d.IndexOf("|") + 1, 4);
  220. if (hastime)
  221. time = d.Substring(d.IndexOf(":") - 3 + 2);
  222. else time = "00:00:00.000";
  223. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  224. dt = DateTime.Parse(date);
  225. }
  226. else if (d.IndexOf("OCT") != -1)
  227. {
  228. month = "10";
  229. d = d.Replace("OCT", "|");
  230. day = d.Substring(0, d.IndexOf("|"));
  231. year = d.Substring(d.IndexOf("|") + 1, 4);
  232. if (hastime)
  233. time = d.Substring(d.IndexOf(":") - 3 + 2);
  234. else time = "00:00:00.000";
  235. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  236. dt = DateTime.Parse(date);
  237. }
  238. else if (d.IndexOf("0CT") != -1)
  239. {
  240. month = "10";
  241. d = d.Replace("0CT", "|");
  242. day = d.Substring(0, d.IndexOf("|"));
  243. year = d.Substring(d.IndexOf("|") + 1, 4);
  244. if (hastime)
  245. time = d.Substring(d.IndexOf(":") - 3 + 2);
  246. else time = "00:00:00.000";
  247. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  248. dt = DateTime.Parse(date);
  249. }
  250. else if (d.IndexOf("NOV") != -1)
  251. {
  252. month = "11";
  253. d = d.Replace("NOV", "|");
  254. day = d.Substring(0, d.IndexOf("|"));
  255. year = d.Substring(d.IndexOf("|") + 1, 4);
  256. if (hastime)
  257. time = d.Substring(d.IndexOf(":") - 3 + 2);
  258. else time = "00:00:00.000";
  259. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  260. dt = DateTime.Parse(date);
  261. }
  262. else
  263. {
  264. month = "12";
  265. d = d.Replace("DEC", "|");
  266. day = d.Substring(0, d.IndexOf("|"));
  267. year = d.Substring(d.IndexOf("|") + 1, 4);
  268. if (hastime)
  269. time = d.Substring(d.IndexOf(":") - 3 + 2);
  270. else time = "00:00:00.000";
  271. string date = string.Format("{0}-{1}-{2} {3}", year, month, day, time);
  272. dt = DateTime.Parse(date);
  273. }
  274. return dt;
  275. }
  276. }
  277. public static class Deserialize
  278. {
  279. public static T FromJson<T>(string json)
  280. {
  281. //Console.WriteLine(json);
  282. return JsonConvert.DeserializeObject<T>(json, Converter.Settings);
  283. }
  284. }
  285. public static class Serialize
  286. {
  287. public static string ToJson<T>(this T self)
  288. {
  289. return JsonConvert.SerializeObject(self, Converter.Settings);
  290. }
  291. }
  292. internal static class Converter
  293. {
  294. public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
  295. {
  296. MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
  297. DateParseHandling = DateParseHandling.None,
  298. DateFormatHandling = DateFormatHandling.MicrosoftDateFormat,
  299. };
  300. }
  301. [JsonObject(MemberSerialization.OptIn)]
  302. public class Settings
  303. {
  304. [JsonProperty(PropertyName = "Remote")]
  305. public bool Remote { get; set; }
  306. [JsonProperty(PropertyName = "LogFile")]
  307. public string LogFile { get; set; }
  308. [JsonProperty(PropertyName = "MailProperties")]
  309. public MailProperties MailProperties { get; set; }
  310. [JsonProperty(PropertyName = "Prelub")]
  311. public Prelub Prelub { get; set; }
  312. [JsonProperty(PropertyName = "Customer")]
  313. public string Customer { get; set; }
  314. }
  315. [JsonObject(MemberSerialization.OptIn)]
  316. public class MailProperties
  317. {
  318. [JsonProperty(PropertyName = "AppID")]
  319. public string AppID { get; set; }
  320. [JsonProperty(PropertyName = "TenentID")]
  321. public string TenentID { get; set; }
  322. [JsonProperty(PropertyName = "ObjectId")]
  323. public string ObjectId { get; set; }
  324. [JsonProperty(PropertyName = "SecretID")]
  325. public string SecretID { get; set; }
  326. [JsonProperty(PropertyName = "SecretV")]
  327. public string SecretV { get; set; }
  328. [JsonProperty(PropertyName = "Mailbox")]
  329. public string Mailbox { get; set; }
  330. [JsonProperty(PropertyName = "Url")]
  331. public string Url { get; set; }
  332. [JsonProperty(PropertyName = "Password")]
  333. public string Password { get; set; }
  334. [JsonProperty(PropertyName = "Username")]
  335. public string Username { get; set; }
  336. [JsonProperty(PropertyName = "Scope")]
  337. public string Scope { get; set; }
  338. [JsonProperty(PropertyName = "Filter")]
  339. public string Filter { get; set; }
  340. }
  341. [JsonObject(MemberSerialization.OptIn)]
  342. public class Prelub
  343. {
  344. [JsonProperty(PropertyName = "LocalService")]
  345. public string LocalService { get; set; }
  346. [JsonProperty(PropertyName = "RemoteService")]
  347. public string RemoteService { get; set; }
  348. }
  349. }
  350. /*
  351. {
  352. "MailProperties": {
  353. "Username": "mcarman@prelub.com",
  354. "Password": "Gr@nt@cc3$$",
  355. "Mailbox": 4,
  356. "Url": "https://outlook.office365.com/ews/Exchange.asmx",
  357. "Filter": "Brandt Import, brandt import, Brandt import, brandt Import, BRANDT IMPORT",
  358. "AppID": "489776b1-ee79-4b14-bc44-9f6bf47332db",
  359. "TenentID": "1fd06c96-d3a4-45e9-9ed7-bcecb394d277",
  360. "ObjectId": "c7647074-edb6-4e8e-8a01-a1ed924fdae9",
  361. "SecretID": "cba04a6c-a233-4646-909b-b50921edbe1c",
  362. "SecretV": "up-8Q~y46~JyQZjJlsAJ-zpXpglpmuPIJ1Gx3a2O"
  363. },
  364. "Remote": false,
  365. "LogFile": "jdis.log",
  366. "Prelub": {
  367. "LocalService": "http://servicesbrandt.rpmindustries.com:8081",
  368. "RemoteService": "https://servicesbrandt.rpmindustries.com"
  369. }
  370. }
  371. */