diff --git a/Backup2Cloud/Conf/SingleConfiguration.cs b/Backup2Cloud/Conf/SingleConfiguration.cs index 6f88d62..a7d6c11 100644 --- a/Backup2Cloud/Conf/SingleConfiguration.cs +++ b/Backup2Cloud/Conf/SingleConfiguration.cs @@ -25,7 +25,8 @@ public struct SingleConfiguration : IConfigurable public HashSet crontab; /// - /// 数据源 + /// 数据源。 + /// 用来将数据保存到path。 /// public IDataSource dataSource; diff --git a/Backup2Cloud/DataSource/CustomDataSource.cs b/Backup2Cloud/DataSource/CustomDataSource.cs index 16911c6..793b202 100644 --- a/Backup2Cloud/DataSource/CustomDataSource.cs +++ b/Backup2Cloud/DataSource/CustomDataSource.cs @@ -34,7 +34,7 @@ public virtual string Tips get { return "command:自定义命令;" + - "params:自定义命令参数,可以为空。"; + "params:自定义命令参数,可以为空。如果包含\"{0}\"(没有空格),将用配置文件的path替代。"; } } @@ -55,11 +55,11 @@ public virtual object GetExample() /// 运行自定义命令。 /// /// - public void SaveData() + public void SaveData(string des) { Process process = string.IsNullOrWhiteSpace(Params) ? Process.Start(Command) : - Process.Start(Command, Params); + Process.Start(Command, Params.Contains("{0}") ? string.Format(Params, des) : Params); #if DEBUG process.OutputDataReceived += (sender, e) => Log.Info(e.Data); process.BeginOutputReadLine(); diff --git a/Backup2Cloud/DataSource/IDataSource.cs b/Backup2Cloud/DataSource/IDataSource.cs index 36ba57f..2b36060 100644 --- a/Backup2Cloud/DataSource/IDataSource.cs +++ b/Backup2Cloud/DataSource/IDataSource.cs @@ -10,6 +10,7 @@ public interface IDataSource : IConfigurable, IExampled /// /// 保存数据。 /// - void SaveData(); + /// 保存的路径 + void SaveData(string des); } } diff --git a/Backup2Cloud/Worker/BackupWorker.cs b/Backup2Cloud/Worker/BackupWorker.cs index e57f952..ed2c4d8 100644 --- a/Backup2Cloud/Worker/BackupWorker.cs +++ b/Backup2Cloud/Worker/BackupWorker.cs @@ -29,8 +29,11 @@ public async Task Execute(IJobExecutionContext context) DateTime start = DateTime.Now; Log.Info(string.Format("开始执行任务\"{0}\"。", conf.name), conf.name); - conf.dataSource.SaveData(); - Log.Info("成功为数据源执行保存命令。", conf.name); + if (conf.dataSource != null) + { + conf.dataSource.SaveData(conf.path); + Log.Info("成功为数据源执行保存命令。", conf.name); + } string suffix = start.ToString("yyyyMMddHHmmss") + ".zip"; file = Compress(conf.path); @@ -39,7 +42,7 @@ public async Task Execute(IJobExecutionContext context) Log.Info("成功上传文件。", conf.name); DateTime end = DateTime.Now; - Log.Info(string.Format("任务\"{0}\"执行成功,用时{1}秒。", conf.name, (end - start).TotalSeconds), conf.name); + Log.Info($"任务\"{ conf.name }\"执行成功,用时{ (end - start).TotalSeconds }秒。", conf.name); } catch (Exception e) { @@ -108,7 +111,7 @@ private string Compress(string path) else { // 都不是 - throw new FileNotFoundException(string.Format("没有找到文件或目录\"{0}\"。", path)); + throw new FileNotFoundException($"没有找到文件或目录\"{ path }\"。"); } return zip;