コード例 #1
0
        public void OneTimeSetUp()
        {
            var origDom = new HtmlDom(roundtripTestBook, true);

            _roundtrippedDom = new HtmlDom(roundtripTestBook, true);             //Will get imported into

            // We want to test that exporting a book with branding in the data-dive and importing into a book with no branding
            // does not reinstate the branding. So we need to remove it from the pre-import DOM, which is otherwise
            // (for this test) the same as what we originally exported.
            var branding =
                _roundtrippedDom.SelectSingleNode("//div[@data-book='outside-back-cover-branding-bottom-html']");

            branding.ParentNode.RemoveChild(branding);
            AssertThatXmlIn.Dom(origDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='simpleFormattingTest']", 1);
            AssertThatXmlIn.Dom(origDom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@id='nestedFormattingTest']", 1);
            var mockLangDisplayNameResolver = new Mock <ILanguageDisplayNameResolver>();

            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("en")).Returns("English");
            var exporter = new SpreadsheetExporter(mockLangDisplayNameResolver.Object);

            exporter.Params  = new SpreadsheetExportParams();
            _sheetFromExport = exporter.Export(origDom, "fakeImagesFolderpath");
            using (var tempFile = TempFile.WithExtension("xslx"))
            {
                _sheetFromExport.WriteToFile(tempFile.Path);
                var sheet    = InternalSpreadsheet.ReadFromFile(tempFile.Path);
                var importer = new SpreadsheetImporter(null, _roundtrippedDom);
                importer.Import(sheet);
            }
        }
コード例 #2
0
        public void OneTimeSetUp()
        {
            var dom = new HtmlDom(imageBook, true);

            _spreadsheetFolder = new TemporaryFolder("SpreadsheetImagesTests");
            _bookFolder        = new TemporaryFolder("SpreadsheetImagesTests_Book");

            var mockLangDisplayNameResolver = new Mock <ILanguageDisplayNameResolver>();

            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("en")).Returns("English");

            _exporter = new SpreadsheetExporter(mockLangDisplayNameResolver.Object);
            var path = SIL.IO.FileLocationUtilities.GetDirectoryDistributedWithApplication(_pathToTestImages);

            // We need all these files in one place so we can verify that all of them get copied except placeHolder.png
            foreach (var name in new [] { "BloomWithTaglineAgainstLight.svg", "man.jpg", "Mars 2.png", "lady24b.png", "empty-file.jpg" })
            {
                RobustFile.Copy(Path.Combine(path, name), Path.Combine(_bookFolder.FolderPath, name));
            }
            var placeHolderSource = Path.Combine(BloomFileLocator.FactoryCollectionsDirectory, "template books", "Basic Book", "placeHolder.png");

            RobustFile.Copy(placeHolderSource, Path.Combine(_bookFolder.FolderPath, "placeHolder.png"));

            _progressSpy     = new ProgressSpy();
            _sheetFromExport =
                _exporter.ExportToFolder(dom, _bookFolder.FolderPath, _spreadsheetFolder.FolderPath, out string outputPath, _progressSpy, OverwriteOptions.Overwrite);
            _rowsFromExport = _sheetFromExport.ContentRows.ToList();
            _sheetFromFile  = InternalSpreadsheet.ReadFromFile(outputPath);
            _rowsFromFile   = _sheetFromFile.ContentRows.ToList();
        }
コード例 #3
0
 public static int Handle(SpreadsheetImportParameters options)
 {
     try
     {
         string folderPath = Directory.GetParent(options.BookPath).FullName;
         BookStorage.SaveCopyBeforeImportOverwrite(folderPath);
         var sheet    = InternalSpreadsheet.ReadFromFile(options.InputPath);
         var dom      = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtmlFile(options.BookPath, false));
         var importer = new SpreadsheetImporter(null, dom, Path.GetDirectoryName(options.InputPath), folderPath);
         if (!string.IsNullOrEmpty(options.ParamsPath))
         {
             importer.Params = SpreadsheetImportParams.FromFile(options.ParamsPath);
         }
         var messages = importer.Import(sheet);
         foreach (var message in messages)
         {
             Debug.WriteLine(message);
             Console.WriteLine(message);
         }
         // Review: A lot of other stuff happens in Book.Save() and BookStorage.SaveHtml().
         // I doubt we need any of it for current purposes, but later we might.
         XmlHtmlConverter.SaveDOMAsHtml5(dom.RawDom, options.BookPath);
         Console.WriteLine("done");
         return(0);                // all went well
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
         return(1);
     }
 }
コード例 #4
0
        public void OneTimeSetUp()
        {
            var dom = new HtmlDom(kSimpleTwoPageBook, true);

            _exporter        = new SpreadsheetExporter();
            _sheetFromExport = _exporter.Export(dom);
            _rowsFromExport  = _sheetFromExport.ContentRows.ToList();
            using (var tempFile = TempFile.WithExtension("xslx"))
            {
                _sheetFromExport.WriteToFile(tempFile.Path);
                _sheetFromFile = InternalSpreadsheet.ReadFromFile(tempFile.Path);
                _rowsFromFile  = _sheetFromFile.ContentRows.ToList();
            }
        }
コード例 #5
0
        public void OneTimeSetUp()
        {
            var dom = new HtmlDom(dataDivBook, true);

            _spreadsheetFolder = new TemporaryFolder("SpreadsheetXmatterTests");
            var mockLangDisplayNameResolver = new Mock <ILanguageDisplayNameResolver>();

            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("en")).Returns("English");
            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("es")).Returns("Español");

            _exporter        = new SpreadsheetExporter(mockLangDisplayNameResolver.Object);
            _sheetFromExport = _exporter.ExportToFolder(dom, "fakeImagesFolderpath", _spreadsheetFolder.FolderPath,
                                                        out string outputPath, null, OverwriteOptions.Overwrite);

            _rowsFromExport = _sheetFromExport.ContentRows.ToList();
            _sheetFromFile  = InternalSpreadsheet.ReadFromFile(outputPath);
            _rowsFromFile   = _sheetFromFile.ContentRows.ToList();
        }
コード例 #6
0
        public void OneTimeSetUp()
        {
            var dom = new HtmlDom(kSimpleTwoPageBook, true);
            var langCodesToLangNames = new Dictionary <string, string>();

            langCodesToLangNames.Add("en", "English");
            langCodesToLangNames.Add("fr", "French");
            langCodesToLangNames.Add("de", "German");
            var mockLangDisplayNameResolver = new Mock <ILanguageDisplayNameResolver>();

            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("en")).Returns("English");
            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("fr")).Returns("French");
            mockLangDisplayNameResolver.Setup(x => x.GetLanguageDisplayName("de")).Returns("German");
            _exporter        = new SpreadsheetExporter(mockLangDisplayNameResolver.Object);
            _sheetFromExport = _exporter.Export(dom, "fakeImagesFolderpath");
            _rowsFromExport  = _sheetFromExport.ContentRows.ToList();
            using (var tempFile = TempFile.WithExtension("xslx"))
            {
                _sheetFromExport.WriteToFile(tempFile.Path);
                _sheetFromFile = InternalSpreadsheet.ReadFromFile(tempFile.Path);
                _rowsFromFile  = _sheetFromFile.ContentRows.ToList();
            }
        }