BlogEngine.Core.FileSystem.FileSystemUtilities.DumpProvider C# (CSharp) Method

DumpProvider() public method

Dumps the file store provider to a zip file, clears the old file store, switches and reloads a new providers clears the new file storage provider, then loads the new file store provider from the zip.
public DumpProvider ( string NewProviderName, string ArchiveOutputLocation ) : string
NewProviderName string The name of the new provider
ArchiveOutputLocation string The output archive location.
return string
        public string DumpProvider(string NewProviderName, string ArchiveOutputLocation)
        {
            string Message = string.Empty;
            CompressDirectory(ArchiveOutputLocation, Blog.CurrentInstance.RootFileStore);
            try
            {
                //file system may throw an error if there is a lock on a file while trying to delete. As this is the
                //old provider we *will* allow for residue to be left behind. The user may wish to manually clear the provider
                BlogService.ClearFileSystem();
            }
            catch
            {
                Message = "Error while clearing the old file system provider, there may have been a lock on a file. You will have to manually clear the old file system. The update operation has bypassed clearing the old file storage, however will continue to import your data into your new file storage.<br/>";
            }
            var config = WebConfigurationManager.OpenWebConfiguration("~");
            BlogFileSystemProviderSection section = (BlogFileSystemProviderSection)config.GetSection("BlogEngine/blogFileSystemProvider");
            var olderProivder = section.DefaultProvider.Clone().ToString();
            section.DefaultProvider = NewProviderName;
            config.Save();
            ConfigurationManager.RefreshSection("BlogEngine/blogFileSystemProvider");
            config = null;
            config = WebConfigurationManager.OpenWebConfiguration("~");
            try
            {
                BlogService.ReloadFileSystemProvider();
                BlogService.ClearFileSystem();
                ExtractDirectory(ArchiveOutputLocation);
            }
            catch
            {
                section = (BlogFileSystemProviderSection)config.GetSection("BlogEngine/blogFileSystemProvider");
                section.DefaultProvider = olderProivder;
                config.Save();
                ConfigurationManager.RefreshSection("BlogEngine/blogFileSystemProvider");
                config = null;
                config = WebConfigurationManager.OpenWebConfiguration("~");
                BlogService.ReloadFileSystemProvider();
                BlogService.ClearFileSystem();
                ExtractDirectory(ArchiveOutputLocation);
                Message = "Error while copying data to the new file storage provider, your changes were not successful.<br/>";
            }
            if (System.IO.File.Exists(ArchiveOutputLocation))
                System.IO.File.Delete(ArchiveOutputLocation);
            return Message;
        }