66
77namespace ServiceStack . VirtualPath
88{
9- public interface IWriteableVirtualPathProvider : IVirtualPathProvider
9+ public static class VirtualPathProviderExtensions
1010 {
11- void WriteFile ( string filePath , string textContents ) ;
11+ private const string ErrorNotWritable = "{0} does not implement IVirtualFileSystem" ;
1212
13- void WriteFile ( string filePath , Stream stream ) ;
14-
15- void WriteFiles ( IEnumerable < IVirtualFile > files , Func < IVirtualFile , string > toPath = null ) ;
16-
17- void DeleteFile ( string filePath ) ;
18-
19- void DeleteFiles ( IEnumerable < string > filePaths ) ;
20-
21- void DeleteFolder ( string dirPath ) ;
22- }
13+ public static bool IsFile ( this IVirtualPathProvider pathProvider , string filePath )
14+ {
15+ return pathProvider . GetFile ( filePath ) != null ;
16+ }
2317
24- public static class WriteableVirtualPathProviderExtensions
25- {
26- private const string ErrorNotWritable = "{0} does not implement IWriteableVirtualPathProvider" ;
18+ public static bool IsDirectory ( this IVirtualPathProvider pathProvider , string filePath )
19+ {
20+ return pathProvider . GetDirectory ( filePath ) != null ;
21+ }
2722
2823 [ Obsolete ( "Renamed to WriteFile" ) ]
2924 public static void AddFile ( this IVirtualPathProvider pathProvider , string filePath , string textContents )
@@ -33,7 +28,7 @@ public static void AddFile(this IVirtualPathProvider pathProvider, string filePa
3328
3429 public static void WriteFile ( this IVirtualPathProvider pathProvider , string filePath , string textContents )
3530 {
36- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
31+ var writableFs = pathProvider as IVirtualFileSystem ;
3732 if ( writableFs == null )
3833 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
3934
@@ -42,7 +37,7 @@ public static void WriteFile(this IVirtualPathProvider pathProvider, string file
4237
4338 public static void WriteFile ( this IVirtualPathProvider pathProvider , string filePath , Stream stream )
4439 {
45- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
40+ var writableFs = pathProvider as IVirtualFileSystem ;
4641 if ( writableFs == null )
4742 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
4843
@@ -51,7 +46,7 @@ public static void WriteFile(this IVirtualPathProvider pathProvider, string file
5146
5247 public static void WriteFile ( this IVirtualPathProvider pathProvider , string filePath , byte [ ] bytes )
5348 {
54- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
49+ var writableFs = pathProvider as IVirtualFileSystem ;
5550 if ( writableFs == null )
5651 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
5752
@@ -63,7 +58,7 @@ public static void WriteFile(this IVirtualPathProvider pathProvider, string file
6358
6459 public static void DeleteFile ( this IVirtualPathProvider pathProvider , string filePath )
6560 {
66- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
61+ var writableFs = pathProvider as IVirtualFileSystem ;
6762 if ( writableFs == null )
6863 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
6964
@@ -72,16 +67,25 @@ public static void DeleteFile(this IVirtualPathProvider pathProvider, string fil
7267
7368 public static void DeleteFiles ( this IVirtualPathProvider pathProvider , IEnumerable < string > filePaths )
7469 {
75- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
70+ var writableFs = pathProvider as IVirtualFileSystem ;
7671 if ( writableFs == null )
7772 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
7873
7974 writableFs . DeleteFiles ( filePaths ) ;
8075 }
8176
77+ public static void DeleteFiles ( this IVirtualPathProvider pathProvider , IEnumerable < IVirtualFile > files )
78+ {
79+ var writableFs = pathProvider as IVirtualFileSystem ;
80+ if ( writableFs == null )
81+ throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
82+
83+ writableFs . DeleteFiles ( files . Map ( x => x . VirtualPath ) ) ;
84+ }
85+
8286 public static void DeleteFolder ( this IVirtualPathProvider pathProvider , string dirPath )
8387 {
84- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
88+ var writableFs = pathProvider as IVirtualFileSystem ;
8589 if ( writableFs == null )
8690 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
8791
@@ -90,7 +94,7 @@ public static void DeleteFolder(this IVirtualPathProvider pathProvider, string d
9094
9195 public static void WriteFiles ( this IVirtualPathProvider pathProvider , IEnumerable < IVirtualFile > srcFiles , Func < IVirtualFile , string > toPath = null )
9296 {
93- var writableFs = pathProvider as IWriteableVirtualPathProvider ;
97+ var writableFs = pathProvider as IVirtualFileSystem ;
9498 if ( writableFs == null )
9599 throw new InvalidOperationException ( ErrorNotWritable . Fmt ( pathProvider . GetType ( ) . Name ) ) ;
96100
0 commit comments