namespace Pithos.Core.Agents
{
- [Export,PartCreationPolicy(CreationPolicy.NonShared)]
+// [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; }
throw new ArgumentNullException("state");
Contract.EndContractBlock();
- Debug.Assert(!Ignore(state.Path));
+ if (Ignore(state.Path))
+ return CompletedTask<object>.Default;
var networkState = NetworkGate.GetNetworkState(state.Path);
//Skip if the file is already being downloaded or uploaded and
}
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))
+ var pithosPath = Path.Combine(RootPath, "pithos");
+ if (pithosPath.Equals(filePath, StringComparison.InvariantCultureIgnoreCase))
+ return true;
+ 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(AccountInfo) { Path = filePath, FileName = e.Name, TriggeringChange = e.ChangeType });
+
+ _agent.Post(new WorkflowState{AccountInfo=AccountInfo, Path = filePath, FileName = e.Name, TriggeringChange = e.ChangeType });
}
if (Ignore(oldFullPath) || Ignore(fullPath))
return;
- _agent.Post(new WorkflowState(AccountInfo)
+ _agent.Post(new WorkflowState
{
+ AccountInfo=AccountInfo,
OldPath = oldFullPath,
OldFileName = e.OldName,
Path = fullPath,
return false;
}
- public FileInfo GetFileInfo(string relativePath)
+ public FileSystemInfo GetFileSystemInfo(string relativePath)
{
if (String.IsNullOrWhiteSpace(relativePath))
throw new ArgumentNullException("relativePath");
Contract.EndContractBlock();
var absolutePath = Path.Combine(RootPath, relativePath);
-// Debug.Assert(File.Exists(absolutePath),String.Format("Path {0} doesn't exist",absolutePath));
- return new FileInfo(absolutePath);
+ if (Directory.Exists(absolutePath))
+ return new DirectoryInfo(absolutePath).WithProperCapitalization();
+ else
+ return new FileInfo(absolutePath).WithProperCapitalization();
}
public void Delete(string relativePath)
{
- var absolutePath = Path.Combine(RootPath, relativePath);
+ var absolutePath = Path.Combine(RootPath, relativePath).ToLower();
if (File.Exists(absolutePath))
- {
- File.Delete(absolutePath);
- _ignoreFiles[absolutePath.ToLower()] = absolutePath.ToLower();
+ {
+ try
+ {
+ File.Delete(absolutePath);
+ }
+ //The file may have been deleted by another thread. Just ignore the relevant exception
+ catch (FileNotFoundException) { }
}
+ else if (Directory.Exists(absolutePath))
+ {
+ try
+ {
+ Directory.Delete(absolutePath, true);
+ }
+ //The directory may have been deleted by another thread. Just ignore the relevant exception
+ catch (DirectoryNotFoundException){}
+ }
+
+ //_ignoreFiles[absolutePath] = absolutePath;
StatusKeeper.ClearFileStatus(absolutePath);
}
}