Revision 0b346191 trunk/Pithos.Core/Agents/NetworkAgent.cs

b/trunk/Pithos.Core/Agents/NetworkAgent.cs
44 44
using System.IO;
45 45
using System.Linq;
46 46
using System.Net;
47
using System.Threading;
47 48
using System.Threading.Tasks;
48 49
using System.Threading.Tasks.Dataflow;
49 50
using Castle.ActiveRecord;
......
63 64
        private ActionBlock<CloudDeleteAction> _deleteAgent;
64 65
        readonly ConcurrentDictionary<string,DateTime> _deletedFiles=new ConcurrentDictionary<string, DateTime>();
65 66

  
67

  
68
        private readonly AutoResetEvent _pauseAgent = new AutoResetEvent(false);
69

  
66 70
        [System.ComponentModel.Composition.Import]
67 71
        public IStatusKeeper StatusKeeper { get; set; }
68 72
        
......
80 84
                Action loop = null;
81 85
                loop = () =>
82 86
                {
87
                    _pauseAgent.WaitOne();
83 88
                    var message = inbox.Receive();
84 89
                    var process=message.Then(Process,inbox.CancellationToken);
85 90
                    inbox.LoopAsync(process, loop);
......
228 233
                    //agent
229 234
                    using (var gate = NetworkGate.Acquire(action.LocalFile.FullName, NetworkOperation.Deleting))
230 235
                    {
231
                        
236

  
232 237
                        //Add the file URL to the deleted files list
233 238
                        var key = GetFileKey(action.CloudFile);
234
                        _deletedFiles[key]=DateTime.Now;
235

  
239
                        _deletedFiles[key] = DateTime.Now;
236 240

  
241
                        _pauseAgent.Reset();
237 242
                        // and then delete the file from the server
238 243
                        DeleteCloudFile(accountInfo, cloudFile);
239 244

  
......
254 259
                    Log.ErrorFormat("{0} : {1} -> {2}  failed because the directory was not found.\n Rescheduling a delete",
255 260
                        action.Action, action.LocalFile, action.CloudFile);
256 261
                    //Repost a delete action for the missing file
257
                    _deleteAgent.Post(action);                    
262
                    _deleteAgent.Post(action);
258 263
                }
259 264
                catch (FileNotFoundException)
260 265
                {
......
269 274
                                     action.Action, action.LocalFile, action.CloudFile, exc);
270 275

  
271 276
                    _deleteAgent.Post(action);
272
                }                
277
                }
278
                finally
279
                {
280
                    if (_deleteAgent.InputCount == 0)
281
                        _pauseAgent.Set();
282

  
283
                }
273 284
            }
274 285
        }
275 286

  

Also available in: Unified diff