From d96293151210a36f4ff4584e75682f4087a14f49 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 30 Aug 2021 17:23:53 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 65 +++++++++++++++++------- source/Plugins/AyaNova.Plugin.V8/util.cs | 10 ++-- 2 files changed, 54 insertions(+), 21 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index da43e38..babad38 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -240,6 +240,7 @@ namespace AyaNova.PlugIn.V8 private string MissingDataNamePrefix = "zV8migrate_substitute";//append guid to ensure uniqueness + private async System.Threading.Tasks.Task CreateSubstitute(Guid id, RootObjectTypes desiredType, long? extraV8Id = null) { //create the simplest possible version of this object desired @@ -373,7 +374,7 @@ namespace AyaNova.PlugIn.V8 private bool V7UseInventory = false; private List Allv8WarehouseIds = new List(); - + private long SmallestFileUploadRejectedAsTooBig = long.MaxValue; @@ -390,7 +391,7 @@ namespace AyaNova.PlugIn.V8 progress.StartedImport(); progress.Append("Exporting data to AyaNova server @ " + util.ApiBaseUrl); progress.Append(util.PRE_RELEASE_VERSION_STRING); - + Exception ExceptionDuringMigrate = null; try { @@ -406,6 +407,9 @@ namespace AyaNova.PlugIn.V8 V7ToV8WorkOrderItemStatusIdMap.Clear(); TagMap.Clear(); LocaleMap.Clear(); + SmallestFileUploadRejectedAsTooBig = long.MaxValue; + + //add default raven language and codes LocaleMap.Add("English", 1); LocaleMap.Add("EspaƱol", 2); @@ -415,8 +419,8 @@ namespace AyaNova.PlugIn.V8 V7ToV8IdMap.Add(User.AdministratorID, 1); - - + + //ERASE DB progress.Append("Erasing AyaNova 8 data"); @@ -542,7 +546,7 @@ namespace AyaNova.PlugIn.V8 await PostExportLogToV8(progress); progress.Append("\r\n************\r\nLog and help links saved in v8 Memo to SuperUser account (Home->Memos)"); - + progress.Append("Export completed"); progress.Op(""); @@ -4273,7 +4277,7 @@ namespace AyaNova.PlugIn.V8 ScheduleMarker c = ScheduleMarker.GetItem(i.LT_O_ScheduleMarker.Value); - + //Many schedulemarkers may not have related records so allow for that!! if (c.IsFollowUp) { @@ -4281,7 +4285,7 @@ namespace AyaNova.PlugIn.V8 AddImportTag(tags); dynamic d = new JObject(); progress.Op("FollowUp " + c.ID.ToString()); - + //export //FollowUps only ever apply to a single user in v7 so no need to split them out here it's just for one user @@ -4334,7 +4338,7 @@ namespace AyaNova.PlugIn.V8 v8FollowId = await Getv7v8IdMapNullOk(c.FollowID, RootObjectTypes.Workorder, false, true); if (v8FollowId == null) { - progress.Append("Follow up for WO skipped due to WO non-existance"); + progress.Append("Follow up for WO with ID: " + c.FollowID.ToString() + " skipped due to WO non-existance"); continue; } d.objectId = v8FollowId; @@ -4343,17 +4347,17 @@ namespace AyaNova.PlugIn.V8 break; case RootObjectTypes.WorkorderQuote: { - Guid woid=Guid.Empty; + Guid woid = Guid.Empty; try { Workorder o = Workorder.GetWorkorderByRelativeNoMRU(RootObjectTypes.WorkorderQuote, c.FollowID); - woid=o.ID; + woid = o.ID; } catch (Exception ex) { if (ex is FetchException || ex is System.Security.SecurityException)//Note: workorder will throw a security exception if resulting ID is guid.empty for...reasons.. { - progress.Append("Follow up for Quote skipped due to Quote non-existance"); + progress.Append("Follow up for Quote with ID: " + c.FollowID.ToString() + " skipped due to Quote non-existance"); continue; } throw; @@ -4361,7 +4365,7 @@ namespace AyaNova.PlugIn.V8 v8FollowId = await Getv7v8IdMapNullOk(woid, RootObjectTypes.Workorder, false, true); if (v8FollowId == null) { - progress.Append("Follow up for quote skipped due to quote non-existance"); + progress.Append("Follow up for Quote with ID: " + c.FollowID.ToString() + " skipped due to quote non-existance"); continue; } d.objectId = v8FollowId; @@ -4380,7 +4384,7 @@ namespace AyaNova.PlugIn.V8 { if (ex is FetchException || ex is System.Security.SecurityException)//Note: workorder will throw a security exception if resulting ID is guid.empty for...reasons.. { - progress.Append("Follow up for PM skipped due to PM non-existance"); + progress.Append("Follow up for PM with ID: " + c.FollowID.ToString() + " skipped due to PM non-existance"); continue; } throw; @@ -4388,7 +4392,7 @@ namespace AyaNova.PlugIn.V8 v8FollowId = await Getv7v8IdMapNullOk(woid, RootObjectTypes.Workorder, false, true); if (v8FollowId == null) { - progress.Append("Follow up for PM skipped due to PM non-existance"); + progress.Append("Follow up for PM with ID: " + c.FollowID.ToString() + " skipped due to PM non-existance"); continue; } d.objectId = v8FollowId; @@ -4412,7 +4416,7 @@ namespace AyaNova.PlugIn.V8 SetTags(d, tags); - + var rMainObject = await util.PostAsync("review", d); long RavenId = util.IdFromResponse(rMainObject); Addv7v8IdMap(c.ID, RavenId); @@ -4665,7 +4669,7 @@ namespace AyaNova.PlugIn.V8 { //this is the match, do the fixup //v8 inventory starts with 1 billion so every adjustment will always be *down* - + if (v7o.LT_PartByWarehouseInventory_Label_QuantityOnHand < 0) { //don't allow negative inventory, log and set to zero instead @@ -5594,6 +5598,7 @@ namespace AyaNova.PlugIn.V8 //iterate the files foreach (AssignedDoc doc in docs) { + if (!progress.KeepGoing) return null; //is it a local file? @@ -5614,6 +5619,13 @@ namespace AyaNova.PlugIn.V8 progress.SubOp("Assigned doc: \"" + doc.URL + "\" " + AyaBizUtils.FileSizeDisplay((decimal)fi.Length)); + + if (fi.Length > SmallestFileUploadRejectedAsTooBig) + { + progress.Append("Assigned doc. file " + doc.Description + " " + doc.URL + " too large (" + fi.Length.ToString() + ") for this server. Adjust destination server settings to allow"); + NonFileUrls += (ImportTag + " - Assigned doc. file " + doc.Description + " " + doc.URL + " too large (" + fi.Length.ToString() + ") for this server. Adjust destination server settings to allow.\n"); + continue; + } //Compile the FileData property DateTimeOffset dtLastModified = fi.LastWriteTimeUtc; @@ -5666,7 +5678,26 @@ namespace AyaNova.PlugIn.V8 formDataContent.Add(AttachmentFile); //Upload - await util.PostFormDataAsync("attachment", formDataContent); + try + { + await util.PostFormDataAsync("attachment", formDataContent); + } + catch (Exception ex) + { + if (ex.Message.Contains("413")) + { + if (SmallestFileUploadRejectedAsTooBig > fi.Length) + SmallestFileUploadRejectedAsTooBig = fi.Length; + progress.Append("Assigned doc. file " + doc.Description + " " + doc.URL + " too large (" + fi.Length.ToString() + ") for this server. Adjust destination server settings to allow"); + NonFileUrls += (ImportTag + " - Assigned doc. file " + doc.Description + " " + doc.URL + " too large (" + fi.Length.ToString() + ") for this server. Adjust destination server settings to allow.\n"); + continue; + + } + else + { + throw; + } + } //No need to map it or save response as long as it works that's all that matters diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index a4fb361..409861d 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -165,7 +165,7 @@ namespace AyaNova.PlugIn.V8 var responseAsString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { - throw new Exception("GET error, route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase); + throw new Exception("GET error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase); } else return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; @@ -247,7 +247,7 @@ namespace AyaNova.PlugIn.V8 { if (string.IsNullOrWhiteSpace(postJson)) postJson = "n/a"; - throw new Exception("POST error, route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPOSTED OBJECT:\r\n" + postJson); + throw new Exception("POST error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPOSTED OBJECT:\r\n" + postJson); } else return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; @@ -333,7 +333,7 @@ namespace AyaNova.PlugIn.V8 { if (string.IsNullOrWhiteSpace(putJson)) putJson = "n/a"; - throw new Exception("PUT error, route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPUT OBJECT:\r\n" + putJson); + throw new Exception("PUT error, code: " + (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase + "\r\nPUT OBJECT:\r\n" + putJson); } else return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) }; @@ -370,6 +370,8 @@ namespace AyaNova.PlugIn.V8 } + + private async static Task TryPostFormDataAsync(string route, MultipartFormDataContent formContent) { var requestMessage = new HttpRequestMessage(HttpMethod.Post, ApiBaseUrl + route); @@ -398,7 +400,7 @@ namespace AyaNova.PlugIn.V8 var responseAsString = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { - throw new Exception("POST FORMDATA error, route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase); + throw new Exception("POST FORMDATA error, code: "+ (int)response.StatusCode + ", route: " + route + "\r\n" + responseAsString + "\r\n" + response.ReasonPhrase); } else return new ApiResponse() { HttpResponse = response, ObjectResponse = Parse(responseAsString) };