88
99namespace Files . App . Storage . Storables
1010{
11- public sealed class FtpStorageFolder : FtpStorable , ILocatableFolder , IModifiableFolder , IFolderExtended , INestedFolder , IDirectCopy , IDirectMove
11+ public sealed class FtpStorageFolder : FtpStorable , IModifiableFolder , IChildFolder , IDirectCopy , IDirectMove , IGetFirstByName
1212{
1313public FtpStorageFolder ( string path , string name , IFolder ? parent )
1414: base ( path , name , parent )
1515{
1616}
1717
1818/// <inheritdoc/>
19- public async Task < INestedFile > GetFileAsync ( string fileName , CancellationToken cancellationToken = default )
19+ public async Task < IStorableChild > GetFirstByNameAsync ( string folderName , CancellationToken cancellationToken = default )
2020{
2121using var ftpClient = GetFtpClient ( ) ;
2222await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
2323
24- var path = FtpHelpers . GetFtpPath ( PathHelpers . Combine ( Path , fileName ) ) ;
24+ var path = FtpHelpers . GetFtpPath ( PathHelpers . Combine ( Id , folderName ) ) ;
2525var item = await ftpClient . GetObjectInfo ( path , token : cancellationToken ) ;
2626
27- if ( item is null || item . Type != FtpObjectType . File )
27+ if ( item is null )
2828throw new FileNotFoundException ( ) ;
2929
30- return new FtpStorageFile ( path , item . Name , this ) ;
31- }
32-
33- /// <inheritdoc/>
34- public async Task < INestedFolder > GetFolderAsync ( string folderName , CancellationToken cancellationToken = default )
35- {
36- using var ftpClient = GetFtpClient ( ) ;
37- await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
38-
39- var path = FtpHelpers . GetFtpPath ( PathHelpers . Combine ( Path , folderName ) ) ;
40- var item = await ftpClient . GetObjectInfo ( path , token : cancellationToken ) ;
41-
42- if ( item is null || item . Type != FtpObjectType . Directory )
43- throw new DirectoryNotFoundException ( ) ;
30+ if ( item . Type == FtpObjectType . Directory )
31+ return new FtpStorageFolder ( path , item . Name , this ) ;
32+ else
33+ return new FtpStorageFile ( path , item . Name , this ) ;
4434
45- return new FtpStorageFolder ( path , item . Name , this ) ;
4635}
4736
4837/// <inheritdoc/>
49- public async IAsyncEnumerable < INestedStorable > GetItemsAsync ( StorableKind kind = StorableKind . All , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
38+ public async IAsyncEnumerable < IStorableChild > GetItemsAsync ( StorableType kind = StorableType . All , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
5039{
5140using var ftpClient = GetFtpClient ( ) ;
5241await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
5342
54- if ( kind == StorableKind . Files )
43+ if ( kind == StorableType . File )
5544{
56- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
45+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
5746{
5847if ( item . Type == FtpObjectType . File )
5948yield return new FtpStorageFile ( item . FullName , item . Name , this ) ;
6049}
6150}
62- else if ( kind == StorableKind . Folders )
51+ else if ( kind == StorableType . Folder )
6352{
64- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
53+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
6554{
6655if ( item . Type == FtpObjectType . Directory )
6756yield return new FtpStorageFolder ( item . FullName , item . Name , this ) ;
6857}
6958}
7059else
7160{
72- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
61+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
7362{
7463if ( item . Type == FtpObjectType . File )
7564yield return new FtpStorageFile ( item . FullName , item . Name , this ) ;
@@ -81,18 +70,24 @@ public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind =
8170}
8271
8372/// <inheritdoc/>
84- public async Task DeleteAsync ( INestedStorable item , bool permanently = false , CancellationToken cancellationToken = default )
73+ public Task < IFolderWatcher > GetFolderWatcherAsync ( CancellationToken cancellationToken = default )
74+ {
75+ return Task . FromException < IFolderWatcher > ( new NotSupportedException ( ) ) ;
76+ }
77+
78+ /// <inheritdoc/>
79+ public async Task DeleteAsync ( IStorableChild item , CancellationToken cancellationToken = default )
8580{
8681using var ftpClient = GetFtpClient ( ) ;
8782await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
8883
89- if ( item is ILocatableFile locatableFile )
84+ if ( item is IFile locatableFile )
9085{
91- await ftpClient . DeleteFile ( locatableFile . Path , cancellationToken ) ;
86+ await ftpClient . DeleteFile ( locatableFile . Id , cancellationToken ) ;
9287}
93- else if ( item is ILocatableFolder locatableFolder )
88+ else if ( item is IFolder locatableFolder )
9489{
95- await ftpClient . DeleteDirectory ( locatableFolder . Path , cancellationToken ) ;
90+ await ftpClient . DeleteDirectory ( locatableFolder . Id , cancellationToken ) ;
9691}
9792else
9893{
@@ -101,7 +96,7 @@ public async Task DeleteAsync(INestedStorable item, bool permanently = false, Ca
10196}
10297
10398/// <inheritdoc/>
104- public async Task < INestedStorable > CreateCopyOfAsync ( INestedStorable itemToCopy , bool overwrite = default , CancellationToken cancellationToken = default )
99+ public async Task < IStorableChild > CreateCopyOfAsync ( IStorableChild itemToCopy , bool overwrite = default , CancellationToken cancellationToken = default )
105100{
106101if ( itemToCopy is IFile sourceFile )
107102{
@@ -117,24 +112,24 @@ public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy,
117112}
118113
119114/// <inheritdoc/>
120- public async Task < INestedStorable > MoveFromAsync ( INestedStorable itemToMove , IModifiableFolder source , bool overwrite = default , CancellationToken cancellationToken = default )
115+ public async Task < IStorableChild > MoveFromAsync ( IStorableChild itemToMove , IModifiableFolder source , bool overwrite = default , CancellationToken cancellationToken = default )
121116{
122117using var ftpClient = GetFtpClient ( ) ;
123118await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
124119
125120var newItem = await CreateCopyOfAsync ( itemToMove , overwrite , cancellationToken ) ;
126- await source . DeleteAsync ( itemToMove , true , cancellationToken ) ;
121+ await source . DeleteAsync ( itemToMove , cancellationToken ) ;
127122
128123return newItem ;
129124}
130125
131126/// <inheritdoc/>
132- public async Task < INestedFile > CreateFileAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
127+ public async Task < IChildFile > CreateFileAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
133128{
134129using var ftpClient = GetFtpClient ( ) ;
135130await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
136131
137- var newPath = $ "{ Path } /{ desiredName } ";
132+ var newPath = $ "{ Id } /{ desiredName } ";
138133if ( overwrite && await ftpClient . FileExists ( newPath , cancellationToken ) )
139134throw new IOException ( "File already exists." ) ;
140135
@@ -159,12 +154,12 @@ public async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrit
159154}
160155
161156/// <inheritdoc/>
162- public async Task < INestedFolder > CreateFolderAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
157+ public async Task < IChildFolder > CreateFolderAsync ( string desiredName , bool overwrite = default , CancellationToken cancellationToken = default )
163158{
164159using var ftpClient = GetFtpClient ( ) ;
165160await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
166161
167- var newPath = $ "{ Path } /{ desiredName } ";
162+ var newPath = $ "{ Id } /{ desiredName } ";
168163if ( overwrite && await ftpClient . DirectoryExists ( newPath , cancellationToken ) )
169164throw new IOException ( "Directory already exists." ) ;
170165
0 commit comments