コード例 #1
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TestSecondaryTertiaryShouldNotGenerateHeader()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&b << az / c <<< AZ / C" + Environment.NewLine + "&f << gz";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(data.Count, 0, "Header created for two wedges");
                    Assert.AreEqual(mapChars.Count, 3, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["az"], "b");
                    Assert.AreEqual(mapChars["AZ"], "b");
                    // Rules following the '/' rule should not be skipped LT-18309
                    Assert.AreEqual(mapChars["gz"], "f");
                }
            }
        }
コード例 #2
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableDoesNotCrash()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&[last tertiary ignorable] = \\";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    // The second test catches the real world scenario, GetDigraphs is actually called many times, but the first time
                    // is the only one that should trigger the algorithm, afterward the information is cached in the exporter.
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                }
            }
        }
コード例 #3
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleSecondaryIgnored()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "& [before 2] a < aa <<< Aa <<< AA";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 0, "No characters should be generated by a before 2 rule");
                    Assert.AreEqual(mapChars.Count, 0, "The rule should have been ignored, no characters ought to have been mapped");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
コード例 #4
0
        private void TestBeginCssClassForFlowType(string flowType)
        {
            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");

                    var frag = new XmlDocument();
                    frag.LoadXml("<p css='some#style' flowType='" + flowType + "'/>");

                    exporter.BeginCssClassIfNeeded(frag.DocumentElement);
                    writer.Flush();
                    stream.Seek(0, SeekOrigin.Begin);
                    using (var reader = new StreamReader(stream))
                    {
                        output = reader.ReadToEnd();
                    }
                }
            }
            Assert.That(output, Is.StringContaining("class=\"someNUMBER_SIGNstyle\""));
        }
コード例 #5
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRulePrimaryGetsADigraph()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "& [before 1] a < aa <<< Aa <<< AA";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 1, "Wrong number of character mappings found");
                    Assert.AreEqual(mapChars.Count, 2, "Wrong number of character mappings found");
                    Assert.AreEqual(ignoreSet.Count, 0, "Ignorable character incorrectly parsed from rule");
                }
            }
        }
コード例 #6
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromICUSortRules()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&b < az << a < c <<< ch"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    ISet <string> ignoreSet;
                    var           data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 2, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["a"], "az");
                    Assert.AreEqual(mapChars["ch"], "c");
                }
            }
        }
コード例 #7
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_UnicodeTertiaryIgnorableWorks()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "&[last tertiary ignorable] = \\uA78C";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomICU;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    Set <string> ignoreSet = null;
                    Set <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 1, "Ignorable character not parsed from rule");
                    Assert.IsTrue(ignoreSet.Contains('\uA78C'.ToString(CultureInfo.InvariantCulture)));
                }
            }
        }
コード例 #8
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromSortRulesWithNoMapping()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new SimpleRulesCollationDefinition("standard")
            {
                SimpleRules = "b" + Environment.NewLine + "ñe ñ"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    ISet <string> ignoreSet;
                    var           data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(data.Count, 2, "Two Digraphs should be returned");
                    Assert.AreEqual(mapChars["ñ"], "ñe");
                }
            }
        }
コード例 #9
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_BeforeRuleCombinedWithNormalRuleWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "& a < bb & [before 1] a < aa"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(data.Count, 2, "The [before 1] rule should have added one additional character");
                }
            }
        }
コード例 #10
0
        public void XHTMLExportGetDigraphMapsFromICUSortRules_TertiaryIgnorableMixedSpacingWorks()
        {
            CoreWritingSystemDefinition ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.DefaultCollation = new IcuRulesCollationDefinition("standard")
            {
                IcuRules = "&[last tertiary ignorable]= '!'\r\n&[last tertiary ignorable] ='?'"
            };

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, m_propertyTable, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars = null;
                    ISet <string> ignoreSet = null;
                    ISet <string> data      = null;
                    Assert.DoesNotThrow(() => data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet));
                    Assert.AreEqual(mapChars.Count, 0, "Too many characters found equivalents");
                    Assert.AreEqual(ignoreSet.Count, 2, "Ignorable character not parsed from rule");
                    CollectionAssert.AreEquivalent(ignoreSet, new[] { "!", "?" });
                }
            }
        }
