예제 #1
0
 /// <summary>
 ///     Nạp cấu hình của service
 /// </summary>
 /// <returns></returns>
 private NotifierProperties GetConfig()
 {
     try
     {
         var    myProperties = new NotifierProperties();
         string filePath     = string.Format("{0}{1}.xml", AppPath, myProperties.GetType().Name);
         var    myFileStream = new FileStream(filePath, FileMode.Open);
         var    mySerializer = new XmlSerializer(myProperties.GetType());
         myProperties = (NotifierProperties)mySerializer.Deserialize(myFileStream);
         myFileStream.Flush();
         myFileStream.Close();
         return(myProperties);
     }
     catch (Exception ex)
     {
         return(new NotifierProperties());
     }
 }
예제 #2
0
        private void FrmConfig_FormClosing(object sender, FormClosingEventArgs e)
        {
            var myWriter = new StreamWriter(string.Format("{0}{1}.xml", AppDomain.CurrentDomain.BaseDirectory, Object.GetType().Name));

            try
            {
                var mySerializer = new XmlSerializer(Object.GetType());
                mySerializer.Serialize(myWriter, Object);
            }
            catch (Exception)
            {
            }
            finally
            {
                myWriter.Flush();
                myWriter.Close();
            }
        }