Replaced object load and update with direct HQL execution to resolve database locks...
[pithos-ms-client] / trunk / Pithos.Core / Agents / FileAgent.cs
index 37891b9..761199c 100644 (file)
@@ -14,31 +14,36 @@ using log4net.Core;
 
 namespace Pithos.Core.Agents
 {
-    [Export]
+//    [Export]
     public class FileAgent
     {
         Agent<WorkflowState> _agent;
         private FileSystemWatcher _watcher;
 
-        [Import]
+        //[Import]
         public IStatusKeeper StatusKeeper { get; set; }
-        [Import]
+        //[Import]
         public IPithosWorkflow Workflow { get; set; }
-        [Import]
+        //[Import]
         public WorkflowAgent WorkflowAgent { get; set; }
 
-        public string RootPath { get; private set; }
+        private AccountInfo AccountInfo { get; set; }
+
+        private string RootPath { get;  set; }
 
         private static readonly ILog Log = LogManager.GetLogger("FileAgent");
 
-        public void Start(string rootPath)
+        public void Start(AccountInfo accountInfo,string rootPath)
         {
+            if (accountInfo==null)
+                throw new ArgumentNullException("accountInfo");
             if (String.IsNullOrWhiteSpace(rootPath))
                 throw new ArgumentNullException("rootPath");
             if (!Path.IsPathRooted(rootPath))
                 throw new ArgumentException("rootPath must be an absolute path","rootPath");
             Contract.EndContractBlock();
 
+            AccountInfo = accountInfo;
             RootPath = rootPath;
             _watcher = new FileSystemWatcher(rootPath);
             _watcher.IncludeSubdirectories = true;            
@@ -103,20 +108,12 @@ namespace Pithos.Core.Agents
             }
             catch (Exception exc)
             {
-                Log.WarnFormat("Error occured while indexing{0. The file will be skipped}\n{1}", state.Path, exc);
+                Log.WarnFormat("Error occured while indexing{0}. The file will be skipped\n{1}",
+                               state.Path, exc);
             }
             return CompletedTask<object>.Default;
         }
 
-
-/*
-        private Task Process(Task<WorkflowState> action)
-        {
-            return action.ContinueWith(t => Process(t.Result));
-        }
-*/
-
-
         public bool Pause
         {
             get { return _watcher == null || !_watcher.EnableRaisingEvents; }
@@ -127,7 +124,15 @@ namespace Pithos.Core.Agents
             }
         }
 
-        public string FragmentsPath { get; set; }
+        public string CachePath { get; set; }
+
+        private List<string> _selectivePaths = new List<string>();
+        public List<string> SelectivePaths
+        {
+            get { return _selectivePaths; }
+            set { _selectivePaths = value; }
+        }
+
 
         public void Post(WorkflowState workflowState)
         {
@@ -187,7 +192,7 @@ namespace Pithos.Core.Agents
 
         private bool Ignore(string filePath)
         {
-            if (filePath.StartsWith(FragmentsPath))
+            if (filePath.StartsWith(CachePath))
                 return true;
             if (_ignoreFiles.ContainsKey(filePath.ToLower()))
                 return true;
@@ -197,11 +202,13 @@ namespace Pithos.Core.Agents
         //Post a Change message for all events except rename
         void OnFileEvent(object sender, FileSystemEventArgs e)
         {
-            //Ignore events that affect the Fragments folder
+            //Ignore events that affect the cache folder
             var filePath = e.FullPath;
             if (Ignore(filePath)) 
                 return;
-            _agent.Post(new WorkflowState { Path = filePath, FileName = e.Name, TriggeringChange = e.ChangeType });
+            if (Directory.Exists(filePath))
+                return;            
+            _agent.Post(new WorkflowState{AccountInfo=AccountInfo, Path = filePath, FileName = e.Name, TriggeringChange = e.ChangeType });
         }
 
 
@@ -215,6 +222,7 @@ namespace Pithos.Core.Agents
 
             _agent.Post(new WorkflowState
             {
+                AccountInfo=AccountInfo,
                 OldPath = oldFullPath,
                 OldFileName = e.OldName,
                 Path = fullPath,