commit cfed7823a8bd55d0a338f8ffb60e5734f930fb8b
Author: Panagiotis Kanavos <pkanavos@gmail.com>
Date:   Thu Oct 13 23:14:47 2011 +0300

    Added log4net for client profile
    Refactored to allow retrieval of shared objects

diff --git a/trunk/Pithos.Core/Agents/FileAgent.cs b/trunk/Pithos.Core/Agents/FileAgent.cs
index 8b67103..44f032c 100644
--- a/trunk/Pithos.Core/Agents/FileAgent.cs
+++ b/trunk/Pithos.Core/Agents/FileAgent.cs
@@ -27,10 +27,18 @@ namespace Pithos.Core.Agents
 
         public string RootPath { get; private set; }
 
+
         public void Start(string rootPath)
         {
+            if (String.IsNullOrWhiteSpace(rootPath))
+                throw new ArgumentNullException("rootPath");
+            if (!Path.IsPathRooted(rootPath))
+                throw new ArgumentException("rootPath must be an absolute path","rootPath");
+            Contract.EndContractBlock();
+
             RootPath = rootPath;
             _watcher = new FileSystemWatcher(rootPath);
+            _watcher.IncludeSubdirectories = true;            
             _watcher.Changed += OnFileEvent;
             _watcher.Created += OnFileEvent;
             _watcher.Deleted += OnFileEvent;
@@ -55,6 +63,10 @@ namespace Pithos.Core.Agents
 
         private Task<object> Process(WorkflowState state)
         {
+            if (state==null)
+                throw new ArgumentNullException("state");
+            Contract.EndContractBlock();
+
             Debug.Assert(!Ignore(state.Path));
 
             var networkState = NetworkGate.GetNetworkState(state.Path);
@@ -116,6 +128,10 @@ namespace Pithos.Core.Agents
 
         public void Post(WorkflowState workflowState)
         {
+            if (workflowState == null)
+                throw new ArgumentNullException("workflowState");
+            Contract.EndContractBlock();
+
             _agent.Post(workflowState);
         }
 
@@ -131,7 +147,8 @@ namespace Pithos.Core.Agents
             }
             _watcher = null;
 
-            _agent.Stop();
+            if (_agent!=null)
+                _agent.Stop();
         }
 
         // Enumerate all files in the Pithos directory except those in the Fragment folder
@@ -217,11 +234,14 @@ namespace Pithos.Core.Agents
 
         private WorkflowState UpdateFileStatus(WorkflowState state)
         {
-            Debug.Assert(!state.Path.Contains("fragments"));
-            Debug.Assert(!state.Path.EndsWith(".ignore", StringComparison.InvariantCultureIgnoreCase));
+            if (state==null)
+                throw new ArgumentNullException("state");
+            if (String.IsNullOrWhiteSpace(state.Path))
+                throw new ArgumentException("The state's Path can't be empty","state");
+            Contract.EndContractBlock();
 
-            string path = state.Path;
-            FileStatus status = _statusDict[state.TriggeringChange];
+            var path = state.Path;
+            var status = _statusDict[state.TriggeringChange];
             var oldStatus = Workflow.StatusKeeper.GetFileStatus(path);
             if (status == oldStatus)
             {
@@ -238,6 +258,10 @@ namespace Pithos.Core.Agents
 
         private WorkflowState UpdateOverlayStatus(WorkflowState state)
         {
+            if (state==null)
+                throw new ArgumentNullException("state");
+            Contract.EndContractBlock();
+
             if (state.Skip)
                 return state;
 
@@ -248,10 +272,10 @@ namespace Pithos.Core.Agents
                     this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified);
                     break;
                 case FileStatus.Deleted:
-                    //this.StatusKeeper.RemoveFileOverlayStatus(state.Path);
+                    //this.StatusAgent.RemoveFileOverlayStatus(state.Path);
                     break;
                 case FileStatus.Renamed:
-                    this.StatusKeeper.RemoveFileOverlayStatus(state.OldPath);
+                    this.StatusKeeper.ClearFileStatus(state.OldPath);
                     this.StatusKeeper.SetFileOverlayStatus(state.Path, FileOverlayStatus.Modified);
                     break;
                 case FileStatus.Unchanged:
@@ -319,7 +343,7 @@ namespace Pithos.Core.Agents
             Contract.EndContractBlock();            
 
             var absolutePath = Path.Combine(RootPath, relativePath);
-            Debug.Assert(File.Exists(absolutePath),String.Format("Path {0} doesn't exist",absolutePath));
+//            Debug.Assert(File.Exists(absolutePath),String.Format("Path {0} doesn't exist",absolutePath));
 
             return new FileInfo(absolutePath);
             
