@@ -25,10 +25,12 @@ public partial class DataLakeFunctions
2525 {
2626 private readonly ILogger < DataLakeFunctions > _logger ;
2727 private readonly DataLakeConfigFactory _configFactory ;
28- public DataLakeFunctions ( ILogger < DataLakeFunctions > logger , DataLakeConfigFactory configFactory )
28+ private readonly IDataLakeClientFactory _clientFactory ;
29+ public DataLakeFunctions ( ILogger < DataLakeFunctions > logger , DataLakeConfigFactory configFactory , IDataLakeClientFactory clientFactory )
2930 {
3031 _logger = logger ;
3132 _configFactory = configFactory ;
33+ _clientFactory = clientFactory ;
3234 }
3335
3436
@@ -50,9 +52,8 @@ public async Task<IActionResult> DataLakeGetItems(
5052 if ( string . IsNullOrWhiteSpace ( dataLakeConfig . AccountUri ) )
5153 throw new ArgumentException ( $ "Account Uri '{ dataLakeConfig . AccountUri } ' not found. Check the URI is correct.") ;
5254
53- var clientFactory = new DataLakeClientFactory ( _logger ) ;
54- var client = clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
55- return await GetItemsAsync ( client , dataLakeConfig , getItemsConfig , _logger ) ;
55+ var client = _clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
56+ return await GetItemsAsync ( client , dataLakeConfig , getItemsConfig ) ;
5657 }
5758 catch ( ArgumentException ex )
5859 {
@@ -83,15 +84,14 @@ public async Task<IActionResult> DataLakeCheckPathCase(
8384 if ( string . IsNullOrWhiteSpace ( dataLakeConfig . AccountUri ) )
8485 throw new ArgumentException ( $ "Account Uri '{ dataLakeConfig . AccountUri } ' not found. Check the URI is correct.") ;
8586
86- var clientFactory = new DataLakeClientFactory ( _logger ) ;
87- var client = clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
87+ var client = _clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
8888
8989 var paramsJsonFragment = GetParamsJsonFragment ( dataLakeConfig , getItemsConfig ) ;
90- var validatedPath = await CheckPathAsync ( client , getItemsConfig . Path , true , _logger ) ;
90+ var validatedPath = await CheckPathAsync ( client , getItemsConfig . Path , true ) ;
9191
9292 // If multiple files match, the function will throw and the catch block will return a BadRequestObjectResult
9393 // If the path could not be found as a directory, try for a file...
94- validatedPath = validatedPath ?? await CheckPathAsync ( client , getItemsConfig . Path , false , _logger ) ;
94+ validatedPath ??= await CheckPathAsync ( client , getItemsConfig . Path , false ) ;
9595
9696 var resultJson = "{" +
9797 $ "{ paramsJsonFragment } , \" validatedPath\" :\" { validatedPath } \" " +
@@ -119,6 +119,18 @@ public async Task<IActionResult> DataLakeCheckPathCase(
119119
120120
121121
122+ private string GetParamsJsonFragment ( DataLakeConfig dataLakeConfig , object parameters )
123+ {
124+ return $ "\" debugInfo\" : { AssemblyHelpers . GetAssemblyVersionInfoJson ( ) } ," +
125+ $ "\" storageContainerUrl\" : { dataLakeConfig . BaseUrl } ," +
126+ parameters == null ?
127+ string . Empty :
128+ $ "\" parameters\" : { JsonConvert . SerializeObject ( parameters , Formatting . Indented , new JsonSerializerSettings { NullValueHandling = Newtonsoft . Json . NullValueHandling . Ignore } ) } ";
129+ }
130+
131+
132+
133+
122134
123135
124136
@@ -134,17 +146,9 @@ public async Task<IActionResult> DataLakeCheckPathCase(
134146
135147
136148
137- private string GetParamsJsonFragment ( DataLakeConfig dataLakeConfig , object parameters )
138- {
139- return $ "\" debugInfo\" : { AssemblyHelpers . GetAssemblyVersionInfoJson ( ) } ," +
140- $ "\" storageContainerUrl\" : { dataLakeConfig . BaseUrl } ," +
141- parameters == null ?
142- string . Empty :
143- $ "\" parameters\" : { JsonConvert . SerializeObject ( parameters , Formatting . Indented , new JsonSerializerSettings { NullValueHandling = Newtonsoft . Json . NullValueHandling . Ignore } ) } ";
144- }
145149
146150
147- private async Task < string > CheckPathAsync ( DataLakeFileSystemClient client , string path , bool isDirectory , ILogger log )
151+ private async Task < string > CheckPathAsync ( DataLakeFileSystemClient client , string path , bool isDirectory )
148152 {
149153 if ( path == null || path . Trim ( ) == "/" )
150154 return null ;
@@ -156,7 +160,7 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
156160 if ( pathExists )
157161 return path ;
158162
159- log . LogInformation ( $ "${ ( isDirectory ? "Directory" : "File" ) } '${ path } ' not found, checking paths case using case insensitive compare...") ;
163+ _logger . LogInformation ( $ "${ ( isDirectory ? "Directory" : "File" ) } '${ path } ' not found, checking paths case using case insensitive compare...") ;
160164
161165 // Split the paths so we can test them seperately
162166 var directoryPath = isDirectory ? path : Path . GetDirectoryName ( path ) . Replace ( Path . DirectorySeparatorChar , '/' ) ;
@@ -170,7 +174,7 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
170174 foreach ( var directoryPart in directoryParts )
171175 {
172176 var searchItem = directoryPart ;
173- var validPaths = MatchPathItemsCaseInsensitive ( client , validDirectory , searchItem , true , log ) ;
177+ var validPaths = MatchPathItemsCaseInsensitive ( client , validDirectory , searchItem , true ) ;
174178
175179 if ( validPaths . Count == 0 )
176180 return null ;
@@ -189,13 +193,13 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
189193 if ( client . GetFileClient ( testFilePath ) . Exists ( ) )
190194 return testFilePath ;
191195
192- var files = MatchPathItemsCaseInsensitive ( client , validDirectory , filename , false , log ) ;
196+ var files = MatchPathItemsCaseInsensitive ( client , validDirectory , filename , false ) ;
193197 if ( files . Count > 1 )
194198 throw new Exception ( "Multiple paths matched with case insensitive compare." ) ;
195199 return files . FirstOrDefault ( ) ;
196200 }
197201
198- private IList < string > MatchPathItemsCaseInsensitive ( DataLakeFileSystemClient client , string basePath , string searchItem , bool isDirectory , ILogger log )
202+ private IList < string > MatchPathItemsCaseInsensitive ( DataLakeFileSystemClient client , string basePath , string searchItem , bool isDirectory )
199203 {
200204 var paths = client . GetPaths ( basePath ) . ToList ( ) ;
201205 return paths . Where ( p => p . IsDirectory == isDirectory && Path . GetFileName ( p . Name ) . Equals ( searchItem , StringComparison . CurrentCultureIgnoreCase ) )
@@ -205,10 +209,10 @@ private IList<string> MatchPathItemsCaseInsensitive(DataLakeFileSystemClient cli
205209 }
206210
207211
208- private async Task < IActionResult > GetItemsAsync ( DataLakeFileSystemClient client , DataLakeConfig dataLakeConfig , DataLakeGetItemsConfig getItemsConfig , ILogger log )
212+ private async Task < IActionResult > GetItemsAsync ( DataLakeFileSystemClient client , DataLakeConfig dataLakeConfig , DataLakeGetItemsConfig getItemsConfig )
209213 {
210214 var directory = getItemsConfig . IgnoreDirectoryCase ?
211- await CheckPathAsync ( client , getItemsConfig . Directory , true , log ) :
215+ await CheckPathAsync ( client , getItemsConfig . Directory , true ) :
212216 getItemsConfig . Directory ;
213217
214218 var paramsJsonFragment = GetParamsJsonFragment ( dataLakeConfig , getItemsConfig ) ;
@@ -237,7 +241,7 @@ await CheckPathAsync(client, getItemsConfig.Directory, true, log) :
237241 {
238242 var dynamicLinqQuery = filter . GetDynamicLinqString ( ) ;
239243 string dynamicLinqQueryValue = filter . GetDynamicLinqValue ( ) ;
240- log . LogInformation ( $ "Applying filter: paths.AsQueryable().Where(\" { dynamicLinqQuery } \" , \" { filter . Value } \" ).ToList()") ;
244+ _logger . LogInformation ( $ "Applying filter: paths.AsQueryable().Where(\" { dynamicLinqQuery } \" , \" { filter . Value } \" ).ToList()") ;
241245 paths = paths . AsQueryable ( ) . Where ( dynamicLinqQuery , dynamicLinqQueryValue ) . ToList ( ) ;
242246 }
243247
0 commit comments