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

ProcessPathwayExport() private method

private ProcessPathwayExport ( ) : void
return void
		private void ProcessPathwayExport()
		{
			IApp app = (IApp)m_mediator.PropertyTable.GetValue("App");
			string cssDialog = Path.Combine(PathwayUtils.PathwayInstallDirectory, "CssDialog.dll");
			var sf = ReflectionHelper.CreateObject(cssDialog, "SIL.PublishingSolution.Contents", null);
			Debug.Assert(sf != null);
			FdoCache cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");
			ReflectionHelper.SetProperty(sf, "DatabaseName", cache.ProjectId.Name);
			bool fContentsExists = SelectOption("ReversalIndexXHTML");
			if (fContentsExists)
			{
				// Inform Pathway if the reversal index is empty (or doesn't exist).  See FWR-3283.
				var riGuid = ReversalIndexEntryUi.GetObjectGuidIfValid(m_mediator, "ReversalIndexGuid");
				if (!riGuid.Equals(Guid.Empty))
				{
					try
					{
						IReversalIndex ri = m_cache.ServiceLocator.GetObject(riGuid) as IReversalIndex;
						fContentsExists = ri.EntriesOC.Count > 0;
					}
					catch
					{
						fContentsExists = false; // Can't get an index if we have a bad guid.
					}
				}
			}
			ReflectionHelper.SetProperty(sf, "ExportReversal", fContentsExists);
			ReflectionHelper.SetProperty(sf, "ReversalExists", fContentsExists);
			ReflectionHelper.SetProperty(sf, "GrammarExists", false);

			DialogResult result = (DialogResult)ReflectionHelper.GetResult(sf, "ShowDialog");
			if (result == DialogResult.Cancel)
				return;

			const string MainXhtml = "main.xhtml";
			const string ExpCss = "main.css";
			const string RevXhtml = "FlexRev.xhtml";

			string strOutputPath = (string)ReflectionHelper.GetProperty(sf, "OutputLocationPath");
			string strDictionaryName = (string)ReflectionHelper.GetProperty(sf, "DictionaryName");
			string outPath = Path.Combine(strOutputPath, strDictionaryName);

			bool fExistingDirectoryInput = (bool)ReflectionHelper.GetProperty(sf, "ExistingDirectoryInput");
			if (fExistingDirectoryInput)
			{
				string inputPath = (string)ReflectionHelper.GetProperty(sf, "ExistingDirectoryLocationPath");
				if (inputPath != outPath)
				{
					string dirFilter = string.Empty;
					if (strOutputPath == inputPath)
					{
						dirFilter = strDictionaryName;
					}
					try
					{
						if (!Folders.Copy(inputPath, outPath, dirFilter, app.ApplicationName))
							return;
					}
					catch (Exception ex)
					{

						MessageBox.Show(ex.Message);
						return;
					}
				}
			}

			if (!Folders.CreateDirectory(outPath, app.ApplicationName))
				return;

			string mainFullName = Path.Combine(outPath, MainXhtml);
			string revFullXhtml = Path.Combine(outPath, RevXhtml);
			if (!(bool)ReflectionHelper.GetProperty(sf, "ExportMain"))
				mainFullName = "";
			if (!(bool)ReflectionHelper.GetProperty(sf, "ExportReversal"))
				revFullXhtml = "";

			switch (result)
			{
				// No = Skip export of data from Flex but still prepare exported output (ODT, PDF or whatever)
				case DialogResult.No:
					break;

				case DialogResult.Yes:
					if (!DoFlexExports(ExpCss, mainFullName, revFullXhtml))
					{
						this.Close();
						return;
					}
					break;
			}

			string psExport = Path.Combine(PathwayUtils.PathwayInstallDirectory, "PsExport.dll");
			var exporter = ReflectionHelper.CreateObject(psExport, "SIL.PublishingSolution.PsExport", null);
			Debug.Assert(exporter != null);
			ReflectionHelper.SetProperty(exporter, "DataType", "Dictionary");
			ReflectionHelper.SetProperty(exporter, "ProgressBar", null);
			ReflectionHelper.CallMethod(exporter, "Export", mainFullName != "" ? mainFullName : revFullXhtml);

			RegistryKey applicationKey = app.SettingsKey;
			UsageEmailDialog.IncrementLaunchCount(applicationKey);
			Assembly assembly = exporter.GetType().Assembly;

			const string FeedbackEmailAddress = "[email protected]";
			const string utilityLabel = "Pathway";

			UsageEmailDialog.DoTrivialUsageReport(utilityLabel, applicationKey, FeedbackEmailAddress,
				string.Format("1. What do you hope {0} will do for you?%0A%0A2. What languages are you working on?", utilityLabel),
				false, 1, assembly);
			UsageEmailDialog.DoTrivialUsageReport(utilityLabel, applicationKey, FeedbackEmailAddress,
				string.Format("1. Do you have suggestions to improve the program?%0A%0A2. What are you happy with?"),
				false, 10, assembly);
			UsageEmailDialog.DoTrivialUsageReport(utilityLabel, applicationKey, FeedbackEmailAddress,
				string.Format("1. What would you like to say to others about {0}?%0A%0A2. What languages have you used with {0}", utilityLabel),
				false, 40, assembly);

			this.Close();
		}