Exemplo n.º 1
0
        private void ExportProcess(List<XmlDocument> usxBooksToExport, string publicationName, string format, string outputLocationPath, DialogResult result)
        {
#if (TIME_IT)
                DateTime dt1 = DateTime.Now;    // time this thing
#endif
            bool success;
            var inProcess = new InProcess(0, 6);
            var curdir = Environment.CurrentDirectory;
            var myCursor = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            inProcess.Text = "Scripture Export";
            inProcess.Show();
            inProcess.PerformStep();
            inProcess.ShowStatus = true;
            inProcess.SetStatus("Processing Scripture Export");

            string pubName = publicationName;

            MFormat = format;

            // Get the file name as set on the dialog.
            MOutputLocationPath = outputLocationPath;
            inProcess.PerformStep();
            if (MFormat.StartsWith("theWord"))
            {
                ExportUsx(usxBooksToExport);
            }

            inProcess.PerformStep();

            string cssFullPath = Common.PathCombine(MOutputLocationPath, pubName + ".css");
            StyToCss styToCss = new StyToCss();
            styToCss.ConvertStyToCss(_mProjectName, cssFullPath, string.Empty);
            string fileName = Common.PathCombine(MOutputLocationPath, pubName + ".xhtml");
            inProcess.PerformStep();

            if (File.Exists(fileName))
            {
                // TODO: Localize string
                var msg = LocalizationManager.GetString("ParatextPathwayLink.ExportProcess.Message1", " already exists. Overwrite?", "");
                result = MessageBox.Show(string.Format("{0}" + Environment.NewLine + msg, fileName), string.Empty, MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    fileName = Common.PathCombine(MOutputLocationPath, pubName + "-" + DateTime.Now.Second + ".xhtml");
                }
                else if (result == DialogResult.No)
                {
                    return;
                }
            }
            inProcess.PerformStep();
            XmlDocument scrBooksDoc = CombineUsxDocs(usxBooksToExport, MFormat);
            inProcess.PerformStep();
            if (string.IsNullOrEmpty(scrBooksDoc.InnerText))
            {
                var message = LocalizationManager.GetString("ParatextPathwayLink.ExportProcess.Message2", "The current book has no content to export.", "");
                MessageBox.Show(message, string.Empty, MessageBoxButtons.OK);
                return;
            }
            ConvertUsxToPathwayXhtmlFile(scrBooksDoc.InnerXml, fileName);
            success = true;
            Cursor.Current = myCursor;
            inProcess.PerformStep();
            inProcess.Close();

            PsExport exporter = new PsExport();
            exporter.DataType = "Scripture";
            exporter.Export(fileName);
        }
Exemplo n.º 2
0
        private void btnFlexTest2_Click(object sender, EventArgs e)
        {
            ExportThroughPathway dlg = new ExportThroughPathway();
            dlg.InputType = "Dictionary";
            dlg.ShowDialog();

            string target = dlg.Format; //"OpenOffice";
            var tpe = new PsExport {Destination = target, DataType = dlg.InputType};
            tpe.Export(txtInputPath.Text);

        }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            InputFormat inFormat = InputFormat.XHTML;
            var projectInfo = new PublicationInformation
                                  {
                                      ProjectInputType = "Dictionary",
                                      DefaultXhtmlFileWithPath = null,
                                      DefaultCssFileWithPath = null,
                                      IsOpenOutput = false,
                                      ProjectName = "main",
                                  };
            var backendPath = Common.ProgInstall;
            var exportType = "OpenOffice/LibreOffice";
            bool bOutputSpecified = false;
            var files = new List<string>();
            bool bShowDialog = false;
            try
            {
                int i = 0;
                if (args.Length == 0)
                {
                    Usage();
                    Environment.Exit(0);
                }
                while (i < args.Length)
                {
                    i = ProcessExportType(args, i, projectInfo, files, ref inFormat, ref bShowDialog, ref exportType, ref bOutputSpecified);
                }

                SettingProcessExportFile(projectInfo, files);

                Common.ProgBase = Common.GetPSApplicationPath();
                // load settings from the settings file
                Param.LoadSettings();
                Param.Value[Param.InputType] = projectInfo.ProjectInputType;
                Param.LoadSettings();
                if (bOutputSpecified)
                {
                    // the user has specified an output -- update the settings so we export to that output
                    Param.SetValue(Param.PrintVia, exportType);
                    Param.Write();
                }

                // if the caller wants to display the Export Through Pathway dialog, do it now.
                if (bShowDialog)
                {
                    var dlg = new ExportThroughPathway();
                    dlg.InputType = projectInfo.ProjectInputType;
                    dlg.DatabaseName = projectInfo.ProjectName;
                    if (dlg.ShowDialog() == DialogResult.Yes)
                    {
                        exportType = dlg.Format;
                    }
                    else
                    {
                        // cancel export and exit out of PathwayB
                        Environment.Exit(0);
                    }
                }

                // run headless from the command line
                Common.Testing = true;
                ProcessInputFormat(inFormat, files, projectInfo);

                if (projectInfo.DefaultXhtmlFileWithPath == null)
                {
                    Usage();
                    throw new ArgumentException("Missing required option: (DefaultXhtmlFileWithPath).");
                }
                if (projectInfo.DefaultCssFileWithPath == null)
                {
                    Usage();
                    throw new ArgumentException("Missing required option: (DefaultCssFileWithPath).");
                }
                if (!File.Exists(projectInfo.DefaultXhtmlFileWithPath))
                    throw new ArgumentException(string.Format("Missing {0}", projectInfo.DefaultXhtmlFileWithPath));
                if (!File.Exists(projectInfo.DefaultCssFileWithPath))
                    throw new ArgumentException(string.Format("Missing {0}", projectInfo.DefaultCssFileWithPath));
                projectInfo.DictionaryPath = Path.GetDirectoryName(projectInfo.DefaultXhtmlFileWithPath);

                if (projectInfo.ProjectInputType.ToLower() == "dictionary")
                {
                    Param.SetValue(Param.ReversalIndex, projectInfo.IsReversalExist ? "True" : "False");
                    Param.SetValue(Param.InputType, projectInfo.ProjectInputType);
                    Param.Write();
                }

                var tpe = new PsExport { Destination = Param.PrintVia, DataType = projectInfo.ProjectInputType };
                tpe.ProgressBar = null;
                tpe.Export(projectInfo.DefaultXhtmlFileWithPath);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception err)
            {
                Console.WriteLine("PathwayB encountered an error while processing: " + err.Message);
                if (err.StackTrace != null)
                {
                    Console.WriteLine(err.StackTrace);
                }
                Environment.Exit(-1);
            }
            Environment.Exit(0);
        }
