@@ -30,7 +30,7 @@ public async Task Execute(Parameters parameters)
30
30
throw new WrongCommandFormatException ( "Source is required" ) ;
31
31
}
32
32
33
-
33
+
34
34
if ( string . IsNullOrWhiteSpace ( parameters . Target ) )
35
35
{
36
36
_output . WriteInfo ( string . Format ( "Uploading file '{0}' to the root folder of space '{1}'..." , parameters . Source , parameters . SpaceName ) ) ;
@@ -48,7 +48,7 @@ public async Task Execute(Parameters parameters)
48
48
49
49
50
50
ProgressBar progress = null ;
51
- _apiClient . FileProgress += ( object sender , FileEventArgs e ) =>
51
+ _apiClient . OnDataUploadProgress += ( object sender , FileTransferProgressEventArgs e ) =>
52
52
{
53
53
if ( e . State == FileProgressState . Starting )
54
54
{
@@ -64,8 +64,8 @@ public async Task Execute(Parameters parameters)
64
64
progress . Dispose ( ) ;
65
65
progress = null ;
66
66
}
67
- else if ( e . State == FileProgressState . Cancelled )
68
- {
67
+ else if ( e . State == FileProgressState . Cancelled )
68
+ {
69
69
progress . Dispose ( ) ;
70
70
progress = null ;
71
71
_output . WriteError ( "File upload canceled." ) ;
@@ -74,51 +74,56 @@ public async Task Execute(Parameters parameters)
74
74
75
75
using ( var apiSession = await OpenSession ( parameters ) )
76
76
{
77
- var browsing = await _apiClient . BrowseSpaceAsync ( apiSession , parameters . Target , _cancellationTokenSource . Token ) ;
78
- if ( ! browsing . CanUploadFiles )
79
- {
80
- throw new Exception ( "Uploading to this space is disabled" ) ;
81
- }
82
77
83
-
84
- if ( parameters . YesToAll )
85
- {
86
- // don't care if file exists.
87
- _output . WriteInfo ( string . Format ( "YES key was passed. File will be overridden if it already exists" ) ) ;
88
- await _apiClient . UploadFileAsync ( apiSession , parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteFileifExists : true ) ;
89
- }
90
- else
91
78
{
79
+ var spaceBrowsing = await _apiClient . SpaceBrowseAsync ( apiSession , parameters . Target , _cancellationTokenSource . Token ) ;
80
+ var spaceStatus = await _apiClient . GetSpaceStatusAsync ( apiSession , _cancellationTokenSource . Token ) ;
81
+ if ( ! spaceStatus . UserPermissions . Contains ( UserSpacePermission . FileUpload ) )
82
+ {
83
+ throw new Exception ( "Uploading to this space is disabled" ) ;
84
+ }
85
+
86
+ var transferUtility = new DataTransferUtility ( _apiClient , apiSession ) ;
92
87
93
- var fileExists = browsing . FileExists ( Path . GetFileName ( parameters . Source ) ) ;
94
- if ( fileExists )
88
+ if ( parameters . YesToAll )
95
89
{
96
- if ( _output . IsOutputRedirected )
97
- {
98
- _output . WriteError ( string . Format ( "Unable to upload file '{0}' due to file already exists. Use /y to override it " , parameters . Target ) ) ;
99
- }
100
- else
90
+ // don't care if file exists.
91
+ _output . WriteInfo ( string . Format ( "YES key was passed. File will be overridden if it already exists" ) ) ;
92
+ await transferUtility . SpaceUploadFileAsync ( parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteExistingFile : true ) ;
93
+ }
94
+ else
95
+ {
96
+
97
+ var fileExists = spaceBrowsing . FileExists ( Path . GetFileName ( parameters . Source ) ) ;
98
+ if ( fileExists )
101
99
{
102
- _output . WriteInfo ( "Uploading file already exists. Would you like to override it? Y/N" ) ;
103
- _output . WriteInfo ( "You may pass /y parameter to override file without any questions" ) ;
104
- var answer = _input . ReadLine ( ) ;
105
- if ( answer . Trim ( ) . ToLowerInvariant ( ) . StartsWith ( "y" ) )
100
+ if ( _output . IsOutputRedirected )
106
101
{
107
- _output . WriteInfo ( "Uploading file..." ) ;
108
- await _apiClient . UploadFileAsync ( apiSession , parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteFileifExists : true ) ;
109
- _output . WriteInfo ( "Operation complete" ) ;
102
+ _output . WriteError ( string . Format ( "Unable to upload file '{0}' due to file already exists. Use /y to override it " , parameters . Target ) ) ;
110
103
}
111
104
else
112
105
{
113
- _output . WriteInfo ( "Operation canceled" ) ;
106
+ _output . WriteInfo ( "Uploading file already exists. Would you like to override it? Y/N" ) ;
107
+ _output . WriteInfo ( "You may pass /y parameter to override file without any questions" ) ;
108
+ var answer = _input . ReadLine ( ) ;
109
+ if ( answer . Trim ( ) . ToLowerInvariant ( ) . StartsWith ( "y" ) )
110
+ {
111
+ _output . WriteInfo ( "Uploading file..." ) ;
112
+ await transferUtility . SpaceUploadFileAsync ( parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteExistingFile : true ) ;
113
+ _output . WriteInfo ( "Operation complete" ) ;
114
+ }
115
+ else
116
+ {
117
+ _output . WriteInfo ( "Operation canceled" ) ;
118
+ }
114
119
}
115
120
}
116
- }
117
- else
118
- {
119
- await _apiClient . UploadFileAsync ( apiSession , parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteFileifExists : false ) ;
120
- }
121
+ else
122
+ {
123
+ await transferUtility . SpaceUploadFileAsync ( parameters . Source , parameters . Target , _cancellationTokenSource . Token , overwriteExistingFile : false ) ;
124
+ }
121
125
126
+ }
122
127
}
123
128
}
124
129
}
0 commit comments