Revision 174bbb6e trunk/Pithos.Core/Agents/FileAgent.cs

b/trunk/Pithos.Core/Agents/FileAgent.cs
41 41
#endregion
42 42
using System;
43 43
using System.Collections.Generic;
44
using System.ComponentModel.Composition;
45
using System.Diagnostics;
46 44
using System.Diagnostics.Contracts;
47 45
using System.IO;
48 46
using System.Linq;
49 47
using System.Reflection;
50
using System.Text;
51 48
using System.Threading.Tasks;
52 49
using Pithos.Interfaces;
53 50
using Pithos.Network;
54 51
using log4net;
55
using log4net.Core;
56 52

  
57 53
namespace Pithos.Core.Agents
58 54
{
......
67 63

  
68 64
        //[Import]
69 65
        public IStatusKeeper StatusKeeper { get; set; }
66

  
67
        public IStatusNotification StatusNotification { get; set; }
70 68
        //[Import]
71 69
        public IPithosWorkflow Workflow { get; set; }
72 70
        //[Import]
......
89 87

  
90 88
            AccountInfo = accountInfo;
91 89
            RootPath = rootPath;
92
            _watcher = new FileSystemWatcher(rootPath) {IncludeSubdirectories = true};
90
            _watcher = new FileSystemWatcher(rootPath) {IncludeSubdirectories = true,InternalBufferSize=8*4096};
93 91
            _adapter = new FileSystemWatcherAdapter(_watcher);
94 92

  
95 93
            _adapter.Changed += OnFileEvent;
96 94
            _adapter.Created += OnFileEvent;
97 95
            _adapter.Deleted += OnFileEvent;
98
            _adapter.Renamed += OnRenameEvent;
96
            //_adapter.Renamed += OnRenameEvent;
99 97
            _adapter.Moved += OnMoveEvent;
100 98
            _watcher.EnableRaisingEvents = true;
101 99

  
......
135 133

  
136 134
            try
137 135
            {
136
                //StatusKeeper.EnsureFileState(state.Path);
137
                
138 138
                UpdateFileStatus(state);
139 139
                UpdateOverlayStatus(state);
140 140
                UpdateFileChecksum(state);
......
193 193
        {
194 194
            if (_watcher != null)
195 195
            {
196
                _watcher.Changed -= OnFileEvent;
197
                _watcher.Created -= OnFileEvent;
198
                _watcher.Deleted -= OnFileEvent;
199
                _watcher.Renamed -= OnRenameEvent;
200 196
                _watcher.Dispose();
201 197
            }
202 198
            _watcher = null;
......
329 325
        }
330 326

  
331 327

  
328
/*
332 329
        //Post a Change message for renames containing the old and new names
333 330
        void OnRenameEvent(object sender, RenamedEventArgs e)
334 331
        {
......
347 344
                TriggeringChange = e.ChangeType
348 345
            });
349 346
        }
347
*/
350 348

  
351
        //Post a Change message for renames containing the old and new names
349
        //Post a Change message for moves containing the old and new names
352 350
        void OnMoveEvent(object sender, MovedEventArgs e)
353 351
        {
354 352
            var oldFullPath = e.OldFullPath;
......
415 413
            switch (state.Status)
416 414
            {
417 415
                case FileStatus.Created:
416
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash);
417
                    break;
418 418
                case FileStatus.Modified:
419
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified);
419
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash);
420 420
                    break;
421 421
                case FileStatus.Deleted:
422 422
                    //this.StatusAgent.RemoveFileOverlayStatus(state.Path);
423 423
                    break;
424 424
                case FileStatus.Renamed:
425 425
                    this.StatusKeeper.ClearFileStatus(state.OldPath);
426
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified);
426
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified,state.ShortHash);
427 427
                    break;
428 428
                case FileStatus.Unchanged:
429
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Normal);
429
                    this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Normal,state.ShortHash);
430 430
                    break;
431 431
            }
432 432

  
......
451 451
            if (Directory.Exists(path))
452 452
                return state;
453 453

  
454

  
454 455
            var info = new FileInfo(path);
455
            string hash = info.CalculateHash(StatusKeeper.BlockSize,StatusKeeper.BlockHash);
456
            StatusKeeper.UpdateFileChecksum(path, hash);
456
            StatusNotification.Notify(new StatusNotification(String.Format("Hashing [{0}]",info.Name)));
457

  
458
            var shortHash = info.ComputeShortHash(); 
459
            
460
            string merkleHash = info.CalculateHash(StatusKeeper.BlockSize,StatusKeeper.BlockHash);
461
            StatusKeeper.UpdateFileChecksum(path,shortHash, merkleHash);
457 462

  
458
            state.Hash = hash;
463
            state.Hash = merkleHash;
459 464
            return state;
460 465
        }
461 466

  

Also available in: Unified diff