コード例 #1
0
 public void Remove_TwoWritingSystemsOneIsDeleted_OneWritingSystemRemains()
 {
     RepositoryUnderTest.Set(new WritingSystemDefinition("en"));
     RepositoryUnderTest.Set(new WritingSystemDefinition("de"));
     RepositoryUnderTest.Remove("en");
     Assert.That(RepositoryUnderTest.Contains("de"), Is.True);
     Assert.That(RepositoryUnderTest.Contains("en"), Is.False);
 }
コード例 #2
0
        /// <summary>
        /// Replaces an existing writing system with the specified new writing system if they
        /// have the same identifier.
        /// </summary>
        /// <param name="ws">The writing system.</param>
        public void Replace(CoreWritingSystemDefinition ws)
        {
            lock (m_syncRoot)
            {
                CoreWritingSystemDefinition existingWs;
                if (TryGet(ws.LanguageTag, out existingWs))
                {
                    if (existingWs == ws)
                    {
                        // don't do anything
                        return;
                    }

                    m_handleWSs.Remove(existingWs.Handle);
                    m_repo.Remove(existingWs.Id);
                    m_repo.Set(ws);
                    ws.WritingSystemFactory = this;
                    ws.Handle = existingWs.Handle;
                    m_handleWSs[ws.Handle] = ws;
                }
                else
                {
                    Set(ws);
                }
            }
        }
コード例 #3
0
        protected virtual void OnChangeNotifySharedStore(T ws)
        {
            DateTime lastDateModified;

            if (_writingSystemsToIgnore.TryGetValue(ws.LanguageTag, out lastDateModified) && ws.DateModified > lastDateModified)
            {
                _writingSystemsToIgnore.Remove(ws.LanguageTag);
            }

            if (_globalRepository != null)
            {
                T globalWs;
                if (_globalRepository.TryGet(ws.LanguageTag, out globalWs))
                {
                    if (ws.DateModified > globalWs.DateModified)
                    {
                        T newWs = WritingSystemFactory.Create(ws);
                        try
                        {
                            _globalRepository.Remove(ws.LanguageTag);
                            _globalRepository.Set(newWs);
                        }
                        catch (Exception)
                        {
                            // Live with it if we can't update the global store. In a CS world we might
                            // well not have permission.
                        }
                    }
                }

                else
                {
                    _globalRepository.Set(WritingSystemFactory.Create(ws));
                }
            }
        }
コード例 #4
0
        public void Write_LoadedWritingSystemIsDeleted_DeletionIsRoundTripped()
        {
            using (var e = new TestEnvironment())
            {
                //Write out two writing systems
                IWritingSystemRepository wsCollectionToBeWritten =
                    GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                IWritingSystemDefinition ws = TestEnvironment.CreateDetailedWritingSystem("en");
                wsCollectionToBeWritten.Set(ws);
                IWritingSystemDefinition ws2 = TestEnvironment.CreateDetailedWritingSystem("th");
                wsCollectionToBeWritten.Set(ws2);
                wsCollectionToBeWritten.Save();

                //load them up again
                IWritingSystemRepository loadedWsCollection = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                loadedWsCollection.Remove(ws.Id);                 //remove one
                loadedWsCollection.Save();

                //Now check that it hasn't come back!
                IWritingSystemRepository loadedWsCollection2 =
                    GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                Assert.IsFalse(loadedWsCollection2.Contains(ws.Id));
            }
        }
コード例 #5
0
        internal void SetWritingSystemsForFields()
        {
            var liftDom = new XmlDocument();

            liftDom.Load(_path);             //will throw if the file is ill-formed
            var missingWritingSystems = new StringBuilder();

            foreach (XmlNode node in liftDom.SelectNodes("//@lang"))
            {
                if (node.Value == "x-spec" && !_writingSystems.Contains("x-spec"))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse("x-spec"));
                }
                if (!_writingSystems.Contains(node.Value))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse(node.Value));
                    missingWritingSystems.AppendFormat("{0},", node.Value);
                }
            }
            _writingSystems.Save();

            if (missingWritingSystems.Length > 0)
            {
                var list = missingWritingSystems.ToString().Trim(new[] { ',' });
                ErrorReport.NotifyUserOfProblem(
                    "WeSay had a problem locating information on at least one input system used in the LIFT export from FLEx.  One known cause of this is an old version of FLEx. In the folder containing the LIFT file, there should have been '___.ldml' files for the following input systems: {0}.\r\nBecause these input system definitions were not found, WeSay will create blank input systems for each of these, which you will need to set up with the right fonts, keyboards, etc.", list);
            }
            // replace all "v" fields with the first lexical-unit writing system
            //and all "en" with the first translation one...

            var vernacular = GetTopWritingSystem(liftDom, "//lexical-unit/form/@lang");

            if (vernacular != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation, vernacular);
                if (_writingSystems.Contains(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation))
                {
                    _writingSystems.Remove(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation);
                }
            }
            var analysis = GetTopWritingSystem(liftDom, "//sense/gloss/@lang");

            if (analysis == String.Empty)
            {
                analysis = GetTopWritingSystem(liftDom, "//sense/definition/@lang");
                //nb: we don't want to remove english, even if they don't use it
            }
            if (analysis != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.AnalysisWritingSystemIdForProjectCreation, analysis);
            }

            AddWritingSystemsForField(liftDom, "//lexical-unit/form/@lang", LexEntry.WellKnownProperties.LexicalUnit);
            AddWritingSystemsForField(liftDom, "//sense/gloss/@lang", LexSense.WellKnownProperties.Gloss);

            AddWritingSystemsForField(liftDom, "//sense/definition/form/@lang", LexSense.WellKnownProperties.Definition);

            AddAllGlossWritingSystemsToDefinition();

            AddWritingSystemsForField(liftDom, "//example/form/@lang", LexExampleSentence.WellKnownProperties.ExampleSentence);
            AddWritingSystemsForField(liftDom, "//translation/form/@lang", LexExampleSentence.WellKnownProperties.Translation);

            //------------ hack
            var gloss = _viewTemplate.GetField(LexSense.WellKnownProperties.Gloss);
            var def   = _viewTemplate.GetField(LexSense.WellKnownProperties.Definition);

            foreach (var id in def.WritingSystemIds)
            {
                if (!gloss.WritingSystemIds.Contains(id))
                {
                    gloss.WritingSystemIds.Add(id);
                }
            }
            foreach (var id in gloss.WritingSystemIds)
            {
                if (!def.WritingSystemIds.Contains(id))
                {
                    def.WritingSystemIds.Add(id);
                }
            }
        }