Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ws">The ws.</param>
        protected override void OnChangeNotifySharedStore(WritingSystemDefinition ws)
        {
            base.OnChangeNotifySharedStore(ws);

            if (m_globalStore != null)
            {
                WritingSystemDefinition globalWs;
                if (m_globalStore.TryGet(ws.Id, out globalWs))
                {
                    if (ws.DateModified > globalWs.DateModified)
                    {
                        WritingSystemDefinition newWs = ws.Clone();
                        newWs.Modified = true;
                        try
                        {
                            m_globalStore.Remove(ws.Id);
                            m_globalStore.Set(newWs);
                        }
                        catch (UnauthorizedAccessException)
                        {
                            // Live with it if we can't update the global store. In a CS world we might
                            // well not have permission.
                        }
                    }
                }

                else
                {
                    m_globalStore.Set(ws.Clone());
                }
            }
        }
Exemple #2
0
 /// <summary>
 /// Gets the specified writing system. Throws KeyNotFoundException if it can not be found,
 /// there is a TryGet available to avoid this.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <returns></returns>
 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);
     }
 }
Exemple #3
0
        /// <summary>
        /// Creates a new writing system.
        /// </summary>
        /// <returns></returns>
        public IWritingSystem Create(string identifier)
        {
            lock (m_syncRoot)
            {
                if (m_globalStore != null)
                {
                    IWritingSystemDefinition globalWs;
                    if (m_globalStore.TryGet(identifier, out globalWs))
                    {
                        return((PalasoWritingSystem)m_globalStore.MakeDuplicate(globalWs));
                    }
                }
            }

            LanguageSubtag languageSubtag;
            ScriptSubtag   scriptSubtag;
            RegionSubtag   regionSubtag;
            VariantSubtag  variantSubtag;

            if (!LangTagUtils.GetSubtags(identifier, out languageSubtag, out scriptSubtag, out regionSubtag, out variantSubtag))
            {
                throw new ArgumentException(identifier + " is not a valid RFC5646 language tag.");
            }
            var result = Create(languageSubtag, scriptSubtag, regionSubtag, variantSubtag);

            if (TemplateFolder != null)
            {
                // try in our master template file
                // Todo: have property TemplateFolderPath, initialize in FdoBackendProvider.InitializeWritingSystemManager
                var template = Path.Combine(TemplateFolder, Path.ChangeExtension(identifier, "ldml"));
                if (File.Exists(template))
                {
                    var loader = new FwLdmlAdaptor();
                    loader.Read(template, (WritingSystemDefinition)result);
                }
            }
            return(result);
        }