Exemplo n.º 1
0
 public IniFile(string fileName, System.Text.Encoding encoding, double interval)
 {
     if (fileName == null)
     {
         throw new ArgumentNullException("fileName");
     }
     if (fileName.Length == 0)
     {
         throw new ArgumentOutOfRangeException("fileName");
     }
     if (!File.Exists(fileName))
     {
         File.WriteAllText(fileName, string.Empty, encoding);
     }
     this.FileName = Path.GetFullPath(fileName);
     this.Encoding = encoding;
     this.Comment  = new List <string>();
     this.Sections = new IniFileSectionCollection();
     this.Refresh();
     if (interval > 0.0)
     {
         this.simpleTimerProvider_0 = new SimpleTimerProvider <IniFile>(this, interval);
         if (action_0 == null)
         {
             action_0 = new Action <IniFile>(IniFile.smethod_1);
         }
         this.simpleTimerProvider_0.Run(action_0);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 从指定文件初始化 <see cref="IniFile"/> 类的新实例。
        /// </summary>
        /// <param name="fileName">指定 ini 文件的完整路径。</param>
        /// <param name="encoding">指定 ini 文件的字符编码。</param>
        /// <param name="interval">指定自动保存的时间间隔。</param>
        public IniFile(string fileName, Encoding encoding, double interval)
        {
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }
            if (fileName.Length == 0)
            {
                throw new ArgumentOutOfRangeException("fileName");
            }
            if (File.Exists(fileName) == false)
            {
                File.WriteAllText(fileName, String.Empty, encoding);
            }

            this.FileName = Path.GetFullPath(fileName);
            this.Encoding = encoding;
            this.Comment  = new List <string>();
            this.Sections = new IniFileSectionCollection();

            this.Refresh();

            if (interval <= 0)
            {
                return;
            }

            this._saveTimerProvider = new SimpleTimerProvider <IniFile>(this, interval);
            this._saveTimerProvider.Run(ini => ini.Save());
        }