SIL.FieldWorks.FDO.FDOTests.FdoTestHelper.CreateAnalysisForWord C# (CSharp) Method

CreateAnalysisForWord() private method

private CreateAnalysisForWord ( string word, ISegment segment, int ws, bool fCreateGlosses ) : void
word string
segment ISegment
ws int
fCreateGlosses bool
return void
		private static void CreateAnalysisForWord(string word, ISegment segment, int ws,
			bool fCreateGlosses)
		{
			FdoCache cache = segment.Cache;
			IWfiWordformFactory wfFactory = cache.ServiceLocator.GetInstance<IWfiWordformFactory>();
			IWfiWordformRepository wfRepo = cache.ServiceLocator.GetInstance<IWfiWordformRepository>();
			IWfiGlossFactory glossFactory = cache.ServiceLocator.GetInstance<IWfiGlossFactory>();
			IWfiAnalysisFactory wfiAnalysisFactory = cache.ServiceLocator.GetInstance<IWfiAnalysisFactory>();

			ITsString tssForm = cache.TsStrFactory.MakeString(word, cache.DefaultVernWs);
			IWfiWordform form;
			IAnalysis analysis;
			if (wfRepo.TryGetObject(tssForm, out form))
				analysis = (fCreateGlosses) ? (IAnalysis)form.AnalysesOC.First().MeaningsOC.First() : form;
			else
			{
				analysis = form = wfFactory.Create(tssForm);
				IWfiAnalysis actualWfiAnalysis = wfiAnalysisFactory.Create();
				form.AnalysesOC.Add(actualWfiAnalysis);
				if (fCreateGlosses)
				{
					IWfiGloss gloss = glossFactory.Create();
					actualWfiAnalysis.MeaningsOC.Add(gloss);
					gloss.Form.set_String(ws, "G" + word + "g");
					analysis = gloss;
				}
			}
			segment.AnalysesRS.Add(analysis);
		}