@@ -122,6 +122,26 @@ Namespace Providers
122122 Return RemoteItem IsNot Nothing
123123 End Function
124124
125+ ''' <summary>
126+ ''' Async alternative to <see cref="RemoteItemExists"/>
127+ ''' </summary>
128+ ''' <param name="remotePath"></param>
129+ Public Overridable Async Function RemoteItemExistsAsync(remotePath As String ) As Task( Of Boolean )
130+ Dim RemoteItem As DmsResourceItem = Await Me .ListRemoteItemAsync(remotePath)
131+ Return RemoteItem IsNot Nothing
132+ End Function
133+
134+ ''' <summary>
135+ ''' Async alternative to <see cref="ListRemoteItem"/>
136+ ''' Default implementation calls the synchronous implementation on a background task to preserve compatibility.
137+ ''' </summary>
138+ ''' <param name="remotePath"></param>
139+ Public Overridable Async Function ListRemoteItemAsync(remotePath As String ) As Task( Of DmsResourceItem)
140+ Return Await Task.Run( Function ()
141+ Return Me .ListRemoteItem(remotePath)
142+ End Function )
143+ End Function
144+
125145 ''' <summary>
126146 ''' An existance check for a remote item
127147 ''' </summary>
@@ -137,6 +157,18 @@ Namespace Providers
137157 End If
138158 End Function
139159
160+ ''' <summary>
161+ ''' Async alternative to <see cref="RemoteItemExistsAs"/>
162+ ''' </summary>
163+ Public Overridable Async Function RemoteItemExistsAsAsync(remotePath As String ) As Task( Of DmsResourceItem.FoundItemType)
164+ Dim RemoteItem As DmsResourceItem = Await Me .ListRemoteItemAsync(remotePath)
165+ If RemoteItem Is Nothing Then
166+ Return DmsResourceItem.FoundItemType.NotFound
167+ Else
168+ Return CType ( CType (RemoteItem.ItemType, Byte ), DmsResourceItem.FoundItemType)
169+ End If
170+ End Function
171+
140172 ''' <summary>
141173 ''' An existance check for a remote item (collissions with remote items under the very same name are checked)
142174 ''' </summary>
@@ -154,6 +186,20 @@ Namespace Providers
154186 End If
155187 End Function
156188
189+ ''' <summary>
190+ ''' Async alternative to <see cref="RemoteItemExistsUniquelyAs"/>
191+ ''' </summary>
192+ Public Overridable Async Function RemoteItemExistsUniquelyAsAsync(remotePath As String ) As Task( Of DmsResourceItem.FoundItemResult)
193+ Dim RemoteItem As DmsResourceItem = Await Me .ListRemoteItemAsync(remotePath)
194+ If RemoteItem Is Nothing Then
195+ Return DmsResourceItem.FoundItemResult.NotFound
196+ ElseIf RemoteItem.ExtendedInfosCollisionDetected Then
197+ Return DmsResourceItem.FoundItemResult.WithNameCollisions
198+ Else
199+ Return CType ( CType (RemoteItem.ItemType, Byte ), DmsResourceItem.FoundItemResult)
200+ End If
201+ End Function
202+
157203 ''' <summary>
158204 ''' Reset file system cache and force refresh on next access
159205 ''' </summary>
@@ -170,13 +216,33 @@ Namespace Providers
170216 End Select
171217 End Sub
172218
219+ ''' <summary>
220+ ''' Async alternative to <see cref="ResetCachesForRemoteItems"/>
221+ ''' Default implementation runs the sync override in a background task.
222+ ''' </summary>
223+ Public Overridable Async Function ResetCachesForRemoteItemsAsync(remoteItem As DmsResourceItem, searchType As SearchItemType) As Task
224+ Await Task.Run( Sub ()
225+ Me .ResetCachesForRemoteItems(remoteItem, searchType)
226+ End Sub )
227+ End Function
228+
173229 ''' <summary>
174230 ''' Reset file system cache and force refresh on next access
175231 ''' </summary>
176232 ''' <param name="remoteFolderPath"></param>
177233 ''' <param name="searchType"></param>
178234 Public MustOverride Sub ResetCachesForRemoteItems(remoteFolderPath As String , searchType As SearchItemType)
179235
236+ ''' <summary>
237+ ''' Async alternative to <see cref="ResetCachesForRemoteItems(String,SearchItemType)"/>
238+ ''' Default implementation calls synchronous override on background thread.
239+ ''' </summary>
240+ Public Overridable Async Function ResetCachesForRemoteItemsAsync(remoteFolderPath As String , searchType As SearchItemType) As Task
241+ Await Task.Run( Sub ()
242+ Me .ResetCachesForRemoteItems(remoteFolderPath, searchType)
243+ End Sub )
244+ End Function
245+
180246 ''' <summary>
181247 ''' List all child items (files/folders/collections) for a remote path
182248 ''' </summary>
@@ -185,6 +251,16 @@ Namespace Providers
185251 ''' <returns></returns>
186252 Public MustOverride Function ListAllRemoteItems(remoteFolderPath As String , searchType As SearchItemType) As List( Of DmsResourceItem)
187253
254+ ''' <summary>
255+ ''' Async alternative to <see cref="ListAllRemoteItems"/>
256+ ''' Default implementation calls synchronous override on background thread.
257+ ''' </summary>
258+ Public Overridable Async Function ListAllRemoteItemsAsync(remoteFolderPath As String , searchType As SearchItemType) As Task( Of List( Of DmsResourceItem))
259+ Return Await Task.Run( Function ()
260+ Return Me .ListAllRemoteItems(remoteFolderPath, searchType)
261+ End Function )
262+ End Function
263+
188264 ''' <summary>
189265 ''' List all child collections for a remote path
190266 ''' </summary>
@@ -200,6 +276,19 @@ Namespace Providers
200276 Return Result
201277 End Function
202278
279+ ''' <summary>
280+ ''' Async alternative to <see cref="ListAllCollectionItems"/>
281+ ''' </summary>
282+ Public Overridable Async Function ListAllCollectionItemsAsync(remoteFolderPath As String ) As Task( Of List( Of DmsResourceItem))
283+ Dim Result As New List( Of DmsResourceItem)
284+ For Each Item In Await Me .ListAllRemoteItemsAsync(remoteFolderPath, SearchItemType.Collections)
285+ If Item.ItemType = DmsResourceItem.ItemTypes.Collection Then
286+ Result.Add(Item)
287+ End If
288+ Next
289+ Return Result
290+ End Function
291+
203292 ''' <summary>
204293 ''' List all child folders for a remote path
205294 ''' </summary>
@@ -215,6 +304,19 @@ Namespace Providers
215304 Return Result
216305 End Function
217306
307+ ''' <summary>
308+ ''' Async alternative to <see cref="ListAllFolderItems"/>
309+ ''' </summary>
310+ Public Overridable Async Function ListAllFolderItemsAsync(remoteFolderPath As String ) As Task( Of List( Of DmsResourceItem))
311+ Dim Result As New List( Of DmsResourceItem)
312+ For Each Item In Await Me .ListAllRemoteItemsAsync(remoteFolderPath, SearchItemType.Folders)
313+ If Item.ItemType = DmsResourceItem.ItemTypes.Folder Then
314+ Result.Add(Item)
315+ End If
316+ Next
317+ Return Result
318+ End Function
319+
218320 ''' <summary>
219321 ''' List all child files for a remote path
220322 ''' </summary>
@@ -230,6 +332,19 @@ Namespace Providers
230332 Return Result
231333 End Function
232334
335+ ''' <summary>
336+ ''' Async alternative to <see cref="ListAllFileItems"/>
337+ ''' </summary>
338+ Public Overridable Async Function ListAllFileItemsAsync(remoteFolderPath As String ) As Task( Of List( Of DmsResourceItem))
339+ Dim Result As New List( Of DmsResourceItem)
340+ For Each Item In Await Me .ListAllRemoteItemsAsync(remoteFolderPath, SearchItemType.Files)
341+ If Item.ItemType = DmsResourceItem.ItemTypes.File Then
342+ Result.Add(Item)
343+ End If
344+ Next
345+ Return Result
346+ End Function
347+
233348 ''' <summary>
234349 ''' List all child collection names for a remote path
235350 ''' </summary>
@@ -245,6 +360,19 @@ Namespace Providers
245360 Return Result
246361 End Function
247362
363+ ''' <summary>
364+ ''' Async alternative to <see cref="ListAllCollectionNames"/>
365+ ''' </summary>
366+ Public Overridable Async Function ListAllCollectionNamesAsync(remoteFolderPath As String ) As Task( Of List( Of String ))
367+ Dim Result As New List( Of String )
368+ For Each Item In Await Me .ListAllCollectionItemsAsync(remoteFolderPath)
369+ If Item.ItemType = DmsResourceItem.ItemTypes.Collection Then
370+ Result.Add(Item.Name)
371+ End If
372+ Next
373+ Return Result
374+ End Function
375+
248376 ''' <summary>
249377 ''' List all child folder names for a remote path
250378 ''' </summary>
@@ -260,6 +388,19 @@ Namespace Providers
260388 Return Result
261389 End Function
262390
391+ ''' <summary>
392+ ''' Async alternative to <see cref="ListAllFolderNames"/>
393+ ''' </summary>
394+ Public Overridable Async Function ListAllFolderNamesAsync(remoteFolderPath As String ) As Task( Of List( Of String ))
395+ Dim Result As New List( Of String )
396+ For Each Item In Await Me .ListAllFolderItemsAsync(remoteFolderPath)
397+ If Item.ItemType = DmsResourceItem.ItemTypes.Folder Then
398+ Result.Add(Item.Name)
399+ End If
400+ Next
401+ Return Result
402+ End Function
403+
263404 ''' <summary>
264405 ''' List all child file names for a remote path
265406 ''' </summary>
@@ -275,6 +416,19 @@ Namespace Providers
275416 Return Result
276417 End Function
277418
419+ ''' <summary>
420+ ''' Async alternative to <see cref="ListAllFileNames"/>
421+ ''' </summary>
422+ Public Overridable Async Function ListAllFileNamesAsync(remoteFolderPath As String ) As Task( Of List( Of String ))
423+ Dim Result As New List( Of String )
424+ For Each Item In Await Me .ListAllFileItemsAsync(remoteFolderPath)
425+ If Item.ItemType = DmsResourceItem.ItemTypes.File Then
426+ Result.Add(Item.Name)
427+ End If
428+ Next
429+ Return Result
430+ End Function
431+
278432 ''' <summary>
279433 ''' Load a remote collection item based on its ID
280434 ''' </summary>
@@ -629,6 +783,37 @@ Namespace Providers
629783 End Select
630784 End Sub
631785
786+ ''' <summary>
787+ ''' Async alternative to Move
788+ ''' </summary>
789+ Public Async Function MoveAsync(remoteSourcePath As String , remoteDestinationPath As String ) As Task
790+ Await Me .MoveAsync(remoteSourcePath, remoteDestinationPath, False , False )
791+ End Function
792+
793+ ''' <summary>
794+ ''' Async alternative to Move
795+ ''' </summary>
796+ Public Overridable Async Function MoveAsync(remoteSourcePath As String , remoteDestinationPath As String , allowOverwrite As Boolean ?, allowCreationOfRemoteDirectory As Boolean ) As Task
797+ Dim FoundRemoteSourceItem As DmsResourceItem.FoundItemResult = Await Me .RemoteItemExistsUniquelyAsAsync(remoteSourcePath)
798+ Me .CopyMoveArgumentsCheck(FoundRemoteSourceItem, remoteSourcePath, remoteDestinationPath, allowOverwrite, allowCreationOfRemoteDirectory)
799+ Dim ParentDirPathSource As String = Me .ParentDirectoryPath(remoteSourcePath)
800+ Dim ParentDirPathDestination As String = Me .ParentDirectoryPath(remoteDestinationPath)
801+ Select Case FoundRemoteSourceItem
802+ Case DmsResourceItem.FoundItemResult.File
803+ Await Me .MoveFileItemAsync(remoteSourcePath, remoteDestinationPath, allowOverwrite)
804+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathSource, SearchItemType.Files)
805+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathDestination, SearchItemType.Files)
806+ Case DmsResourceItem.FoundItemResult.Folder, DmsResourceItem.FoundItemResult.Collection
807+ Await Me .MoveDirectoryItemAsync(remoteSourcePath, remoteDestinationPath)
808+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathSource, SearchItemType.Folders)
809+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathDestination, SearchItemType.Folders)
810+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathSource, SearchItemType.Collections)
811+ Await Me .ResetCachesForRemoteItemsAsync(ParentDirPathDestination, SearchItemType.Collections)
812+ Case Else
813+ Throw New NotImplementedException
814+ End Select
815+ End Function
816+
632817 ''' <summary>
633818 ''' Move a remote DMS item
634819 ''' </summary>
@@ -664,6 +849,13 @@ Namespace Providers
664849 ''' <param name="remoteDestinationPath"></param>
665850 ''' <param name="allowOverwrite"></param>
666851 Protected MustOverride Sub MoveFileItem(remoteSourcePath As String , remoteDestinationPath As String , allowOverwrite As Boolean ?)
852+ ''' <summary>
853+ ''' Async alternative to MoveFileItem. Default implementation calls synchronous override on background thread.
854+ ''' </summary>
855+ Protected Overridable Async Function MoveFileItemAsync(remoteSourcePath As String , remoteDestinationPath As String , allowOverwrite As Boolean ?) As Task
856+ Await Task.Run( Sub ()
857+ Me .MoveFileItem(remoteSourcePath, remoteDestinationPath, allowOverwrite)
858+ End Sub )
667859
668860 ''' <summary>
669861 ''' Move a remote DMS item
@@ -672,6 +864,14 @@ Namespace Providers
672864 ''' <param name="remoteDestinationPath"></param>
673865 Protected MustOverride Sub MoveDirectoryItem(remoteSourcePath As String , remoteDestinationPath As String )
674866
867+ ''' <summary>
868+ ''' Async alternative to MoveDirectoryItem. Default implementation calls synchronous override on background thread.
869+ ''' </summary>
870+ Protected Overridable Async Function MoveDirectoryItemAsync(remoteSourcePath As String , remoteDestinationPath As String ) As Task
871+ Await Task.Run( Sub ()
872+ Me .MoveDirectoryItem(remoteSourcePath, remoteDestinationPath)
873+ End Sub )
874+
675875 ''' <summary>
676876 ''' Delete a remote item (folder, collection or file)
677877 ''' </summary>
0 commit comments