Example #1
0
        /// <summary>
        /// Attempts to move this file to the target folder.
        /// If folder contains a file with same name, and it's currently in use, we rename the hot file beforehand.
        /// </summary>
        /// <param name="foldr"></param>
        /// <returns>True if operation was successful.</returns>
        public bool HotSwapTo(FolderShim foldr)
        {
            Trace_i("Hotswapping “{0}” to \\{1}\\...", this.Name, foldr.Name);
            string e;
            var    destFilePath = _fs.CombinePath(foldr.Path, this.Name);

            if (_fs.TryMoveFile(this.Path, out e, destFilePath))
            {
                return(Trace_o(
                           "Normal Move operation succeeded because target file is not in use."));
            }

            var newLocation = destFilePath + "_hot-swapped";

            if (!_fs.TryMoveFile(destFilePath, out e, newLocation))
            {
                return(Error_o(
                           "Unable to move hot file to temp location." + L.F + e));
            }

            if (!_fs.TryMoveFile(this.Path, out e, destFilePath))
            {
                return(Error_o(
                           "Unable to move file to the original location of the relocated hot file." + L.F + e));
            }

            if (!_fs.TryMoveFile(newLocation, out e, this.Path))
            {
                return(Error_o(
                           "Unable to move relocated hot file to the original location of the source file." + L.F + e));
            }

            return(Trace_o("Hot swap successful. Currently in-use: " + this.Path));
        }
Example #2
0
 private string Append(string path)
 {
     return(_fs.CombinePath(this.Path, path));
 }