11using System . Diagnostics . CodeAnalysis ;
2+ using System . Runtime . CompilerServices ;
23using System . Text . Json . Serialization ;
34using Microsoft . Extensions . FileSystemGlobbing ;
45using Microsoft . Extensions . FileSystemGlobbing . Abstractions ;
6+ using Microsoft . Extensions . Logging ;
57using ModularPipelines . JsonUtils ;
8+ using ModularPipelines . Logging ;
69
710namespace ModularPipelines . FileSystem ;
811
@@ -71,14 +74,23 @@ public Folder Root
7174
7275 public Folder Create ( )
7376 {
77+ ModuleLogger . Current . LogInformation ( "Creating Folder: {Path}" , this ) ;
78+
7479 Directory . CreateDirectory ( Path ) ;
7580 return this ;
7681 }
7782
78- public void Delete ( ) => DirectoryInfo . Delete ( true ) ;
83+ public void Delete ( )
84+ {
85+ ModuleLogger . Current . LogInformation ( "Deleting Folder: {Path}" , this ) ;
86+
87+ DirectoryInfo . Delete ( true ) ;
88+ }
7989
8090 public void Clean ( )
8191 {
92+ ModuleLogger . Current . LogInformation ( "Cleaning Folder: {Path}" , this ) ;
93+
8294 foreach ( var directory in DirectoryInfo . EnumerateDirectories ( "*" , SearchOption . TopDirectoryOnly ) )
8395 {
8496 directory . Delete ( true ) ;
@@ -103,40 +115,80 @@ public Folder CopyTo(string targetPath)
103115 {
104116 System . IO . File . Copy ( newPath , newPath . Replace ( this , targetPath ) , true ) ;
105117 }
118+
119+ ModuleLogger . Current . LogInformation ( "Copying Folder: {Source} > {Destination}" , this , targetPath ) ;
106120
107121 return new Folder ( targetPath ) ;
108122 }
109123
110124 public Folder MoveTo ( string path )
111125 {
126+ ModuleLogger . Current . LogInformation ( "Moving Folder: {Source} > {Destination}" , this , path ) ;
127+
112128 DirectoryInfo . MoveTo ( path ) ;
113129 return this ;
114130 }
115131
116- public Folder GetFolder ( string name ) => new DirectoryInfo ( System . IO . Path . Combine ( Path , name ) ) ;
132+ public Folder GetFolder ( string name )
133+ {
134+ var directoryInfo = new DirectoryInfo ( System . IO . Path . Combine ( Path , name ) ) ;
135+
136+ ModuleLogger . Current . LogInformation ( "Getting Folder: {Path}" , directoryInfo . FullName ) ;
137+
138+ return directoryInfo ;
139+ }
117140
118- public Folder CreateFolder ( string name ) => GetFolder ( name ) . Create ( ) ;
141+ public Folder CreateFolder ( string name )
142+ {
143+ var folder = GetFolder ( name ) . Create ( ) ;
144+
145+ ModuleLogger . Current . LogInformation ( "Creating Folder: {Path}" , folder ) ;
146+
147+ return folder ;
148+ }
119149
120- public File GetFile ( string name ) => new FileInfo ( System . IO . Path . Combine ( Path , name ) ) ;
150+ public File GetFile ( string name )
151+ {
152+ var fileInfo = new FileInfo ( System . IO . Path . Combine ( Path , name ) ) ;
153+
154+ ModuleLogger . Current . LogInformation ( "Getting File: {Path}" , fileInfo . FullName ) ;
155+
156+ return fileInfo ;
157+ }
121158
122- public File CreateFile ( string name ) => GetFile ( name ) . Create ( ) ;
159+ public File CreateFile ( string name )
160+ {
161+ return GetFile ( name ) . Create ( ) ;
162+ }
123163
124- public IEnumerable < Folder > GetFolders ( Func < Folder , bool > predicate ) = > GetFolders ( predicate , _ => false ) ;
164+ public IEnumerable < Folder > GetFolders ( Func < Folder , bool > predicate , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > GetFolders ( predicate , _ => false , predicateExpression ) ;
125165
126- public IEnumerable < File > GetFiles ( Func < File , bool > predicate ) = > GetFiles ( predicate , _ => false ) ;
166+ public IEnumerable < File > GetFiles ( Func < File , bool > predicate , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > GetFiles ( predicate , _ => false , predicateExpression ) ;
127167
128- public IEnumerable < Folder > GetFolders ( Func < Folder , bool > predicate , Func < Folder , bool > exclusionFilters ) => SafeWalk . EnumerateFolders ( this , exclusionFilters )
129- . Select ( x => new Folder ( x ) )
130- . Distinct ( )
131- . Where ( predicate ) ;
168+ public IEnumerable < Folder > GetFolders ( Func < Folder , bool > predicate , Func < Folder , bool > exclusionFilters , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" )
169+ {
170+ ModuleLogger . Current . LogInformation ( "Searching Folders in: {Path} > {Expression}" , this , predicate ) ;
132171
133- public IEnumerable < File > GetFiles ( Func < File , bool > predicate , Func < Folder , bool > directoryExclusionFilters ) => SafeWalk . EnumerateFiles ( this , directoryExclusionFilters )
134- . Select ( x => new File ( x ) )
135- . Distinct ( )
136- . Where ( predicate ) ;
172+ return SafeWalk . EnumerateFolders ( this , exclusionFilters )
173+ . Select ( x => new Folder ( x ) )
174+ . Distinct ( )
175+ . Where ( predicate ) ;
176+ }
177+
178+ public IEnumerable < File > GetFiles ( Func < File , bool > predicate , Func < Folder , bool > directoryExclusionFilters , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" )
179+ {
180+ ModuleLogger . Current . LogInformation ( "Searching Files in: {Path} > {Expression}" , this , predicate ) ;
181+
182+ return SafeWalk . EnumerateFiles ( this , directoryExclusionFilters )
183+ . Select ( x => new File ( x ) )
184+ . Distinct ( )
185+ . Where ( predicate ) ;
186+ }
137187
138188 public IEnumerable < File > GetFiles ( string globPattern )
139189 {
190+ ModuleLogger . Current . LogInformation ( "Searching Files in: {Path} > {Glob}" , this , globPattern ) ;
191+
140192 return new Matcher ( StringComparison . OrdinalIgnoreCase )
141193 . AddInclude ( globPattern )
142194 . Execute ( new DirectoryInfoWrapper ( DirectoryInfo ) )
@@ -145,13 +197,13 @@ public IEnumerable<File> GetFiles(string globPattern)
145197 . Distinct ( ) ;
146198 }
147199
148- public File ? FindFile ( Func < File , bool > predicate ) = > FindFile ( predicate , _ => false ) ;
200+ public File ? FindFile ( Func < File , bool > predicate , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > FindFile ( predicate , _ => false , predicateExpression ) ;
149201
150- public Folder ? FindFolder ( Func < Folder , bool > predicate ) = > FindFolder ( predicate , _ => false ) ;
202+ public Folder ? FindFolder ( Func < Folder , bool > predicate , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > FindFolder ( predicate , _ => false , predicateExpression ) ;
151203
152- public File ? FindFile ( Func < File , bool > predicate , Func < Folder , bool > directoryExclusionFilters ) = > GetFiles ( predicate , directoryExclusionFilters ) . FirstOrDefault ( ) ;
204+ public File ? FindFile ( Func < File , bool > predicate , Func < Folder , bool > directoryExclusionFilters , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > GetFiles ( predicate , directoryExclusionFilters , predicateExpression ) . FirstOrDefault ( ) ;
153205
154- public Folder ? FindFolder ( Func < Folder , bool > predicate , Func < Folder , bool > directoryExclusionFilters ) = > GetFolders ( predicate , directoryExclusionFilters ) . FirstOrDefault ( ) ;
206+ public Folder ? FindFolder ( Func < Folder , bool > predicate , Func < Folder , bool > directoryExclusionFilters , [ CallerArgumentExpression ( "predicate" ) ] string predicateExpression = "" ) = > GetFolders ( predicate , directoryExclusionFilters , predicateExpression ) . FirstOrDefault ( ) ;
155207
156208 public IEnumerable < File > ListFiles ( )
157209 {
@@ -171,6 +223,9 @@ public static Folder CreateTemporaryFolder()
171223 {
172224 var tempDirectory = System . IO . Path . Combine ( System . IO . Path . GetTempPath ( ) , System . IO . Path . GetRandomFileName ( ) . Replace ( "." , string . Empty ) ) ;
173225 Directory . CreateDirectory ( tempDirectory ) ;
226+
227+ ModuleLogger . Current . LogInformation ( "Creating Temporary Folder: {Path}" , tempDirectory ) ;
228+
174229 return tempDirectory ! ;
175230 }
176231
0 commit comments