コード例 #1
0
 public override void Save()
 {
     if (_globalRepository != null)
     {
         _globalRepository.Save();
     }
 }
コード例 #2
0
            public void CreateLdmlWritingSystemDefinitionFile()
            {
                IWritingSystemRepository wsCollectionToBeWritten = GetWritingSystemRepository(PathToWritingSystemsFolder);
                IWritingSystemDefinition ws = CreateDetailedWritingSystem("en");

                wsCollectionToBeWritten.Set(ws);
                wsCollectionToBeWritten.Save();
            }
コード例 #3
0
        public static WeSayWordsProject InitializeForTests()
        {
            WeSayWordsProject project = new WeSayWordsProject();

            try
            {
                File.Delete(WeSayWordsProject.PathToPretendLiftFile);
            }
            catch (Exception) { }
            DirectoryInfo projectDirectory   = Directory.CreateDirectory(Path.GetDirectoryName(WeSayWordsProject.PathToPretendLiftFile));
            string        pathToLdmlWsFolder = BasilProject.GetPathToLdmlWritingSystemsFolder(projectDirectory.FullName);

            if (File.Exists(WeSayWordsProject.PathToPretendWritingSystemPrefs))
            {
                File.Delete(WeSayWordsProject.PathToPretendWritingSystemPrefs);
            }

            if (Directory.Exists(pathToLdmlWsFolder))
            {
                Directory.Delete(pathToLdmlWsFolder, true);
            }

            Palaso.Lift.Utilities.CreateEmptyLiftFile(WeSayWordsProject.PathToPretendLiftFile, "InitializeForTests()", true);

            //setup writing systems
            Directory.CreateDirectory(pathToLdmlWsFolder);
            IWritingSystemRepository wsc = LdmlInFolderWritingSystemRepository.Initialize(
                pathToLdmlWsFolder,
                OnMigrationHandler,
                OnWritingSystemLoadProblem,
                WritingSystemCompatibility.Flex7V0Compatible
                );

            IWritingSystemDefinition _ws1 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.VernacularIdForTest);

            _ws1.DefaultFontName = "Arial";
            _ws1.DefaultFontSize = 30;
            wsc.Set(_ws1);
            IWritingSystemDefinition _ws2 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.AnalysisIdForTest);

            _ws2.DefaultFontName = new Font(FontFamily.GenericSansSerif, 12).Name;
            _ws2.DefaultFontSize = new Font(FontFamily.GenericSansSerif, 12).Size;
            wsc.Set(_ws2);
            IWritingSystemDefinition _ws3 = WritingSystemDefinition.Parse(WritingSystemsIdsForTests.OtherIdForTest);

            _ws3.DefaultFontName = "Arial";
            _ws3.DefaultFontSize = 15;
            wsc.Set(_ws3);


            wsc.Save();

            project.SetupProjectDirForTests(WeSayWordsProject.PathToPretendLiftFile);
            project.BackupMaker = null;            //don't bother. Modern tests which might want to check backup won't be using this old approach anyways.
            return(project);
        }
コード例 #4
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
            IEnumerable <string> idsInFile,
            IdReplacementStrategy replaceIdsInFile,
            IWritingSystemRepository writingSystemRepository)
        {
            List <string> originalIds = idsInFile.ToList();
            List <string> updatedIds  = originalIds.ToList();

            foreach (string wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Clean it
                    var rfcTagCleaner = new IetfLanguageTagCleaner(wsId);
                    rfcTagCleaner.Clean();
                    newId = rfcTagCleaner.GetCompleteTag();
                }

                WritingSystemDefinition conformantWritingSystem;
                writingSystemRepository.WritingSystemFactory.Create(newId, out conformantWritingSystem);
                // If it changed, then change
                if (conformantWritingSystem.LanguageTag != wsId)
                {
                    conformantWritingSystem.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                        conformantWritingSystem.LanguageTag, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.LanguageTag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.LanguageTag);
                }

                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.LanguageTag))
                {
                    continue;
                }

                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
コード例 #5
0
        public void Set_IdOfNewWritingSystemIsSetToOldIdOfOtherWritingSystem_GetReturnsCorrectWritingSystems()
        {
            var ws = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(ws);
            RepositoryUnderTest.Save();
            ws.Variants.Add("orig");
            RepositoryUnderTest.Set(ws);
            var newWs = new WritingSystemDefinition("en");

            RepositoryUnderTest.Set(newWs);
            Assert.That(RepositoryUnderTest.Get("en-x-orig"), Is.EqualTo(ws));
        }
