Revision 29a6b387 trunk/Pithos.Core/Agents/NetworkAgent.cs

b/trunk/Pithos.Core/Agents/NetworkAgent.cs
80 80
        public IPithosSettings Settings { get; set; }
81 81

  
82 82
        private bool _firstPoll = true;
83
        private TaskCompletionSource<bool> _tcs;
84

  
83 85
        public void Start()
84 86
        {
85 87
            _firstPoll = true;
......
430 432
            }
431 433
        }*/
432 434

  
433
        
435
        public void SynchNow()
436
        {             
437
            if (_tcs!=null)
438
                _tcs.SetResult(true);
439
            else
440
            {
441
                //TODO: This may be OK for testing purposes, but we have no guarantee that it will
442
                //work properly in production
443
                PollRemoteFiles(repeat:false);
444
            }
445
        }
434 446

  
435 447
        //Remote files are polled periodically. Any changes are processed
436
        public async Task PollRemoteFiles(DateTime? since = null)
437
        {            
438
            await TaskEx.Delay(TimeSpan.FromSeconds(Settings.PollingInterval),_agent.CancellationToken);
448
        public async Task PollRemoteFiles(DateTime? since = null,bool repeat=true)
449
        {
450

  
451
            _tcs = new TaskCompletionSource<bool>();
452
            var wait = TaskEx.Delay(TimeSpan.FromSeconds(Settings.PollingInterval), _agent.CancellationToken);
453
            var signaledTask=await TaskEx.WhenAny(_tcs.Task,wait);
454
            //If polling is signalled by SynchNow, ignore the since tag
455
            if (signaledTask is Task<bool>)
456
                since = null;
439 457

  
440 458
            using (log4net.ThreadContext.Stacks["Retrieve Remote"].Push("All accounts"))
441 459
            {
......
452 470
                    await TaskEx.WhenAll(tasks.ToList());
453 471

  
454 472
                    _firstPoll = false;
455
                    PollRemoteFiles(nextSince);
473
                    if (repeat)
474
                        PollRemoteFiles(nextSince);
456 475
                }
457 476
                catch (Exception ex)
458 477
                {

Also available in: Unified diff