示例#1
0
 public static bool LoadPropertiesFromStream(string fileName)
 {
     if (!System.IO.File.Exists(fileName))
     {
         return(false);
     }
     try
     {
         using (PropertyService.LockPropertyFile())
         {
             using (XmlTextReader xmlTextReader = new XmlTextReader(fileName))
             {
                 while (xmlTextReader.Read())
                 {
                     if (xmlTextReader.IsStartElement() && xmlTextReader.LocalName == PropertyService.propertyXmlRootNodeName)
                     {
                         PropertyService.properties.ReadProperties(xmlTextReader, PropertyService.propertyXmlRootNodeName);
                         return(true);
                     }
                 }
             }
         }
     }
     catch (XmlException)
     {
     }
     return(false);
 }
示例#2
0
 public static void Save()
 {
     using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
     {
         XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, System.Text.Encoding.UTF8);
         xmlTextWriter.Formatting = Formatting.Indented;
         xmlTextWriter.WriteStartElement(PropertyService.propertyXmlRootNodeName);
         PropertyService.properties.WriteProperties(xmlTextWriter);
         xmlTextWriter.WriteEndElement();
         xmlTextWriter.Flush();
         memoryStream.Position = 0L;
         string path = System.IO.Path.Combine(FileUtility.LocalUserAppDataPath, PropertyService.propertyFileName);
         using (PropertyService.LockPropertyFile())
         {
             using (System.IO.FileStream fileStream = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.None))
             {
                 memoryStream.WriteTo(fileStream);
             }
         }
     }
 }