From bb7ed7a03e8c213be1bb7a3ba3740be9666dbf4b Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 28 Apr 2020 20:24:05 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 26 +++++++++----- source/Plugins/AyaNova.Plugin.V8/util.cs | 45 ++++++++++++++++++++---- 2 files changed, 55 insertions(+), 16 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 62dcce7..0aa1421 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -169,10 +169,8 @@ namespace AyaNova.PlugIn.V8 /* TODO: - * EMPTY DB ROUTE - * custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem - - + * Userskill, user cert as tags? + * custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem */ @@ -332,8 +330,6 @@ namespace AyaNova.PlugIn.V8 #region users private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress) { - - UserPickList pl = UserPickList.GetList(false); progress.Append("Dumping " + pl.Count.ToString() + " Users"); foreach (UserPickList.UserPickListInfo i in pl) @@ -367,7 +363,6 @@ namespace AyaNova.PlugIn.V8 } - d.active = false;//all imported users are inactive to start d.roles = 0;//todo: try to determine role from v7 member of group? or is that even possible? d.login = util.RandomString(); @@ -379,15 +374,28 @@ namespace AyaNova.PlugIn.V8 Tagit(c.DispatchZoneID, tags); SetTags(d, tags); - await util.PostAsync("User", d.ToString()); + var a=await util.PostAsync("User", d.ToString()); + long RavenId = util.IdFromResponse(a); + Map.Add(c.ID, RavenId); + + //USER OPTIONS + a=await util.GetAsync("UserOptions/"+RavenId.ToString()); + d=a.ObjectResponse["data"]; + d.uiColor = System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.ScheduleBackColor)); + d.emailAddress = c.EmailAddress; + + + //JObject xtra = new JObject(); - //xtra.Add("hexaScheduleBackColor", System.Drawing.ColorTranslator.ToHtml(System.Drawing.Color.FromArgb(c.ScheduleBackColor))); + //xtra.Add("hexaScheduleBackColor", ); //DumpObjectToFolder(tempArchiveFolder, c, "user." + c.ID.ToString(), objectExcludeProperties, new TypeAndID(RootObjectTypes.User, c.ID), null, xtra); } + //todo fixup post import + progress.Append("TODO: User, fixup translationID, headofficeid, clientid vendorid"); } #endregion clients diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index a931ae1..6305e3a 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -122,19 +122,18 @@ namespace AyaNova.PlugIn.V8 - public async static Task GetAsync(string route, string authToken = null, string bodyJsonData = null) + public async static Task GetAsync(string route) { - - var requestMessage = new HttpRequestMessage(HttpMethod.Get, route); if (!string.IsNullOrWhiteSpace(JWT)) requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); - if (!string.IsNullOrWhiteSpace(bodyJsonData)) - requestMessage.Content = new StringContent(bodyJsonData, System.Text.Encoding.UTF8, "application/json"); - HttpResponseMessage response = await client.SendAsync(requestMessage); var responseAsString = await response.Content.ReadAsStringAsync(); + if (!response.IsSuccessStatusCode) + { + throw new Exception("GET error, route: " + route + "\n" + responseAsString + "\n" + response.ReasonPhrase); + } return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; } @@ -159,6 +158,27 @@ namespace AyaNova.PlugIn.V8 return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; } + public async static Task PutAsync(string route, string putJson = null) + { + + + var requestMessage = new HttpRequestMessage(HttpMethod.Put, route); + if (!string.IsNullOrWhiteSpace(JWT)) + requestMessage.Headers.Authorization = new AuthenticationHeaderValue("Bearer", JWT); + + if (!string.IsNullOrWhiteSpace(putJson)) + requestMessage.Content = new StringContent(putJson, System.Text.Encoding.UTF8, "application/json"); + + HttpResponseMessage response = await client.SendAsync(requestMessage); + var responseAsString = await response.Content.ReadAsStringAsync(); + if (!response.IsSuccessStatusCode) + { + throw new Exception("PUT error, route: " + route + "\n" + responseAsString + "\n" + response.ReasonPhrase); + } + + return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; + } + //eoc public class ApiResponse @@ -186,6 +206,17 @@ namespace AyaNova.PlugIn.V8 } return JObject.Parse(jsonString); } + + + public static long IdFromResponse(ApiResponse a) + { + return a.ObjectResponse["data"]["id"].Value(); + } + + public static uint CTokenFromResponse(ApiResponse a) + { + return a.ObjectResponse["data"]["concurrencyToken"].Value(); + } #endregion #region Misc utils @@ -228,7 +259,7 @@ namespace AyaNova.PlugIn.V8 if (s.Length > maxLength) s = s.Substring(0, maxLength); return s; - } + } #endregion