public static Snapshot ToSnapshot(this JSnapshot jSnapshot) { if (jSnapshot == null) { throw new ArgumentNullException(nameof(jSnapshot)); } Snapshot snapshot = new() { Id = jSnapshot.Id, OriginalPath = jSnapshot.OriginalPath, CreationTime = jSnapshot.CreationTime }; IEnumerable <HDirectory> directories = jSnapshot.GetHDirectories(); if (directories != null) { snapshot.Directories.AddRange(directories); } IEnumerable <HFile> files = jSnapshot.GetHFiles(); if (files != null) { snapshot.Files.AddRange(files); } return(snapshot); }
public Snapshot ReadSnapshot(string filePath) { using StreamReader streamReader = File.OpenText(filePath); using JsonTextReader jsonTextReader = new(streamReader); JsonSerializer serializer = new(); JSnapshot jSnapshot = (JSnapshot)serializer.Deserialize(jsonTextReader, typeof(JSnapshot)); return(jSnapshot.ToSnapshot()); }
public void Open() { if (!File.Exists(filePath)) { return; } using StreamReader streamReader = File.OpenText(filePath); using JsonTextReader jsonTextReader = new(streamReader); JsonSerializer serializer = new(); Snapshot = (JSnapshot)serializer.Deserialize(jsonTextReader, typeof(JSnapshot)); }
private static IEnumerable <HFile> GetHFiles(this JSnapshot jSnapshot) { return(jSnapshot.Files? .Select(x => x.ToHFile()) .ToList()); }
private static IEnumerable <HDirectory> GetHDirectories(this JSnapshot jSnapshot) { return(jSnapshot.Directories? .Select(x => x.ToHDirectory()) .ToList()); }