Fixed a duplication bug in the Snapshot Merge function.

This commit is contained in:
Admin
2020-12-06 17:08:38 -06:00
parent d758e42afb
commit 9f9fdac66a
3 changed files with 17 additions and 16 deletions
Binary file not shown.
+1 -3
View File
@@ -171,13 +171,11 @@ namespace DataOrganizer
var snapShot = new Snapshot(files, folderGroup); var snapShot = new Snapshot(files, folderGroup);
ActiveSnapshotForPrimaryTree.MergeSnapshot(snapShot); ActiveSnapshotForPrimaryTree.MergeSnapshot(snapShot);
var newFiles = snapShot.Files.Values.Except(ActiveSnapshotForPrimaryTree.Files.Values);
var existingFiles = ActiveSnapshotForPrimaryTree.Files.Values.Except(snapShot.Files.Values);
var newFilesCount = 0; var newFilesCount = 0;
var modifiedFilesCount = 0; var modifiedFilesCount = 0;
var deletedFilesCount = 0; var deletedFilesCount = 0;
foreach(var f in newFiles) foreach(var f in ActiveSnapshotForPrimaryTree.Files.Values.Where(x => x.Status == FileSnapshot.FileStatus.PendingInsert))//newFiles)
{ {
var newNode = new TreeNode(f.Name) { Name = f.FullPath, BackColor = Color.LightBlue, ToolTipText = "New File Found!" }; var newNode = new TreeNode(f.Name) { Name = f.FullPath, BackColor = Color.LightBlue, ToolTipText = "New File Found!" };
var folders = ProcessFileFolders(f); var folders = ProcessFileFolders(f);
+16 -13
View File
@@ -167,44 +167,47 @@ namespace DataOrganizer
public void MergeSnapshot(Snapshot snapshot) public void MergeSnapshot(Snapshot snapshot)
{ {
//TODO: build this out var newFiles = new List<FileSnapshot>();
var newFiles = Files.Values.Except(snapshot.Files.Values);
var newFolders = Directories.Values.Except(snapshot.Directories.Values);
var newOrgFolders = OrganizationFolders.Values.Except(snapshot.OrganizationFolders.Values);
var existingFiles = Files.Values.Except(snapshot.Files.Values); var existingFiles = Files.Values.Except(snapshot.Files.Values);
foreach(var file in snapshot.Files)
if (!Files.ContainsKey(file.Key)) newFiles.Add(file.Value);
foreach (var folder in snapshot.OrganizationFolders)
{
if (!OrganizationFolders.ContainsKey(folder.Key) && folder.Key != Root.FullPath)
{
Root.AddDirectory(snapshot.Directories[folder.Key]);
OrganizationFolders.Add(folder.Key, new List<FileSnapshot>());
}
}
foreach (var existingFile in existingFiles) foreach (var existingFile in existingFiles)
{ {
if (!snapshot.Files.ContainsKey(existingFile.FullPath)) if (!snapshot.Files.ContainsKey(existingFile.FullPath))
{ {
existingFile.Status = FileSnapshot.FileStatus.PendingDelete; existingFile.Status = FileSnapshot.FileStatus.PendingDelete;
//deletedFiles.Add(existingFile);
//pendingChanges++;
} }
else if (existingFile.ModifiedDate != snapshot.Files[existingFile.FullPath].ModifiedDate) else if (existingFile.ModifiedDate != snapshot.Files[existingFile.FullPath].ModifiedDate)
{ {
existingFile.ModifiedDate = snapshot.Files[existingFile.FullPath].ModifiedDate; existingFile.ModifiedDate = snapshot.Files[existingFile.FullPath].ModifiedDate;
//modifiedFiles.Add(snapShot.Files[existingFile.FullPath]);
//pendingChanges++;
} }
} }
foreach(var newFile in newFiles) foreach(var newFile in newFiles)
{ {
if(!Files.ContainsKey(newFile.FullPath)) Files.Add(newFile.FullPath, newFile); Files.Add(newFile.FullPath, newFile);
Folder folder = newFile.ParentFolder; Folder folder = newFile.ParentFolder;
while(folder != null) while(folder != null)
{ {
if (!Directories.ContainsKey(folder.FullPath)) if (!Directories.ContainsKey(folder.FullPath))
{
Directories.Add(folder.FullPath, folder); Directories.Add(folder.FullPath, folder);
}
if (folder.Parent == null && !OrganizationFolders.ContainsKey(folder.FullPath)) OrganizationFolders.Add(folder.FullPath, folder.Files.Values.ToList());
folder = folder.Parent; folder = folder.Parent;
} }
OrganizationFolders[newFile.OrganizationalFolder.FullPath].Add(newFile);
} }
} }