Revision 4ec636f6 trunk/Pithos.Core/Agents/StatusAgent.cs

b/trunk/Pithos.Core/Agents/StatusAgent.cs
7 7
using System.Linq;
8 8
using System.Threading;
9 9
using System.Threading.Tasks;
10
using System.Threading.Tasks.Dataflow;
11 10
using Castle.ActiveRecord;
12 11
using Castle.ActiveRecord.Framework.Config;
13 12
using Pithos.Interfaces;
......
25 24
        [System.ComponentModel.Composition.Import]
26 25
        public IPithosSettings Settings { get; set; }
27 26

  
28
        //private Agent<Action> _persistenceAgent;
29
        private ActionBlock<Action> _persistenceAgent;
27
        private Agent<Action> _persistenceAgent;
30 28

  
31 29

  
32 30
        private static readonly ILog Log = LogManager.GetLogger("StatusAgent");
......
76 74

  
77 75
        public void StartProcessing(CancellationToken token)
78 76
        {
79
            _persistenceAgent = new ActionBlock<Action>(async action=>
77
            _persistenceAgent = Agent<Action>.Start(queue =>
80 78
            {
81
                    try
82
                    {
83
                        await TaskEx.Run(action);
84
                    }
85
                    catch (Exception ex)
79
                Action loop = null;
80
                loop = () =>
81
                {
82
                    var job = queue.Receive();
83
                    job.ContinueWith(t =>
86 84
                    {
87
                        Log.ErrorFormat("[ERROR] STATE \n{0}",ex);
88
                    }
85
                        var action = job.Result;
86
                        try
87
                        {
88
                            action();
89
                        }
90
                        catch (Exception ex)
91
                        {
92
                            Log.ErrorFormat("[ERROR] STATE \n{0}",ex);
93
                        }
94
                        queue.DoAsync(loop);
95
                    });
96
                };
97
                loop();
89 98
            });
90 99
            
91 100
        }
......
94 103

  
95 104
        public void Stop()
96 105
        {
97
            _persistenceAgent.Complete();            
106
            _persistenceAgent.Stop();            
98 107
        }
99 108
       
100 109

  
......
118 127
                             select new {state.Id, state.FilePath}).ToList();
119 128
            //and check each one
120 129
            var missingStates= (from path in statePaths
121
                               where !File.Exists(path.FilePath)
130
                                where !File.Exists(path.FilePath) && !Directory.Exists(path.FilePath)
122 131
                               select path.Id).ToList();
123 132
            //Finally, retrieve the states that correspond to the deleted files            
124 133
            var deletedFiles = from state in fileStates 
......
245 254
                    }
246 255
                    else
247 256
                    {
248
                        state = new FileState {FilePath = filePath};
257
                        state = new FileState {FilePath = filePath,Id=Guid.NewGuid()};
249 258
                        setter(state);
250 259
                        state.Save();
251 260
                    }                    
......
287 296
                    if (state == null)
288 297
                    {
289 298
                        Log.WarnFormat("[NOFILE] Unable to set status for {0}.", filePath);
290
                        return;
299
                        state = new FileState { FilePath = path, Id = Guid.NewGuid() };
300
                        state.Create();                        
291 301
                    }
292 302
                    setter(state);
293 303
                    state.Save();
......
335 345

  
336 346
            try
337 347
            {
338
                var state = FileState.FindByFilePath(path);
339
                return state == null ? FileOverlayStatus.Unversioned : state.OverlayStatus;
348

  
349
                //var state = FileState.FindByFilePath(path);
350
                var st=from state in FileState.Queryable
351
                       where state.FilePath == path.ToLower()
352
                       select state.OverlayStatus; ;                
353
                return st.FirstOrDefault(); // state == null ? FileOverlayStatus.Unversioned : state.OverlayStatus;
340 354
            }
341 355
            catch (Exception exc)
342 356
            {
......
427 441
                throw new ArgumentException("The path must be rooted", "path");
428 442
            Contract.EndContractBlock();
429 443

  
444
            checked HERE to fix conflicts
445

  
430 446
            UpdateStatus(path.ToLower(),state=>
431 447
                                  {
432 448
                                      state.FileStatus = fileStatus;

Also available in: Unified diff