Exemplo n.º 1
0
		/// <summary>
		///
		/// </summary>
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
			{
				// add a custom field named "MyRestrictions" to LexEntry.
				FieldDescription custom = new FieldDescription(Cache);
				custom.Class = LexEntryTags.kClassId;
				custom.Name = "MyRestrictions";
				custom.Type = CellarPropertyType.MultiString;
				custom.WsSelector = (int)WritingSystemServices.kwsAnalVerns;
				custom.Userlabel = "MyRestrictions";
				custom.UpdateCustomField();
			});
		}
Exemplo n.º 2
0
		public void LiftImport_ExampleCustomFieldUpdatedDuringMerge()
		{
			var rangesWithStatusList = new[]
			{
				@"<?xml version=""1.0"" encoding=""UTF-8"" ?>",
				@"<lift-ranges>",
				@"<range id=""status"">",
				@"<range-element id=""Confirmed"" guid=""bd80cd3e-ea5e-11de-9871-0013722f8dec"">",
				@"<label>",
				@"<form lang=""en""><text>Confirmed</text></form>",
				@"</label>",
				@"<abbrev>",
				@"<form lang=""en""><text>Conf</text></form>",
				@"</abbrev>",
				@"</range-element>",
				@"<range-element id=""Pending"" guid=""bd964254-ea5e-11de-8cdf-0013722f8dec"">",
				@"<label>",
				@"<form lang=""en""><text>Pending</text></form>",
				@"</label>",
				@"<abbrev>",
				@"<form lang=""en""><text>Pend</text></form>",
				@"</abbrev>",
				@"</range-element>",
				@"</range>",
				@"</lift-ranges>"
			};
			var lifDataWithExampleWithPendingStatus = new[]
			{
				@"<?xml version=""1.0"" encoding=""UTF-8"" ?>",
				@"<lift producer=""SIL.FLEx 8.0.10.41829"" version=""0.13"">",
				@"<header>",
				@"<ranges>",
				@"<range id=""status"" href=""file://*****:*****@"</ranges>",
				@"<fields>",
				@"<field tag=""EntryStatus"">",
				@"<form lang=""en""><text></text></form>",
				@"<form lang=""qaa-x-spec""><text>Class=LexEntry; Type=ReferenceAtom; WsSelector=kwsAnal; DstCls=CmPossibility; range=status</text></form>",
				@"</field>",
				@"<field tag=""CustomExampleStatus"">",
				@"<form lang=""en""><text></text></form>",
				@"<form lang=""qaa-x-spec""><text>Class=LexExampleSentence; Type=ReferenceAtom; WsSelector=kwsAnal; DstCls=CmPossibility; range=status</text></form>",
				@"</field>",
				@"</fields>",
				@"</header>",
				@"<entry dateCreated=""2013-07-14T21:32:58Z"" dateModified=""2013-07-14T21:46:21Z"" id=""tester_edae30f5-49f0-4025-97ce-3a2022bf7fa3"" guid=""edae30f5-49f0-4025-97ce-3a2022bf7fa3"">",
				@"<lexical-unit>",
				@"<form lang=""fr""><text>tester</text></form>",
				@"</lexical-unit>",
				@"<trait  name=""morph-type"" value=""stem""/>",
				@"<trait name=""EntryStatus"" value=""Pending""/>",
				@"<sense id=""c1811b5c-aec1-42f7-87c2-6bbb4b76ff60"">",
				@"<example source=""A reference"">",
				@"<form lang=""fr""><text>An example sentence</text></form>",
				@"<translation type=""Free translation"">",
				@"<form lang=""en""><text>A translation</text></form>",
				@"</translation>",
				@"<note type=""reference"">",
				@"<form lang=""en""><text>A reference</text></form>",
				@"</note>",
				@"<trait name=""CustomExampleStatus"" value=""Pending""/>",
				@"</example>",
				@"</sense>",
				@"</entry>",
				@"</lift>"
			};
			var lifDataWithExampleWithConfirmedStatus = new[]
			{
				@"<?xml version=""1.0"" encoding=""UTF-8"" ?>",
				@"<lift producer=""SIL.FLEx 8.0.10.41829"" version=""0.13"">",
				@"<header>",
				@"<ranges>",
				@"<range id=""status"" href=""file://*****:*****@"</ranges>",
				@"<fields>",
				@"<field tag=""EntryStatus"">",
				@"<form lang=""en""><text></text></form>",
				@"<form lang=""qaa-x-spec""><text>Class=LexEntry; Type=ReferenceAtom; WsSelector=kwsAnal; DstCls=CmPossibility; range=status</text></form>",
				@"</field>",
				@"<field tag=""CustomExampleStatus"">",
				@"<form lang=""en""><text></text></form>",
				@"<form lang=""qaa-x-spec""><text>Class=LexExampleSentence; Type=ReferenceAtom; WsSelector=kwsAnal; DstCls=CmPossibility; range=status</text></form>",
				@"</field>",
				@"</fields>",
				@"</header>",
				@"<entry dateCreated=""2014-07-14T21:32:58Z"" dateModified=""2014-07-14T21:46:21Z"" id=""tester_edae30f5-49f0-4025-97ce-3a2022bf7fa3"" guid=""edae30f5-49f0-4025-97ce-3a2022bf7fa3"">",
				@"<lexical-unit>",
				@"<form lang=""fr""><text>tester</text></form>",
				@"</lexical-unit>",
				@"<trait  name=""morph-type"" value=""stem""/>",
				@"<trait name=""EntryStatus"" value=""Confirmed""/>",
				@"<sense id=""c1811b5c-aec1-42f7-87c2-6bbb4b76ff60"">",
				@"<example source=""A reference"">",
				@"<form lang=""fr""><text>An example sentence</text></form>",
				@"<translation type=""Free translation"">",
				@"<form lang=""en""><text>A translation</text></form>",
				@"</translation>",
				@"<note type=""reference"">",
				@"<form lang=""en""><text>A reference</text></form>",
				@"</note>",
				@"<trait name=""CustomExampleStatus"" value=""Confirmed""/>",
				@"</example>",
				@"</sense>",
				@"</entry>",
				@"</lift>"
			};
			var wsEn = Cache.WritingSystemFactory.GetWsFromStr("en");
			var statusList = Cache.ServiceLocator.GetInstance<ICmPossibilityListFactory>().CreateUnowned("status", wsEn);
			var confirmed = Cache.ServiceLocator.GetInstance<ICmPossibilityFactory>().Create(new Guid("bd80cd3e-ea5e-11de-9871-0013722f8dec"), statusList);
			confirmed.Name.set_String(wsEn, Cache.TsStrFactory.MakeString("Confirmed", wsEn));
			var pending = Cache.ServiceLocator.GetInstance<ICmPossibilityFactory>().Create(new Guid("bd964254-ea5e-11de-8cdf-0013722f8dec"), statusList);
			pending.Name.set_String(wsEn, Cache.TsStrFactory.MakeString("Pending", wsEn));
			var entryNew = new FieldDescription(Cache)
			{
				Type = CellarPropertyType.ReferenceAtomic,
				Class = LexEntryTags.kClassId,
				Name = "EntryStatus",
				ListRootId = statusList.Guid
			};
			var exampleNew = new FieldDescription(Cache)
			{
				Type = CellarPropertyType.ReferenceAtomic,
				Class = LexExampleSentenceTags.kClassId,
				Name = "CustomExampleStatus",
				ListRootId = statusList.Guid
			};
			entryNew.UpdateCustomField();
			exampleNew.UpdateCustomField();
			var repoEntry = Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
			var repoSense = Cache.ServiceLocator.GetInstance<ILexSenseRepository>();
			Assert.AreEqual(0, repoEntry.Count);
			var rangeFile = CreateInputFile(rangesWithStatusList);
			var pendingLiftFile = CreateInputFile(lifDataWithExampleWithPendingStatus);
			// Verify basic import of custom field data matching existing custom list and items
			TryImport(pendingLiftFile, rangeFile, FlexLiftMerger.MergeStyle.MsKeepBoth, 1);
			Assert.AreEqual(1, repoEntry.Count);
			Assert.AreEqual(1, repoSense.Count);
			var entry = repoEntry.AllInstances().First();
			var sense = repoSense.AllInstances().First();
			Assert.AreEqual(1, sense.ExamplesOS.Count);
			var example = sense.ExamplesOS[0];
			var entryCustomData = new CustomFieldData()
			{
				CustomFieldname = "EntryStatus",
				CustomFieldType = CellarPropertyType.ReferenceAtom,
				cmPossibilityNameRA = "Pending"
			};
			var exampleCustomData = new CustomFieldData()
			{
				CustomFieldname = "CustomExampleStatus",
				CustomFieldType = CellarPropertyType.ReferenceAtom,
				cmPossibilityNameRA = "Pending"
			};
			VerifyCustomField(entry, entryCustomData, entryNew.Id);
			VerifyCustomField(example, exampleCustomData, exampleNew.Id);
			// SUT - Verify merging of changes to custom field data
			var confirmedLiftFile = CreateInputFile(lifDataWithExampleWithConfirmedStatus);
			TryImport(confirmedLiftFile, rangeFile, FlexLiftMerger.MergeStyle.MsKeepBoth, 1);
			entry = repoEntry.AllInstances().First();
			sense = repoSense.AllInstances().First();
			Assert.AreEqual(1, sense.ExamplesOS.Count);
			example = sense.ExamplesOS[0];
			entryCustomData.cmPossibilityNameRA = "Confirmed";
			exampleCustomData.cmPossibilityNameRA = "Confirmed";
			Assert.AreEqual(1, repoEntry.Count);
			Assert.AreEqual(1, repoSense.Count);
			VerifyCustomField(entry, entryCustomData, entryNew.Id);
			VerifyCustomField(example, exampleCustomData, exampleNew.Id);
		}
