Exemple #1
0
        private void ExportToSpreadsheet(ApiRequest request)
        {
            var book     = _bookSelection.CurrentSelection;
            var bookPath = book.GetPathHtmlFile();

            try
            {
                var    dom                = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtmlFile(bookPath, false));
                var    exporter           = new SpreadsheetExporter(_webSocketServer, book.CollectionSettings);
                string outputParentFolder = request.RequiredPostDynamic().parentFolderPath;
                string outputFolder       = Path.Combine(outputParentFolder, Path.GetFileNameWithoutExtension(bookPath));
                SetSpreadsheetFolder(book, outputFolder);
                string imagesFolderPath = Path.GetDirectoryName(bookPath);

                exporter.ExportToFolderWithProgress(dom, imagesFolderPath, outputFolder, outputFilePath =>
                {
                    if (outputFilePath != null)
                    {
                        PathUtilities.OpenFileInApplication(outputFilePath);
                    }
                });
            }
            catch (Exception ex)
            {
                var msg = LocalizationManager.GetString("Spreadsheet:ExportFailed", "Export failed: ");
                NonFatalProblem.Report(ModalIf.All, PassiveIf.None, msg + ex.Message, exception: ex);
            }
            request.PostSucceeded();
        }
        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();
        }
        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);
            }
        }
 public static int Handle(SpreadsheetExportParameters options)
 {
     try
     {
         var collectionSettings = GetCollectionSettings(options.BookPath);
         var exporter           = new SpreadsheetExporter(null, collectionSettings);
         if (!string.IsNullOrEmpty(options.ParamsPath))
         {
             exporter.Params = SpreadsheetExportParams.FromFile(options.ParamsPath);
         }
         var    dom = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtmlFile(options.BookPath, false));
         string imagesFolderPath = Path.GetDirectoryName(options.BookPath);
         // It's too dangerous to use the output path they gave us, since we're going to wipe out any existing
         // content of the directory we pass to ExportToFolder. If they give us a parent folder by mistake, that
         // could be something huge, like "my documents". So assume it IS a parent folder, and make one within it.
         string outputFolderPath = Path.Combine(options.OutputPath, Path.GetFileNameWithoutExtension(imagesFolderPath));
         var    _sheet           = exporter.ExportToFolder(dom, imagesFolderPath, outputFolderPath, out string unused,
                                                           null, options.Overwrite ? OverwriteOptions.Overwrite: OverwriteOptions.Quit);
         return(0);                // all went well
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
         return(1);
     }
 }
Exemple #5
0
        public void GetContent_ReturnsExpected(string input, string expected)
        {
            var doc = new XmlDocument();

            doc.PreserveWhitespace = true;
            doc.LoadXml(input);
            var result = SpreadsheetExporter.GetContent(doc.DocumentElement);

            Assert.That(result, Is.EqualTo(expected));
        }
Exemple #6
0
        public void NoRetainMarkup_OmitsIt()
        {
            var dom      = new HtmlDom(kVerySimpleBook, true);
            var exporter = new SpreadsheetExporter();
            var sheet    = exporter.Export(dom);
            var rows     = sheet.ContentRows.ToList();
            var offset   = sheet.StandardLeadingColumns.Length;

            Assert.That(rows[0].GetCell(offset).Content.Trim(), Is.EqualTo(
                            "This elephant is running amok. Causing much damage."));
        }
Exemple #7
0
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        var repository     = new NHibernateRepository(Configure.SQLite());
        var accessPoint    = new AccessPoint(new SimpliciTIDriver());
        var watchPool      = new WatchPool();
        var watchDataSaver = new WatchDataSaver(repository, watchPool, accessPoint);
        var excelCreator   = new SpreadsheetExporter();
        var gui            = new Gui(repository, accessPoint, watchPool, watchDataSaver, excelCreator);

        Application.Run(gui);
    }
Exemple #8
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();
            }
        }
Exemple #9
0
        public void RetainMarkup_KeepsIt()
        {
            var dom      = new HtmlDom(kVerySimpleBook, true);
            var exporter = new SpreadsheetExporter();

            exporter.Params = new SpreadsheetExportParams()
            {
                RetainMarkup = true
            };
            var sheet  = exporter.Export(dom);
            var rows   = sheet.ContentRows.ToList();
            var offset = sheet.StandardLeadingColumns.Length;

            Assert.That(rows[0].GetCell(offset).Content.Trim(), Is.EqualTo(
                            "<p><span id=\"e4bc05e5-4d65-4016-9bf3-ab44a0df3ea2\" class=\"bloom-highlightSegment\" recordingmd5=\"undefined\">This elephant is running amok.</span> <span id=\"i2ba966b6-4212-4821-9268-04e820e95f50\" class=\"bloom-highlightSegment\" recordingmd5=\"undefined\">Causing much damage.</span></p>"));
        }
Exemple #10
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();
        }
Exemple #11
0
        public void OneTimeSetUp()
        {
            _dom = new HtmlDom(SpreadsheetTests.kSimpleTwoPageBook, true);
            AssertThatXmlIn.Dom(_dom.RawDom).HasSpecifiedNumberOfMatchesForXpath("//div[@lang='en']/p[text()='Riding on elephants can be risky.']", 1);             // unchanged

            var exporter = new SpreadsheetExporter();

            _sheet = exporter.Export(_dom);
            var indexDe = _sheet.ColumnForLang("de");

            _sheet.Header.SetCell(indexDe, "[tpi]");
            _sheet.ContentRows.First().SetCell(_sheet.ColumnForLang("en"), "<p>This elephant is running amok.</p>");
            _sheet.ContentRows.Skip(2).First().SetCell(_sheet.ColumnForLang("fr"), "<p>Riding on French elephants can be very risky.</p>");
            var importer = new SpreadsheetImporter(this._dom, _sheet);

            InitializeImporter(importer);
            importer.Import();
        }
 public static int Handle(SpreadsheetExportParameters options)
 {
     try
     {
         var dom      = new HtmlDom(XmlHtmlConverter.GetXmlDomFromHtmlFile(options.BookPath, false));
         var exporter = new SpreadsheetExporter();
         if (!string.IsNullOrEmpty(options.ParamsPath))
         {
             exporter.Params = SpreadsheetExportParams.FromFile(options.ParamsPath);
         }
         var _sheet = exporter.Export(dom);
         _sheet.WriteToFile(options.OutputPath);
         return(0);                // all went well
     }
     catch (Exception ex)
     {
         Debug.WriteLine(ex.Message);
         Console.WriteLine(ex.Message);
         Console.WriteLine(ex.StackTrace);
         return(1);
     }
 }
        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();
            }
        }
Exemple #14
0
        public static void Main()
        {
            Random generator = new Random(Seed: 32);

            CompetitorResult[] results =
                Enumerable.Repeat(-1, 20)
                .Select(_ => CompetitorResult.GetRandom(generator))
                .ToArray();

            var exporter = new SpreadsheetExporter <CompetitorResult>("The best competition ever")
            {
                { "Full Name", x => x.FullName },
                { "Total", x => x.Statuses.Select(y => y.Sum()).Sum().ToString() }
            };

            exporter.Add("problem1", x => x.Statuses[0].Select(Convert.ToString));
            exporter.Add("problem2", x => x.Statuses[1].Select(Convert.ToString));
            exporter.Add("problem3", x => x.Statuses[2].Select(Convert.ToString));


            exporter.Export("wb.xlsx", data: results);

            Process.Start("wb.xlsx");
        }