-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathApply.cs
64 lines (53 loc) · 1.82 KB
/
Apply.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Threading.Tasks;
namespace SourceGit.ViewModels
{
public class Apply : Popup
{
[Required(ErrorMessage = "Patch file is required!!!")]
[CustomValidation(typeof(Apply), nameof(ValidatePatchFile))]
public string PatchFile
{
get => _patchFile;
set => SetProperty(ref _patchFile, value, true);
}
public bool IgnoreWhiteSpace
{
get => _ignoreWhiteSpace;
set => SetProperty(ref _ignoreWhiteSpace, value);
}
public Models.ApplyWhiteSpaceMode SelectedWhiteSpaceMode
{
get;
set;
}
public Apply(Repository repo)
{
_repo = repo;
SelectedWhiteSpaceMode = Models.ApplyWhiteSpaceMode.Supported[0];
}
public static ValidationResult ValidatePatchFile(string file, ValidationContext _)
{
if (File.Exists(file))
return ValidationResult.Success;
return new ValidationResult($"File '{file}' can NOT be found!!!");
}
public override Task<bool> Sure()
{
_repo.SetWatcherEnabled(false);
ProgressDescription = "Apply patch...";
var log = _repo.CreateLog("Apply Patch");
return Task.Run(() =>
{
var succ = new Commands.Apply(_repo.FullPath, _patchFile, _ignoreWhiteSpace, SelectedWhiteSpaceMode.Arg, null).Use(log).Exec();
log.Complete();
CallUIThread(() => _repo.SetWatcherEnabled(true));
return succ;
});
}
private readonly Repository _repo = null;
private string _patchFile = string.Empty;
private bool _ignoreWhiteSpace = true;
}
}