コード例 #11
0
        public void XHTMLExportGetLeadChar_SurrogatePairDoesNotCrash()
        {
            string         data = null;
            IWritingSystem wsEn;

            Cache.ServiceLocator.WritingSystemManager.GetOrSet("ipo", out wsEn);
            Cache.ServiceLocator.WritingSystems.AddToCurrentVernacularWritingSystems(wsEn);
            string entryLetter = "\U00016F00\U00016F51\U00016F61\U00016F90";
            Dictionary <string, Set <string> > wsDigraphMap = new Dictionary <string, Set <string> >();
            Dictionary <string, Dictionary <string, string> > wsCharEquivalentMap = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, Set <string> > wsIgnorableCharMap = new Dictionary <string, Set <string> >();

            Assert.DoesNotThrow(() => data = ConfiguredExport.GetLeadChar(entryLetter, "ipo", wsDigraphMap, wsCharEquivalentMap, wsIgnorableCharMap, Cache));
            Assert.AreEqual(data.Length, 2, "Surrogate pair should contains 2 characters");
        }
コード例 #12
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromOtherSortRules()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "fr";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.OtherLanguage;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 0, "No equivalents expected");
                }
            }
        }
コード例 #13
0
        public void XHTMLExportGetDigraphMapsFirstCharactersFromToolboxSortRules()
        {
            var ws = Cache.LangProject.DefaultVernacularWritingSystem;

            ws.SortRules = "b" + Environment.NewLine + "az a" + Environment.NewLine + "c ch";
            ws.SortUsing = WritingSystemDefinition.SortRulesType.CustomSimple;

            var    exporter = new ConfiguredExport(null, null, 0);
            string output;

            using (var stream = new MemoryStream())
            {
                using (var writer = new StreamWriter(stream))
                {
                    exporter.Initialize(Cache, null, writer, null, "xhtml", null, "dicBody");
                    Dictionary <string, string> mapChars;
                    Set <string> ignoreSet;
                    var          data = exporter.GetDigraphs(ws.Id, out mapChars, out ignoreSet);
                    Assert.AreEqual(mapChars.Count, 2, "Too many characters found equivalents");
                    Assert.AreEqual(mapChars["a"], "az");
                    Assert.AreEqual(mapChars["ch"], "c");
                }
            }
        }
コード例 #14
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Exports the configured doc view.
        /// </summary>
        /// <param name="progressDlg">The progress dialog.</param>
        /// <param name="parameters">The parameters.</param>
        /// <returns>Always null.</returns>
        /// ------------------------------------------------------------------------------------
        private object ExportConfiguredDocView(IAdvInd4 progressDlg, params object[] parameters)
        {
            Debug.Assert(parameters.Length == 3);
            m_progressDlg = progressDlg;
            if (m_xvc == null)
            {
                return(null);
            }

            string  outPath = (string)parameters[0];
            string  fxtPath = (string)parameters[1];
            FxtType ft      = (FxtType)parameters[2];

            try
            {
                m_cache.EnableBulkLoadingIfPossible(true);

                using (TextWriter w = new StreamWriter(outPath))
                {
                    FileInfo outFile = new FileInfo(outPath);
#if DEBUG
                    string dirPath   = Path.GetTempPath();
                    int    copyCount = 1;
                    string s         = string.Format("Starting Configured Export at {0}",
                                                     System.DateTime.Now.ToLongTimeString());
                    Debug.WriteLine(s);
#endif
                    m_ce = new ConfiguredExport(null, m_cache.MainCacheAccessor, m_hvoRootObj);
                    m_ce.Initialize(m_cache, w, ft.m_sDataType, ft.m_sFormat, outPath);
                    m_ce.UpdateProgress += new SIL.FieldWorks.Common.Controls.ConfiguredExport.ProgressHandler(ce_UpdateProgress);
                    m_xvc.Display(m_ce, m_hvoRootObj, m_seqView.RootFrag);
                    m_ce.Finish(ft.m_sDataType);
                    w.Close();
#if DEBUG
                    s = string.Format("Finished Configured Export Dump at {0}",
                                      System.DateTime.Now.ToLongTimeString());
                    Debug.WriteLine(s);
#endif
                    if (ft.m_sXsltFiles != null && ft.m_sXsltFiles.Length != 0)
                    {
                        string[] rgsXslts = ft.m_sXsltFiles.Split(new char[] { ';' });
                        int      cXslts   = rgsXslts.GetLength(0);
                        progressDlg.Position = 0;
                        progressDlg.SetRange(0, cXslts);
                        progressDlg.Message =
                            xWorksStrings.ProcessingIntoFinalForm;
                        int idx = fxtPath.LastIndexOfAny(new char[] { '/', '\\' });
                        if (idx < 0)
                        {
                            idx = 0;
                        }
                        else
                        {
                            ++idx;
                        }
                        string basePath = fxtPath.Substring(0, idx);
                        for (int ix = 0; ix <= cXslts; ++ix)
                        {
#if DEBUG
                            File.Copy(outPath, Path.Combine(dirPath, "DebugOnlyExportStage" + copyCount + ".txt"), true);
                            copyCount++;
                            if (ix < cXslts)
                            {
                                s = String.Format("Starting Configured Export XSLT file {0} at {1}",
                                                  rgsXslts[ix], System.DateTime.Now.ToLongTimeString());
                            }
                            else
                            {
                                s = String.Format("Starting final postprocess phase at {0}",
                                                  System.DateTime.Now.ToLongTimeString());
                            }
                            Debug.WriteLine(s);
#endif
                            if (ix < cXslts)
                            {
                                string sXsltPath = basePath + rgsXslts[ix];
                                m_ce.PostProcess(sXsltPath, outPath, ix + 1);
                            }
                            else
                            {
                                m_ce.PostProcess(null, outPath, ix + 1);
                            }
                            progressDlg.Step(0);
                        }
                    }

                    if (ft.m_sFormat.ToLowerInvariant() == "xhtml")
                    {
                        IVwStylesheet vss = null;
                        if (m_seqView.RootBox != null)
                        {
                            vss = m_seqView.RootBox.Stylesheet;
                        }
                        m_ce.WriteCssFile(Path.ChangeExtension(outPath, ".css"), vss);
                    }
                    m_ce = null;
#if DEBUG
                    File.Copy(outPath, Path.Combine(dirPath, "DebugOnlyExportStage" + copyCount + ".txt"), true);
                    s = string.Format("Totally Finished Configured Export at {0}",
                                      System.DateTime.Now.ToLongTimeString());
                    Debug.WriteLine(s);
#endif
                }
            }
            finally
            {
                m_cache.EnableBulkLoadingIfPossible(false);
            }
            return(null);
        }