Exemplo n.º 3
0
		public void TestLiftImport5_CustomFieldsStringsAndMultiUnicode()
		{
			SetWritingSystems("fr");

			var repoEntry = Cache.ServiceLocator.GetInstance<ILexEntryRepository>();
			var repoSense = Cache.ServiceLocator.GetInstance<ILexSenseRepository>();
			Assert.AreEqual(0, repoEntry.Count);
			Assert.AreEqual(0, repoSense.Count);
			// One custom field is defined in FW but not in the file
			var fdNew = new FieldDescription(Cache)
			{
				Type = CellarPropertyType.MultiUnicode,
				Class = LexEntryTags.kClassId,
				Name = "UndefinedCustom",
				Userlabel = "UndefinedCustom",
				HelpString = "some help",
				WsSelector = WritingSystemServices.kwsAnalVerns,
				DstCls = 0,
				ListRootId = Guid.Empty
			};
			fdNew.UpdateCustomField();

			var sOrigFile = CreateInputFile(s_LiftData5);

			var logFile = TryImport(sOrigFile, 2);
			File.Delete(sOrigFile);
			Assert.IsNotNull(logFile);
			File.Delete(logFile);
			Assert.AreEqual(2, repoEntry.Count);
			Assert.AreEqual(2, repoSense.Count);

			ILexEntry entry;
			Assert.IsTrue(repoEntry.TryGetObject(new Guid("7e4e4484-d691-4ffa-8fb1-10cf4941ac14"), out entry));
			Assert.AreEqual(1, entry.SensesOS.Count);
			var sense0 = entry.SensesOS[0];
			Assert.AreEqual(sense0.Guid, new Guid("29b7913f-0d28-4ee9-a57e-177f68a96654"));
			var customData = new CustomFieldData()
								{
									CustomFieldname = "CustomFldSense",
									CustomFieldType = CellarPropertyType.String,
									StringFieldText = "Sense custom fiield in English",
									StringFieldWs = "en"
								};
			m_customFieldSenseIds = GetCustomFlidsOfObject(sense0);
			VerifyCustomField(sense0, customData, m_customFieldSenseIds["CustomFldSense"]);

			//===================================================================================
			Assert.IsNotNull(entry.LexemeFormOA);
			Assert.IsNotNull(entry.LexemeFormOA.MorphTypeRA);
			Assert.AreEqual("stem", entry.LexemeFormOA.MorphTypeRA.Name.AnalysisDefaultWritingSystem.Text);
			Assert.AreEqual("Babababa", entry.LexemeFormOA.Form.VernacularDefaultWritingSystem.Text);
			Assert.IsNotNull(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa);
			// ReSharper disable PossibleNullReferenceException
			Assert.IsNotNull((sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA);
			Assert.AreEqual("Noun",
							(sense0.MorphoSyntaxAnalysisRA as IMoStemMsa).PartOfSpeechRA.Name.AnalysisDefaultWritingSystem.Text);
			// ReSharper restore PossibleNullReferenceException
			Assert.AreEqual("Papi", sense0.Gloss.AnalysisDefaultWritingSystem.Text);
			m_customFieldEntryIds = GetCustomFlidsOfObject(entry);
			customData = new CustomFieldData()
							{
								CustomFieldname = "UndefinedCustom",
								CustomFieldType = CellarPropertyType.MultiUnicode,
							};
			customData.MultiUnicodeStrings.Add("Undefined custom field");
			customData.MultiUnicodeWss.Add("en");
			VerifyCustomField(entry, customData, m_customFieldEntryIds["UndefinedCustom"]);

			customData = new CustomFieldData()
			{
				CustomFieldname = "CustomFldEntry",
				CustomFieldType = CellarPropertyType.String,
				StringFieldText = "Entry custom field",
				StringFieldWs = "en"
			};
			VerifyCustomField(entry, customData, m_customFieldEntryIds["CustomFldEntry"]);

			//"<field type=\"CustomFldEntryMulti\">",
			//        "<form lang=\"fr\"><text>Entry Multi Frn</text></form>",
			//        "<form lang=\"es\"><text>Entry Multi Spn</text></form>",
			//        "<form lang=\"en\"><text>Entry Multi Eng</text></form>",
			//        "</field>",
			customData = new CustomFieldData()
							{
								CustomFieldname = "CustomFldEntryMulti",
								CustomFieldType = CellarPropertyType.MultiUnicode,
							};
			customData.MultiUnicodeStrings.Add("Entry Multi Frn");
			customData.MultiUnicodeStrings.Add("Entry Multi Spn");
			customData.MultiUnicodeStrings.Add("Entry Multi Eng");
			customData.MultiUnicodeWss.Add("fr");
			customData.MultiUnicodeWss.Add("es");
			customData.MultiUnicodeWss.Add("en");

			VerifyCustomField(entry, customData, m_customFieldEntryIds["CustomFldEntryMulti"]);

			foreach (var example in sense0.ExamplesOS)
			{
				m_customFieldExampleSentencesIds = GetCustomFlidsOfObject(example);
				customData = new CustomFieldData()
								{
									CustomFieldname = "CustomFldExample",
									CustomFieldType = CellarPropertyType.String,
									StringFieldText = "example sentence custom field",
									StringFieldWs = "fr"
								};
				VerifyCustomField(example, customData, m_customFieldExampleSentencesIds["CustomFldExample"]);
			}

			//==================================Allomorph Custom Field Test===== MultiString
			var form = entry.AlternateFormsOS[0];

			m_customFieldAllomorphsIds = GetCustomFlidsOfObject(form);
			customData = new CustomFieldData()
							{
								CustomFieldname = "CustomFldAllomorf",
								CustomFieldType = CellarPropertyType.MultiUnicode,
							};
			customData.MultiUnicodeStrings.Add("Allomorph multi French");
			customData.MultiUnicodeStrings.Add("Allomorph multi Spanish");
			customData.MultiUnicodeStrings.Add("Allomorph multi English");
			customData.MultiUnicodeWss.Add("fr");
			customData.MultiUnicodeWss.Add("es");
			customData.MultiUnicodeWss.Add("en");
			VerifyCustomField(form, customData, m_customFieldAllomorphsIds["CustomFldAllomorf"]);
			//"<field type=\"CustomFldAllomorphSingle\">",
			//"<form lang=\"fr\"><text>Allomorph single Vernacular</text></form>",
			//"</field>",
			customData = new CustomFieldData()
							{
								CustomFieldname = "CustomFldAllomorphSingle",
								CustomFieldType = CellarPropertyType.String,
								StringFieldText = "Allomorph single Vernacular",
								StringFieldWs = "fr"
							};
			VerifyCustomField(form, customData, m_customFieldAllomorphsIds["CustomFldAllomorphSingle"]);
		}
Exemplo n.º 4
0
        private void DeleteCustomField(FieldDescription fd)
        {
            // delete custom field that was added to a LexEntry for testing
            if (fd.IsCustomField && fd.IsInstalled)
            {
                fd.MarkForDeletion = true;
                AddCustomFieldDlg.UpdateCachedObjects(Cache, fd);

                Cache.ActionHandlerAccessor.BeginUndoTask("UndoUpdateCustomField", "RedoUpdateCustomField");
                fd.UpdateCustomField();
                Cache.ActionHandlerAccessor.EndUndoTask();
            }
            FieldDescription.ClearDataAbout();
        }
Exemplo n.º 5
0
 private FieldDescription CreateCustomMultipleRefFieldInLexSense(Guid listGuid)
 {
     // create new custom field for a LexSense for testing
     var fd = new FieldDescription(Cache)
     {
         Userlabel = "New Test Custom Field",
         HelpString = string.Empty,
         Class = LexSenseTags.kClassId,
         Type = CellarPropertyType.ReferenceCollection,
         WsSelector = 0,
         DstCls = CmPossibilityTags.kClassId,
         ListRootId = listGuid
     };
     fd.UpdateCustomField();
     return fd;
 }
Exemplo n.º 6
0
 private FieldDescription CreateCustomAtomicReferenceFieldToCustomListInLexEntry(Guid listGuid)
 {
     // create new custom field for a LexEntry for testing
     var fd = new FieldDescription(Cache)
     {
         Userlabel = "New Test Custom Field",
         HelpString = string.Empty,
         Class = LexEntryTags.kClassId,
         Type = CellarPropertyType.ReferenceAtomic,
         WsSelector = 0,
         DstCls = CmPossibilityTags.kClassId,
         ListRootId = listGuid
     };
     fd.UpdateCustomField();
     return fd;
 }