@@ -30,7 +30,7 @@ public async Task Execute(Parameters parameters)
3030 throw new WrongCommandFormatException ( "Source is required" ) ;
3131 }
3232
33-
33+
3434 if ( string . IsNullOrWhiteSpace ( parameters . Target ) )
3535 {
3636 _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)
4848
4949
5050 ProgressBar progress = null ;
51- _apiClient . FileProgress += ( object sender , FileEventArgs e ) =>
51+ _apiClient . OnDataUploadProgress += ( object sender , FileTransferProgressEventArgs e ) =>
5252 {
5353 if ( e . State == FileProgressState . Starting )
5454 {
@@ -64,8 +64,8 @@ public async Task Execute(Parameters parameters)
6464 progress . Dispose ( ) ;
6565 progress = null ;
6666 }
67- else if ( e . State == FileProgressState . Cancelled )
68- {
67+ else if ( e . State == FileProgressState . Cancelled )
68+ {
6969 progress . Dispose ( ) ;
7070 progress = null ;
7171 _output . WriteError ( "File upload canceled." ) ;
@@ -74,51 +74,56 @@ public async Task Execute(Parameters parameters)
7474
7575 using ( var apiSession = await OpenSession ( parameters ) )
7676 {
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- }
8277
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
9178 {
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 ) ;
9287
93- var fileExists = browsing . FileExists ( Path . GetFileName ( parameters . Source ) ) ;
94- if ( fileExists )
88+ if ( parameters . YesToAll )
9589 {
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 )
10199 {
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 )
106101 {
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 ) ) ;
110103 }
111104 else
112105 {
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+ }
114119 }
115120 }
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+ }
121125
126+ }
122127 }
123128 }
124129 }
0 commit comments