Replaced object load and update with direct HQL execution to resolve database locks...
[pithos-ms-client] / trunk / Pithos.Core / Agents / FileAgent.cs
index ba323a3..761199c 100644 (file)
@@ -14,17 +14,17 @@ 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; }
 
         private AccountInfo AccountInfo { get; set; }
@@ -108,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; }
@@ -132,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)
         {
@@ -192,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;
@@ -202,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(AccountInfo) { 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 });
         }
 
 
@@ -218,8 +220,9 @@ namespace Pithos.Core.Agents
             if (Ignore(oldFullPath) || Ignore(fullPath))
                 return;
 
-            _agent.Post(new WorkflowState(AccountInfo)
+            _agent.Post(new WorkflowState
             {
+                AccountInfo=AccountInfo,
                 OldPath = oldFullPath,
                 OldFileName = e.OldName,
                 Path = fullPath,