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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public void UpdateSnapshot(FolderContentSnapshot snapshot)
        {
            using (var database = new LiteDatabase(DatabaseName))
            {
                var snapshots = database.GetCollection <FolderContentSnapshot>(CollectionName);

                snapshots.Update(snapshot);
            }
        }
Пример #4
0
        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);
        }