protected override void ExecuteModify(ModuleService oldService, ModuleService newService)
{
switch (transContext)
{
case "BeginTransaction":
{
//we rename folder to new name
string rootFolder = this.resource["RootFolder"].ToString();
if (rootFolder == "")
{
rootFolder = "c:\\ProvisioningModuleTestFolder\\";
}
if (rootFolder.Substring(rootFolder.Length - 1, 1) != "\\")
{
rootFolder += "\\";
}
string newFolderName = string.Empty;
string oldFolderName = string.Empty;
newFolderName = newService.Properties.Find(p => p.Name == "Name").Value;
oldFolderName = oldService.Properties.Find(p => p.Name == "Name").Value;
string newFolderFullPath = rootFolder + newFolderName;
string oldFolderFullPath = rootFolder + oldFolderName;
if (oldFolderName != newFolderName)
{
if (Directory.Exists(oldFolderFullPath))
{
if (Directory.Exists(newFolderFullPath))
{
throw ExceptionHelper.GetModuleException("ID422010", null, null);
}
else
{
Directory.Move(oldFolderFullPath, newFolderFullPath);
}
}
else
{
throw ExceptionHelper.GetModuleException("ID422007", null, null);
}
}
}
break;
case "CommitTransaction":
{
//nothing to do folder is already renamed
}
break;
case "RollBackTransaction":
{
//we should revert renamed folder name
string rootFolder = this.resource["RootFolder"].ToString();
if (rootFolder == "")
{
rootFolder = "c:\\ProvisioningModuleTestFolder\\";
}
if (rootFolder.Substring(rootFolder.Length - 1, 1) != "\\")
{
rootFolder += "\\";
}
string newFolderName = string.Empty;
string oldFolderName = string.Empty;
newFolderName = newService.Properties.Find(p => p.Name == "Name").Value;
oldFolderName = oldService.Properties.Find(p => p.Name == "Name").Value;
string newFolderFullPath = rootFolder + newFolderName;
string oldFolderFullPath = rootFolder + oldFolderName;
if (newFolderName != oldFolderName)
{
//now we expect that folder with newFolderFUllPath exists, and we should revert its name to oldfolderfullpath
if (Directory.Exists(newFolderFullPath))
{
if (Directory.Exists(oldFolderFullPath))
{
//nothing to do, old folder already exists - well this shouldn't happened
}
else
{
Directory.Move(newFolderFullPath, oldFolderFullPath);
}
}
else
{
//nothing to do, folder don't exists and we don't have what to revert - well this shouldn't happened
}
}
}
break;
}
}