-
Notifications
You must be signed in to change notification settings - Fork 0
/
SyncJob.cs
52 lines (45 loc) · 1.71 KB
/
SyncJob.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
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace DirectorySync {
public class SyncJob
{
public SyncJob(string pathA, string pathB, string logPath, int logFileLimit)
: this(pathA, pathB, new List<FileStatusLine>(), logPath, -1, logFileLimit)
{ }
[JsonConstructor]
public SyncJob(string pathA, string pathB, IList<FileStatusLine> statusLines, string logPath, int currentPid, int logFileLimit)
{
this.LogPath = logPath;
this.PathA = pathA ?? throw new ArgumentNullException(nameof(pathA));
this.PathB = pathB ?? throw new ArgumentNullException(nameof(pathB));
this.StatusLines = statusLines ?? new List<FileStatusLine>();
this.CurrentPid = currentPid;
this.LogFileLimit = logFileLimit;
}
public string PathA { get; }
public string PathB { get; }
public IList<FileStatusLine> StatusLines { get; }
public string LogPath { get; }
public int CurrentPid { get; set; }
public int LogFileLimit { get; }
public void Save(string outputFile)
{
var json = JsonConvert.SerializeObject(this);
File.WriteAllText(outputFile, json);
}
public static SyncJob Load(string inputFile)
{
var json = File.ReadAllText(inputFile);
return JsonConvert.DeserializeObject<SyncJob>(json);
}
}
public class FileStatusLine
{
public string Key { get; set; }
public DateTime LastModified { get; set; }
public override string ToString()
=> $"[ Key = { Key }, LastModified = { LastModified } ]";
}
}