public static IEnumerable <FileDetails> GetDeletedFiles(FolderContentSnapshot newSnapshot, FolderContentSnapshot oldSnapshot) { var deletedFiles = new List <FileDetails>(); foreach (var file in oldSnapshot.Files) { var fileNameOnly = file.FileName.Substring(file.FileName.LastIndexOf('\\') + 1).ToLower(); if (excludedFiles.Contains(fileNameOnly)) { continue; } if (newSnapshot.Files.All(x => x.FileName.ToLower() != file.FileName.ToLower())) { deletedFiles.Add(new FileDetails { FileName = file.FileName, ChangeDate = file.ChangeDate, FolderId = newSnapshot.FolderId }); } } return(deletedFiles); }
public FolderContentSnapshot ReadSnapshot(Guid folderId) { FolderContentSnapshot result = null; using (var database = new LiteDatabase(DatabaseName)) { // Open collection var snapshots = database.GetCollection <FolderContentSnapshot>(CollectionName); result = snapshots.Find(x => x.FolderId == folderId).SingleOrDefault(); // create empty snapshot of nothing has been found if (result == null) { result = new FolderContentSnapshot() { FolderId = folderId, SnapshotDate = DateTime.Now, Files = new List <FileDetails>() }; // add newly created snapshot to database to ensure its existance in future snapshots.Insert(result); } } return(result); }
public void UpdateSnapshot(FolderContentSnapshot snapshot) { using (var database = new LiteDatabase(DatabaseName)) { var snapshots = database.GetCollection <FolderContentSnapshot>(CollectionName); snapshots.Update(snapshot); } }
public FolderContentSnapshot CreateSnapshot(FolderDetails folder) { var snapshot = new FolderContentSnapshot(); var existingFiles = Directory.GetFiles(folder.FolderName, "*", SearchOption.TopDirectoryOnly); foreach (var file in existingFiles) { var fileInfo = new FileInfo(file); snapshot.Files.Add(new FileDetails { FileName = file, ChangeDate = fileInfo.LastWriteTime, FolderId = folder.FolderId }); } snapshot.FolderId = folder.FolderId; snapshot.SnapshotDate = DateTime.Now; return(snapshot); }