Bloom.Collection.CollectionSettings.RenameCollection C# (CSharp) Method

RenameCollection() public static method

public static RenameCollection ( string fromDirectory, string toDirectory ) : string
fromDirectory string
toDirectory string
return string
        public static string RenameCollection(string fromDirectory, string toDirectory)
        {
            if (!Directory.Exists(fromDirectory))
            {
                throw new ApplicationException("Bloom could not complete the renaming of the collection, because there isn't a directory with the source name anymore: " + fromDirectory);
            }

            if (Directory.Exists(toDirectory)) //there's already a folder taking this name
            {
                throw new ApplicationException("Bloom could not complete the renaming of the collection, because there is already a directory with the new name: " + toDirectory);
            }

            //this is just a sanity check, it will throw if the existing directory doesn't have a collection
            FindSettingsFileInFolder(fromDirectory);

            //first rename the directory, as that is the part more likely to fail (because *any* locked file in there will cause a failure)
            SIL.IO.RobustIO.MoveDirectory(fromDirectory, toDirectory);
            string  collectionSettingsPath;
            try
            {
                collectionSettingsPath = FindSettingsFileInFolder(toDirectory);
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                //we now make a default name based on the name of the directory
                string destinationPath = Path.Combine(toDirectory, Path.GetFileName(toDirectory)+".bloomCollection");
                if (!RobustFile.Exists(destinationPath))
                    RobustFile.Move(collectionSettingsPath, destinationPath);

                return destinationPath;
            }
            catch (Exception error)
            {
                //change the directory name back, so the rename isn't half-done.
                SIL.IO.RobustIO.MoveDirectory(toDirectory, fromDirectory);
                throw new ApplicationException(string.Format("Could change the folder name, but not the collection file name",fromDirectory,toDirectory),error);
            }
        }