private async Task LoadAllDatabases() { Logger.Verbose("ManagerController.LoadDatabasesGloballyAsync:Start"); managerService.ClearDatabases(); if (shellService.Settings.LoadAllDatabases) { string path = Path.Combine(shellService.Settings.DownloadLocation, "Index"); try { if (Directory.Exists(path)) { { IReadOnlyList <IFiles> databases = await GetIFilesAsync(path); foreach (IFiles database in databases) { managerService.AddDatabase(database); } } } } catch (Exception ex) { Logger.Verbose("ManagerController:LoadDatabasesGloballyAsync: {0}", ex); shellService.ShowError(ex, Resources.CouldNotLoadLibrary, ex.Data["Filename"]); } } BlogManaerFinishedLoadingDatabases?.Invoke(this, EventArgs.Empty); Logger.Verbose("ManagerController.LoadDatabasesGloballyAsync:End"); }
public bool ChangeCollection(IBlog blog, Collection oldItem, Collection newItem) { if (oldItem == null || newItem == null) { return(false); } if (QueueManager.Items.Any(x => x.Blog.Name == blog.Name && x.Blog.OriginalBlogType == blog.OriginalBlogType)) { _messageService.ShowWarning(Resources.CannotChangeCollectionOfQueuedBlog); return(false); } var oldFilenameIndex = Path.Combine(blog.Location, blog.Name) + "." + blog.OriginalBlogType; var oldFilenameChild = blog.ChildId; var newRootFolder = Path.Combine(newItem.DownloadLocation, "Index"); var newFilenameIndex = Path.Combine(newRootFolder, blog.Name) + "." + blog.OriginalBlogType; var newFilenameChild = Path.Combine(newRootFolder, Path.GetFileName(oldFilenameChild)); Directory.CreateDirectory(newRootFolder); if (File.Exists(newFilenameIndex) || File.Exists(newFilenameChild)) { _messageService.ShowWarning(Resources.CannotChangeCollectionDestFileExists); return(false); } blog.CollectionId = newItem.Id; blog.Location = newRootFolder; blog.FileDownloadLocation = null; blog.ChildId = newFilenameChild; blog.Save(); File.Delete(oldFilenameIndex); File.Move(oldFilenameChild, newFilenameChild); _managerService.BlogFiles.Remove(blog); _managerService.EnsureUniqueFolder(blog); if (blog.Dirty) { blog.Save(); } if (_shellService.Settings.LoadAllDatabases) { _managerService.RemoveDatabase(_managerService.Databases.FirstOrDefault(db => db.Name.Equals(blog.Name) && db.BlogType.Equals(blog.OriginalBlogType))); } _managerService.BlogFiles.Add(blog); if (_shellService.Settings.LoadAllDatabases) { _managerService.AddDatabase(Files.Load(blog.ChildId)); } return(true); }
private async Task LoadAllDatabasesAsync() { Logger.Verbose("ManagerController.LoadAllDatabasesAsync:Start"); _managerService.ClearDatabases(); string path = Path.Combine(_shellService.Settings.DownloadLocation, "Index"); if (Directory.Exists(path)) { IReadOnlyList <IFiles> databases = await GetIFilesAsync(path); foreach (IFiles database in databases) { _managerService.AddDatabase(database); } } BlogManagerFinishedLoadingDatabases?.Invoke(this, EventArgs.Empty); Logger.Verbose("ManagerController.LoadAllDatabasesAsync:End"); }