public void LcmObjectDeleted() { using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null), "en", "fr", "en", m_ui, TestDirectoryFinder.LcmDirectories, new LcmSettings())) { // Init backend data provider var dataSetup = cache.ServiceLocator.GetInstance <IDataSetup>(); dataSetup.LoadDomain(BackendBulkLoadDomain.All); var lp = cache.LanguageProject; cache.ActionHandlerAccessor.BeginNonUndoableTask(); var peopleList = cache.ServiceLocator.GetInstance <ICmPossibilityListFactory>().Create(); lp.PeopleOA = peopleList; lp.PeopleOA = null; cache.ActionHandlerAccessor.EndNonUndoableTask(); Assert.IsFalse(peopleList.IsValidObject); } }
public void CreateNewLangProject_DbFilesExist() { var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory)); try { // Setup: Create "pre-existing" DB filenames using (new DummyFileMaker(Path.Combine(m_projectsDirectory, "Gumby", LcmFileHelper.GetXmlDataFileName("Gumby")))) { LcmCache.CreateNewLangProj(new DummyProgressDlg(), "Gumby", m_lcmDirectories, new SingleThreadedSynchronizeInvoke(), null, null, null, null, null, null, true); } } finally { RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory)); } }
public void ChangingLangProjDefaultPronunciationWs_ChangesCacheDefaultPronunciationWs() { using (var cache = LcmCache.CreateCacheWithNewBlankLangProj(new TestProjectId(BackendProviderType.kMemoryOnly, null), "en", "fr", "en", m_ui, m_lcmDirectories, new LcmSettings())) { var wsFr = cache.DefaultPronunciationWs; Assert.That(cache.LangProject.DefaultPronunciationWritingSystem.Handle, Is.EqualTo(wsFr)); CoreWritingSystemDefinition wsObjGerman = null; CoreWritingSystemDefinition wsObjSpanish = null; UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "de", false, true, out wsObjGerman); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsFr)); cache.LangProject.DefaultVernacularWritingSystem = wsObjGerman; cache.LangProject.CurrentPronunciationWritingSystems.Clear(); // Now it re-evaluates to the new default vernacular. Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); // This no longer works..._IPA does not make a valid WS ID. //IWritingSystem wsObjGermanIpa; //WritingSystemServices.FindOrCreateWritingSystem(cache, "de__IPA", false, true, out wsObjGermanIpa); //cache.LangProject.CurrentPronunciationWritingSystems.Clear(); //// Once there is an IPA one, we should prefer that //Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGermanIpa.Handle)); // Unless we clear the list it does not regenerate. WritingSystemServices.FindOrCreateWritingSystem(cache, TestDirectoryFinder.TemplateDirectory, "es", false, true, out wsObjSpanish); // Once we've found a real pronunciation WS, changing the default vernacular should not change it. Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); }); UndoableUnitOfWorkHelper.Do("undoit", "redoit", cache.ActionHandlerAccessor, () => { cache.LangProject.CurPronunWss = "es"; Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle)); }); cache.ActionHandlerAccessor.Undo(); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjGerman.Handle)); cache.ActionHandlerAccessor.Redo(); Assert.That(cache.DefaultPronunciationWs, Is.EqualTo(wsObjSpanish.Handle)); } }
/// <summary> /// Actually create the system. /// Called by subclass overrides of CreateCache(), with parameters that suit /// the subclass. /// </summary> /// <param name="projectId"></param> /// <param name="loadType"></param> /// <param name="settings"></param> /// <returns>a working LcmCache</returns> protected LcmCache BootstrapSystem(IProjectIdentifier projectId, BackendBulkLoadDomain loadType, LcmSettings settings) { LcmCache retval; if (m_internalRestart) { retval = LcmCache.CreateCacheFromExistingData(projectId, "en", new DummyLcmUI(), TestDirectoryFinder.LcmDirectories, settings, new DummyProgressDlg()); } else { retval = LcmCache.CreateCacheWithNewBlankLangProj(projectId, "en", "fr", "en", new DummyLcmUI(), TestDirectoryFinder.LcmDirectories, settings); } var dataSetup = retval.ServiceLocator.GetInstance <IDataSetup>(); dataSetup.LoadDomain(loadType); return(retval); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Creates analyses for the words and punctuation forms of the specified segment. Words /// will have WfiWordforms created if they don't already exist. /// </summary> /// <param name="segment">The segment.</param> /// <param name="paraContents">The para contents.</param> /// <param name="ichBeginOffset">The beginning character offset.</param> /// <param name="ichLimOffset">The character offset limit.</param> /// <param name="fCreateGlosses">if set to <c>true</c> create glosses in addition to the /// WfiWordforms for each surface form.</param> /// ------------------------------------------------------------------------------------ public static void CreateAnalyses(ISegment segment, ITsString paraContents, int ichBeginOffset, int ichLimOffset, bool fCreateGlosses) { LcmCache cache = segment.Cache; ILcmServiceLocator servloc = cache.ServiceLocator; if (SegmentBreaker.HasLabelText(paraContents, ichBeginOffset, ichLimOffset)) { IPunctuationForm labelPunc = servloc.GetInstance <IPunctuationFormFactory>().Create(); segment.AnalysesRS.Add(labelPunc); labelPunc.Form = paraContents.GetSubstring(ichBeginOffset, ichLimOffset); } else { ParseSegBaseline(segment, ichBeginOffset, ichLimOffset, (iForm, word, iAnalysis) => { CreateAnalysisForWord(word, segment, cache.DefaultAnalWs, fCreateGlosses); return(true); }, (sPunc, iAnalysis) => CreatePuncForm(segment, TsStringUtils.MakeString(sPunc, cache.DefaultVernWs)), (ichOrc, iAnalysis) => CreatePuncForm(segment, paraContents.Substring(segment.BeginOffset + ichOrc, 1))); } }
public void CreateNewLangProject_NameWithSingleQuote() { const string dbName = "!!t'st"; string dbDir = Path.Combine(m_projectsDirectory, dbName); SureRemoveDb(dbName); var expectedDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory)) { dbDir }; var writingSystemsCommonDir = Path.Combine(m_projectsDirectory, LcmFileHelper.ksWritingSystemsDir); List <string> currentDirs = null; try { string dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories, new SingleThreadedSynchronizeInvoke()); currentDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory)); if (currentDirs.Contains(writingSystemsCommonDir) && !expectedDirs.Contains(writingSystemsCommonDir)) { expectedDirs.Add(writingSystemsCommonDir); } CollectionAssert.AreEquivalent(expectedDirs, currentDirs); string dbFileBase = Path.GetFileNameWithoutExtension(dbFileName); Assert.AreEqual(dbName, dbFileBase); } finally { if (currentDirs != null) { RemoveTestDirs(expectedDirs, currentDirs); } } }
/// <summary> /// Constructs a custom field that includes a writing system selector and adds it into the cach with a default destClassId and using the lable as the name /// </summary> public CustomFieldForTest(LcmCache cache, string customFieldLabel, int classId, int ws, CellarPropertyType fieldType, Guid listGuid) : this(cache, customFieldLabel, customFieldLabel, classId, 0, ws, fieldType, listGuid) { }
/// <summary> /// /// </summary> protected void DisposeEverythingButBase() { m_cache?.Dispose(); m_cache = null; m_actionHandler = null; }
public void UpdateWritingSystemsFromGlobalStore_CopiesNewerWsOnly( string globalEn, string globalFr, string localEn, string localFr, string localEnResult, string localFrResult) { const string dbName = "UpdateWsFromGsTest"; SureRemoveDb(dbName); var preExistingDirs = new List <string>(Directory.GetDirectories(m_projectsDirectory)); try { // create project var dbFileName = LcmCache.CreateNewLangProj(new DummyProgressDlg(), dbName, m_lcmDirectories, new SingleThreadedSynchronizeInvoke()); // SUT // Request XML backend with project settings that have ProjectSharing set to true var projectId = new TestProjectId(BackendProviderType.kXML, dbFileName); using (var cache = LcmCache.CreateCacheFromExistingData(projectId, "en", m_ui, m_lcmDirectories, new LcmSettings(), new DummyProgressDlg())) { var globalPath = Path.Combine(m_projectsDirectory, $"{Path.GetFileNameWithoutExtension(dbFileName)}_GlobalWss"); var globalPathWithVersion = CoreGlobalWritingSystemRepository.CurrentVersionPath(globalPath); Directory.CreateDirectory(globalPathWithVersion); var storePath = Path.Combine(cache.ProjectId.ProjectFolder, LcmFileHelper.ksWritingSystemsDir); File.Copy(Path.Combine(storePath, "en.ldml"), Path.Combine(globalPathWithVersion, "en.ldml")); File.Copy(Path.Combine(storePath, "fr.ldml"), Path.Combine(globalPathWithVersion, "fr.ldml")); var wsManager = cache.ServiceLocator.WritingSystemManager; // Add new Ws for French and English in global repo var globalRepoForTest = new CoreGlobalWritingSystemRepository(globalPath); // Set up WritingSystemStore for test wsManager.WritingSystemStore = new CoreLdmlInFolderWritingSystemRepository(storePath, cache.ServiceLocator.DataSetup.ProjectSettingsStore, cache.ServiceLocator.DataSetup.UserSettingsStore, globalRepoForTest); var enWs = globalRepoForTest.Get("en"); var frWs = globalRepoForTest.Get("fr"); Assert.That(string.IsNullOrEmpty(enWs.SpellCheckingId), Is.True); Assert.That(string.IsNullOrEmpty(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId), Is.True); Assert.That(string.IsNullOrEmpty(frWs.SpellCheckingId), Is.True); Assert.That(string.IsNullOrEmpty(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId), Is.True); // Update the spellCheckIds in the global repository if (globalEn != null) { enWs.SpellCheckingId = globalEn; } if (globalFr != null) { frWs.SpellCheckingId = globalFr; } globalRepoForTest.Set(enWs); globalRepoForTest.Set(frWs); globalRepoForTest.Save(); // Update the cache version of the repository var enWsFromCache = cache.ServiceLocator.WritingSystemManager.Get("en"); var frWsFromCache = cache.ServiceLocator.WritingSystemManager.Get("fr"); enWsFromCache.SpellCheckingId = localEn; frWsFromCache.SpellCheckingId = localFr; cache.ServiceLocator.WritingSystemManager.Set(enWsFromCache); cache.ServiceLocator.WritingSystemManager.Set(frWsFromCache); cache.ServiceLocator.WritingSystemManager.Save(); enWs = globalRepoForTest.Get("en"); frWs = globalRepoForTest.Get("fr"); // Verify preconditions Assert.That(enWs.SpellCheckingId, Is.StringMatching(globalEn)); Assert.That(frWs.SpellCheckingId, Is.StringMatching(globalFr)); Assert.That(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId, Is.StringMatching(localEn)); Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFr)); // SUT cache.UpdateWritingSystemsFromGlobalStore("en"); Assert.That(cache.WritingSystemFactory.get_Engine("en").SpellCheckingId, Is.StringMatching(localEnResult)); Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFr)); cache.UpdateWritingSystemsFromGlobalStore("fr"); Assert.That(cache.WritingSystemFactory.get_Engine("fr").SpellCheckingId, Is.StringMatching(localFrResult)); } } finally { RemoveTestDirs(preExistingDirs, Directory.GetDirectories(m_projectsDirectory)); } }