This commit is contained in:
2020-04-28 18:53:00 +00:00
parent c239ae57f4
commit 27a6edca44
2 changed files with 70 additions and 58 deletions

View File

@@ -156,6 +156,13 @@ namespace AyaNova.PlugIn.V8
/// then zip it all up into a single archive file and then erase the temporary folder /// then zip it all up into a single archive file and then erase the temporary folder
/// </summary> /// </summary>
private async void DoExport() private async void DoExport()
{
//Show progress form
ProgressForm progress = new ProgressForm();
progress.Show();
progress.StartedImport();
progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl);
try
{ {
Map.Clear(); Map.Clear();
@@ -167,19 +174,14 @@ namespace AyaNova.PlugIn.V8
*/ */
//Show progress form
ProgressForm progress = new ProgressForm();
progress.Show();
progress.StartedImport();
progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl);
//Export in correct order: //Export in correct order:
//ERASE DB //ERASE DB
var a = await util.PostAsync("License/PermanentlyEraseAllData", "I understand"); var a = await util.PostAsync("License/PermanentlyEraseAllData", "\"I understand\"");
if (!a.HttpResponse.IsSuccessStatusCode) { MessageBox.Show("Error erasing database: \n" + a.HttpResponse.ReasonPhrase); return;} if (!a.HttpResponse.IsSuccessStatusCode) { MessageBox.Show("Error erasing database: \n" + a.HttpResponse.ReasonPhrase); return; }
//TAGS //TAGS
ExportUnitModelCategories(progress); ExportUnitModelCategories(progress);
@@ -208,6 +210,12 @@ namespace AyaNova.PlugIn.V8
progress.Append("Export completed"); progress.Append("Export completed");
}
catch (Exception ex)
{
progress.Append("Export failed with error:");
progress.Append(ex.Message);
}
progress.FinishedImport(); progress.FinishedImport();
//----------------------------------- //-----------------------------------
@@ -375,15 +383,15 @@ namespace AyaNova.PlugIn.V8
d.userType = 7;//7 is the RAVEN user type for subcontractor d.userType = 7;//7 is the RAVEN user type for subcontractor
d.active = false;//all imported users are inactive to start 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.roles = 0;//todo: try to determine role from v7 member of group? or is that even possible?
d.employeeNumber = c.EmployeeNumber; d.employeeNumber = c.EmployeeNumber;
d.notes = c.Notes; d.notes = c.Notes;
Tagit(c.RegionID,tags); Tagit(c.RegionID, tags);
Tagit(c.DispatchZoneID, tags); Tagit(c.DispatchZoneID, tags);
SetTags(d, tags); SetTags(d, tags);
var a=await util.PostAsync("User", d.ToString()); var a = await util.PostAsync("User", d.ToString());
//JObject xtra = new JObject(); //JObject xtra = new JObject();
@@ -654,10 +662,10 @@ namespace AyaNova.PlugIn.V8
private void SetTags(dynamic d, List<string> tags) private void SetTags(dynamic d, List<string> tags)
{ {
dynamic dtags= new JArray(); dynamic dtags = new JArray();
foreach(string s in tags) foreach (string s in tags)
dtags.Add(s); dtags.Add(s);
d.tags=dtags; d.tags = dtags;
} }

View File

@@ -150,6 +150,10 @@ namespace AyaNova.PlugIn.V8
HttpResponseMessage response = await client.SendAsync(requestMessage); HttpResponseMessage response = await client.SendAsync(requestMessage);
var responseAsString = await response.Content.ReadAsStringAsync(); var responseAsString = await response.Content.ReadAsStringAsync();
if (!response.IsSuccessStatusCode)
{
throw new Exception(responseAsString + "\n" + response.ReasonPhrase);
}
return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };
} }