コード例 #6
0
 public void Save_WritingSystemReadFromLdmlAndChanged_ChangesSaved()
 {
     using (var e = new TestEnvironment())
     {
         e.CreateLdmlWritingSystemDefinitionFile();
         IWritingSystemRepository loadedWsCollection = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
         ((WritingSystemDefinition)loadedWsCollection.Get("en")).Keyboard = "changed";
         loadedWsCollection.Save();
         IWritingSystemRepository reloadedWsCollection =
             GetWritingSystemRepository(e.PathToWritingSystemsFolder);
         TestEnvironment.AssertWritingSystemCollectionsAreEqual(loadedWsCollection, reloadedWsCollection);
     }
 }
		/// <summary>
		/// Resets any property values that were removed during migration so that they are not lost.
		/// </summary>
		public void ResetRemovedProperties(IWritingSystemRepository repo)
		{
			foreach (KeyValuePair<string, List<Action<WritingSystemDefinition>>> kvp in _removedPropertiesSetters)
			{
				WritingSystemDefinition ws;
				if (repo.TryGet(kvp.Key, out ws))
				{
					foreach (Action<WritingSystemDefinition> setter in kvp.Value)
						setter(ws);
				}
			}
			repo.Save();
		}
コード例 #8
0
 public void Roundtripping_Works()
 {
     using (var e = new TestEnvironment())
     {
         IWritingSystemRepository wsCollectionToBeWritten = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
         IWritingSystemDefinition ws = TestEnvironment.CreateDetailedWritingSystem("th");
         wsCollectionToBeWritten.Set(ws);
         IWritingSystemDefinition ws2 = TestEnvironment.CreateDetailedWritingSystem("en");
         wsCollectionToBeWritten.Set(ws2);
         wsCollectionToBeWritten.Save();
         IWritingSystemRepository loadedWsCollection = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
         TestEnvironment.AssertWritingSystemCollectionsAreEqual(wsCollectionToBeWritten, loadedWsCollection);
     }
 }
コード例 #9
0
 /// <summary>
 /// Resets any property values that were removed during migration so that they are not lost.
 /// </summary>
 public void ResetRemovedProperties(IWritingSystemRepository repo)
 {
     foreach (KeyValuePair <string, List <Action <WritingSystemDefinition> > > kvp in _removedPropertiesSetters)
     {
         WritingSystemDefinition ws;
         if (repo.TryGet(kvp.Key, out ws))
         {
             foreach (Action <WritingSystemDefinition> setter in kvp.Value)
             {
                 setter(ws);
             }
         }
     }
     repo.Save();
 }
コード例 #10
0
        public void Load_OnlyLdmlWritingSystemFilesExist_WritingSystemsAreLoadedFromThoseFiles()
        {
            using (var e = new TestEnvironment())
            {
                IWritingSystemRepository wsCollectionToBeWritten =
                    GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                IWritingSystemDefinition ws = TestEnvironment.CreateDetailedWritingSystem("en");
                wsCollectionToBeWritten.Set(ws);
                IWritingSystemDefinition ws2 = TestEnvironment.CreateDetailedWritingSystem("de");
                wsCollectionToBeWritten.Set(ws2);
                wsCollectionToBeWritten.Save();

                IWritingSystemRepository loadedWsCollection = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                TestEnvironment.AssertWritingSystemCollectionsAreEqual(wsCollectionToBeWritten, loadedWsCollection);
            }
        }
コード例 #11
0
 /// <summary>
 /// Persists all modified writing systems.
 /// </summary>
 public void Save()
 {
     lock (m_syncRoot)
     {
         foreach (CoreWritingSystemDefinition ws in m_repo.AllWritingSystems)
         {
             if (ws.MarkedForDeletion)
             {
                 m_handleWSs.Remove(ws.Handle);
                 if (m_userWritingSystem == ws)
                 {
                     m_userWritingSystem = null;
                 }
             }
         }
         m_repo.Save();
     }
 }
コード例 #12
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));
            }
        }
