2 using System.Collections.Generic;
3 using System.ComponentModel.Composition;
5 using System.Runtime.InteropServices;
7 using System.Threading;
8 using System.Threading.Tasks;
9 using Pithos.Interfaces;
11 using System.Diagnostics;
16 [Export(typeof(IPithosWorkflow))]
17 public class PithosWorkflow:IPithosWorkflow
20 public IPithosSettings Settings { get; set; }
23 public IStatusKeeper StatusKeeper { get; set; }
25 public FileStatus SetFileStatus(string path, FileStatus status)
27 Debug.Assert(!path.Contains(FolderConstants.CacheFolder));
28 Debug.Assert(!path.EndsWith(".ignore",StringComparison.InvariantCultureIgnoreCase));
30 if (String.IsNullOrWhiteSpace(path))
31 throw new ArgumentNullException("path", "The path parameter must not be emtpy");
33 var oldStatus=StatusKeeper.GetFileStatus(path);
35 if (oldStatus == status)
40 case FileStatus.Unchanged :
42 case FileStatus.Created:
43 if (status == FileStatus.Modified)
46 case FileStatus.Modified:
47 case FileStatus.Renamed:
48 if (status == FileStatus.Created)
51 case FileStatus.Deleted:
54 StatusKeeper.SetFileStatus(path, status);
58 public void ClearFileStatus(string path)
60 if (String.IsNullOrWhiteSpace(path))
61 throw new ArgumentNullException("path", "The path parameter must not be emtpy");
63 StatusKeeper.ClearFileStatus(path.ToLower());
67 public Task<FileStream> OpenStreamWithWaiting(string path)
69 if (String.IsNullOrWhiteSpace(path))
70 throw new ArgumentNullException("path","The path parameter must not be emtpy");
72 if (!File.Exists(path))
73 throw new FileNotFoundException("The specified file or path does not exist", path);
75 return new Task<FileStream>(() =>
82 var stream=File.OpenRead(path);