public void DeleteBook_FirstBookInEditableCollection_RemovedFromCollection()
        {
            AddBook();
            var book       = _collection.GetBookInfos().First();
            var bookFolder = book.FolderPath;

            _collection.DeleteBook(book);

            Assert.IsFalse(_collection.GetBookInfos().Contains(book));
            Assert.IsFalse(Directory.Exists(bookFolder));
        }
Exemplo n.º 2
0
        private bool LoadOneCollection(BookCollection collection, FlowLayoutPanel flowLayoutPanel)
        {
            collection.CollectionChanged += OnCollectionChanged;
            bool loadedAtLeastOneBook = false;

            foreach (Book.BookInfo bookInfo in collection.GetBookInfos())
            {
                try
                {
                    var isSuitableSourceForThisEditableCollection = (_model.IsShellProject && bookInfo.IsSuitableForMakingShells) ||
                                                                    (!_model.IsShellProject && bookInfo.IsSuitableForVernacularLibrary);

                    if (isSuitableSourceForThisEditableCollection || collection.Type == BookCollection.CollectionType.TheOneEditableCollection)
                    {
                        if (!bookInfo.IsExperimental || Settings.Default.ShowExperimentalBooks)
                        {
                            loadedAtLeastOneBook = true;
                            AddOneBook(bookInfo, flowLayoutPanel);
                        }
                    }
                }
                catch (Exception error)
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Could not load the book at " + bookInfo.FolderPath);
                }
            }
            return(loadedAtLeastOneBook);
        }
