From 27a6edca44e0a6fb3ff75da10777fab5a119cdd5 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 28 Apr 2020 18:53:00 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 124 ++++++++++++----------- source/Plugins/AyaNova.Plugin.V8/util.cs | 4 + 2 files changed, 70 insertions(+), 58 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 2336976..1b9f237 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -156,58 +156,66 @@ namespace AyaNova.PlugIn.V8 /// then zip it all up into a single archive file and then erase the temporary folder /// private async void DoExport() - { - Map.Clear(); - - /* - TODO: - * EMPTY DB ROUTE - * custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem - - - */ - + { //Show progress form - ProgressForm progress = new ProgressForm(); progress.Show(); progress.StartedImport(); progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl); + try + { + Map.Clear(); + + /* + TODO: + * EMPTY DB ROUTE + * custom fields processor for: User, Client, Contract, HeadOffice, LoanItem, part, project, purchaseorder, unit, unitmodel, vendor, workorderitem + + + */ - //Export in correct order: - - //ERASE DB - var a = await util.PostAsync("License/PermanentlyEraseAllData", "I understand"); - if (!a.HttpResponse.IsSuccessStatusCode) { MessageBox.Show("Error erasing database: \n" + a.HttpResponse.ReasonPhrase); return;} - - //TAGS - ExportUnitModelCategories(progress); - ExportUnitServiceTypes(progress); - ExportWorkorderItemTypes(progress); - ExportRegions(progress); - ExportClientGroups(progress); - ExportWorkorderCategories(progress); - ExportPartCategories(progress); - ExportScheduleableUserGroups(progress); - ExportDispatchZones(progress); - - //BIZ objects - ExportUsers(progress); - - //dumpGlobalSettings(tempArchiveFolder, progress); - //dumpLocales(tempArchiveFolder, progress); - - //dumpSeedNumbers(tempArchiveFolder, progress); - //dumpClients(tempArchiveFolder, progress); - //dumpHeadOffices(tempArchiveFolder, progress); - // - //NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export + //Export in correct order: + + //ERASE DB + var a = await util.PostAsync("License/PermanentlyEraseAllData", "\"I understand\""); + if (!a.HttpResponse.IsSuccessStatusCode) { MessageBox.Show("Error erasing database: \n" + a.HttpResponse.ReasonPhrase); return; } + + //TAGS + ExportUnitModelCategories(progress); + ExportUnitServiceTypes(progress); + ExportWorkorderItemTypes(progress); + ExportRegions(progress); + ExportClientGroups(progress); + ExportWorkorderCategories(progress); + ExportPartCategories(progress); + ExportScheduleableUserGroups(progress); + ExportDispatchZones(progress); + + //BIZ objects + ExportUsers(progress); + + //dumpGlobalSettings(tempArchiveFolder, progress); + //dumpLocales(tempArchiveFolder, progress); + + //dumpSeedNumbers(tempArchiveFolder, progress); + //dumpClients(tempArchiveFolder, progress); + //dumpHeadOffices(tempArchiveFolder, progress); + // - progress.Append("Export completed"); + //NOTE: when get to PRIORITY, or WORKORDER STATUS be sure to add color code as per already done in USER export + + + progress.Append("Export completed"); + } + catch (Exception ex) + { + progress.Append("Export failed with error:"); + progress.Append(ex.Message); + } progress.FinishedImport(); //----------------------------------- @@ -222,7 +230,7 @@ namespace AyaNova.PlugIn.V8 #region Global settings private void ExportGlobalSettings(ProgressForm progress) { - + progress.Append("STUB: Dumping Global Settings"); ////DumpObjectToFolder(tempArchiveFolder, AyaBizUtils.GlobalSettings, "globalsettings", objectExcludeProperties, new TypeAndID(RootObjectTypes.Global, Address.GlobalAddressID)); } @@ -231,7 +239,7 @@ namespace AyaNova.PlugIn.V8 #region locales private void ExportLocales(ProgressForm progress) { - // List objectExcludeProperties = new List(standardExcludePropertiesList); + // List objectExcludeProperties = new List(standardExcludePropertiesList); //Skip stock locales already handled in Raven List SkipLocales = new List(); @@ -256,8 +264,8 @@ namespace AyaNova.PlugIn.V8 #region REGIONS private void ExportRegions(ProgressForm progress) { - // List objectExcludeProperties = new List(standardExcludePropertiesList); - + // List objectExcludeProperties = new List(standardExcludePropertiesList); + RegionList l = RegionList.GetList(string.Empty); progress.Append("Dumping " + l.Count.ToString() + " Regions"); foreach (RegionList.RegionListInfo i in l) @@ -281,7 +289,7 @@ namespace AyaNova.PlugIn.V8 } private void ExportSeedNumbers(ProgressForm progress) { - // List objectExcludeProperties = new List(standardExcludePropertiesList); + // List objectExcludeProperties = new List(standardExcludePropertiesList); progress.Append("Dumping seeds"); //create a new object with the id numbers in it and then dump it WorkorderPMList pml = WorkorderPMList.GetList(" \r\n" + @@ -323,7 +331,7 @@ namespace AyaNova.PlugIn.V8 #region headoffices private void ExportHeadOffices(ProgressForm progress) { - + PickListAutoComplete pl = PickListAutoComplete.GetList("**", "headoffice"); progress.Append("Dumping " + pl.Count.ToString() + " Head offices"); @@ -369,21 +377,21 @@ namespace AyaNova.PlugIn.V8 User c = User.GetItem(i.ID); dynamic d = new JObject(); d.name = c.FirstName + " " + c.LastName; - + d.userType = (int)c.UserType; if (c.VendorID != Guid.Empty) d.userType = 7;//7 is the RAVEN user type for subcontractor 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.notes = c.Notes; - Tagit(c.RegionID,tags); + Tagit(c.RegionID, tags); Tagit(c.DispatchZoneID, tags); SetTags(d, tags); - var a=await util.PostAsync("User", d.ToString()); + var a = await util.PostAsync("User", d.ToString()); //JObject xtra = new JObject(); @@ -652,13 +660,13 @@ namespace AyaNova.PlugIn.V8 } - private void SetTags(dynamic d, List tags) - { - dynamic dtags= new JArray(); - foreach(string s in tags) - dtags.Add(s); - d.tags=dtags; - } + private void SetTags(dynamic d, List tags) + { + dynamic dtags = new JArray(); + foreach (string s in tags) + dtags.Add(s); + d.tags = dtags; + } diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index 4d4ccb3..8cae373 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -150,6 +150,10 @@ namespace AyaNova.PlugIn.V8 HttpResponseMessage response = await client.SendAsync(requestMessage); var responseAsString = await response.Content.ReadAsStringAsync(); + if (!response.IsSuccessStatusCode) + { + throw new Exception(responseAsString + "\n" + response.ReasonPhrase); + } return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; }