コード例 #13
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
            IEnumerable <string> idsInFile,
            IdReplacementStrategy replaceIdsInFile,
            IWritingSystemRepository writingSystemRepository
            )
        {
            var originalIds = new List <string>(idsInFile);
            var updatedIds  = new List <string>(idsInFile);

            foreach (var wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId = wsId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Check for the writing system repository compatibility mode
                    if (writingSystemRepository.CompatibilityMode == WritingSystemCompatibility.Flex7V0Compatible)
                    {
                        if (!wsId.StartsWith("x-"))
                        {
                            // Clean it
                            var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
                            rfcTagCleaner.Clean();
                            newId = rfcTagCleaner.GetCompleteTag();
                        }
                    }
                    else
                    {
                        // Clean it
                        var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
                        rfcTagCleaner.Clean();
                        newId = rfcTagCleaner.GetCompleteTag();
                    }
                }
                var conformantWritingSystem = WritingSystemDefinition.Parse(newId);
                // If it changed, then change
                if (conformantWritingSystem.Bcp47Tag != wsId)
                {
                    conformantWritingSystem = WritingSystemDefinition.CreateCopyWithUniqueId(conformantWritingSystem, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.Bcp47Tag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.Bcp47Tag);
                }
                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.Bcp47Tag))
                {
                    continue;
                }
                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
コード例 #14
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
			IEnumerable<string> idsInFile,
			IdReplacementStrategy replaceIdsInFile,
			IWritingSystemRepository writingSystemRepository)
        {
            List<string> originalIds = idsInFile.ToList();
            List<string> updatedIds = originalIds.ToList();
            foreach (string wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Clean it
                    var rfcTagCleaner = new IetfLanguageTagCleaner(wsId);
                    rfcTagCleaner.Clean();
                    newId = rfcTagCleaner.GetCompleteTag();
                }

                WritingSystemDefinition conformantWritingSystem;
                writingSystemRepository.WritingSystemFactory.Create(newId, out conformantWritingSystem);
                // If it changed, then change
                if (conformantWritingSystem.LanguageTag != wsId)
                {
                    conformantWritingSystem.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                        conformantWritingSystem.LanguageTag, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.LanguageTag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.LanguageTag);
                }

                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.LanguageTag))
                    continue;

                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
コード例 #15
0
		///<summary>
		/// Constructor.
		///</summary>
		///<param name="idsInFile"></param>
		///<param name="replaceIdsInFile"></param>
		///<param name="writingSystemRepository"></param>
		public static void FindOrphans(
			IEnumerable<string> idsInFile,
			IdReplacementStrategy replaceIdsInFile,
			IWritingSystemRepository writingSystemRepository
		) {
			var originalIds = new List<string>(idsInFile);
			var updatedIds = new List<string>(idsInFile);
			foreach (var wsId in originalIds)
			{
				// Check if it's in the repo
				if (writingSystemRepository.Contains(wsId))
				{
					continue;
				}
				string newId = wsId;
				if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
				{
					newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
				}
				else
				{
					// It's an orphan
					// Check for the writing system repository compatibility mode
					if (writingSystemRepository.CompatibilityMode == WritingSystemCompatibility.Flex7V0Compatible)
					{
						if (!wsId.StartsWith("x-"))
						{
							// Clean it
							var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
							rfcTagCleaner.Clean();
							newId = rfcTagCleaner.GetCompleteTag();
						}
					}
					else
					{
						// Clean it
						var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
						rfcTagCleaner.Clean();
						newId = rfcTagCleaner.GetCompleteTag();
					}
				}
				var conformantWritingSystem = WritingSystemDefinition.Parse(newId);
				// If it changed, then change
				if (conformantWritingSystem.Bcp47Tag != wsId)
				{
					conformantWritingSystem = WritingSystemDefinition.CreateCopyWithUniqueId(conformantWritingSystem, updatedIds);
					replaceIdsInFile(wsId, conformantWritingSystem.Bcp47Tag);
					updatedIds.Remove(wsId);
					updatedIds.Add(conformantWritingSystem.Bcp47Tag);
				}
				// Check if it's in the repo
				if (writingSystemRepository.Contains(conformantWritingSystem.Bcp47Tag))
				{
					continue;
				}
				// It's not in the repo so set it
				writingSystemRepository.Set(conformantWritingSystem);
			}
			writingSystemRepository.Save();
		}
コード例 #16
0
//        public virtual void CreateEmptyProjectFiles(string projectDirectoryPath)
//      {
//            _projectDirectoryPath = projectDirectoryPath;
//            //  Directory.CreateDirectory(ProjectCommonDirectory);
//            InitStringCatalog();
//            InitWritingSystems();
//            Save();
        //    }

        public virtual void Save()
        {
            _writingSystems.Save();
        }
コード例 #17
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);
                }
            }
        }