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;
14 [Export(typeof(IPithosWorkflow))]
15 public class PithosWorkflow:IPithosWorkflow
18 public IPithosSettings Settings { get; set; }
21 public IStatusKeeper StatusKeeper { get; set; }
23 public FileStatus SetFileStatus(string path, FileStatus status)
25 if (String.IsNullOrWhiteSpace(path))
26 throw new ArgumentNullException("path", "The path parameter must not be emtpy");
28 var oldStatus=StatusKeeper.GetFileStatus(path);
30 if (oldStatus == status)
35 case FileStatus.Unchanged :
37 case FileStatus.Created:
38 if (status == FileStatus.Modified)
41 case FileStatus.Modified:
42 case FileStatus.Renamed:
43 if (status == FileStatus.Created)
46 case FileStatus.Deleted:
49 StatusKeeper.SetFileStatus(path, status);
53 public void ClearFileStatus(string path)
55 if (String.IsNullOrWhiteSpace(path))
56 throw new ArgumentNullException("path", "The path parameter must not be emtpy");
58 StatusKeeper.ClearFileStatus(path);
61 public void RaiseChangeNotification(string path)
63 if (String.IsNullOrWhiteSpace(path))
64 throw new ArgumentNullException("path", "The path parameter must not be emtpy");
66 if (!Directory.Exists(path ) && !File.Exists(path))
67 throw new FileNotFoundException("The specified file or path does not exist",path);
70 IntPtr pathPointer = Marshal.StringToCoTaskMemAuto(path);
74 NativeMethods.SHChangeNotify(HChangeNotifyEventID.SHCNE_UPDATEITEM,
75 HChangeNotifyFlags.SHCNF_PATHW | HChangeNotifyFlags.SHCNF_FLUSHNOWAIT,
76 pathPointer, IntPtr.Zero);
80 Marshal.FreeHGlobal(pathPointer);
85 public Task<FileStream> OpenStreamWithWaiting(string path)
87 if (String.IsNullOrWhiteSpace(path))
88 throw new ArgumentNullException("path","The path parameter must not be emtpy");
90 if (!File.Exists(path))
91 throw new FileNotFoundException("The specified file or path does not exist", path);
93 return new Task<FileStream>(() =>
100 var stream=File.OpenRead(path);