This commit is contained in:
2020-04-28 20:24:05 +00:00
parent 7de2a003e3
commit bb7ed7a03e
2 changed files with 55 additions and 16 deletions

View File

@@ -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

View File

@@ -122,19 +122,18 @@ namespace AyaNova.PlugIn.V8
public async static Task<ApiResponse> GetAsync(string route, string authToken = null, string bodyJsonData = null)
public async static Task<ApiResponse> 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<ApiResponse> 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<long>();
}
public static uint CTokenFromResponse(ApiResponse a)
{
return a.ObjectResponse["data"]["concurrencyToken"].Value<uint>();
}
#endregion
#region Misc utils
@@ -228,7 +259,7 @@ namespace AyaNova.PlugIn.V8
if (s.Length > maxLength)
s = s.Substring(0, maxLength);
return s;
}
}
#endregion