8
8
9
9
namespace Files . App . Storage . Storables
10
10
{
11
- public sealed class FtpStorageFolder : FtpStorable , ILocatableFolder , IModifiableFolder , IFolderExtended , INestedFolder , IDirectCopy , IDirectMove
11
+ public sealed class FtpStorageFolder : FtpStorable , IModifiableFolder , IChildFolder , IDirectCopy , IDirectMove , IGetFirstByName
12
12
{
13
13
public FtpStorageFolder ( string path , string name , IFolder ? parent )
14
14
: base ( path , name , parent )
15
15
{
16
16
}
17
17
18
18
/// <inheritdoc/>
19
- public async Task < INestedFile > GetFileAsync ( string fileName , CancellationToken cancellationToken = default )
19
+ public async Task < IStorableChild > GetFirstByNameAsync ( string folderName , CancellationToken cancellationToken = default )
20
20
{
21
21
using var ftpClient = GetFtpClient ( ) ;
22
22
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
23
23
24
- var path = FtpHelpers . GetFtpPath ( PathHelpers . Combine ( Path , fileName ) ) ;
24
+ var path = FtpHelpers . GetFtpPath ( PathHelpers . Combine ( Id , folderName ) ) ;
25
25
var item = await ftpClient . GetObjectInfo ( path , token : cancellationToken ) ;
26
26
27
- if ( item is null || item . Type != FtpObjectType . File )
27
+ if ( item is null )
28
28
throw new FileNotFoundException ( ) ;
29
29
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 ) ;
44
34
45
- return new FtpStorageFolder ( path , item . Name , this ) ;
46
35
}
47
36
48
37
/// <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 )
50
39
{
51
40
using var ftpClient = GetFtpClient ( ) ;
52
41
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
53
42
54
- if ( kind == StorableKind . Files )
43
+ if ( kind == StorableType . File )
55
44
{
56
- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
45
+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
57
46
{
58
47
if ( item . Type == FtpObjectType . File )
59
48
yield return new FtpStorageFile ( item . FullName , item . Name , this ) ;
60
49
}
61
50
}
62
- else if ( kind == StorableKind . Folders )
51
+ else if ( kind == StorableType . Folder )
63
52
{
64
- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
53
+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
65
54
{
66
55
if ( item . Type == FtpObjectType . Directory )
67
56
yield return new FtpStorageFolder ( item . FullName , item . Name , this ) ;
68
57
}
69
58
}
70
59
else
71
60
{
72
- foreach ( var item in await ftpClient . GetListing ( Path , cancellationToken ) )
61
+ foreach ( var item in await ftpClient . GetListing ( Id , cancellationToken ) )
73
62
{
74
63
if ( item . Type == FtpObjectType . File )
75
64
yield return new FtpStorageFile ( item . FullName , item . Name , this ) ;
@@ -81,18 +70,24 @@ public async IAsyncEnumerable<INestedStorable> GetItemsAsync(StorableKind kind =
81
70
}
82
71
83
72
/// <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 )
85
80
{
86
81
using var ftpClient = GetFtpClient ( ) ;
87
82
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
88
83
89
- if ( item is ILocatableFile locatableFile )
84
+ if ( item is IFile locatableFile )
90
85
{
91
- await ftpClient . DeleteFile ( locatableFile . Path , cancellationToken ) ;
86
+ await ftpClient . DeleteFile ( locatableFile . Id , cancellationToken ) ;
92
87
}
93
- else if ( item is ILocatableFolder locatableFolder )
88
+ else if ( item is IFolder locatableFolder )
94
89
{
95
- await ftpClient . DeleteDirectory ( locatableFolder . Path , cancellationToken ) ;
90
+ await ftpClient . DeleteDirectory ( locatableFolder . Id , cancellationToken ) ;
96
91
}
97
92
else
98
93
{
@@ -101,7 +96,7 @@ public async Task DeleteAsync(INestedStorable item, bool permanently = false, Ca
101
96
}
102
97
103
98
/// <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 )
105
100
{
106
101
if ( itemToCopy is IFile sourceFile )
107
102
{
@@ -117,24 +112,24 @@ public async Task<INestedStorable> CreateCopyOfAsync(INestedStorable itemToCopy,
117
112
}
118
113
119
114
/// <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 )
121
116
{
122
117
using var ftpClient = GetFtpClient ( ) ;
123
118
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
124
119
125
120
var newItem = await CreateCopyOfAsync ( itemToMove , overwrite , cancellationToken ) ;
126
- await source . DeleteAsync ( itemToMove , true , cancellationToken ) ;
121
+ await source . DeleteAsync ( itemToMove , cancellationToken ) ;
127
122
128
123
return newItem ;
129
124
}
130
125
131
126
/// <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 )
133
128
{
134
129
using var ftpClient = GetFtpClient ( ) ;
135
130
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
136
131
137
- var newPath = $ "{ Path } /{ desiredName } ";
132
+ var newPath = $ "{ Id } /{ desiredName } ";
138
133
if ( overwrite && await ftpClient . FileExists ( newPath , cancellationToken ) )
139
134
throw new IOException ( "File already exists." ) ;
140
135
@@ -159,12 +154,12 @@ public async Task<INestedFile> CreateFileAsync(string desiredName, bool overwrit
159
154
}
160
155
161
156
/// <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 )
163
158
{
164
159
using var ftpClient = GetFtpClient ( ) ;
165
160
await ftpClient . EnsureConnectedAsync ( cancellationToken ) ;
166
161
167
- var newPath = $ "{ Path } /{ desiredName } ";
162
+ var newPath = $ "{ Id } /{ desiredName } ";
168
163
if ( overwrite && await ftpClient . DirectoryExists ( newPath , cancellationToken ) )
169
164
throw new IOException ( "Directory already exists." ) ;
170
165
0 commit comments