This commit is contained in:
2020-05-04 14:19:35 +00:00
parent 7c6e0d4deb
commit ff98f938a7
2 changed files with 45 additions and 0 deletions

View File

@@ -324,11 +324,35 @@ namespace AyaNova.PlugIn.V8
#region BIZ OBJECT Export methods
List<string> UsedNames = new List<string>();
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;

View File

@@ -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