SIL.FieldWorks.XWorks.ExportDialog.ExportConfiguredDocView C# (CSharp) Method

ExportConfiguredDocView() protected method

Exports the configured doc view.
protected ExportConfiguredDocView ( IThreadedProgress progressDlg, object parameters ) : object
progressDlg IThreadedProgress The progress dialog.
parameters object The parameters.
return object
		protected object ExportConfiguredDocView(IThreadedProgress progressDlg, object[] parameters)
		{
			Debug.Assert(parameters.Length == 4);
			m_progressDlg = progressDlg;
			if (m_xvc == null)
				return null;

			var outPath = (string) parameters[0];
			var fxtPath = (string) parameters[1];
			var ft = (FxtType) parameters[2];
			var vss = (IVwStylesheet) parameters[3];

			using (TextWriter w = new StreamWriter(outPath))
			{
				// FileInfo outFile = new FileInfo(outPath); // CS 219
#if DEBUG
				string dirPath = Path.GetTempPath();
				int copyCount = 1;
				string s = string.Format("Starting Configured Export at {0}",
					DateTime.Now.ToLongTimeString());
				Debug.WriteLine(s);
#endif
				m_ce = new ConfiguredExport(null, m_xvc.DataAccess, m_hvoRootObj);
				string sBodyClass = (m_areaOrig == "notebook") ? "notebookBody" : "dicBody";
				m_ce.Initialize(m_cache, m_mediator, w, ft.m_sDataType, ft.m_sFormat, outPath, sBodyClass);
				m_ce.UpdateProgress += 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}",
					DateTime.Now.ToLongTimeString());
				Debug.WriteLine(s);
#endif
				if (!string.IsNullOrEmpty(ft.m_sXsltFiles))
				{
					string[] rgsXslts = ft.m_sXsltFiles.Split(new[] { ';' });
					int cXslts = rgsXslts.GetLength(0);
					progressDlg.Position = 0;
					progressDlg.Minimum = 0;
					progressDlg.Maximum = cXslts;
					progressDlg.Message = xWorksStrings.ProcessingIntoFinalForm;
					int idx = fxtPath.LastIndexOfAny(new[] { '/', '\\' });
					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], DateTime.Now.ToLongTimeString());
						else
							s = String.Format("Starting final postprocess phase at {0}",
								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")
				{
					m_ce.WriteCssFile(Path.ChangeExtension(outPath, ".css"), vss, AllowDictionaryParagraphIndent(ft));
				}
				m_ce = null;
#if DEBUG
				File.Copy(outPath, Path.Combine(dirPath, "DebugOnlyExportStage" + copyCount + ".txt"), true);
				s = string.Format("Totally Finished Configured Export at {0}",
					DateTime.Now.ToLongTimeString());
				Debug.WriteLine(s);
#endif
			}

			return null;
		}