Beispiel #1
0
        /// <summary>
        /// Deletes files and directories scheduled for deletion by the settings provider.
        /// </summary>
        /// <param name="settings"><see cref="ISettingsProvider"/> managing the files and directories scheduled for deletion.</param>
        /// <param name="provider"><see cref="IFileSystem"/> managing where the files and directories are located.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="settings"/> or <paramref name="provider"/> is null.</exception>
        protected async Task DeleteScheduledFiles(ISettingsProvider settings, IFileSystem provider)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (provider == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            // Files
            foreach (var item in settings.GetFilesScheduledForDeletion().ToList()) // Create a new list because the original will be continuously modified
            {
                if (CurrentFileSystem.FileExists(item))
                {
                    CurrentFileSystem.DeleteFile(item);
                }
                CurrentSettingsProvider.UnscheduleFileForDeletion(item);
                await CurrentSettingsProvider.Save(provider);
            }

            // Directories
            foreach (var item in settings.GetDirectoriesScheduledForDeletion().ToList())
            {
                if (CurrentFileSystem.DirectoryExists(item))
                {
                    CurrentFileSystem.DeleteDirectory(item);
                }
                CurrentSettingsProvider.UnscheduleDirectoryForDeletion(item);
                await CurrentSettingsProvider.Save(provider);
            }
        }
Beispiel #2
0
        void IFileSystem.DeleteDirectory(string path)
        {
            var fixedPath = FixPath(path);

            if (!BlacklistedPaths.Contains(fixedPath))
            {
                BlacklistedPaths.Add(fixedPath);
            }

            var virtualPath = GetVirtualPath(path);

            if (CurrentFileSystem != null && CurrentFileSystem.FileExists(virtualPath))
            {
                CurrentFileSystem.DeleteFile(virtualPath);
            }
        }