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;
}
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; }
}
}
- 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)
{
private bool Ignore(string filePath)
{
- if (filePath.StartsWith(FragmentsPath))
+ if (filePath.StartsWith(CachePath))
return true;
if (_ignoreFiles.ContainsKey(filePath.ToLower()))
return true;
//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 });
}
_agent.Post(new WorkflowState
{
+ AccountInfo=AccountInfo,
OldPath = oldFullPath,
OldFileName = e.OldName,
Path = fullPath,