Exemplo n.º 3
0
        private void SetupChangeNotifications(BookCollection collection)
        {
            collection.CollectionChanged += (sender, args) =>
            {
                _webSocketServer.SendEvent("editableCollectionList", "reload:" + collection.PathToDirectory);
            };

            _localizationChangedEvent?.Subscribe(unused =>
            {
                if (collection.IsFactoryInstalled)
                {
                    _webSocketServer.SendEvent("editableCollectionList", "reload:" + collection.PathToDirectory);
                }
                else
                {
                    // This is tricky. Reloading the collection won't do it, because nothing has changed that would cause
                    // the buttons to re-render. But some of them may be showing a string like "Missing title" that
                    // is localizable. This is not very efficient, as we may process updates for many books that
                    // don't need it or don't even have buttons due to laziness. But changing UI language is really rare.
                    foreach (var info in collection.GetBookInfos())
                    {
                        BookCommands.RequestButtonLabelUpdate(collection.PathToDirectory, info.Id);
                    }
                }
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns>True if the collection should be shown</returns>
        private bool LoadOneCollection(BookCollection collection, FlowLayoutPanel flowLayoutPanel)
        {
            collection.CollectionChanged += OnCollectionChanged;
            bool loadedAtLeastOneBook = false;

            foreach (Book.BookInfo bookInfo in collection.GetBookInfos())
            {
                try
                {
                    if (IsSuitableSourceForThisEditableCollection(bookInfo) || collection.Type == BookCollection.CollectionType.TheOneEditableCollection)
                    {
                        if (!bookInfo.IsExperimental || Settings.Default.ShowExperimentalBooks)
                        {
                            loadedAtLeastOneBook = true;
                            AddOneBook(bookInfo, flowLayoutPanel, collection.Name.ToLower() == "templates");
                        }
                    }
                }
                catch (Exception error)
                {
                    Palaso.Reporting.ErrorReport.NotifyUserOfProblem(error, "Could not load the book at " + bookInfo.FolderPath);
                }
            }
            if (collection.Name == BookCollection.DownloadedBooksCollectionNameInEnglish)
            {
                _downloadedBookCollection        = collection;
                collection.FolderContentChanged += DownLoadedBooksChanged;
                collection.WatchDirectory();                 // In case another instance downloads a book.
                var bloomLibrayLink = new LinkLabel()
                {
                    Text =
                        L10NSharp.LocalizationManager.GetString("CollectionTab.bloomLibraryLinkLabel",
                                                                "Get more source books at BloomLibrary.org",
                                                                "Shown at the bottom of the list of books. User can click on it and it will attempt to open a browser to show the Bloom Library"),
                    Width     = 400,
                    Margin    = new Padding(17, 0, 0, 0),
                    LinkColor = Palette.TextAgainstDarkBackground
                };
                bloomLibrayLink.Click += new EventHandler(OnBloomLibrary_Click);
                flowLayoutPanel.Controls.Add(bloomLibrayLink);
                return(true);
            }
            return(loadedAtLeastOneBook);
        }
Exemplo n.º 5
0
    public static IEnumerable <BookHistoryEvent> GetAllEvents(BookCollection collection)
    {
        var all = collection.GetBookInfos().Select(bookInfo =>
        {
            var events = BookHistory.GetHistory(bookInfo);
            // add in the title, which isn't in the database (this could done in a way that involves less duplication)
            events.ForEach(e =>
            {
                e.Title         = bookInfo.Title;
                e.ThumbnailPath = Path.Combine(bookInfo.FolderPath, "thumbnail.png").ToLocalhost();
            });
            return(events);
        });

        // strip out, if there are no events
        var booksWithHistory = from b in all where b.Any() select b;

        return(booksWithHistory.SelectMany(e => e));
    }
Exemplo n.º 6
0
    public static IEnumerable <BookHistoryEvent> GetAllEvents(BookCollection collection)
    {
        var all = collection.GetBookInfos().Select(bookInfo =>
        {
            if (Directory.Exists(bookInfo.FolderPath))
            {
                return(GetBookEvents(bookInfo));
            }
            else
            {
                Debug.Fail($"Trying to get history of folder {bookInfo.FolderPath} but it does not exist");
                // In production, if the book doesn't exist we just don't include any history for it.
                return(new List <BookHistoryEvent>());
            }
        });

        // strip out, if there are no events
        var booksWithHistory = from b in all where b.Any() select b;

        return(booksWithHistory.SelectMany(e => e));
    }
Exemplo n.º 7
0
        private void GetLibraryBooks(IRequestInfo info)
        {
            var books = _booksInProjectLibrary.GetBookInfos();

            info.WriteCompleteOutput(GetBookListItems(books));
        }
Exemplo n.º 8
0
        public static void ChangeLayoutForAllContentPagesInAllBooks(IProgress progress, string collectionPath, string bookPath, string pageGuid)
        {
            if (!File.Exists(bookPath))
            {
                MessageBox.Show("Could not find template book " + bookPath);
                return;
            }
            if (!File.Exists(collectionPath))
            {
                MessageBox.Show("Could not find collection file " + collectionPath);
                return;
            }
            var problems                    = new StringBuilder();
            var collectionFolder            = Path.GetDirectoryName(collectionPath);
            var collection                  = new BookCollection(collectionFolder, BookCollection.CollectionType.TheOneEditableCollection, new BookSelection());
            var collectionSettings          = new CollectionSettings(collectionPath);
            XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[] { BloomFileLocator.GetInstalledXMatterDirectory() });
            var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(),
                                               ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());

            var templateBookInfo = new BookInfo(Path.GetDirectoryName(bookPath), true);
            var templateBook     = new Book.Book(templateBookInfo, new BookStorage(templateBookInfo.FolderPath, locator, new BookRenamedEvent(), collectionSettings),
                                                 null, collectionSettings, null, null, new BookRefreshEvent());

            var   pageDictionary = templateBook.GetTemplatePagesIdDictionary();
            IPage page           = null;

            if (!pageDictionary.TryGetValue(pageGuid, out page))
            {
                MessageBox.Show("Could not find template page " + pageGuid);
                return;
            }

            int i = 0;

            foreach (var bookInfo in collection.GetBookInfos())
            {
                i++;
                try
                {
                    var book = new Book.Book(bookInfo,
                                             new BookStorage(bookInfo.FolderPath, locator, new BookRenamedEvent(), collectionSettings),
                                             null, collectionSettings, null, null, new BookRefreshEvent());
                    //progress.WriteMessage("Processing " + book.TitleBestForUserDisplay + " " + i + "/" + collection.GetBookInfos().Count());
                    progress.ProgressIndicator.PercentCompleted = i * 100 / collection.GetBookInfos().Count();

                    book.ChangeLayoutForAllContentPages(page);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    problems.AppendLine(Path.GetFileName(bookInfo.FolderPath));
                }
            }
            if (problems.Length == 0)
            {
                MessageBox.Show("All books converted successfully");
            }
            else
            {
                MessageBox.Show("Bloom had problems converting the following books; please check them:\n" + problems);
            }
        }
Exemplo n.º 9
0
        public static void ChangeLayoutForAllContentPagesInAllBooks(IProgress progress, string collectionPath, string bookPath, string pageGuid)
        {
            if (!File.Exists(bookPath))
            {
                MessageBox.Show("Could not find template book " + bookPath);
                return;
            }
            if (!File.Exists(collectionPath))
            {
                MessageBox.Show("Could not find collection file " + collectionPath);
                return;
            }
            var collectionFolder = Path.GetDirectoryName(collectionPath);

            if (File.Exists(TeamCollectionManager.GetTcLinkPathFromLcPath(collectionFolder)))
            {
                MessageBox.Show("Change Layout command cannot currently be used in Team Collections");
                return;
                // To make this possible, we'd need to spin up a TeamCollectionManager and TeamCollection and pass the latter
                // to the Book as its SaveContext and still changes would be forbidden unless every book was checked out.
            }

            var problems                    = new StringBuilder();
            var collection                  = new BookCollection(collectionFolder, BookCollection.CollectionType.TheOneEditableCollection, new BookSelection(), null);
            var collectionSettings          = new CollectionSettings(collectionPath);
            XMatterPackFinder xmatterFinder = new XMatterPackFinder(new[]
            {
                BloomFileLocator.GetFactoryXMatterDirectory()
            });
            var locator = new BloomFileLocator(collectionSettings, xmatterFinder, ProjectContext.GetFactoryFileLocations(),
                                               ProjectContext.GetFoundFileLocations(), ProjectContext.GetAfterXMatterFileLocations());

            // AlwaysSaveable is fine here, as we checked above that it's not a TC.
            var templateBookInfo = new BookInfo(Path.GetDirectoryName(bookPath), true, new AlwaysEditSaveContext());
            var templateBook     = new Book.Book(templateBookInfo, new BookStorage(templateBookInfo.FolderPath, locator, new BookRenamedEvent(), collectionSettings),
                                                 null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent(), new NoEditSaveContext());

            var   pageDictionary = templateBook.GetTemplatePagesIdDictionary();
            IPage page           = null;

            if (!pageDictionary.TryGetValue(pageGuid, out page))
            {
                MessageBox.Show("Could not find template page " + pageGuid);
                return;
            }

            int i = 0;

            foreach (var bookInfo in collection.GetBookInfos())
            {
                i++;
                try
                {
                    var book = new Book.Book(bookInfo,
                                             new BookStorage(bookInfo.FolderPath, locator, new BookRenamedEvent(), collectionSettings),
                                             null, collectionSettings, null, null, new BookRefreshEvent(), new BookSavedEvent());
                    //progress.WriteMessage("Processing " + book.TitleBestForUserDisplay + " " + i + "/" + collection.GetBookInfos().Count());
                    progress.ProgressIndicator.PercentCompleted = i * 100 / collection.GetBookInfos().Count();

                    book.ChangeLayoutForAllContentPages(page);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                    problems.AppendLine(Path.GetFileName(bookInfo.FolderPath));
                }
            }
            if (problems.Length == 0)
            {
                MessageBox.Show("All books converted successfully");
            }
            else
            {
                MessageBox.Show("Bloom had problems converting the following books; please check them:\n" + problems);
            }
        }