Revision 2341c603 trunk/Pithos.Core/Agents/PollAgent.cs

b/trunk/Pithos.Core/Agents/PollAgent.cs
79 79
        [System.ComponentModel.Composition.Import]
80 80
        public NetworkAgent NetworkAgent { get; set; }
81 81

  
82
        [System.ComponentModel.Composition.Import]
83
        public Selectives Selectives { get; set; }
84

  
82 85
        public IStatusNotification StatusNotification { get; set; }
83 86

  
87
        public bool Pause
88
        {
89
            get {
90
                return _pause;
91
            }
92
            set {
93
                _pause = value;                
94
                if (!_pause)
95
                    _unPauseEvent.Set();
96
                else
97
                {
98
                    _unPauseEvent.Reset();
99
                }
100
            }
101
        }
102

  
84 103
        private bool _firstPoll = true;
85 104

  
86 105
        //The Sync Event signals a manual synchronisation
87 106
        private readonly AsyncManualResetEvent _syncEvent = new AsyncManualResetEvent();
88 107

  
108
        private readonly AsyncManualResetEvent _unPauseEvent = new AsyncManualResetEvent(true);
109

  
89 110
        private readonly ConcurrentDictionary<string, DateTime> _lastSeen = new ConcurrentDictionary<string, DateTime>();
90 111
        private readonly ConcurrentDictionary<Uri, AccountInfo> _accounts = new ConcurrentDictionary<Uri,AccountInfo>();
91 112

  
......
117 138
                var nextSince = since;
118 139
                try
119 140
                {
141
                    await _unPauseEvent.WaitAsync();
120 142
                    UpdateStatus(PithosStatus.PollSyncing);
121 143

  
122 144
                    var tasks = from accountInfo in _accounts.Values
......
164 186
        {
165 187
            var sync = _syncEvent.WaitAsync();
166 188
            var wait = TaskEx.Delay(TimeSpan.FromSeconds(Settings.PollingInterval), NetworkAgent.CancellationToken);
189
            
167 190
            var signaledTask = await TaskEx.WhenAny(sync, wait);
168

  
191
            
192
            //Pausing takes precedence over manual sync or awaiting
193
            _unPauseEvent.Wait();
194
            
169 195
            //Wait for network processing to finish before polling
170 196
            var pauseTask=NetworkAgent.ProceedEvent.WaitAsync();
171 197
            await TaskEx.WhenAll(signaledTask, pauseTask);
......
274 300
                        
275 301
                        var differencer = _differencer.PostSnapshot(accountInfo, cleanRemotes);
276 302

  
277
                        var filterUris = SelectiveUris[accountInfo.AccountKey];
303
                        var filterUris = Selectives.SelectiveUris[accountInfo.AccountKey];
278 304

  
279 305
                        ProcessDeletedFiles(accountInfo, differencer.Deleted.FilterDirectlyBelow(filterUris));
280 306

  
......
295 321
                            .Except(NetworkAgent.GetEnumerable(), new LocalFileComparer())
296 322
                            .ToList();
297 323

  
324
                        await _unPauseEvent.WaitAsync();
298 325
                        //Queue all the actions
299 326
                        foreach (var message in distinctActions)
300 327
                        {
......
355 382

  
356 383
        readonly AccountsDifferencer _differencer = new AccountsDifferencer();
357 384
        private Dictionary<Uri, List<Uri>> _selectiveUris = new Dictionary<Uri, List<Uri>>();
385
        private bool _pause;
358 386

  
359 387
        /// <summary>
360 388
        /// Deletes local files that are not found in the list of cloud files
......
607 635
            }
608 636
        }
609 637

  
610
        public void SetSyncUris(Uri accountKey, Uri[] uris)
611
        {            
612
            SelectiveUris[accountKey]=uris.ToList();
613
        }
614

  
615
        protected Dictionary<Uri,List<Uri>> SelectiveUris
616
        {
617
            get { return _selectiveUris;}
618
            set { _selectiveUris = value; }
619
        }
620

  
621 638
        public void AddAccount(AccountInfo accountInfo)
622 639
        {
623 640
            //Avoid adding a duplicate accountInfo

Also available in: Unified diff