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