SIL.CoreImpl.PalasoWritingSystemManager.Get C# (CSharp) Method

Get() public method

Gets the specified writing system. Throws KeyNotFoundException if it can not be found, there is a TryGet available to avoid this.
public Get ( string identifier ) : IWritingSystem
identifier string The identifier.
return IWritingSystem
		public IWritingSystem Get(string identifier)
		{
			lock (m_syncRoot)
			{
				IWritingSystemDefinition wrsys;
				if (!m_localStore.TryGet(identifier, out wrsys))
				{
					if (identifier.StartsWith("cmn"))
					{
						var ident = identifier.Remove(0, 3).Insert(0, "zh");
						if (!m_localStore.TryGet(ident, out wrsys) && identifier.StartsWith("cmn"))
						{
							ident = ident.Insert(2, "-CN");
							m_localStore.TryGet(ident, out wrsys);
						}
					}
					else if (identifier.StartsWith("zh"))
					{
						var ident = identifier.Insert(2, "-CN");
						m_localStore.TryGet(ident, out wrsys);
					}
					else if (identifier.StartsWith("pes"))
					{
						var ident = identifier.Remove(0, 3).Insert(0, "fa");
						m_localStore.TryGet(ident, out wrsys);
					}
					else if (identifier.StartsWith("zlm"))
					{
						var ident = identifier.Remove(0, 3).Insert(0, "ms");
						m_localStore.TryGet(ident, out wrsys);
					}
					else if (identifier.StartsWith("arb"))
					{
						var ident = identifier.Remove(2, 1); // changes to "ar"
						m_localStore.TryGet(ident, out wrsys);
					}
					if (wrsys == null) //if all other special cases did not apply or work
					{
						//throw the expected exception for Get
						throw new KeyNotFoundException("The writing system " + identifier + " was not found in this manager.");
					}
				}
				return (IWritingSystem)wrsys;
			}
		}

Same methods

PalasoWritingSystemManager::Get ( int handle ) : IWritingSystem

Usage Example

        public void GlobalStore_WritingSystemsToIgnore()
        {
            string storePath1      = PrepareTempStore("Store1");
            string storePath2      = PrepareTempStore("Store2");
            string globalStorePath = PrepareTempStore("GlobalStore");

            var globalStore = new GlobalFileWritingSystemStore(globalStorePath);
            var wsManager   = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            var ws = wsManager.Set("en-US");

            ws.SpellCheckingId = "id1";
            wsManager.Save();

            Thread.Sleep(1000);

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
            ws = wsManager.Set("en-US");
            ws.SpellCheckingId = "id2";
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            IEnumerable <IWritingSystem> sharedWss = wsManager.CheckForNewerGlobalWritingSystems();

            Assert.AreEqual(1, sharedWss.Count());
            Assert.AreEqual("en-US", sharedWss.First().Id);
            ws = wsManager.Get("en-US");
            Assert.AreEqual("id1", ws.SpellCheckingId);
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
            Assert.AreEqual(0, sharedWss.Count());
            wsManager.Save();

            Thread.Sleep(1000);

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath2, globalStore), globalStore);
            ws = wsManager.Get("en-US");
            ws.LegacyMapping = "encoding converter";
            wsManager.Save();

            wsManager = new PalasoWritingSystemManager(
                new LocalFileWritingSystemStore(storePath1, globalStore), globalStore);
            ws = wsManager.Get("en-US");
            Assert.IsNullOrEmpty(ws.LegacyMapping);
            sharedWss = wsManager.CheckForNewerGlobalWritingSystems();
            Assert.AreEqual(1, sharedWss.Count());
            IWritingSystem sharedWs = sharedWss.First();

            Assert.AreEqual("en-US", sharedWs.Id);
            wsManager.Replace(sharedWs);
            wsManager.Save();
            ws = wsManager.Get("en-US");
            Assert.AreEqual("encoding converter", ws.LegacyMapping);
        }
All Usage Examples Of SIL.CoreImpl.PalasoWritingSystemManager::Get