Added warning for missing account folder
authorpkanavos <pkanavos@gmail.com>
Fri, 12 Oct 2012 13:04:41 +0000 (16:04 +0300)
committerpkanavos <pkanavos@gmail.com>
Fri, 12 Oct 2012 13:04:41 +0000 (16:04 +0300)
Added warning for lost connectivity

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

index c320ce0..dd3afb7 100644 (file)
@@ -393,6 +393,19 @@ namespace Pithos.Client.WPF {
 \r
                                Monitors[account.AccountKey] = monitor;\r
 \r
+                if (!Directory.Exists(account.RootPath))\r
+                {\r
+                    account.IsActive = false;\r
+                    Notify(new Notification\r
+                    {\r
+                        Level = TraceLevel.Error,\r
+                        Title = "Missing account folder",\r
+                        Message = String.Format("Can't find the root folder for account {0} at {1}. The account was deactivated.\r" +\r
+                        "If the account's files were stored in a removable disk, please connect it and reactivate the account", account.AccountName, account.RootPath)\r
+                    });\r
+                }\r
+\r
+\r
                                if (account.IsActive)\r
                                {\r
                                        //Don't start a monitor if it doesn't have an account and ApiKey\r
index 327e4bf..277213a 100644 (file)
@@ -125,6 +125,14 @@ namespace Pithos.Core.Agents
 \r
         private readonly AsyncManualResetEvent _unPauseEvent = new AsyncManualResetEvent(true);\r
 \r
+\r
+        public bool IsConnectedToInternet\r
+        {\r
+            get {\r
+                return !MS.WindowsAPICodePack.Internal.CoreHelpers.RunningOnVista \r
+                    || Microsoft.WindowsAPICodePack.Net.NetworkListManager.IsConnectedToInternet;\r
+            }\r
+        }\r
 /*\r
         private CancellationTokenSource _currentOperationCancellation=new CancellationTokenSource();\r
 */\r
index 0686b0d..22dd208 100644 (file)
@@ -169,6 +169,9 @@ namespace Pithos.Core.Agents
             TaskEx.Run(() => _moves.AddOrUpdate(args.OldFullPath, args,(s,e)=>e));            \r
         }\r
 \r
+\r
+        private bool _hasConnection;\r
+\r
         /// <summary>\r
         /// Remote files are polled periodically. Any changes are processed\r
         /// </summary>\r
@@ -183,6 +186,7 @@ namespace Pithos.Core.Agents
 \r
             //GC.Collect();\r
 \r
+            \r
             using (ThreadContext.Stacks["Retrieve Remote"].Push("All accounts"))\r
             {\r
                 //If this poll fails, we will retry with the same since value\r
@@ -192,36 +196,54 @@ namespace Pithos.Core.Agents
                     _unPauseEvent.Wait();\r
                     UpdateStatus(PithosStatus.PollSyncing);\r
 \r
-                    var accountBatches=new Dictionary<Uri, IEnumerable<string>>();\r
-                    IEnumerable<string> batch = null;\r
-                    if (_batchQueue.TryDequeue(out batch) && batch != null)\r
-                        foreach (var account in _accounts.Values)\r
+                    if (!NetworkAgent.IsConnectedToInternet)\r
+                    {\r
+                        if (_hasConnection)\r
                         {\r
-                            var accountBatch = batch.Where(path => path.IsAtOrBelow(account.AccountPath));\r
-                            accountBatches[account.AccountKey] = accountBatch;\r
+                            StatusNotification.Notify(new Notification\r
+                            {\r
+                                Level = TraceLevel.Error,\r
+                                Title = "Internet Connection problem",\r
+                                Message ="Internet connectivity was lost. Synchronization will continue when connectivity is restored"\r
+                            });\r
                         }\r
-                    \r
-                    var moves=Interlocked.Exchange(ref _moves, new ConcurrentDictionary<string, MovedEventArgs>());\r
-\r
-                    var tasks = new List<Task<DateTimeOffset?>>();\r
-                    foreach(var accountInfo in _accounts.Values)\r
-                    {\r
-                        IEnumerable<string> accountBatch ;\r
-                        accountBatches.TryGetValue(accountInfo.AccountKey,out accountBatch);\r
-                        var t=ProcessAccountFiles (accountInfo, accountBatch, moves,since);\r
-                        tasks.Add(t);\r
+                        _hasConnection = false;\r
                     }\r
+                    else\r
+                    {\r
+                        _hasConnection = true;\r
 \r
-                    var taskList = tasks.ToList();\r
-                    var nextTimes=await TaskEx.WhenAll(taskList).ConfigureAwait(false);\r
+                        var accountBatches = new Dictionary<Uri, IEnumerable<string>>();\r
+                        IEnumerable<string> batch = null;\r
+                        if (_batchQueue.TryDequeue(out batch) && batch != null)\r
+                            foreach (var account in _accounts.Values)\r
+                            {\r
+                                var accountBatch = batch.Where(path => path.IsAtOrBelow(account.AccountPath));\r
+                                accountBatches[account.AccountKey] = accountBatch;\r
+                            }\r
 \r
-                    _firstPoll = false;\r
-                    //Reschedule the poll with the current timestamp as a "since" value\r
+                        var moves = Interlocked.Exchange(ref _moves, new ConcurrentDictionary<string, MovedEventArgs>());\r
 \r
-                    if (nextTimes.Length>0)\r
-                        nextSince = nextTimes.Min();\r
-                    if (Log.IsDebugEnabled)\r
-                        Log.DebugFormat("Next Poll for changes since [{0}]",nextSince);\r
+                        var tasks = new List<Task<DateTimeOffset?>>();\r
+                        foreach (var accountInfo in _accounts.Values)\r
+                        {\r
+                            IEnumerable<string> accountBatch;\r
+                            accountBatches.TryGetValue(accountInfo.AccountKey, out accountBatch);\r
+                            var t = ProcessAccountFiles(accountInfo, accountBatch, moves, since);\r
+                            tasks.Add(t);\r
+                        }\r
+\r
+                        var taskList = tasks.ToList();\r
+                        var nextTimes = await TaskEx.WhenAll(taskList).ConfigureAwait(false);\r
+\r
+                        _firstPoll = false;\r
+                        //Reschedule the poll with the current timestamp as a "since" value\r
+\r
+                        if (nextTimes.Length > 0)\r
+                            nextSince = nextTimes.Min();\r
+                        if (Log.IsDebugEnabled)\r
+                            Log.DebugFormat("Next Poll for changes since [{0}]", nextSince);\r
+                    }\r
                 }\r
                 catch (Exception ex)\r
                 {\r