protected override NameValueCollection Prepare(FdoToolbox.Core.Configuration.FdoBulkCopyTaskDefinition def)
{
/* There is subtle precondition that would've resulted in all connection references being named to a
* single reference, thus invalidating the whole task when loaded.
*
* If the task definition has any connection names to an *already* loaded connection, a rename operation
* could overwrite a previous rename operation. Consider:
*
* Connection A) SDF_Desktop
* Connection B) SDFConnection0
*
* Loaded Connections:
* - SDFConnection0
* - SDFConnection1
*
* If during loading, SDF_Desktop matches to SDFConnection0, and SDFConnection0 matches to SDFConnection1 the rename operations
* would then be:
*
* 1) Rename SDF_Desktop to SDFConnection0
* 2) Rename SDF_Connection0 to SDFConnection1
*
* As a result, all referenced connections will eventually be renamed to SDFConnection1, which is not what we want.
*
* The solution bere is to "fix" the definition by renaming the named connections to something we know is not already a loaded
* connection. This is done regardless to ensure consistent behaviour. Thsi method performs this solution.
*/
string prefix = "Connection";
int counter = 0;
FdoConnectionManager connMgr = ServiceManager.Instance.GetService<FdoConnectionManager>();
NameValueCollection nameMappings = new NameValueCollection();
foreach (FdoConnectionEntryElement el in def.Connections)
{
string newName = prefix + counter;
while (connMgr.GetConnection(newName) != null)
{
counter++;
newName = prefix + counter;
}
string oldName = el.name;
def.UpdateConnectionReferences(oldName, newName);
nameMappings.Add(newName, oldName);
counter++;
}
return nameMappings;
}