From ff98f938a7f6754ba1d1895aa05f5e6f8fe7b350 Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Mon, 4 May 2020 14:19:35 +0000 Subject: [PATCH] --- source/Plugins/AyaNova.Plugin.V8/V8.cs | 24 ++++++++++++++++++++++++ source/Plugins/AyaNova.Plugin.V8/util.cs | 21 +++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/source/Plugins/AyaNova.Plugin.V8/V8.cs b/source/Plugins/AyaNova.Plugin.V8/V8.cs index 293ffb4..a4a9d8f 100644 --- a/source/Plugins/AyaNova.Plugin.V8/V8.cs +++ b/source/Plugins/AyaNova.Plugin.V8/V8.cs @@ -324,11 +324,35 @@ namespace AyaNova.PlugIn.V8 #region BIZ OBJECT Export methods + List UsedNames = new List(); + long LUniqueName = 1; + private string GetUniqueName(string tryName) { + + string retName=tryName; + do + { + if (!UsedNames.Contains(retName)) + { + UsedNames.Add(retName); + return retName; + } + retName = util.UniqueNameBuilder(tryName, LUniqueName++, 255); + } while (true); + + } + + private void ResetUniqueNames() + { + LUniqueName = 1; + UsedNames.Clear(); + } #region users private async System.Threading.Tasks.Task ExportUsers(ProgressForm progress) { if (!progress.KeepGoing) return; + UsedNames.clear + //Step 1: export the CustomFields to FormCustom if applicable so that when doing individual items we can export their custom data too var ocf = ObjectHasCustomFieldDataToExport("User"); bool ShouldExportCustom = ocf != null; diff --git a/source/Plugins/AyaNova.Plugin.V8/util.cs b/source/Plugins/AyaNova.Plugin.V8/util.cs index 824c047..4effa95 100644 --- a/source/Plugins/AyaNova.Plugin.V8/util.cs +++ b/source/Plugins/AyaNova.Plugin.V8/util.cs @@ -270,6 +270,24 @@ namespace AyaNova.PlugIn.V8 #region Misc utils + //Used to ensure a unique name generated by appending -nnn is within length requirements by splitting and chopping part of text to keep name + public static string UniqueNameBuilder(string oldName, long appendValue, int maxLength) + { + //deadman switch + if (appendValue > int.MaxValue) + { + throw new System.OverflowException("UniqueNameBuilder: Unique name could not be generated for item \""+oldName+"\" after "+int.MaxValue.ToString()+" attempts"); + } + var appendString = "-" + appendValue.ToString(); + string ret = oldName + appendString; + var diff = maxLength - ret.Length; + if (diff < 0) + { + ret = oldName.Substring(0, Math.Abs(diff)) + appendString; + } + return ret; + } + //used to set nonsense values from imported user login and password //just in case they are set active after import but never have their passwords set //so they can't be as easily hacked into @@ -492,6 +510,9 @@ namespace AyaNova.PlugIn.V8 public long Id { get; set; } public string Name { get; set; } } + + + #endregion }//eoc