Exemplo n.º 4
0
        private void BtnTETest_Click(object sender, EventArgs e)
        {
            var plugin = new PsExport {DataType = "Scripture"};
            string outputpath = "c:/1pe/1pe";
            plugin.Export(outputpath);

        }
Exemplo n.º 5
0
        private void BtnFlexTest_Click(object sender, EventArgs e)
        {
            PrintVia printVia = new PrintVia();
            printVia.InputType = "Dictionary";
            printVia.ShowDialog();

            string target = printVia.BackEnd; //"OpenOffice";
            var tpe = new PsExport {Destination = target, DataType = printVia.InputType};
            tpe.Export(txtInputPath.Text);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Test PsExport function.
        /// </summary>
        /// <param name="testName">test name (also folder name of test)</param>
        /// <param name="mainXhtml">input xhtml name in folder</param>
        /// <param name="dataType"></param>
        /// <param name="target">desired destination</param>
        /// <param name="tests">array of tests to apply to result</param>
        /// <param name="msg">message to identify test if error occurs</param>
        protected void ExportTest(string testName, string mainXhtml, string dataType, string target, string msg = null, ArrayList tests = null)
        {
            CommonOutputSetup(testName);
            CopyExistingFile(mainXhtml);
            var cssName = Path.GetFileNameWithoutExtension(mainXhtml) + ".css";
            CopyExistingFile(cssName);
            if (Directory.Exists(FileInput("Pictures")))
                FolderTree.Copy(FileInput("Pictures"), FileOutput("Pictures"));
            foreach (string fullPath in Directory.GetFiles(_inputTestPath, "*.jpg"))
            {
                var fileName = Path.GetFileName(fullPath);
                File.Copy(fullPath, Common.PathCombine(_outputTestPath, fileName), true);
            }
            CopyExistingFile("FlexRev.xhtml");
            CopyExistingFile("FlexRev.css");

            var tpe = new SIL.PublishingSolution.PsExport { Destination = target, DataType = dataType};
            if (testName.ToLower() == "t5" || testName.ToLower() == "t8")
            {
                tpe._fromNUnit = true;
            }
            tpe.Export(FileOutput(mainXhtml));
            switch (target)
            {
                case "OpenOffice":
                    if (tests != null)
                        OdtTest.DoTests(_outputTestPath, tests);
                    else
                        OdtTest.AreEqual(_expectTestPath, _outputTestPath, msg);
                    break;
                case "Pdf":
                    var outName = Path.GetFileNameWithoutExtension(mainXhtml) + ".pdf";
                    Assert.True(File.Exists(FileOutput(outName)), msg);
                    //FileAssert.AreEqual(FileExpect(outName), FileOutput(outName), msg);
                    break;
                default:
                    Assert.Fail(msg + " unkown destination");
                    break;
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Test DeExport function.
        /// </summary>
        /// <param name="testName">test name (also folder name of test)</param>
        /// <param name="mainXhtml">input xhtml name in folder</param>
        /// <param name="jobFileName">job file in folder</param>
        /// <param name="target">desired destination</param>
        /// <param name="msg">message to identify test if error occurs</param>
        protected void SeExportTest(string testName, string mainXhtml, string jobFileName, string target, string msg)
        {
            CommonOutputSetup(testName);
            File.Copy(FileInput(mainXhtml), FileOutput(mainXhtml), true);
            string cssPath = Path.GetFileNameWithoutExtension(mainXhtml);
            File.Copy(FileInput(cssPath) + ".css", FileOutput(cssPath) +".css", true);
            JobCopy(jobFileName);
            FolderTree.Copy(FileInput("Pictures"), FileOutput("Pictures"));

            var tpe = new SIL.PublishingSolution.PsExport { DataType = "Scripture", Destination = target };
            tpe.SeExport(mainXhtml, jobFileName, _outputTestPath);
            switch (target)
            {
                case "OpenOffice/LibreOffice":
                    OdtTest.AreEqual(_expectTestPath, _outputTestPath, msg);
                    break;
                case "Pdf (using Prince)":
                    var outName = Path.GetFileNameWithoutExtension(mainXhtml) + ".pdf";
                    Assert.True(File.Exists(FileOutput(outName)), msg);
                    //FileAssert.AreEqual(FileExpect(outName), FileOutput(outName), msg);
                    break;
                default:
                    Assert.Fail(msg + " unkown destination");
                    break;
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Tests AcquireUserSettings
        /// </summary>
        /// <param name="testName">Test name (and fold name of test).</param>
        /// <param name="mainName">input xhtml name in folder</param>
        /// <param name="cssName">css name in folder</param>
        /// <param name="msg">message identifying test if mismatch (failure).</param>
        protected void AcquireUserSettingsTest(string testName, string mainName, string cssName, string msg)
        {
            CommonOutputSetup(testName);
            Param.SetValue(Param.InputType, "Dictionary");
            Param.LoadSettings();

            File.Copy(FileInput(mainName), FileOutput(mainName));
            JobCopy(cssName);

            var tpe = new SIL.PublishingSolution.PsExport() { DataType = "Scripture" };
            var mainFullName = FileOutput(mainName);
            string job = tpe.GetFluffedCssFullName(mainFullName, _outputTestPath, FileOutput(cssName));
            TextFileAssert.AreEqual(FileExpect(Path.GetFileName(job)), job, msg);
        }
Exemplo n.º 9
0
        private void ExportProcess(List <XmlDocument> usxBooksToExport, string publicationName, string format, string outputLocationPath, DialogResult result)
        {
#if (TIME_IT)
            DateTime dt1 = DateTime.Now;        // time this thing
#endif
            var inProcess = new InProcess(0, 6);
            var myCursor  = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
            inProcess.Text = "Scripture Export";
            inProcess.Show();
            inProcess.PerformStep();
            inProcess.ShowStatus = true;
            inProcess.SetStatus("Processing Scripture Export");

            string pubName = publicationName;

            MFormat = format;

            // Get the file name as set on the dialog.
            MOutputLocationPath = outputLocationPath;
            inProcess.PerformStep();
            if (MFormat.StartsWith("theWord"))
            {
                ExportUsx(usxBooksToExport);
            }

            inProcess.PerformStep();

            string   cssFullPath = Common.PathCombine(MOutputLocationPath, pubName + ".css");
            StyToCss styToCss    = new StyToCss();
            styToCss.ConvertStyToCss(_mDatabaseName, cssFullPath);
            string fileName = Common.PathCombine(MOutputLocationPath, pubName + ".xhtml");
            inProcess.PerformStep();

            if (File.Exists(fileName))
            {
                var msg = LocalizationManager.GetString("ParatextPathwayLink.ExportProcess.Message1", " already exists. Overwrite?", "");
                result = MessageBox.Show(string.Format("{0}" + Environment.NewLine + msg, fileName), string.Empty, MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    fileName = Common.PathCombine(MOutputLocationPath, pubName + "-" + DateTime.Now.Second + ".xhtml");
                }
                else if (result == DialogResult.No)
                {
                    return;
                }
            }
            inProcess.PerformStep();
            XmlDocument scrBooksDoc = CombineUsxDocs(usxBooksToExport, MFormat);
            inProcess.PerformStep();
            if (string.IsNullOrEmpty(scrBooksDoc.InnerText))
            {
                var message = LocalizationManager.GetString("ParatextPathwayLink.ExportProcess.Message2", "The current book has no content to export.", "");
                MessageBox.Show(message, string.Empty, MessageBoxButtons.OK);
                return;
            }
            ConvertUsxToPathwayXhtmlFile(scrBooksDoc.InnerXml, fileName);
            Cursor.Current = myCursor;
            inProcess.PerformStep();
            inProcess.Close();

            if (!Common.Testing)
            {
                PsExport exporter = new PsExport();
                exporter.DataType = "Scripture";
                exporter.Export(fileName);
            }
        }
Exemplo n.º 10
0
        private static void Main(string[] args)
        {
            InputFormat inFormat    = InputFormat.XHTML;
            var         projectInfo = new PublicationInformation
            {
                ProjectInputType         = "Dictionary",
                DefaultXhtmlFileWithPath = null,
                DefaultCssFileWithPath   = null,
                IsOpenOutput             = false,
                ProjectName = "main",
            };


            var  exportType       = "OpenOffice/LibreOffice";
            bool bOutputSpecified = false;
            var  files            = new List <string>();
            bool bShowDialog      = false;

            try
            {
                int i = 0;
                if (args.Length == 0)
                {
                    Usage();
                    Environment.Exit(0);
                }
                while (i < args.Length)
                {
                    i = ProcessExportType(args, i, projectInfo, files, ref inFormat, ref bShowDialog, ref exportType, ref bOutputSpecified);
                }

                if (_exportOutputTypes)
                {
                    Backend.Load(Common.FromRegistry("Export"));
                    var exportTypes = Backend.GetExportType(projectInfo.ProjectInputType);
                    SilTools.Utils.SerializeData(files[0], exportTypes);
                    Environment.Exit(0);
                }

                Common.Testing = !projectInfo.IsOpenOutput;

                SettingProcessExportFile(projectInfo, files);
                Common.SaveInputType(projectInfo.ProjectInputType);
                Common.ProgBase = Common.GetPSApplicationPath();
                // load settings from the settings file
                Param.SetLoadType = projectInfo.ProjectInputType;
                Param.LoadSettings();
                Param.Value[Param.InputType] = projectInfo.ProjectInputType;
                Param.LoadSettings();
                if (bOutputSpecified)
                {
                    // the user has specified an output -- update the settings so we export to that output
                    Param.SetValue(Param.PrintVia, exportType);
                    Param.Write();
                }

                // if the caller wants to display the Export Through Pathway dialog, do it now.
                if (bShowDialog)
                {
                    var dlg = new ExportThroughPathway();
                    dlg.InputType    = projectInfo.ProjectInputType;
                    dlg.DatabaseName = projectInfo.ProjectName;
                    if (dlg.ShowDialog() == DialogResult.Yes)
                    {
                        exportType = dlg.Format;
                    }
                    else
                    {
                        // cancel export and exit out of PathwayB
                        Environment.Exit(0);
                    }
                }

                // run headless from the command line
                ProcessInputFormat(inFormat, files, projectInfo);

                if (projectInfo.DefaultXhtmlFileWithPath == null)
                {
                    Usage();
                    throw new ArgumentException("Missing required option: (DefaultXhtmlFileWithPath).");
                }
                if (projectInfo.DefaultCssFileWithPath == null)
                {
                    Usage();
                    throw new ArgumentException("Missing required option: (DefaultCssFileWithPath).");
                }
                if (!File.Exists(projectInfo.DefaultXhtmlFileWithPath))
                {
                    throw new ArgumentException(string.Format("Missing {0}", projectInfo.DefaultXhtmlFileWithPath));
                }
                if (!File.Exists(projectInfo.DefaultCssFileWithPath))
                {
                    throw new ArgumentException(string.Format("Missing {0}", projectInfo.DefaultCssFileWithPath));
                }
                projectInfo.DictionaryPath = Path.GetDirectoryName(projectInfo.DefaultXhtmlFileWithPath);

                if (projectInfo.ProjectInputType.ToLower() == "dictionary")
                {
                    Param.SetValue(Param.ReversalIndex, projectInfo.IsReversalExist ? "True" : "False");
                    Param.SetValue(Param.InputType, projectInfo.ProjectInputType);
                    Param.Write();
                }

                var tpe = new PsExport {
                    Destination = Param.Value[Param.PrintVia], DataType = projectInfo.ProjectInputType
                };
                tpe.ProgressBar = null;
                tpe.Export(projectInfo.DefaultXhtmlFileWithPath);
            }
            catch (ArgumentException ex)
            {
                Console.WriteLine(ex.Message);
            }
            catch (Exception err)
            {
                Console.WriteLine("PathwayB encountered an error while processing: " + err.Message);
                if (err.StackTrace != null)
                {
                    Console.WriteLine(err.StackTrace);
                }
                Environment.Exit(-1);
            }
            Environment.Exit(0);
        }