Inheritance: IThreadedProgress
		public void CreateScrStylesTest_UpdateDB()
		{
			// PART 1: Setup a new Scripture with a simple stylesheet
			Cache.LangProject.TranslatedScriptureOA = null;
			IScripture scr = Cache.LanguageProject.TranslatedScriptureOA =
				Cache.ServiceLocator.GetInstance<IScriptureFactory>().Create();
			Assert.AreEqual(0, scr.StylesOC.Count, "For this test, we want to start with an empty list");

			// Create an xml style document with some styles
			XmlDocument doc = new XmlDocument();
			doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine +
				"<Styles>" + Environment.NewLine +
				"<markup version=\"2D065FD9-0F30-4104-8246-52F7103AC78F\">" + Environment.NewLine +
				// Chapter Number
				"<tag guid=\"0f4ee4e0-6954-4e1d-8a9a-b36346e6fa33\" userlevel=\"0\" id=\"Chapter_Number\" structure=\"body\" use=\"chapter\" context=\"text\" type=\"character\">" + Environment.NewLine +
				"<sfm>\\c</sfm>" + Environment.NewLine +
				"<usage wsId=\"en\">Start of chapter</usage>" + Environment.NewLine +
				"<font type=\"heading\" size=\"20 pt\" bold=\"false\" italic=\"false\" color=\"black\" superscript=\"false\" dropCap=\"2 lines\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Hebrew Title
				"<tag guid=\"d8a64396-aa10-4662-9348-5fa4f9e725e8\" userlevel=\"0\" id=\"Hebrew_Title\" structure=\"heading\" context=\"text\" type=\"paragraph\">" + Environment.NewLine +
				"<sfm>\\d</sfm>" + Environment.NewLine +
				"<usage wsId=\"es\">Título hebreo</usage>" + Environment.NewLine +
				"<font size=\"10 pt\" bold=\"false\" italic=\"false\" color=\"black\" superscript=\"false\" dropCap=\"false\"/>" + Environment.NewLine +
				"<paragraph basedOn=\"Paragraph\" next=\"Paragraph\" alignment=\"center\" background=\"white\" indentLeft=\"0\" indentRight=\"0\" firstLine=\"8 pt\" spaceBefore=\"0\" spaceAfter=\"0\" border=\"top\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Unused Replaced Style
				"<tag guid=\"5c246da3-8e17-4e80-832a-e43576802dd0\" userlevel=\"2\" id=\"Unused_Replaced_Style\" context=\"text\" type=\"paragraph\">" + Environment.NewLine +
				"<usage wsId=\"en\">This unused style shouldn't show up in replacement list</usage>" + Environment.NewLine +
				"<font/>" + Environment.NewLine +
				"<paragraph basedOn=\"Paragraph\" next=\"Paragraph\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Unused Deleted Style
				"<tag guid=\"1808b50f-5ad7-43c1-bdbf-9fc1fe3c1d5c\" userlevel=\"1\" id=\"Unused_Deleted_Style\" context=\"text\" type=\"paragraph\">" + Environment.NewLine +
				"<usage wsId=\"en\">This unused style shouldn't show up in deleted list</usage>" + Environment.NewLine +
				"<font/>" + Environment.NewLine +
				"<paragraph basedOn=\"Paragraph\" next=\"Paragraph\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Paragraph
				"<tag guid=\"45193615-3eac-4c57-980a-2bba7fe4dd08\" userlevel=\"0\" id=\"Paragraph\" structure=\"body\" use=\"prose\" context=\"text\" type=\"paragraph\">" + Environment.NewLine +
				"<usage wsId=\"en\">Generic prose paragraph</usage>" + Environment.NewLine +
				"<usage wsId=\"es\">Un párrafo general</usage>" + Environment.NewLine +
				"<sfm>\\p</sfm>" + Environment.NewLine +
				"<font size=\"10 pt\"/>" + Environment.NewLine +
				"<paragraph next=\"Paragraph\" firstLine=\"8 pt\" basedOn=\"Normal\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Delete Me
				"<tag guid=\"12640d9e-6cea-492c-a97b-daa83a6b75d8\" userlevel=\"0\" id=\"Delete_Me\" context=\"general\" type=\"character\">" + Environment.NewLine +
				"<usage wsId=\"en\">Junk</usage>" + Environment.NewLine +
				"<font/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				// Normal
				"<tag guid=\"914dcc30-e2ca-4042-ae91-a5d30e3ca13e\" userlevel=\"0\" id=\"Normal\" context=\"internal\" type=\"paragraph\">" + Environment.NewLine +
				"<font size=\"10 pt\" bold=\"false\" italic=\"false\" color=\"black\" superscript=\"false\"/>" + Environment.NewLine +
				"<paragraph next=\"Paragraph\" alignment=\"left\" background=\"white\" indentLeft=\"0\" indentRight=\"0\" firstLine=\"0 pt\" spaceBefore=\"0\" spaceAfter=\"0\"/>" + Environment.NewLine +
				"</tag>" + Environment.NewLine +
				"</markup>" + Environment.NewLine +
				"</Styles>");

			// Run CreateScrStyles() the first time
			XmlNode teStyles = doc.SelectSingleNode("Styles");
			DummyTeStylesXmlAccessor.CallCreateScrStyles(scr, teStyles);

			// PART 2: Update the xml style document with 2 new styles, 1 updated style, and 2 deleted styles

			// Select a node in the existing stylesheet to change (and to insert a new style before)
			XmlNode markup = StylesXmlAccessor.GetMarkupNode(teStyles);

			// Change the version number
			XmlNode version = markup.Attributes.GetNamedItem("version");
			version.Value = "60250A17-9B56-466b-8E7B-E27A0EB03D3E";

			// Add a new character style
			XmlNode styleNode = doc.CreateNode(XmlNodeType.Element, "tag", null);
			styleNode.Attributes.Append(NewAttribute(doc, "guid", "ac9282df-3426-43c6-a2c7-0fbdfb323a82"));
			styleNode.Attributes.Append(NewAttribute(doc, "userlevel", "2"));
			styleNode.Attributes.Append(NewAttribute(doc, "id", "MyNewCharStyle"));
			styleNode.Attributes.Append(NewAttribute(doc, "structure", "body"));
			styleNode.Attributes.Append(NewAttribute(doc, "use", "prose"));
			styleNode.Attributes.Append(NewAttribute(doc, "context", "text"));
			styleNode.Attributes.Append(NewAttribute(doc, "type", "character"));
			styleNode.InnerXml = "<usage wsId=\"en\">Use this for fun</usage>" + Environment.NewLine +
				"<font size=\"23 pt\" bold=\"true\" italic=\"true\" color=\"green\" superscript=\"false\"/>";
			markup.ReplaceChild(styleNode, markup.SelectSingleNode("tag[@id='Delete_Me']"));

			// Replace a paragraph style with a new one
			styleNode = doc.CreateNode(XmlNodeType.Element, "tag", null);
			styleNode.Attributes.Append(NewAttribute(doc, "guid", "797d2f7d-576f-49ee-b7fd-ab5bfcf251a3"));
			styleNode.Attributes.Append(NewAttribute(doc, "userlevel", "1"));
			styleNode.Attributes.Append(NewAttribute(doc, "id", "MyNewParaStyle"));
			styleNode.Attributes.Append(NewAttribute(doc, "context", "text"));
			styleNode.Attributes.Append(NewAttribute(doc, "type", "paragraph"));
			styleNode.InnerXml = "<usage wsId=\"en\">Replaces Hebrew Title</usage>" + Environment.NewLine +
				"<font size=\"13 pt\" bold=\"false\" italic=\"true\" superscript=\"false\"/>" + Environment.NewLine +
				"<paragraph next=\"Paragraph\" basedOn=\"Paragraph\" alignment=\"center\"/>";
			markup.ReplaceChild(styleNode, markup.SelectSingleNode("tag[@id='Hebrew_Title']"));

			// Modify the Paragraph style
			styleNode = markup.SelectSingleNode("tag[@id='Paragraph']");
			styleNode.SelectSingleNode("font").Attributes.GetNamedItem("size").Value = "96 pt";
			styleNode.SelectSingleNode("paragraph").Attributes.GetNamedItem("next").Value = "MyNewParaStyle";

			// Remove the two unused styles
			styleNode = markup.SelectSingleNode("tag[@id='Unused_Replaced_Style']");
			markup.RemoveChild(styleNode);
			styleNode = markup.SelectSingleNode("tag[@id='Unused_Deleted_Style']");
			markup.RemoveChild(styleNode);

			XmlNode replacements = doc.CreateNode(XmlNodeType.Element, "replacements", null);
			replacements.InnerXml = "<change old=\"Hebrew_Title\" new=\"MyNewParaStyle\"/>" +
				"<change old=\"Unused_Replaced_Style\" new=\"Paragraph\"/>";
			teStyles.AppendChild(replacements);


			// Run CreateScrStyles() the second time
			DummyTeStylesXmlAccessor acc = new DummyTeStylesXmlAccessor(scr, teStyles);
			IThreadedProgress progressDlg = new DummyProgressDlg();
			acc.InitLoading(progressDlg, scr, teStyles);

			//Verify the styles
			ICmResource styleSheetResource = (from res in scr.ResourcesOC
											  where res.Name.Equals("TeStyles")
											  select res).FirstOrDefault();
			Debug.Assert(styleSheetResource != null, "Style sheet resource not in database.");
			Assert.AreEqual(new Guid("60250A17-9B56-466b-8E7B-E27A0EB03D3E"),
				styleSheetResource.Version);
			Assert.AreEqual(DummyTeStylesXmlAccessor.ReservedStyleCount + 2, scr.StylesOC.Count,
				"Should have added all the reserved styles (including the 3 in the test XML), plus 4 additional ones in the original stylesheet (but then they all get deleted, so don't count them), plus 2 new ones in the updated stylesheet.");
			ITsTextProps tts;
			int nVar;
			foreach (IStStyle style in scr.StylesOC)
			{
				tts = style.Rules;
				switch(style.Name)
				{
					case "MyNewCharStyle":
						Assert.AreEqual(2, style.UserLevel);
						Assert.AreEqual(FunctionValues.Prose, style.Function);
						Assert.AreEqual(StyleType.kstCharacter, style.Type);
						Assert.AreEqual((int)FwTextToggleVal.kttvInvert,
							tts.GetIntPropValues((int)FwTextPropType.ktptItalic,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvInvert,
							tts.GetIntPropValues((int)FwTextPropType.ktptBold,
							out nVar));
						Assert.AreEqual(23000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFontSize,
							out nVar));
						Assert.AreEqual(0x8000,
							tts.GetIntPropValues((int)FwTextPropType.ktptForeColor,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptSuperscript,
							out nVar));
						Assert.AreEqual("Use this for fun",
							style.Usage.get_String(m_wsEn).Text);
						break;
					case "MyNewParaStyle":
						Assert.AreEqual(1, style.UserLevel);
						Assert.AreEqual(FunctionValues.Prose, style.Function);
						Assert.AreEqual(StyleType.kstParagraph, style.Type);
						Assert.AreEqual((int)FwTextToggleVal.kttvInvert,
							tts.GetIntPropValues((int)FwTextPropType.ktptItalic,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptBold,
							out nVar));
						Assert.AreEqual(13000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFontSize,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptSuperscript,
							out nVar));
						Assert.AreEqual((int)FwTextAlign.ktalCenter,
							tts.GetIntPropValues((int)FwTextPropType.ktptAlign,
							out nVar));
						Assert.AreEqual("Paragraph", style.BasedOnRA.Name);
						Assert.AreEqual("Paragraph", style.NextRA.Name);
						Assert.AreEqual("Replaces Hebrew Title",
							style.Usage.get_String(m_wsEn).Text);
						break;
					case "Chapter Number":
						Assert.AreEqual(0, style.UserLevel);
						Assert.AreEqual(FunctionValues.Chapter, style.Function);
						Assert.AreEqual(StyleType.kstCharacter, style.Type);
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptItalic,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptBold,
							out nVar));
						Assert.AreEqual(20000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFontSize,
							out nVar));
						Assert.AreEqual(0,
							tts.GetIntPropValues((int)FwTextPropType.ktptForeColor,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptSuperscript,
							out nVar));
						Assert.AreEqual("Start of chapter",
							style.Usage.get_String(m_wsEn).Text);
						break;
					case "Paragraph":
						Assert.AreEqual(0, style.UserLevel);
						Assert.AreEqual(ContextValues.Text, style.Context);
						Assert.AreEqual(StructureValues.Body, style.Structure);
						Assert.AreEqual(FunctionValues.Prose, style.Function);
						Assert.AreEqual(StyleType.kstParagraph, style.Type);
						Assert.AreEqual(96000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFontSize,
							out nVar));
						Assert.AreEqual(8000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFirstIndent,
							out nVar));
						Assert.AreEqual("Normal", style.BasedOnRA.Name);
						Assert.AreEqual("Paragraph", style.NextRA.Name,
							"This value is fixed. Can't be changed by modifying stylesheet.");
						Assert.AreEqual("Generic prose paragraph",
							style.Usage.get_String(m_wsEn).Text);
						Assert.AreEqual("Un pa\u0301rrafo general",
							style.Usage.get_String(m_wsEs).Text);
						break;
					case "Normal":
						Assert.AreEqual(0, style.UserLevel);
						Assert.AreEqual(ContextValues.Internal, style.Context);
						Assert.AreEqual(StyleType.kstParagraph, style.Type);
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptItalic,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptBold,
							out nVar));
						Assert.AreEqual(10000,
							tts.GetIntPropValues((int)FwTextPropType.ktptFontSize,
							out nVar));
						Assert.AreEqual(0,
							tts.GetIntPropValues((int)FwTextPropType.ktptForeColor,
							out nVar));
						Assert.AreEqual((int)FwTextToggleVal.kttvOff,
							tts.GetIntPropValues((int)FwTextPropType.ktptSuperscript,
							out nVar));
						Assert.AreEqual((int)FwTextAlign.ktalLeading,
							tts.GetIntPropValues((int)FwTextPropType.ktptAlign,
							out nVar));
						Assert.IsNull(style.BasedOnRA);
						Assert.AreEqual("Paragraph", style.NextRA.Name);
						break;
					case ScrStyleNames.SectionHead:
					case ScrStyleNames.IntroParagraph:
					case ScrStyleNames.IntroSectionHead:
					case ScrStyleNames.Remark:
					case ScrStyleNames.MainBookTitle:
					case ScrStyleNames.NormalFootnoteParagraph:
					case ScrStyleNames.CrossRefFootnoteParagraph:
					case ScrStyleNames.Figure:
					case ScrStyleNames.Header:
						Assert.AreEqual(StyleType.kstParagraph, style.Type);
						break;
					case ScrStyleNames.CanonicalRef:
					case ScrStyleNames.FootnoteMarker:
					case ScrStyleNames.FootnoteTargetRef:
					case ScrStyleNames.UntranslatedWord:
					case ScrStyleNames.VerseNumber:
					case ScrStyleNames.NotationTag:
						Assert.AreEqual(StyleType.kstCharacter, style.Type);
						break;
					default:
						Assert.Fail("Got an unexpected style: " + style.Name);
						break;
				}
			}
			Assert.AreEqual(2, acc.StyleReplacements.Count);
			Assert.AreEqual("MyNewParaStyle", acc.StyleReplacements["Hebrew Title"]);
			Assert.AreEqual(String.Empty, acc.StyleReplacements["Delete Me"]);
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Exposes the CreateScrStyles method
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public static void CallCreateScrStyles(IScripture scr, XmlNode teStyles)
		{
			IThreadedProgress progressDlg = new DummyProgressDlg();
			DummyTeStylesXmlAccessor acc = new DummyTeStylesXmlAccessor(scr, teStyles);
			acc.InitLoading(progressDlg, scr, teStyles);
		}
		public void PortAllBEPsTestsUsingAnUnopenedSource(
			[Values(FDOBackendProviderType.kXML, FDOBackendProviderType.kDb4oClientServer)]
			FDOBackendProviderType sourceType,
			[Values(FDOBackendProviderType.kXML, FDOBackendProviderType.kDb4oClientServer, FDOBackendProviderType.kMemoryOnly)]
			FDOBackendProviderType targetType)
		{
			var path = Path.Combine(Path.GetTempPath(), "FieldWorksTest");
			if (!Directory.Exists(path))
				Directory.CreateDirectory(path);
			var sourceBackendStartupParameters = GenerateBackendStartupParameters(false, sourceType);
			var targetBackendStartupParameters = GenerateBackendStartupParameters(true, targetType);

			var sourceGuids = new List<Guid>();

			DeleteDatabase(sourceBackendStartupParameters);
			DeleteDatabase(targetBackendStartupParameters);

			// Set up data source
			var projId = new TestProjectId(sourceBackendStartupParameters.ProjectId.Type,
													sourceBackendStartupParameters.ProjectId.Path);
			using (FdoCache sourceCache = FdoCache.CreateCacheWithNewBlankLangProj(
				projId, "en", "fr", "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, new FdoSettings()))
			{
				// BEP is a singleton, so we shouldn't call Dispose on it. This will be done
				// by service locator.
				var sourceDataSetup = GetMainBEPInterface(sourceCache);
				sourceCache.ServiceLocator.GetInstance<IUndoStackManager>().Save(); // persist the new db so we can reopen it.
				sourceDataSetup.LoadDomain(BackendBulkLoadDomain.All);
				sourceGuids.AddRange(GetAllCmObjects(sourceCache).Select(obj => obj.Guid)); // Collect all source Guids
			}

			// Migrate source data to new BEP.
			IThreadedProgress progressDlg = new DummyProgressDlg();
			using (var targetCache = FdoCache.CreateCacheWithNoLangProj(
				new TestProjectId(targetBackendStartupParameters.ProjectId.Type, null), "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, new FdoSettings()))
			{
				// BEP is a singleton, so we shouldn't call Dispose on it. This will be done
				// by service locator.
				var targetDataSetup = GetMainBEPInterface(targetCache);
				targetDataSetup.InitializeFromSource(new TestProjectId(targetBackendStartupParameters.ProjectId.Type,
																		targetBackendStartupParameters.ProjectId.Path), sourceBackendStartupParameters, "en", progressDlg);
				targetDataSetup.LoadDomain(BackendBulkLoadDomain.All);
				CompareResults(sourceGuids, targetCache);
			}
			sourceGuids.Clear();
		}
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Make DeleteDeprecatedStylesAndDetermineReplacements accessible
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public void CallDeleteDeprecatedStylesAndDetermineReplacements()
		{
			IThreadedProgress progressDlg = new DummyProgressDlg();
			m_progressDlg = progressDlg;
			DeleteDeprecatedStylesAndDetermineReplacements();
			m_progressDlg = null;
		}
Beispiel #5
0
		private string TryImport(string sOrigFile, string sOrigRangesFile, FlexLiftMerger.MergeStyle mergeStyle, int expectedCount, bool trustModificationTimes = true)
		{
			string logfile = null;

			IProgress progressDlg = new DummyProgressDlg();
			var fMigrationNeeded = Migrator.IsMigrationNeeded(sOrigFile);
			var sFilename = fMigrationNeeded
								? Migrator.MigrateToLatestVersion(sOrigFile)
								: sOrigFile;
			var flexImporter = new FlexLiftMerger(Cache, mergeStyle, trustModificationTimes);
			var parser = new LiftParser<LiftObject, CmLiftEntry, CmLiftSense, CmLiftExample>(flexImporter);
			flexImporter.LiftFile = sOrigFile;

			//The following are the calls to import the Ranges file and then the Data file.
			if (!String.IsNullOrEmpty(sOrigRangesFile))
				flexImporter.LoadLiftRanges(sOrigRangesFile);
			var cEntries = parser.ReadLiftFile(sFilename);

			Assert.AreEqual(expectedCount, cEntries);
			if (fMigrationNeeded)
				File.Delete(sFilename);
			flexImporter.ProcessPendingRelations(progressDlg);
			logfile = flexImporter.DisplayNewListItems(sOrigFile, cEntries);

			return logfile;
		}