コード例 #1
0
        private Bloom.Book.Book MakeBookWithOneAudioFile(string translationGroupText, string pageNumber = "1",
                                                         string pageLabel = "Some page label")
        {
            var html = $@"<html> <body>
					{GetHtmlForPage(translationGroupText, pageNumber, pageLabel)}
				</body> </html>"                ;
            var book = CreateBookWithPhysicalFile(html);

            var audioDir = AudioProcessor.GetAudioFolderPath(book.FolderPath);

            Directory.CreateDirectory(audioDir);
            File.WriteAllText(Path.Combine(audioDir, "iExist.mp3"), "hello");

            return(book);
        }
コード例 #2
0
        public void CheckAudioForAllImageDescriptions_AudioFolderMissing_JustReturnsNormalMissingAudioError()
        {
            var testBook = MakeBookWithOneAudioFile($@"<div class='bloom-translationGroup bloom-imageDescription'>
								<div class='bloom-editable normal-style bloom-content1 bloom-contentNational1 bloom-visibility-code-on' lang='{
					_bookData.Language1.Iso639Code
				}'>
									{"<p><span id='bogus123' class='audio-sentence'>A flower.</span></p>"}
								</div>
							</div>
						</div>"                        );

            SIL.IO.RobustIO.DeleteDirectoryAndContents(AudioProcessor.GetAudioFolderPath(testBook.FolderPath));
            var results = AccessibilityCheckers.CheckAudioForAllImageDescriptions(testBook);

            Assert.AreEqual(1, results.Count(), "Number of errors does not match expected");
        }
コード例 #3
0
        private void UpdateAudioCheckBoxDisplay()
        {
            var book = _model.Book;

            if (!book.Storage.GetNarrationAudioFileNamesReferencedInBook(false)
                .Any(fileName => RobustFile.Exists(Path.Combine(AudioProcessor.GetAudioFolderPath(book.FolderPath), fileName))))
            {
                _narrationAudioCheckBox.Enabled = false;
            }
            if (!book.Storage.GetBackgroundMusicFileNamesReferencedInBook()
                .Any(fileName => RobustFile.Exists(Path.Combine(AudioProcessor.GetAudioFolderPath(book.FolderPath), fileName))))
            {
                _backgroundMusicCheckBox.Enabled = false;
                _backgroundMusicCheckBox.Checked = false;
            }
        }
コード例 #4
0
        private void GetSpecialLocation(ApiRequest request)
        {
            lock (request)
            {
                switch (request.RequiredPostEnumAsJson <SpecialLocation>())
                {
                case SpecialLocation.CurrentBookAudioDirectory:
                    var currentBookAudioDirectoryPath = AudioProcessor.GetAudioFolderPath(CurrentBook.FolderPath);
                    Directory.CreateDirectory(currentBookAudioDirectoryPath);
                    request.ReplyWithText(currentBookAudioDirectoryPath.Replace("\\", "/"));
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
        }
コード例 #5
0
        private static IEnumerable <Problem> InnerCheckAudio(Book.Book book, string messageTemplate, string translationGroupConstraint)
        {
            var audioFolderPath = AudioProcessor.GetAudioFolderPath(book.FolderPath);

            var audioFolderInfo = new DirectoryInfo(audioFolderPath);

            foreach (XmlElement page in book.OurHtmlDom.SafeSelectNodes("//div[contains(@class,'bloom-page')]"))
            {
                var problemText = GetFirstTextOnPageWithMissingAudio(book, page, audioFolderInfo, translationGroupConstraint);
                if (!string.IsNullOrEmpty(problemText))
                {
                    var pageLabel = HtmlDom.GetNumberOrLabelOfPageWhereElementLives(page);
                    var message   = String.Format(messageTemplate, pageLabel);
                    yield return(new Problem()
                    {
                        message = message, problemText = problemText
                    });
                }
            }
        }
コード例 #6
0
        private static void RemoveUnwantedAudioFiles(string destDirName, ISet <string> audioFilesToInclude)
        {
            // If audioFilesToInclude is null or empty, ALL audio files in the audio subdirectory will be deleted.
            // This could mean that none of them are referenced in the Book's .htm file, but the user can also choose
            // not to upload audio files.
            string audioDir = AudioProcessor.GetAudioFolderPath(destDirName);

            if (!Directory.Exists(audioDir))
            {
                return;
            }

            foreach (var audioFile in Directory.EnumerateFiles(audioDir))
            {
                var fileName = BookStorage.GetNormalizedPathForOS(Path.GetFileName(audioFile));
                if (audioFilesToInclude == null || !audioFilesToInclude.Contains(fileName))
                {
                    RobustFile.Delete(Path.Combine(audioDir, fileName));
                }
            }
        }