Example #1
0
 protected void PerformDump(XDumper dumper, string outputPath, string databaseName, string label)
 {
     startClock();
     dumper.Go(Cache.LanguageProject, File.CreateText(outputPath), m_filters);
     stopClock();
     writeTimeSpan(databaseName + ": " + label);
 }
        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);
        }
Example #3
0
        protected void DoDump(string databaseName, string label, string fxtPath, string answerPath, bool outputGuids, bool bApplyTransform)
        {
#if !Trying
            try
            {
                XDumper dumper     = PrepareDumper(databaseName, fxtPath, outputGuids);
                string  outputPath = CreateTempFile();
                PerformDump(dumper, outputPath, databaseName, label);
                if (answerPath != null)
                {
                    CheckXmlEquals(answerPath, outputPath, bApplyTransform);
                }
            }
            catch (Exception e)
            {
                string s = e.Message;
                if (e.InnerException != null)
                {
                    string s2 = e.InnerException.ToString();
                }
                throw;
            }
#else
            XDumper dumper     = PrepareDumper(databaseName, fxtPath, outputGuids);
            string  outputPath = CreateTempFile();
            PerformDump(dumper, outputPath, databaseName, label);
            CheckXmlEquals(answerPath, outputPath, bApplyTransform);
#endif
        }
Example #4
0
        protected XDumper PrepareDumper(string databaseName, string fxtPath, bool doOutputGuids)
        {
            XDumper dumper = new XDumper(Cache);

            dumper.FxtDocument = new XmlDocument();
            dumper.FxtDocument.Load(fxtPath);
            dumper.OutputGuids = doOutputGuids;
            return(dumper);
        }
Example #5
0
        protected void DoDump(string databaseName, string label, string fxtPath, string answerPath, bool outputGuids, bool bApplyTransform)
        {
            XDumper dumper     = PrepareDumper(databaseName, fxtPath, outputGuids);
            string  outputPath = FileUtils.GetTempFile("xml");

            PerformDump(dumper, outputPath, databaseName, label);
            if (answerPath != null)
            {
                FileAssert.AreEqual(answerPath, outputPath);
            }
        }
Example #6
0
		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();
		}
Example #7
0
		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();
		}
Example #8
0
//		[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);
        }
Example #9
0
        public void TwoTimesSpeedTest()
        {
            string  sFxtPath = Path.Combine(m_testDir, "mdf.xml");
            XDumper dumper   = PrepareDumper("TestLangProj", sFxtPath, false);

            PerformDump(dumper, @"C:\first.txt", "TestLangProj", "first");
            PerformDump(dumper, @"C:\second.txt", "TestLangProj", "second");
            string sAnswerFile = Path.Combine(m_sExpectedResultsPath, "TLPStandardFormatMDF.sfm");

            CheckFilesEqual(sAnswerFile, @"C:\first.txt");
            CheckFilesEqual(@"C:\first.txt", @"C:\second.txt");
        }
Example #10
0
        private void Run()
        {
            string outPath = GetOutputPathname();

            try
            {
                // 1. Export or update external lift file.
                ExportLiftData(outPath);
                // 2. Run Chorus (just run a stub for now until Chorus is real) which will
                //    a. talk to the user if there is no version control system, asking where
                //       the file to merge is, else just check-in the work, grab work from
                //       teammates, and then
                //    b. do the smart merge
                SynchronizeWithExternalSource();
                // 3. Import the lift file, wiping out anything that differs from it
                ImportNewLiftData(outPath);
            }
            catch (WorkerThreadException e)
            {
                if (e.InnerException is CancelException)
                {
                    MessageBox.Show(e.InnerException.Message);
                    return;
                }
                else if (m_dumper != null)
                {
                    MessageBox.Show("error exporting");
                }
            }
            finally
            {
                m_dumper      = null;
                m_progressDlg = null;
                if (m_fTempFiles && File.Exists(outPath))
                {
                    File.Delete(outPath);
                    string x = Path.ChangeExtension(outPath, "lift-ranges");
                    if (File.Exists(x))
                    {
                        File.Delete(x);
                    }
                    string y = x.Replace(".lift-ranges", "-ImportLog.htm");
                    if (File.Exists(y))
                    {
                        File.Delete(y);
                    }
                }
            }
        }
Example #11
0
        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));
        }
Example #12
0
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (IsDisposed)
            {
                return;
            }

            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
                if (m_mediator != null)
                {
                    m_mediator.RemoveColleague(this);
                }
                if (m_fxtDumper != null)
                {
                    m_fxtDumper.Dispose();
                }
                if (m_stringResMan != null)
                {
                    m_stringResMan.ReleaseAllResources();
                }
            }
            m_mediator                  = null;
            m_fxtDumper                 = null;
            m_fxtNode                   = null;
            m_transformsNode            = null;
            m_sHtmlFileName             = null;
            m_configurationParameters   = null;
            m_sProgressDialogTitle      = null;
            m_sRegKeyName               = null;
            m_sFileNameKey              = null;
            m_stringResMan              = null;
            m_AlsoSaveTransformNode     = null;
            m_sAlsoSaveDialogTitle      = null;
            m_sAlsoSaveFileName         = null;
            m_sReplaceDoctype           = null;
            m_sSaveAsWebpageDialogTitle = null;

            base.Dispose(disposing);
        }
Example #13
0
 private void ExportLiftData(string outPath)
 {
     // TODO: if file exists, read it to obtain the list of entries it contains, including
     // deleted entries.  Then use this information in exporting to identify deleted entries
     // in the LIFT file.  This will require something other than FXT to export LIFT files.
     using (m_progressDlg = new ProgressDialogWithTask(this))
     {
         m_progressDlg.CancelButtonVisible = true;
         m_progressDlg.Restartable         = true;
         m_progressDlg.Cancel += new CancelHandler(OnProgressDlgCancel);
         m_progressDlg.Message = "Exporting data in preparation for synchronization";
         using (m_dumper = new SIL.FieldWorks.Common.FXT.XDumper(m_cache))
         {
             m_dumper.UpdateProgress += new XDumper.ProgressHandler(OnDumperUpdateProgress);
             m_progressDlg.SetRange(0, m_dumper.GetProgressMaximum());
             m_progressDlg.RunTask(true, new BackgroundTaskInvoker(ExportLift), outPath);
         }
     }
     m_progressDlg = null;
 }
Example #14
0
 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();
         }
     }
 }
Example #15
0
 /// <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);
     }
 }
Example #16
0
        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");
        }
Example #17
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();
                    }
                }
            }
        }