/// <summary> /// Writes an LDML representation of this writing system to the specified writer. /// </summary> /// <param name="writer">The writer.</param> public void WriteLdml(XmlWriter writer) { var adaptor = new FwLdmlAdaptor(); lock (m_syncRoot) adaptor.Write(writer, this, null); }
private WritingSystemDefinition GetFromFilePath(string filePath) { try { WritingSystemDefinition ws = CreateNew(); var adaptor = new FwLdmlAdaptor(); adaptor.Read(filePath, ws); ws.StoreID = ((PalasoWritingSystem)ws).RFC5646; ws.Modified = false; return(ws); } catch (Exception e) { throw new ArgumentException("GlobalWritingSystemStore was unable to load the LDML file " + filePath, "filePath", e); } }
/// <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); }
/// <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; }
/// <summary> /// Adds the writing system to the store or updates the store information about /// an already-existing writing system. Set should be called when there is a change /// that updates the RFC5646 information. /// </summary> public void Set(IWritingSystemDefinition ws) { m_mutex.WaitOne(); MemoryStream oldData = null; try { string writingSystemFileName = GetFileName(ws); string writingSystemFilePath = GetFilePath(ws); if (!ws.Modified && File.Exists(writingSystemFilePath)) return; // no need to save (better to preserve the modified date) var oldId = ws.StoreID; string incomingFileName = GetFileName(oldId); string incomingFilePath = GetFilePath(oldId); if (!string.IsNullOrEmpty(incomingFileName)) { if (File.Exists(incomingFilePath)) { // load old data to preserve stuff in LDML that we don't use, but don't throw up an error if it fails try { oldData = new MemoryStream(File.ReadAllBytes(incomingFilePath), false); } catch { } if (writingSystemFileName != incomingFileName) { File.Delete(incomingFilePath); // JohnT: Added this without fully understanding, to get things to compile. I don't fully // know when this event should be raised, nor am I sure I am building the argument correctly. // However, I don't think anything (at least in our code) actually uses it. if (WritingSystemIdChanged != null) WritingSystemIdChanged(this, new WritingSystemIdChangedEventArgs(oldId, ((PalasoWritingSystem)ws).RFC5646)); } } } var adaptor = new FwLdmlAdaptor(); try { // Provides FW on Linux multi-user access. Overrides the system // umask and creates the files with the permissions "775". // The "fieldworks" group was created outside the app during // configuration of the package which allows group access. using (new FileModeOverride()) { adaptor.Write(writingSystemFilePath, (WritingSystemDefinition)ws, oldData); } } catch (UnauthorizedAccessException) { // If we can't save the changes, too bad. Inability to save locally is typically caught // when we go to open the modify dialog. If we can't make the global store consistent, // as we well may not be able to in a client-server mode, too bad. } ws.Modified = false; } finally { if (oldData != null) oldData.Dispose(); m_mutex.ReleaseMutex(); } }
private IWritingSystemDefinition GetFromFilePath(string filePath) { try { var ws = (WritingSystemDefinition)CreateNew(); var adaptor = new FwLdmlAdaptor(); adaptor.Read(filePath, ws); ws.StoreID = ((PalasoWritingSystem)ws).RFC5646; ws.Modified = false; return ws; } catch (Exception e) { throw new ArgumentException("GlobalWritingSystemStore was unable to load the LDML file " + filePath, "filePath", e); } }
/// <summary> /// Adds the writing system to the store or updates the store information about /// an already-existing writing system. Set should be called when there is a change /// that updates the RFC5646 information. /// </summary> public void Set(WritingSystemDefinition ws) { m_mutex.WaitOne(); MemoryStream oldData = null; try { string writingSystemFileName = GetFileName(ws); string writingSystemFilePath = GetFilePath(ws); if (!ws.Modified && File.Exists(writingSystemFilePath)) { return; // no need to save (better to preserve the modified date) } var oldId = ws.StoreID; string incomingFileName = GetFileName(oldId); string incomingFilePath = GetFilePath(oldId); if (!string.IsNullOrEmpty(incomingFileName)) { if (File.Exists(incomingFilePath)) { // load old data to preserve stuff in LDML that we don't use, but don't throw up an error if it fails try { oldData = new MemoryStream(File.ReadAllBytes(incomingFilePath), false); } catch { } if (writingSystemFileName != incomingFileName) { File.Delete(incomingFilePath); // JohnT: Added this without fully understanding, to get things to compile. I don't fully // know when this event should be raised, nor am I sure I am building the argument correctly. // However, I don't think anything (at least in our code) actually uses it. if (WritingSystemIdChanged != null) { WritingSystemIdChanged(this, new WritingSystemIdChangedEventArgs(oldId, ((PalasoWritingSystem)ws).RFC5646)); } } } } var adaptor = new FwLdmlAdaptor(); try { adaptor.Write(writingSystemFilePath, ws, oldData); } catch (UnauthorizedAccessException) { // If we can't save the changes, too bad. Inability to save locally is typically caught // when we go to open the modify dialog. If we can't make the global store consistent, // as we well may not be able to in a client-server mode, too bad. } ws.Modified = false; } finally { if (oldData != null) { oldData.Dispose(); } m_mutex.ReleaseMutex(); } }