From 20926758b3bd38943a2862b1fe535a62a5b7b35c Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Tue, 5 May 2020 18:35:49 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 98 ++++++++++++++++++------ source/Plugins/AyaNova.Plugin.V8/util.cs | 49 ++++++++++++ 2 files changed, 123 insertions(+), 24 deletions(-) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index d93ea4d..699b615 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -174,6 +174,18 @@ namespace AyaNova.PlugIn.V8 else Map.Add(v7id, v8id); } + private bool IsDuplicateMapItem(Guid v7id, string name, ProgressForm progress) + { + if (Map.ContainsKey(v7id)) + { + progress.Append("DUPLICATE: " + name + " - has duplicate ID, not exported"); + return true; + } + return false; + + } + + private long SafeGetUserMap(Guid id) { if (!Map.ContainsKey(id)) return 1;//1=raven administrator account @@ -213,12 +225,15 @@ namespace AyaNova.PlugIn.V8 /* TODO: + Add dupe check for v7 id as there should be none, but seeing dupes in some db's + still determining if real dupe or different records Only compare original locale keys for hash not ones added in schema updates or dropped Need more detail when fails on release mode, right now no idea what actually happened I'd like to see a full log sent to the server on fail + not sure, would be a *lot* of data potentially to gather all this eating up memory keep a record of every op/subop etc in progress, on fail push out that list with the exception to somewhere on the server, maybe as an attachment for the manager user? so can view in detail remote users export issues @@ -425,11 +440,13 @@ namespace AyaNova.PlugIn.V8 if (i.ID == User.AdministratorID) continue; User c = User.GetItem(i.ID); + var ObjectTID = new TypeAndID(RootObjectTypes.User, c.ID); dynamic d = new JObject(); d.name = GetUniqueName(c.FirstName + " " + c.LastName); + if (IsDuplicateMapItem(c.ID, c.FirstName+" " + c.LastName, progress)) continue; progress.Op("User " + d.name); d.userType = (int)c.UserType; @@ -568,6 +585,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID,c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -650,6 +668,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -730,6 +749,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -810,6 +830,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -890,6 +911,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(i.DisplayName(AyaBizUtils.GlobalSettings.DefaultPartDisplayFormat));//todo: temporary for testing + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -969,6 +991,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -1046,6 +1069,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = c.PONumber.ToString(); + if (IsDuplicateMapItem(c.ID, i.LT_PurchaseOrder_Label_PONumber.Display, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); // d.active = c.Active; d.notes = c.Notes; @@ -1115,6 +1139,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Serial); + if (IsDuplicateMapItem(c.ID, c.Serial, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -1196,6 +1221,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -1274,6 +1300,7 @@ namespace AyaNova.PlugIn.V8 dynamic d = new JObject(); d.name = GetUniqueName(c.Name); + if (IsDuplicateMapItem(c.ID, c.Name, progress)) continue; progress.Op(ObjectTypeName + " " + d.name); d.active = c.Active; d.notes = c.Notes; @@ -1350,6 +1377,7 @@ namespace AyaNova.PlugIn.V8 tags.Add(ImportTag); Workorder c = Workorder.GetItem(i.LT_O_Workorder.Value); + if (IsDuplicateMapItem(c.ID, c.WorkorderService.ServiceNumber.ToString(), progress)) continue; var ObjectTID = new TypeAndID(RootObjectTypes.WorkorderService, c.ID); //make one on the server to update var rMainObject = await util.PostAsync(RavenObjectName + "/Create?serial=" + c.WorkorderService.ServiceNumber); @@ -1433,6 +1461,7 @@ namespace AyaNova.PlugIn.V8 tags.Add(ImportTag); Workorder c = Workorder.GetItem(i.LT_O_WorkorderQuote.Value); + if (IsDuplicateMapItem(c.ID, c.WorkorderQuote.QuoteNumber.ToString(), progress)) continue; var ObjectTID = new TypeAndID(RootObjectTypes.WorkorderQuote, c.ID); //make one on the server to update var rMainObject = await util.PostAsync(RavenObjectName + "/Create?serial=" + c.WorkorderQuote.QuoteNumber); @@ -1516,6 +1545,7 @@ namespace AyaNova.PlugIn.V8 tags.Add(ImportTag); Workorder c = Workorder.GetItem(i.LT_O_WorkorderPreventiveMaintenance.Value); + if (IsDuplicateMapItem(c.ID, c.WorkorderPreventiveMaintenance.PreventiveMaintenanceNumber.ToString(), progress)) continue; var ObjectTID = new TypeAndID(RootObjectTypes.WorkorderPreventiveMaintenance, c.ID); //make one on the server to update var rMainObject = await util.PostAsync(RavenObjectName + "/Create?serial=" + c.WorkorderPreventiveMaintenance.PreventiveMaintenanceNumber); @@ -1581,21 +1611,30 @@ namespace AyaNova.PlugIn.V8 progress.Op("Start Locales export"); progress.SubOp(""); progress.Append("Exporting customized Locales"); - //checksum locales - //if a recognized checksum then don't import because it means it wasn't modified from stock - /* - Stock fresh trial db (fb) values: - Locale: Custom English hash code: 740187325 - Locale: Deutsch hash code: -257973661 - Locale: English hash code: 740187325 - Locale: Español hash code: -373723947 - Locale: Français hash code: -224208815 - */ - List StockLocaleHashes = new List(); - StockLocaleHashes.Add(-257973661); - StockLocaleHashes.Add(740187325); - StockLocaleHashes.Add(-373723947); - StockLocaleHashes.Add(-224208815); + ////checksum locales + ////if a recognized checksum then don't import because it means it wasn't modified from stock + ///* + // Stock fresh trial db (fb) values: + // Locale Custom English [signature: -1965948581] + // Locale Deutsch [signature: -564065723] + // Locale English [signature: -1965948581] + // Locale Español [signature: -1122936791] + // Locale Français [signature: -679171126] + + //Do not use these keys in hash calculation which were added / modified during various schema updates + // Global.Label.UseInventory.Description + // Locale.Label.LocaleFile + // UnitNameDisplayFormats.Label.ModelSerial + // UnitNameDisplayFormats.Label.SerialModel + // UnitNameDisplayFormats.Label.SerialModelVendor + // UnitNameDisplayFormats.Label.VendorModelSerial + // O.PartBin + //*/ + //List StockLocaleHashes = new List(); + //StockLocaleHashes.Add(-1965948581); + //StockLocaleHashes.Add(-564065723); + //StockLocaleHashes.Add(-1122936791); + //StockLocaleHashes.Add(-679171126); //Get a list of RAVEN translations and ID's var a = await util.GetAsync("Translation/List"); @@ -1611,14 +1650,25 @@ namespace AyaNova.PlugIn.V8 LocalizedTextTable lt = LocalizedTextTable.Load(i.Locale); progress.Op("Checking if locale " + i.Locale + " is customized"); - //calculate hash - List allStrings = new List(); - foreach (var entry in lt.LT) - allStrings.Add(entry.Value); - int CurrentLocaleHash = util.GetOrderIndependentHashCode(allStrings); - allStrings.Clear(); - if (StockLocaleHashes.Contains(CurrentLocaleHash)) continue; - progress.Append("Locale " + i.Locale + " is customized [signature: "+CurrentLocaleHash.ToString()+"]; exporting"); + if (!util.LocaleIsCustomized(i.Locale, lt, progress)) continue; + ////calculate hash + //List allStrings = new List(); + //foreach (var entry in lt.LT) + //{ + // if(entry.Key=="Global.Label.UseInventory.Description") continue; + // if(entry.Key=="Locale.Label.LocaleFile") continue; + // if(entry.Key=="UnitNameDisplayFormats.Label.ModelSerial") continue; + // if(entry.Key=="UnitNameDisplayFormats.Label.SerialModel") continue; + // if(entry.Key=="UnitNameDisplayFormats.Label.SerialModelVendor") continue; + // if(entry.Key=="UnitNameDisplayFormats.Label.VendorModelSerial") continue; + // if (entry.Key == "O.PartBin") continue; + + // allStrings.Add(entry.Value); + //} + //int CurrentLocaleHash = util.GetOrderIndependentHashCode(allStrings); + //allStrings.Clear(); + //if (StockLocaleHashes.Contains(CurrentLocaleHash)) continue; + //progress.Append("Locale " + i.Locale + " is customized [signature: "+CurrentLocaleHash.ToString()+"]; exporting"); //collection to hold items sent to server List exportItems = new List(); @@ -2132,7 +2182,7 @@ namespace AyaNova.PlugIn.V8 if (af == null) continue; progress.SubOp("Wikifile: \"" + af.Name + "\" " + AyaBizUtils.FileSizeDisplay((decimal)af.FileSize)); - + if (IsDuplicateMapItem(i.LT_O_AyaFile.Value, i.LT_O_AyaFile.Display, progress)) continue; //Compile the FileData property var sDate = i.LT_Common_Label_Created.ToString(); DateTimeOffset dtLastModified = DateTime.UtcNow; diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index 4effa95..ea7db15 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -492,6 +492,55 @@ namespace AyaNova.PlugIn.V8 + public static bool LocaleIsCustomized(string localeName, GZTW.AyaNova.BLL.LocalizedTextTable lt, ProgressForm progress) + { + //checksum locales + //if a recognized checksum then don't import because it means it wasn't modified from stock + /* + Stock fresh trial db (fb) values: + Locale Custom English is customized [signature: -2007218741] exporting +Locale Deutsch is customized [signature: -605335883] exporting +Locale English is customized [signature: -2007218741] exporting +Locale Español is customized [signature: -1164206951] exporting +Locale Français is customized [signature: -720441286] exporting + + Do not use these keys in hash calculation which were added / modified during various schema updates + Global.Label.UseInventory.Description + Locale.Label.LocaleFile + UnitNameDisplayFormats.Label.ModelSerial + UnitNameDisplayFormats.Label.SerialModel + UnitNameDisplayFormats.Label.SerialModelVendor + UnitNameDisplayFormats.Label.VendorModelSerial + O.PartBin + */ + List StockLocaleHashes = new List(); + StockLocaleHashes.Add(-605335883); + StockLocaleHashes.Add(-2007218741); + StockLocaleHashes.Add(-1164206951); + StockLocaleHashes.Add(-720441286); + + //calculate hash + List allStrings = new List(); + foreach (var entry in lt.LT) + { + if (entry.Key == "Global.Label.UseInventory.Description") continue; + if (entry.Key == "Locale.Label.LocaleFile") continue; + if (entry.Key == "UnitNameDisplayFormats.Label.ModelSerial") continue; + if (entry.Key == "UnitNameDisplayFormats.Label.SerialModel") continue; + if (entry.Key == "UnitNameDisplayFormats.Label.SerialModelVendor") continue; + if (entry.Key == "UnitNameDisplayFormats.Label.VendorModelSerial") continue; + if (entry.Key == "O.PartBin") continue; + if (entry.Key == "UI.Label.CurrentUserName") continue; + + allStrings.Add(entry.Value); + } + int CurrentLocaleHash = GetOrderIndependentHashCode(allStrings); + + if (StockLocaleHashes.Contains(CurrentLocaleHash)) return false; + progress.Append("Locale " + localeName + " is customized [signature: " + CurrentLocaleHash.ToString() + "] exporting"); + + return true; + } public static int GetOrderIndependentHashCode(IEnumerable source) {