6
6
using Files . Interacts ;
7
7
using Microsoft . Toolkit . Uwp ;
8
8
using System ;
9
+ using System . Collections . Concurrent ;
9
10
using System . Collections . Generic ;
11
+ using System . IO ;
10
12
using System . Linq ;
11
13
using System . Threading . Tasks ;
12
14
using Windows . ApplicationModel . AppService ;
@@ -24,7 +26,7 @@ public static async void CutItem(IShellPage associatedInstance)
24
26
{
25
27
RequestedOperation = DataPackageOperation . Move
26
28
} ;
27
- List < IStorageItem > items = new List < IStorageItem > ( ) ;
29
+ ConcurrentBag < IStorageItem > items = new ConcurrentBag < IStorageItem > ( ) ;
28
30
FilesystemResult result = ( FilesystemResult ) false ;
29
31
30
32
var canFlush = true ;
@@ -33,46 +35,54 @@ public static async void CutItem(IShellPage associatedInstance)
33
35
// First, reset DataGrid Rows that may be in "cut" command mode
34
36
associatedInstance . SlimContentPage . ItemManipulationModel . RefreshItemsOpacity ( ) ;
35
37
36
- foreach ( ListedItem listedItem in associatedInstance . SlimContentPage . SelectedItems . ToList ( ) )
38
+ try
37
39
{
40
+ await Task . WhenAll ( associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . Select ( async listedItem =>
41
+ {
38
42
// FTP don't support cut, fallback to copy
39
43
if ( listedItem is not FtpItem )
40
- {
44
+ {
41
45
// Dim opacities accordingly
42
46
listedItem . Opacity = Constants . UI . DimItemOpacity ;
43
- }
44
-
45
- if ( listedItem is FtpItem ftpItem )
46
- {
47
- canFlush = false ;
48
- if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
49
- {
50
- items . Add ( await new FtpStorageFile ( ftpItem ) . ToStorageFileAsync ( ) ) ;
51
47
}
52
- else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . Folder )
48
+
49
+ if ( listedItem is FtpItem ftpItem )
53
50
{
54
- items . Add ( new FtpStorageFolder ( ftpItem ) ) ;
51
+ canFlush = false ;
52
+ if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
53
+ {
54
+ items . Add ( await new FtpStorageFile ( ftpItem ) . ToStorageFileAsync ( ) ) ;
55
+ }
56
+ else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . Folder )
57
+ {
58
+ items . Add ( new FtpStorageFolder ( ftpItem ) ) ;
59
+ }
55
60
}
56
- }
57
- else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File || listedItem is ZipItem )
58
- {
59
- result = await associatedInstance . FilesystemViewModel . GetFileFromPathAsync ( listedItem . ItemPath )
60
- . OnSuccess ( t => items . Add ( t ) ) ;
61
- if ( ! result )
61
+ else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File || listedItem is ZipItem )
62
62
{
63
- break ;
63
+ result = await associatedInstance . FilesystemViewModel . GetFileFromPathAsync ( listedItem . ItemPath )
64
+ . OnSuccess ( t => items . Add ( t ) ) ;
65
+ if ( ! result )
66
+ {
67
+ throw new IOException ( $ "Failed to process { listedItem . ItemPath } .") ;
68
+ }
64
69
}
65
- }
66
- else
67
- {
68
- result = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( listedItem . ItemPath )
69
- . OnSuccess ( t => items . Add ( t ) ) ;
70
- if ( ! result )
70
+ else
71
71
{
72
- break ;
72
+ result = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( listedItem . ItemPath )
73
+ . OnSuccess ( t => items . Add ( t ) ) ;
74
+ if ( ! result )
75
+ {
76
+ throw new IOException ( $ "Failed to process { listedItem . ItemPath } .") ;
77
+ }
73
78
}
74
- }
79
+ } ) ) ;
80
+ }
81
+ catch
82
+ {
83
+ return ;
75
84
}
85
+
76
86
if ( result . ErrorCode == FileSystemStatusCode . NotFound )
77
87
{
78
88
associatedInstance . SlimContentPage . ItemManipulationModel . RefreshItemsOpacity ( ) ;
@@ -105,7 +115,7 @@ public static async void CutItem(IShellPage associatedInstance)
105
115
var onlyStandard = items . All ( x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder ) ;
106
116
if ( onlyStandard )
107
117
{
108
- items = await items . ToStandardStorageItemsAsync ( ) ;
118
+ items = new ConcurrentBag < IStorageItem > ( await items . ToStandardStorageItemsAsync ( ) ) ;
109
119
}
110
120
if ( ! items . Any ( ) )
111
121
{
@@ -132,47 +142,55 @@ public static async Task CopyItem(IShellPage associatedInstance)
132
142
{
133
143
RequestedOperation = DataPackageOperation . Copy
134
144
} ;
135
- List < IStorageItem > items = new List < IStorageItem > ( ) ;
145
+ ConcurrentBag < IStorageItem > items = new ConcurrentBag < IStorageItem > ( ) ;
136
146
137
147
string copySourcePath = associatedInstance . FilesystemViewModel . WorkingDirectory ;
138
148
FilesystemResult result = ( FilesystemResult ) false ;
139
149
140
150
var canFlush = true ;
141
151
if ( associatedInstance . SlimContentPage . IsItemSelected )
142
152
{
143
- foreach ( ListedItem listedItem in associatedInstance . SlimContentPage . SelectedItems . ToList ( ) )
153
+ try
144
154
{
145
- if ( listedItem is FtpItem ftpItem )
155
+ await Task . WhenAll ( associatedInstance . SlimContentPage . SelectedItems . ToList ( ) . Select ( async listedItem =>
146
156
{
147
- canFlush = false ;
148
- if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
157
+ if ( listedItem is FtpItem ftpItem )
149
158
{
150
- items . Add ( await new FtpStorageFile ( ftpItem ) . ToStorageFileAsync ( ) ) ;
159
+ canFlush = false ;
160
+ if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File )
161
+ {
162
+ items . Add ( await new FtpStorageFile ( ftpItem ) . ToStorageFileAsync ( ) ) ;
163
+ }
164
+ else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . Folder )
165
+ {
166
+ items . Add ( new FtpStorageFolder ( ftpItem ) ) ;
167
+ }
151
168
}
152
- else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . Folder )
153
- {
154
- items . Add ( new FtpStorageFolder ( ftpItem ) ) ;
155
- }
156
- }
157
- else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File || listedItem is ZipItem )
158
- {
159
- result = await associatedInstance . FilesystemViewModel . GetFileFromPathAsync ( listedItem . ItemPath )
160
- . OnSuccess ( t => items . Add ( t ) ) ;
161
- if ( ! result )
169
+ else if ( listedItem . PrimaryItemAttribute == StorageItemTypes . File || listedItem is ZipItem )
162
170
{
163
- break ;
171
+ result = await associatedInstance . FilesystemViewModel . GetFileFromPathAsync ( listedItem . ItemPath )
172
+ . OnSuccess ( t => items . Add ( t ) ) ;
173
+ if ( ! result )
174
+ {
175
+ throw new IOException ( $ "Failed to process { listedItem . ItemPath } .") ;
176
+ }
164
177
}
165
- }
166
- else
167
- {
168
- result = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( listedItem . ItemPath )
169
- . OnSuccess ( t => items . Add ( t ) ) ;
170
- if ( ! result )
178
+ else
171
179
{
172
- break ;
180
+ result = await associatedInstance . FilesystemViewModel . GetFolderFromPathAsync ( listedItem . ItemPath )
181
+ . OnSuccess ( t => items . Add ( t ) ) ;
182
+ if ( ! result )
183
+ {
184
+ throw new IOException ( $ "Failed to process { listedItem . ItemPath } .") ;
185
+ }
173
186
}
174
- }
187
+ } ) ) ;
175
188
}
189
+ catch
190
+ {
191
+ return ;
192
+ }
193
+
176
194
if ( result . ErrorCode == FileSystemStatusCode . Unauthorized )
177
195
{
178
196
// Try again with fulltrust process
@@ -195,7 +213,7 @@ await connection.SendMessageAsync(new ValueSet()
195
213
var onlyStandard = items . All ( x => x is StorageFile || x is StorageFolder || x is SystemStorageFile || x is SystemStorageFolder ) ;
196
214
if ( onlyStandard )
197
215
{
198
- items = await items . ToStandardStorageItemsAsync ( ) ;
216
+ items = new ConcurrentBag < IStorageItem > ( await items . ToStandardStorageItemsAsync ( ) ) ;
199
217
}
200
218
if ( ! items . Any ( ) )
201
219
{
0 commit comments