コード例 #15
0
        protected void DoExport(string outPath, bool fLiftOutput)
        {
            string  fxtPath = (string)m_exportList.SelectedItems[0].Tag;
            FxtType ft      = m_rgFxtTypes[FxtIndex(fxtPath)];

            using (new SIL.FieldWorks.Common.Utils.WaitCursor(this))
            {
                using (ProgressDialogWithTask progressDlg = new ProgressDialogWithTask(this))
                {
                    try
                    {
                        progressDlg.Title = String.Format(xWorksStrings.Exporting0,
                                                          m_exportList.SelectedItems[0].SubItems[0].Text);
                        progressDlg.Message = xWorksStrings.Exporting_;

                        switch (ft.m_ft)
                        {
                        case FxtTypes.kftFxt:
                            using (m_dumper = new XDumper(m_cache))
                            {
                                m_dumper.UpdateProgress +=
                                    new XDumper.ProgressHandler(OnDumperUpdateProgress);
                                m_dumper.SetProgressMessage +=
                                    new EventHandler <XDumper.MessageArgs>(OnDumperSetProgressMessage);
                                progressDlg.SetRange(0, m_dumper.GetProgressMaximum());
                                progressDlg.CancelButtonVisible = true;
                                progressDlg.Restartable         = true;
                                progressDlg.ProgressBarStyle    = ProgressBarStyle.Continuous;
                                progressDlg.Cancel += new CancelHandler(Onm_progressDlg_Cancel);

                                progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportFxt),
                                                    outPath, fxtPath, fLiftOutput);
                            }
                            break;

                        case FxtTypes.kftConfigured:
                        case FxtTypes.kftReversal:
                            progressDlg.SetRange(0, m_seqView.ObjectCount);
                            progressDlg.CancelButtonVisible = true;
                            progressDlg.Cancel += new CancelHandler(ce_Cancel);

                            progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportConfiguredDocView),
                                                outPath, fxtPath, ft);
                            break;
                        }
                    }
                    catch (WorkerThreadException e)
                    {
                        if (e.InnerException is CancelException)
                        {
                            MessageBox.Show(this, e.InnerException.Message);
                            m_ce = null;
                        }
                        else
                        {
                            string msg = xWorksStrings.ErrorExporting_ProbablyBug + "\n" + e.InnerException.Message;
                            MessageBox.Show(this, msg);
                        }
                    }
                    finally
                    {
                        m_progressDlg = null;
                        m_dumper      = null;
                        this.Close();
                    }
                }
            }
        }