Added notification messages for conflicts and multifile operations on Pithos.Core...
authorPanagiotis Kanavos <pkanavos@gmail.com>
Tue, 24 Jan 2012 17:11:20 +0000 (19:11 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Tue, 24 Jan 2012 17:11:20 +0000 (19:11 +0200)
Added simple status display for conflict and multifile operations in ShellViewModel.cs
Added Conflict file status
Modified NetworkAgent.cs to mark local-only files as "in conflict" during the first poll and delete any non-conflict local-only files on subsequent runs. Closes #1466, #1931

trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/Agents/NetworkAgent.cs
trunk/Pithos.Core/IPithosWorkflow.cs
trunk/Pithos.Core/PithosMonitor.cs

index 1c06345..aa03f23 100644 (file)
@@ -659,8 +659,31 @@ namespace Pithos.Client.WPF {
 
                }
 
+           public void NotifyConflicts(IEnumerable<FileSystemInfo> conflictFiles, string message)
+           {
+            if (conflictFiles == null)
+                return;
+            if (!conflictFiles.Any())
+                return;
+            //TODO: Create a more specific message. For now, just show a warning
+            NotifyForFiles(conflictFiles,message,TraceLevel.Warning);
+
+           }
+
+           public void NotifyForFiles(IEnumerable<FileSystemInfo> files, string message,TraceLevel level=TraceLevel.Info)
+           {
+            if (files == null)
+                return;
+            if (!files.Any())
+                return;
+
+            StatusMessage = message;
+
+            _events.Publish(new Notification { Title = "Pithos", Message = message, Level = level});
+        }
+
 
-               public void RemoveMonitor(string accountName)
+           public void RemoveMonitor(string accountName)
                {
                        if (String.IsNullOrWhiteSpace(accountName))
                                return;
index 0cf449e..6ce712a 100644 (file)
@@ -627,24 +627,44 @@ namespace Pithos.Core.Agents
                 throw new ArgumentNullException("cloudFiles");
             Contract.EndContractBlock();
 
-            if (_firstPoll) return;
-            //TODO: Do I need the "Modified" check if I'm not going to delete files that
-            //were not found on the server on the first run?
-            //TODO: Files that were not found on the server on the first run should be marked IN CONFLICT
-            var deleteCandidates = from state in FileState.Queryable
-                                   where state.Modified <= pollTime && state.FilePath.StartsWith(accountInfo.AccountPath)
-                                   select state;
-
-            foreach (var deleteCandidate in deleteCandidates)
+            //Check the Modified date to ensure that were just created and haven't been uploaded yet
+            //NOTE: The NHibernate LINQ provider doesn't support custom functions so we need to break the query 
+            //in two steps
+            //NOTE: DON'T return files that are already in conflict. The first poll would mark them as 
+            //"In Conflict" but subsequent polls would delete them
+            var deleteCandidates = (from state in FileState.Queryable
+                                   where 
+                                        state.Modified <= pollTime 
+                                        && state.FilePath.StartsWith(accountInfo.AccountPath)
+                                        && state.FileStatus != FileStatus.Conflict
+                                   select state).ToList();
+
+            var filesToDelete = (from deleteCandidate in deleteCandidates 
+                         let localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath) 
+                         let relativeFilePath = localFile.AsRelativeTo(accountInfo.AccountPath) 
+                         where !cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath) 
+                         select localFile).ToList();
+
+            //On the first run
+            if (_firstPoll)
             {
-                var localFile = FileInfoExtensions.FromPath(deleteCandidate.FilePath);
-                var relativeFilePath=localFile.AsRelativeTo(accountInfo.AccountPath);
-                if (!cloudFiles.Any(r => Path.Combine(r.Container, r.Name) == relativeFilePath))
+                //Set the status of missing files to Conflict
+                foreach (var item in filesToDelete)
                 {
-                    localFile.Delete();
-                    StatusKeeper.ClearFileStatus(deleteCandidate.FilePath);
+                    StatusKeeper.SetFileState(item.FullName, FileStatus.Conflict, FileOverlayStatus.Deleted);
                 }
+                StatusNotification.NotifyConflicts(filesToDelete, String.Format("{0} local files are missing from Pithos, possibly because they were deleted",filesToDelete.Count));
             }
+            else
+            {
+                foreach (var item in filesToDelete)
+                {
+                    item.Delete();
+                    StatusKeeper.ClearFileStatus(item.FullName);
+                }
+                StatusNotification.NotifyForFiles(filesToDelete, String.Format("{0} files were deleted",filesToDelete.Count),TraceLevel.Info);
+            }
+
         }
 
         private static void CreateContainerFolders(AccountInfo accountInfo, IEnumerable<ContainerInfo> containers)
index 9f2cdc3..d350d72 100644 (file)
@@ -20,6 +20,7 @@ namespace Pithos.Core
         Created,
         Modified,
         Renamed,
-        Deleted
+        Deleted,
+        Conflict
     }
 }
\ No newline at end of file
index 705c5f2..38005df 100644 (file)
@@ -570,5 +570,7 @@ namespace Pithos.Core
         void NotifyChange(string status,TraceLevel level=TraceLevel.Info);
         void NotifyChangedFile(string filePath);
         void NotifyAccount(AccountInfo policy);
+        void NotifyConflicts(IEnumerable<FileSystemInfo> conflictFiles, string message);
+        void NotifyForFiles(IEnumerable<FileSystemInfo> files, string message,TraceLevel level);
     }
 }