Example #1
0
        /// <inheritdoc/>
        public virtual void Rename(FileInfo oldName, FileInfo newName, bool overWrite)
        {
            if (oldName is null)
            {
                throw new ArgumentNullException(nameof(oldName));
            }

            if (newName is null)
            {
                throw new ArgumentNullException(nameof(newName));
            }

            var pairs = new List <RenamePair> {
                new RenamePair(oldName, newName)
            };
            var oldSoftDelete = oldName.SoftDeleteFile();

            if (oldSoftDelete?.Exists == true)
            {
                pairs.Add(new RenamePair(oldSoftDelete, newName.SoftDeleteFile()));
            }

            if (this.Backuper != null)
            {
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(newName.Name);
                pairs.AddRange(this.Backuper.GetRenamePairs(oldName, fileNameWithoutExtension));
            }

            using var transaction = new RenameTransaction(pairs);
            transaction.Commit(overWrite);
        }
Example #2
0
        /// <inheritdoc/>
        public virtual void Rename(FileInfo oldName, FileInfo newName, bool overWrite)
        {
            Ensure.NotNull(oldName, nameof(oldName));
            Ensure.NotNull(newName, nameof(newName));
            var pairs = new List <RenamePair> {
                new RenamePair(oldName, newName)
            };
            var oldSoftDelete = oldName.GetSoftDeleteFileFor();

            if (oldSoftDelete?.Exists == true)
            {
                pairs.Add(new RenamePair(oldSoftDelete, newName.GetSoftDeleteFileFor()));
            }

            if (this.Backuper != null)
            {
                var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(newName.Name);
                pairs.AddRange(this.Backuper.GetRenamePairs(oldName, fileNameWithoutExtension));
            }

            using (var transaction = new RenameTransaction(pairs))
            {
                transaction.Commit(overWrite);
            }
        }