@@ -25,10 +25,12 @@ public partial class DataLakeFunctions
25
25
{
26
26
private readonly ILogger < DataLakeFunctions > _logger ;
27
27
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 )
29
30
{
30
31
_logger = logger ;
31
32
_configFactory = configFactory ;
33
+ _clientFactory = clientFactory ;
32
34
}
33
35
34
36
@@ -50,9 +52,8 @@ public async Task<IActionResult> DataLakeGetItems(
50
52
if ( string . IsNullOrWhiteSpace ( dataLakeConfig . AccountUri ) )
51
53
throw new ArgumentException ( $ "Account Uri '{ dataLakeConfig . AccountUri } ' not found. Check the URI is correct.") ;
52
54
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 ) ;
56
57
}
57
58
catch ( ArgumentException ex )
58
59
{
@@ -83,15 +84,14 @@ public async Task<IActionResult> DataLakeCheckPathCase(
83
84
if ( string . IsNullOrWhiteSpace ( dataLakeConfig . AccountUri ) )
84
85
throw new ArgumentException ( $ "Account Uri '{ dataLakeConfig . AccountUri } ' not found. Check the URI is correct.") ;
85
86
86
- var clientFactory = new DataLakeClientFactory ( _logger ) ;
87
- var client = clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
87
+ var client = _clientFactory . GetDataLakeClient ( dataLakeConfig ) ;
88
88
89
89
var paramsJsonFragment = GetParamsJsonFragment ( dataLakeConfig , getItemsConfig ) ;
90
- var validatedPath = await CheckPathAsync ( client , getItemsConfig . Path , true , _logger ) ;
90
+ var validatedPath = await CheckPathAsync ( client , getItemsConfig . Path , true ) ;
91
91
92
92
// If multiple files match, the function will throw and the catch block will return a BadRequestObjectResult
93
93
// 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 ) ;
95
95
96
96
var resultJson = "{" +
97
97
$ "{ paramsJsonFragment } , \" validatedPath\" :\" { validatedPath } \" " +
@@ -119,6 +119,18 @@ public async Task<IActionResult> DataLakeCheckPathCase(
119
119
120
120
121
121
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
+
122
134
123
135
124
136
@@ -134,17 +146,9 @@ public async Task<IActionResult> DataLakeCheckPathCase(
134
146
135
147
136
148
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
- }
145
149
146
150
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 )
148
152
{
149
153
if ( path == null || path . Trim ( ) == "/" )
150
154
return null ;
@@ -156,7 +160,7 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
156
160
if ( pathExists )
157
161
return path ;
158
162
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...") ;
160
164
161
165
// Split the paths so we can test them seperately
162
166
var directoryPath = isDirectory ? path : Path . GetDirectoryName ( path ) . Replace ( Path . DirectorySeparatorChar , '/' ) ;
@@ -170,7 +174,7 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
170
174
foreach ( var directoryPart in directoryParts )
171
175
{
172
176
var searchItem = directoryPart ;
173
- var validPaths = MatchPathItemsCaseInsensitive ( client , validDirectory , searchItem , true , log ) ;
177
+ var validPaths = MatchPathItemsCaseInsensitive ( client , validDirectory , searchItem , true ) ;
174
178
175
179
if ( validPaths . Count == 0 )
176
180
return null ;
@@ -189,13 +193,13 @@ private async Task<string> CheckPathAsync(DataLakeFileSystemClient client, strin
189
193
if ( client . GetFileClient ( testFilePath ) . Exists ( ) )
190
194
return testFilePath ;
191
195
192
- var files = MatchPathItemsCaseInsensitive ( client , validDirectory , filename , false , log ) ;
196
+ var files = MatchPathItemsCaseInsensitive ( client , validDirectory , filename , false ) ;
193
197
if ( files . Count > 1 )
194
198
throw new Exception ( "Multiple paths matched with case insensitive compare." ) ;
195
199
return files . FirstOrDefault ( ) ;
196
200
}
197
201
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 )
199
203
{
200
204
var paths = client . GetPaths ( basePath ) . ToList ( ) ;
201
205
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
205
209
}
206
210
207
211
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 )
209
213
{
210
214
var directory = getItemsConfig . IgnoreDirectoryCase ?
211
- await CheckPathAsync ( client , getItemsConfig . Directory , true , log ) :
215
+ await CheckPathAsync ( client , getItemsConfig . Directory , true ) :
212
216
getItemsConfig . Directory ;
213
217
214
218
var paramsJsonFragment = GetParamsJsonFragment ( dataLakeConfig , getItemsConfig ) ;
@@ -237,7 +241,7 @@ await CheckPathAsync(client, getItemsConfig.Directory, true, log) :
237
241
{
238
242
var dynamicLinqQuery = filter . GetDynamicLinqString ( ) ;
239
243
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()") ;
241
245
paths = paths . AsQueryable ( ) . Where ( dynamicLinqQuery , dynamicLinqQueryValue ) . ToList ( ) ;
242
246
}
243
247
0 commit comments