Example #1
0
        /// <summary>
        /// 开启自动备份,并返回正在执行的BackupCreater
        /// </summary>
        /// <param name="备份源文件名">备份源文件名</param>
        /// <param name="writeFileProcedure">写文件函数(要求唯一的参数为写文件名)</param>
        /// <param name="interval">备份间隔(毫秒)</param>
        /// <param name="备份后缀名">备份后缀名</param>
        /// <param name="hideBackup">是否设置备份为隐藏文件</param>
        public static BackupCreater Backup(string 备份源文件名, WriteProcedure writeFileProcedure = null, int interval = 1000, string 备份后缀名 = ".backup", bool hideBackup = false)
        {
            var ret = new BackupCreater(备份后缀名, writeFileProcedure, interval, 备份后缀名, hideBackup);

            ret.Start();
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 只执行单步备份操作,并返回正在执行的BackupCreater
        /// </summary>
        /// <param name="备份源文件名">备份源文件名</param>
        /// <param name="writeFileProcedure">写文件函数(要求唯一的参数为写文件名)</param>
        /// <param name="备份后缀名">备份后缀名</param>
        /// <param name="hideBackup">是否设置备份为隐藏文件</param>
        public static BackupCreater BackupOnce(string 备份源文件名, WriteProcedure writeFileProcedure = null, string 备份后缀名 = ".backup", bool hideBackup = false)
        {
            var ret = new BackupCreater(备份后缀名, writeFileProcedure, int.MaxValue, 备份后缀名, hideBackup);

            ret.StartOnce();
            return(ret);
        }
Example #3
0
 /// <summary>
 /// 生成一个新的BackupCreater
 /// </summary>
 /// <param name="备份源文件名">备份源文件名</param>
 /// <param name="writeFileProcedure">写文件函数(要求唯一的参数为写文件名)</param>
 /// <param name="interval">备份间隔(毫秒)</param>
 /// <param name="备份后缀名">备份后缀名</param>
 /// <param name="hideBackup">是否设置备份为隐藏文件</param>
 /// <param name="算法">备份算法</param>
 public BackupCreater(string 备份源文件名, WriteProcedure writeFileProcedure = null, int interval = 1000, string 备份后缀名 = ".backup", bool hideBackup = false, 加密算法 算法 = 加密算法.无)
 {
     this.Original文件名 = 备份源文件名;      // 设置源文件名
     if (writeFileProcedure != null) // 注册备份函数
     {
         this.WriteBackupEvent += writeFileProcedure;
     }
     else
     {
         this.WriteBackupEvent += DefaultBackupFunction;
     }
     if (备份后缀名.StartsWith(".") == false) // 后缀名加.
     {
         this.Backup后缀名 = "." + 备份后缀名;
     }
     else
     {
         this.Backup后缀名 = 备份后缀名;
     }
     this.Encrypt算法        = 算法;         // 设置加密算法
     this.HiddenBackupFile = hideBackup; // 设置隐藏备份
     if (备份源文件名.Contains(":"))
     {
         // 如果含有:号说明是绝对路径,由于在Original文件名第二次设置开始才会同步workingDirectory。
         // 在这里调用是为了同步workingDirectory
         int directoryEndIndex = original文件名.LastIndexOf('\\');
         if (directoryEndIndex != -1)
         {
             this.workingDirectory = original文件名.Substring(0, directoryEndIndex);
         }
     }
     /* 内部操作设置 */
     BackupFileTimer       = new Timer();
     this.Interval         = interval;
     BackupFileTimer.Tick += WriteBackupInvoke;
 }