Skip to content

Commit

Permalink
修复自定义命令格式化问题。
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjusss committed Dec 24, 2018
1 parent a692b3d commit 7421c0d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Backup2Cloud/Conf/SingleConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public struct SingleConfiguration : IConfigurable
public HashSet<string> crontab;

/// <summary>
/// 数据源
/// 数据源。
/// 用来将数据保存到path。
/// </summary>
public IDataSource dataSource;

Expand Down
6 changes: 3 additions & 3 deletions Backup2Cloud/DataSource/CustomDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public virtual string Tips
get
{
return "command:自定义命令;" +
"params:自定义命令参数,可以为空。";
"params:自定义命令参数,可以为空。如果包含\"{0}\"(没有空格),将用配置文件的path替代。";
}
}

Expand All @@ -55,11 +55,11 @@ public virtual object GetExample()
/// 运行自定义命令。
/// </summary>
/// <exception cref="OperationCanceledException"/>
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();
Expand Down
3 changes: 2 additions & 1 deletion Backup2Cloud/DataSource/IDataSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public interface IDataSource : IConfigurable, IExampled
/// <summary>
/// 保存数据。
/// </summary>
void SaveData();
/// <param name="des">保存的路径</param>
void SaveData(string des);
}
}
11 changes: 7 additions & 4 deletions Backup2Cloud/Worker/BackupWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -108,7 +111,7 @@ private string Compress(string path)
else
{
// 都不是
throw new FileNotFoundException(string.Format("没有找到文件或目录\"{0}\"。", path));
throw new FileNotFoundException($"没有找到文件或目录\"{ path }\"。");
}

return zip;
Expand Down

0 comments on commit 7421c0d

Please sign in to comment.