Beispiel #1
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();
					}
				}
			}
		}
Beispiel #2
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);
		}
Beispiel #3
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");
		}
Beispiel #4
0
		private void OnDumperSetProgressMessage(object sender, XDumper.MessageArgs e)
		{
			Debug.Assert(m_progressDlg != null);
			string sMsg = xWorksStrings.ResourceManager.GetString(e.MessageId, xWorksStrings.Culture);
			if (!String.IsNullOrEmpty(sMsg))
				m_progressDlg.Message = sMsg;
			m_progressDlg.Position = 0;
			m_progressDlg.SetRange(0, e.Max);
		}
Beispiel #5
0
		void OnDumperSetProgressMessage(object sender, XDumper.MessageArgs e)
		{
			if (m_progressDlg == null)
				return;
			Debug.WriteLine(String.Format("OnDumperSetProgressMessage(\"{0}\")", e.MessageId));
			string sMsg = FlexChorusStrings.ResourceManager.GetString(e.MessageId, FlexChorusStrings.Culture);
			if (!String.IsNullOrEmpty(sMsg))
				m_progressDlg.Message = sMsg;
			m_progressDlg.SetRange(0, e.Max);
		}
Beispiel #6
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;
			}
		}
Beispiel #7
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);
		}
		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);
				}
			}

		}
Beispiel #9
0
        protected void DoExport(string outPath, bool fLiftOutput)
        {
            string fxtPath = (string)m_exportItems[0].Tag;
            FxtType ft = m_rgFxtTypes[FxtIndex(fxtPath)];
            using (new WaitCursor(this))
            {
                using (var progressDlg = new ProgressDialogWithTask(this))
                {
                    try
                    {
                        progressDlg.Title = String.Format(xWorksStrings.Exporting0,
                            m_exportItems[0].SubItems[0].Text);
                        progressDlg.Message = xWorksStrings.Exporting_;

                        switch (ft.m_ft)
                        {
                            case FxtTypes.kftFxt:
                                m_dumper = new XDumper(m_cache);
                                m_dumper.UpdateProgress += OnDumperUpdateProgress;
                                m_dumper.SetProgressMessage += OnDumperSetProgressMessage;
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = m_dumper.GetProgressMaximum();
                                progressDlg.AllowCancel = true;
                                progressDlg.Restartable = true;

                                progressDlg.RunTask(true, ExportFxt, outPath, fxtPath, fLiftOutput);
                                break;
                            case FxtTypes.kftConfigured:
                            case FxtTypes.kftReversal:
                            case FxtTypes.kftClassifiedDict:
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = m_seqView.ObjectCount;
                                progressDlg.AllowCancel = true;

                                IVwStylesheet vss = m_seqView.RootBox == null ? null : m_seqView.RootBox.Stylesheet;
                                progressDlg.RunTask(true, ExportConfiguredDocView,
                                    outPath, fxtPath, ft, vss);
                                break;
                            case FxtTypes.kftTranslatedLists:
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = m_translatedLists.Count;
                                progressDlg.AllowCancel = true;

                                progressDlg.RunTask(true, ExportTranslatedLists, outPath);
                                break;
                            case FxtTypes.kftSemanticDomains:
                                // Potentially, we could count semantic domains and try to make the export update for each.
                                // In practice this only takes a second or two on a typical modern computer
                                // an the main export routine is borrowed from kftTranslatedLists and set up to count each
                                // list as one step. For now, claiming this export just has one step seems good enough.
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = 1;
                                progressDlg.AllowCancel = true;

                                progressDlg.RunTask(true, ExportSemanticDomains, outPath, ft, fxtPath, m_allQuestions);
                                break;
                            case FxtTypes.kftPathway:
                                break;
                            case FxtTypes.kftLift:
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = 1000;
                                progressDlg.AllowCancel = true;
                                progressDlg.Restartable = true;
                                progressDlg.RunTask(true, ExportLift, outPath, ft.m_filtered);
                                break;
                            case FxtTypes.kftGrammarSketch:
                                progressDlg.Minimum = 0;
                                progressDlg.Maximum = 1000;
                                progressDlg.AllowCancel = true;
                                progressDlg.Restartable = true;
                                progressDlg.RunTask(true, ExportGrammarSketch, outPath, ft.m_sDataType, ft.m_sXsltFiles);
                                break;
                        }
                    }
                    catch (WorkerThreadException e)
                    {
                        if (e.InnerException is CancelException)
                        {
                            MessageBox.Show(this, e.InnerException.Message);
                            m_ce = null;
                        }
                        else if (e.InnerException is LiftFormatException)
                        {
                            // Show the pretty yellow semi-crash dialog box, with instructions for the
                            // user to report the bug.
                            var app = (IApp) m_mediator.PropertyTable.GetValue("App");
                            ErrorReporter.ReportException(new Exception(xWorksStrings.ksLiftExportBugReport, e.InnerException),
                                app.SettingsKey, m_mediator.FeedbackInfoProvider.SupportEmailAddress, this, false);
                        }
                        else
                        {
                            string msg = xWorksStrings.ErrorExporting_ProbablyBug + Environment.NewLine + e.InnerException.Message;
                            MessageBox.Show(this, msg);
                        }
                    }
                    finally
                    {
                        m_progressDlg = null;
                        m_dumper = null;
                        Close();
                    }
                }
            }
        }
Beispiel #10
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();
				}
			}
		}
		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);
		}
Beispiel #12
0
		protected XDumper PrepareDumper(string databaseName, string fxtPath, bool doOutputGuids)
		{
			LoadCache(databaseName);
			XDumper dumper = new XDumper(m_fdoCache);
			dumper.FxtDocument = new XmlDocument();
			dumper.FxtDocument.Load(fxtPath);
			dumper.OutputGuids= doOutputGuids;
			return dumper;
		}
Beispiel #13
0
		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);
		}
Beispiel #14
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();
		}
Beispiel #15
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));
		}
Beispiel #16
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();
		}
Beispiel #17
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;
		}