Esempio n. 1
0
        /// <inheritdoc/>
        public virtual bool TryRestore(FileInfo file)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.ExtensionIsNotAnyOf(file, this.BackupExtensions, "file");
            Ensure.DoesNotExist(file);

            try
            {
                var softDelete = file.GetSoftDeleteFileFor();
                if (softDelete.Exists)
                {
                    this.Restore(file, softDelete);
                    return(true);
                }

                var backup = BackupFile.GetRestoreFileFor(file, this.Setting);
                if (backup != null)
                {
                    this.Restore(file, backup);
                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 2
0
        /// <inheritdoc/>
        public virtual bool TryRestore(FileInfo file)
        {
            if (file is null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            Ensure.ExtensionIsNotAnyOf(file, this.BackupExtensions, "file");
            Ensure.DoesNotExist(file);

            try
            {
                var softDelete = file.SoftDeleteFile();
                if (softDelete.Exists)
                {
                    this.Restore(file, softDelete);
                    return(true);
                }

                var backup = BackupFile.GetRestoreFileFor(file, this.Setting);
                if (backup != null)
                {
                    this.Restore(file, backup);
                    return(true);
                }

                return(false);
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch
#pragma warning restore CA1031 // Do not catch general exception types
            {
                return(false);
            }
        }
Esempio n. 3
0
        // ReSharper disable once UnusedMember.Global
        internal virtual void Restore(FileInfo file)
        {
            Ensure.NotNull(file, nameof(file));
            Ensure.ExtensionIsNotAnyOf(file, this.BackupExtensions, "file");

            var softDelete = file.WithAppendedExtension(FileHelper.SoftDeleteExtension);

            if (softDelete.Exists)
            {
                this.Restore(file, softDelete);
                return;
            }

            var backup = BackupFile.GetRestoreFileFor(file, this.Setting);

            if (backup != null)
            {
                this.Restore(file, backup);
            }
        }