Exemple #1
0
 private static void ReadXMLDicSettings <T>(XmlSerializableDictionary <string, T> Dic, string FilePath)
 {
     if (File.Exists(FilePath))
     {
         try
         {
             lock (Dic)
             {
                 XmlReaderSettings rSettings = new XmlReaderSettings
                 {
                     IgnoreWhitespace = true
                 };
                 using (System.Xml.XmlReader xr = XmlReader.Create(FilePath, rSettings))
                 {
                     Dic.ReadXml(xr);
                     LastFileRead = DateTime.UtcNow;
                 }
             }
         }
         catch (IOException e)
         {
             System.Diagnostics.Debug.WriteLine(e.Message);
             throw;
         }
     }
 }
Exemple #2
0
        private static void SaveXMLDictionarySettings <T>(XmlSerializableDictionary <string, T> Dic, String FilePath)
        {
            try
            {
                var tmpFile = FilePath + ".tmp";
                lock (Dic)
                {
                    using (System.Xml.XmlTextWriter xtw = new System.Xml.XmlTextWriter(tmpFile, Encoding.UTF8))
                    {
                        xtw.Formatting = Formatting.Indented;
                        xtw.WriteStartDocument();
                        xtw.WriteStartElement("dictionary");

                        Dic.WriteXml(xtw);
                        xtw.WriteEndElement();
                    }
                    if (File.Exists(FilePath))
                    {
                        File.Replace(tmpFile, FilePath, FilePath + ".backup", true);
                    }
                    else
                    {
                        File.Move(tmpFile, FilePath);
                    }
                    LastFileRead = GetLastFileModificationUTC(FilePath);
                }
            }
            catch (IOException e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                throw;
            }
        }