private string GetResultString(string insideLangProjClass, string afterLangProjClass, string templateAttributes) { XDumper dumper = new XDumper(Cache); dumper.FxtDocument = new XmlDocument(); //sadly, the current dumper code requires the first thing inside the template to be a class node dumper.FxtDocument.LoadXml(string.Format("<template {0}><class name=\"LangProject\">{1}</class>{2}</template>", templateAttributes, insideLangProjClass, afterLangProjClass)); System.Text.StringBuilder builder = new System.Text.StringBuilder(); StringWriter writer = new StringWriter(builder); dumper.Go(Cache.LangProject as CmObject, writer, new IFilterStrategy[] { }); return builder.ToString(); }
private string GetResultStringFromEntry(LexEntry entry, string insideClass, string afterClass) { string templateAttributes = "requireClassTemplatesForEverything='true' doUseBaseClassTemplatesIfNeeded='true'"; XDumper dumper = new XDumper(Cache); dumper.FxtDocument = new XmlDocument(); //sadly, the current dumper code requires the first thing inside the template to be a class node dumper.FxtDocument.LoadXml(string.Format("<template {0}><class name=\"LexEntry\">{1}</class>{2}</template>", templateAttributes, insideClass, afterClass)); System.Text.StringBuilder builder = new System.Text.StringBuilder(); StringWriter writer = new StringWriter(builder); dumper.Go(entry as CmObject, writer, new IFilterStrategy[] { }); return builder.ToString(); }
static void Main(string[] arguments) { /// <summary> /// any filters that we want, for example, to only output items which satisfy their constraint. /// </summary> IFilterStrategy[] filters=null; if (arguments.Length < 3) { Console.WriteLine("usage: fxt dbName fxtTemplatePath xmlOutputPath (-guids)"); Console.WriteLine(""); Console.WriteLine("example using current directory: fxt TestLangProj WebPageSample.xhtml LangProj.xhtml"); Console.WriteLine("example with environment variables: fxt ZPU \"%fwroot%/distfiles/fxtTest.fxt\" \"%temp%/fxtTest.xml\""); return; } string fxtPath = System.Environment.ExpandEnvironmentVariables(arguments[1]); if(!File.Exists(fxtPath)) { Console.WriteLine("could not find the file "+fxtPath); return; } string outputPath = System.Environment.ExpandEnvironmentVariables(arguments[2]); FdoCache cache = null; try { Console.WriteLine("Initializing cache..."); Dictionary<string, string> cacheOptions = new Dictionary<string, string>(); cacheOptions.Add("db", arguments[0]); cache = FdoCache.Create(cacheOptions); } catch (Exception error) { Console.WriteLine(error.Message); return; } Console.WriteLine("Beginning output..."); DateTime dtstart = DateTime.Now; XDumper d = new XDumper(cache); if (arguments.Length == 4) { if(arguments[3] == "-parserDump") { filters = new IFilterStrategy[]{new ConstraintFilterStrategy()}; } else //boy do we have a brain-dead argument parser in this app! System.Diagnostics.Debug.Assert(arguments[3] == "-guids"); d.OutputGuids = true; } try { d.Go(cache.LangProject as CmObject, fxtPath, File.CreateText(outputPath), filters); //clean up, add the <?xml tag, etc. Won't be necessary if/when we make the dumper use an xmlwriter instead of a textwriter //was introducing changes such as single quote to double quote XmlDocument doc=new XmlDocument(); // doc.Load(outputPath); // doc.Save(outputPath); } catch (Exception error) { if (cache != null) cache.Dispose(); Console.WriteLine(error.Message); return; } TimeSpan tsTimeSpan = new TimeSpan(DateTime.Now.Ticks - dtstart.Ticks); Console.WriteLine("Finished: " + tsTimeSpan.TotalSeconds.ToString() + " Seconds"); if(outputPath.ToLower().IndexOf("fxttestout") > -1) System.Diagnostics.Debug.WriteLine(File.OpenText(outputPath).ReadToEnd()); if (cache != null) cache.Dispose(); System.Diagnostics.Debug.WriteLine("Finished: " + tsTimeSpan.TotalSeconds.ToString() + " Seconds"); }
// [Test] // public void oneTwo() // { // DoDump ("1"); // m_fdoCache.AssumeCacheFullyLoaded = true; // DoDump ("2 no load"); // m_fdoCache.AssumeCacheFullyLoaded = false; // } protected void DoDump (string s) { //string p = SIL.FieldWorks.Common.Utils.DirectoryFinder.FwSourceDirectory+@"\FXT\FxtDll\FxtDllTests\test3NoGloss.xml"; string p = SIL.FieldWorks.Common.Utils.DirectoryFinder.GetFWCodeSubDirectory("WW") + "/M3Parser.fxt"; XDumper dumper = new XDumper(m_fdoCache, p); CmObject lp= m_fdoCache.LangProject; startClock(); dumper.Go(lp); stopClock(); writeTimeSpan(s); }
/// <summary> /// Export the contents of the lexicon to the given file (first and only parameter). /// </summary> /// <returns>the name of the exported LIFT file if successful, or null if an error occurs.</returns> protected object ExportLexicon(IAdvInd4 progressDialog, params object[] parameters) { try { if (m_progressDlg == null) m_progressDlg = progressDialog; string outPath = (string)parameters[0]; progressDialog.Message = String.Format(FlexChorusStrings.ksExportingEntries, m_cache.LangProject.LexDbOA.EntriesOC.Count); using (XDumper dumper = new XDumper(m_cache)) { dumper.UpdateProgress += new XDumper.ProgressHandler(OnDumperUpdateProgress); dumper.SetProgressMessage += new EventHandler<XDumper.MessageArgs>(OnDumperSetProgressMessage); // Don't bother writing out the range information in the export. dumper.SetTestVariable("SkipRanges", true); dumper.SkipAuxFileOutput = true; progressDialog.SetRange(0, dumper.GetProgressMaximum()); progressDialog.Position = 0; // TODO: get better output/input filename? string p = Path.Combine(DirectoryFinder.FWCodeDirectory, @"Language Explorer\Export Templates"); string fxtPath = Path.Combine(p, "LIFT.fxt.xml"); using (TextWriter w = new StreamWriter(outPath)) { dumper.ExportPicturesAndMedia = true; // useless without Pictures directory... dumper.Go(m_cache.LangProject as CmObject, fxtPath, w); } // TODO: validate output? return outPath; } } catch { return null; } }
public void PerformRetrieval(out string sFxtOutputPath, ProgressDialogWorkingOn dlg) { CheckDisposed(); string sPrompt = XmlUtils.GetOptionalAttributeValue(m_fxtNode, "progressPrompt"); if (sPrompt != null) UpdateProgress(sPrompt, dlg); string sFxt = XmlUtils.GetManditoryAttributeValue(m_fxtNode, "file"); string sFxtPath = Path.Combine(DirectoryFinder.FWCodeDirectory, Path.Combine(@"Language Explorer\Configuration\Grammar\FXTs", sFxt)); m_fxtDumper = new XDumper(Cache); sFxtOutputPath = Path.Combine(m_outputDirectory, Cache.DatabaseName + sFxt + "Result.xml"); m_fxtDumper.Go(Cache.LangProject as CmObject, sFxtPath, File.CreateText(sFxtOutputPath)); }
private void DoDump(ParserScheduler.NeedsUpdate eNeedsUpdate, FdoCache cache, string sFxtPath) { using (XDumper fxtDumper = new XDumper(cache)) { //Trace.WriteLine("Retriever.DoDump"); // N.B. It is crucial to include the ConstraintFilterStrategy here // Without it, we end up passing ill-formed environments to the parser - a very bad thing // See LT-6827 An invalid environment is being passed on to the parser and it should not. fxtDumper.Go(cache.LangProject as CmObject, sFxtPath, File.CreateText(m_sFxtOutputPath), new IFilterStrategy[] { new ConstraintFilterStrategy() }); if (eNeedsUpdate == ParserScheduler.NeedsUpdate.GrammarAndLexicon || eNeedsUpdate == ParserScheduler.NeedsUpdate.LexiconOnly) { StartSubTask(ParserCoreStrings.ksRetrievingTemplateInformation); using (XDumper fxtDumperInner = new XDumper(cache)) { m_sFxtTemplateOutputPath = Path.Combine(m_outputDirectory, m_database + "GAFAWSFxtResult.xml"); fxtDumperInner.Go(cache.LangProject as CmObject, m_sGafawsFxtPath, File.CreateText(m_sFxtTemplateOutputPath)); } EndSubTask(); } } }
private void SetUpDataFiles() { string server = Environment.MachineName + "\\SILFW"; string database = "TestLangProj"; string cnxString = "Server=" + server + "; Database=" + database + "; User ID=FWDeveloper;" + "Password=careful; Pooling=false;"; m_sqlConnection = new SqlConnection(cnxString); m_sqlConnection.Open(); SqlCommand command = m_sqlConnection.CreateCommand(); command.CommandText = "select top 1 Dst " + "from LangProject_CurVernWss " + "order by Ord"; m_vernacularWS = (int)command.ExecuteScalar(); m_retriever = new M3ParserModelRetriever("TestLangProj"); using (SIL.FieldWorks.Common.FXT.XDumper fxtDumper = new XDumper(Cache)) { m_sFxtResultFile = Path.Combine(Path.GetTempPath(), "TestLangProjParserFxtResult.xml"); const string ksFXTPath = @"Language Explorer\Configuration\Grammar\FXTs"; string sFxtFile = Path.Combine(ksFXTPath, "M3Parser.fxt"); string sFxtPath = Path.Combine(DirectoryFinder.FWCodeDirectory, sFxtFile); fxtDumper.Go(Cache.LangProject as CmObject, sFxtPath, File.CreateText(m_sFxtResultFile), new IFilterStrategy[] { new ConstraintFilterStrategy() }); } m_fxtResult = new XmlDocument(); m_fxtResult.Load(m_sFxtResultFile); }
protected void PerformDump(XDumper dumper, string outputPath, string databaseName, string label) { startClock(); dumper.Go(m_fdoCache.LangProject as CmObject, File.CreateText(outputPath), m_filters); stopClock(); writeTimeSpan(databaseName+": " + label); }