Added separate notification class
authorPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 27 Jan 2012 13:55:28 +0000 (15:55 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Fri, 27 Jan 2012 13:55:28 +0000 (15:55 +0200)
Now raising notifications when polling starts, when conflicts are detected, when changes are detected

trunk/Pithos.Client.WPF/Shell/Notification.cs
trunk/Pithos.Client.WPF/Shell/ShellViewModel.cs
trunk/Pithos.Core/Agents/NetworkAgent.cs
trunk/Pithos.Core/IStatusNotification.cs [new file with mode: 0644]
trunk/Pithos.Core/Pithos.Core.csproj
trunk/Pithos.Core/PithosMonitor.cs

index a6a7420..4bef1b2 100644 (file)
@@ -2,11 +2,11 @@ using System.Diagnostics;
 
 namespace Pithos.Client.WPF
 {
-    public class Notification
+    /*public class Notification
     {
         public string Title { get; set; }
         public string Message { get; set; }
         public TraceLevel Level { get; set; }
-    }
+    }*/
     
 }
\ No newline at end of file
index 551d1fa..f0e1ea1 100644 (file)
@@ -665,6 +665,8 @@ namespace Pithos.Client.WPF {
                 return;
             if (!conflictFiles.Any())
                 return;
+
+            UpdateStatus();
             //TODO: Create a more specific message. For now, just show a warning
             NotifyForFiles(conflictFiles,message,TraceLevel.Warning);
 
@@ -682,6 +684,11 @@ namespace Pithos.Client.WPF {
             _events.Publish(new Notification { Title = "Pithos", Message = message, Level = level});
         }
 
+        public void Notify(Notification notification)
+        {
+            _events.Publish(notification);
+        }
+
 
            public void RemoveMonitor(string accountName)
                {
@@ -747,9 +754,11 @@ namespace Pithos.Client.WPF {
         //The notifications should be moved to their own view/viewmodel pair
         //and different templates should be used for different message types
         //This will also allow the addition of extra functionality, eg. actions
-        //to perform when clicking on a balloon
+        //
                public void Handle(Notification notification)
                {
+            UpdateStatus();
+
                        if (!Settings.ShowDesktopNotifications)
                                return;
                        BalloonIcon icon;
index 32dde37..e35ba09 100644 (file)
@@ -120,6 +120,7 @@ namespace Pithos.Core.Agents
                 throw new ArgumentException("The action.AccountInfo is empty","action");
             Contract.EndContractBlock();
 
+            StatusKeeper.SetPithosStatus(PithosStatus.Syncing);
             var accountInfo = action.AccountInfo;
 
             using (log4net.ThreadContext.Stacks["NETWORK"].Push("PROCESS"))
@@ -135,7 +136,7 @@ namespace Pithos.Core.Agents
                     if (action.Action == CloudActionType.DeleteCloud)
                     {
                         //Redirect deletes to the delete agent 
-                        _deleteAgent.Post((CloudDeleteAction)action);                        
+                        _deleteAgent.Post((CloudDeleteAction)action);
                     }
                     if (IsDeletedFile(action))
                     {
@@ -155,7 +156,7 @@ namespace Pithos.Core.Agents
                                 await DownloadCloudFile(accountInfo, cloudFile, downloadPath);
                                 break;
                             case CloudActionType.RenameCloud:
-                                var moveAction = (CloudMoveAction) action;
+                                var moveAction = (CloudMoveAction)action;
                                 RenameCloudFile(accountInfo, moveAction);
                                 break;
                             case CloudActionType.MustSynch:
@@ -186,7 +187,7 @@ namespace Pithos.Core.Agents
                     Log.ErrorFormat("{0} : {1} -> {2}  failed because the directory was not found.\n Rescheduling a delete",
                         action.Action, action.LocalFile, action.CloudFile);
                     //Post a delete action for the missing file
-                    Post(new CloudDeleteAction(action));                    
+                    Post(new CloudDeleteAction(action));
                 }
                 catch (FileNotFoundException)
                 {
@@ -201,7 +202,11 @@ namespace Pithos.Core.Agents
                                      action.Action, action.LocalFile, action.CloudFile, exc);
 
                     _agent.Post(action);
-                }                
+                }
+                finally
+                {
+                    StatusKeeper.SetPithosStatus(PithosStatus.InSynch);
+                }
             }
         }
 
@@ -376,6 +381,7 @@ namespace Pithos.Core.Agents
             Contract.EndContractBlock();
 
             StatusKeeper.SetFileOverlayStatus(downloadPath, FileOverlayStatus.Conflict);
+            StatusKeeper.SetPithosStatus(PithosStatus.HasConflicts);
             var message = String.Format("Conflict detected for file {0}", downloadPath);
             Log.Warn(message);
             StatusNotification.NotifyChange(message, TraceLevel.Warning);
@@ -447,7 +453,8 @@ namespace Pithos.Core.Agents
         //Remote files are polled periodically. Any changes are processed
         public async Task PollRemoteFiles(DateTime? since = null,bool repeat=true)
         {
-
+            StatusNotification.Notify(new Notification{Title="Polling Pithos"});
+            StatusKeeper.SetPithosStatus(PithosStatus.Syncing);
 
             using (log4net.ThreadContext.Stacks["Retrieve Remote"].Push("All accounts"))
             {
@@ -504,6 +511,8 @@ namespace Pithos.Core.Agents
                 throw new ArgumentException("The AccountInfo.AccountPath is empty","accountInfo");
             Contract.EndContractBlock();
 
+            StatusNotification.Notify(new Notification{Title=String.Format("Polling {0}",accountInfo.UserName)});
+
             using (log4net.ThreadContext.Stacks["Retrieve Remote"].Push(accountInfo.UserName))
             {
                 Log.Info("Scheduled");
@@ -603,6 +612,10 @@ namespace Pithos.Core.Agents
                             .Except(_agent.GetEnumerable(), new PithosMonitor.LocalFileComparer())
                             .ToList();
 
+                        if (distinctActions.Any())
+                        {
+                            StatusNotification.Notify(new Notification {Title = "Changes Detected",Message=String.Format("{0} files were modified",distinctActions.Count)});
+                        }
                         //Queue all the actions
                         foreach (var message in distinctActions)
                         {
@@ -685,6 +698,7 @@ namespace Pithos.Core.Agents
                 {
                     StatusKeeper.SetFileState(item.FullName, FileStatus.Conflict, FileOverlayStatus.Deleted);
                 }
+                StatusKeeper.SetPithosStatus(PithosStatus.HasConflicts);
                 StatusNotification.NotifyConflicts(filesToDelete, String.Format("{0} local files are missing from Pithos, possibly because they were deleted",filesToDelete.Count));
             }
             else
diff --git a/trunk/Pithos.Core/IStatusNotification.cs b/trunk/Pithos.Core/IStatusNotification.cs
new file mode 100644 (file)
index 0000000..352efb4
--- /dev/null
@@ -0,0 +1,40 @@
+using System.Collections.Generic;\r
+using System.Diagnostics;\r
+using System.IO;\r
+using Pithos.Network;\r
+\r
+namespace Pithos.Core\r
+{\r
+    public interface IStatusNotification\r
+    {        \r
+        void NotifyChange(string status,TraceLevel level=TraceLevel.Info);\r
+        void NotifyChangedFile(string filePath);\r
+        void NotifyAccount(AccountInfo policy);\r
+        void NotifyConflicts(IEnumerable<FileSystemInfo> conflictFiles, string message);\r
+        void NotifyForFiles(IEnumerable<FileSystemInfo> files, string message,TraceLevel level);\r
+        void Notify(Notification notification);\r
+    }\r
+\r
+    public class Notification\r
+    {\r
+        public TraceLevel Level { get; set; }\r
+        public string Title { get; set; }\r
+        public string Message { get; set; }\r
+\r
+        public Notification()\r
+        {\r
+            Level=TraceLevel.Info;\r
+            Title = "";\r
+            Message = "";\r
+        }\r
+    }\r
+\r
+    public class Notification<T>:Notification\r
+    {\r
+        public T Data { get; set; }\r
+    }\r
+\r
+    public class FilesNotification:Notification<IEnumerable<FileSystemInfo>>\r
+    {        \r
+    }\r
+}
\ No newline at end of file
index b20d8b4..ecae140 100644 (file)
     <Compile Include="EnumerableExtensions.cs" />
     <Compile Include="FileHashMap.cs" />
     <Compile Include="FileState.cs" />
+    <Compile Include="IStatusNotification.cs" />
     <Compile Include="IStatusService.cs" />
     <Compile Include="JobQueue.cs" />
     <Compile Include="NetworkGate.cs" />
index 38005df..9c6a220 100644 (file)
@@ -563,14 +563,4 @@ namespace Pithos.Core
             });
         }
     }
-
-
-    public interface IStatusNotification
-    {        
-        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);
-    }
 }