Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue#9807 review 2nd (Replaces PR #11867) DRAFT #12489

Draft
wants to merge 204 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
1cd54bf
Add NetwrokDownloadTests and WebListner
paul1956 Nov 14, 2024
66298ab
Fix merge issues
paul1956 Nov 14, 2024
08be576
Sync changes from PR #11867
paul1956 Nov 15, 2024
24551f1
Simplify code
paul1956 Nov 15, 2024
bf912fe
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 15, 2024
f741607
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Nov 15, 2024
ea1d00f
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Nov 15, 2024
1adf2be
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 19, 2024
fae6727
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Nov 19, 2024
af840f2
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 19, 2024
933b97d
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Nov 19, 2024
8f280c4
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 21, 2024
b5da52c
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Nov 21, 2024
d1b4234
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 22, 2024
f3423d4
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Nov 22, 2024
4e48605
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 23, 2024
1f2e39d
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Nov 23, 2024
c687aa1
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Nov 23, 2024
1782915
Rename NetworkTests to DownloadTests
paul1956 Nov 24, 2024
69a4b60
Rename NetworkDownloadTests to DownloadFileTests
paul1956 Nov 24, 2024
2434e29
Simplify DownloadFileAsync and improve code coverage
paul1956 Nov 25, 2024
10c1989
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 25, 2024
e5d1bd9
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Nov 25, 2024
c6234bb
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Nov 25, 2024
2d92096
Simplify dialog cancel
paul1956 Nov 26, 2024
63e68f1
Cleanup formatting
paul1956 Nov 26, 2024
4324b8b
Improve test coverage for Null or Empty network address
paul1956 Nov 26, 2024
91829aa
Fix formatting
paul1956 Nov 26, 2024
df41d1e
Improve test coverage
paul1956 Nov 26, 2024
ebdc88d
Dispose of HttpListener
paul1956 Nov 27, 2024
2718370
Fix formating
paul1956 Nov 28, 2024
4002f54
Manual merge with tests only
paul1956 Nov 28, 2024
175440a
Clean up formatting issues
paul1956 Nov 28, 2024
1bf3591
Add some Async Tests
paul1956 Nov 28, 2024
f1c6e65
Move download verifiers to separate file
paul1956 Nov 28, 2024
1d0b3e2
Fix broken test
paul1956 Nov 28, 2024
fa37a7b
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Nov 28, 2024
fbd2c7c
Remove Imports Microsoft.VisualBasic.CompilerServices
paul1956 Nov 28, 2024
0baeb02
Fix error cause myy removal of Imports Microsoft.VisualBasic.Compiler…
paul1956 Nov 28, 2024
887616f
Merge
paul1956 Nov 28, 2024
8977f10
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 6, 2024
96ea6b8
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 6, 2024
7f51bcc
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 11, 2024
04ed891
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 11, 2024
a9eb2f5
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 12, 2024
2ad4315
Merge
paul1956 Dec 12, 2024
5b89c04
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 13, 2024
fdbbf0d
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 13, 2024
2b7303c
Fix behaviour cancel dialog behavior to match WebCleintDownload
paul1956 Dec 15, 2024
8d1fe48
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 15, 2024
ffe7e35
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 15, 2024
4657882
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 16, 2024
db6bdf6
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 17, 2024
c1968fc
Merge branch 'master' into FixIssue#9807-2nd-DRAFT
paul1956 Dec 17, 2024
4a532db
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 17, 2024
ccdf42b
Add UploadFile Tests
paul1956 Dec 17, 2024
c7542cc
Avoid merge issues
paul1956 Dec 17, 2024
7324bb1
Sort private variables
paul1956 Dec 17, 2024
65cbc86
Move WebListener.vb to TestUtilities Folder
paul1956 Dec 17, 2024
ae6e5c6
Fix formatting
paul1956 Dec 17, 2024
f3cc2d0
Formatting fixes
paul1956 Dec 17, 2024
5a79bf2
Fix formatting
paul1956 Dec 17, 2024
cdab3aa
Fix formatting
paul1956 Dec 17, 2024
3e0f553
Merge
paul1956 Dec 17, 2024
bd3bd66
Remove WebClientCopy and replace with HttpClientCopy
paul1956 Dec 19, 2024
47f12cd
Correct messaages for ProgressDialog which calls wrong GetResourceStr…
paul1956 Dec 19, 2024
e3ce2e2
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 19, 2024
6a82523
Add more tests and check that files are properly uploaded with correc…
paul1956 Dec 19, 2024
8693579
Address PF for tabbing after _
paul1956 Dec 19, 2024
143917b
Merge
paul1956 Dec 19, 2024
2110608
Add char specifier to Inline single character strings
paul1956 Dec 19, 2024
bf40011
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 19, 2024
a3ead0c
Fix some missing spaces
paul1956 Dec 19, 2024
41f8a19
Use PathSeparatorTestData
paul1956 Dec 20, 2024
73aa2cd
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 20, 2024
eb6ba5c
Fix order of functions
paul1956 Dec 20, 2024
180ffc3
Sort and cleanup comments
paul1956 Dec 20, 2024
a7b20cc
Minor formatting changes
paul1956 Dec 20, 2024
4a920dd
Clean up XML Comments in ClipBoardProxy
paul1956 Dec 20, 2024
c633809
Update cooment for Cllipboard to restore changes lost in merge
paul1956 Dec 20, 2024
0302c9c
Sync ClipBoardProxy
paul1956 Dec 20, 2024
7c774ad
Merge Master
paul1956 Dec 20, 2024
4f9d051
Cleanup NetworkUploadFile and consolidate is interactive
paul1956 Dec 20, 2024
5769aee
Add and use InteractiveEnvironment
paul1956 Dec 20, 2024
1a977c9
Fix merge issues
paul1956 Dec 20, 2024
15aa370
Fix spacing
paul1956 Dec 20, 2024
8ae6b24
Move clientHandler initialization
paul1956 Dec 20, 2024
d74231a
Fix formatting
paul1956 Dec 20, 2024
cf837e1
Fix formatting
paul1956 Dec 20, 2024
03fc394
Merge
paul1956 Dec 20, 2024
29b7296
Get all tests to work
paul1956 Dec 20, 2024
354ccdf
Improve UploadFile and DownloadFile Tests
paul1956 Dec 20, 2024
468e669
Add SR strings from WebClient
paul1956 Dec 20, 2024
6e313e2
Fix error handling and add new strings for to replace WebClient
paul1956 Dec 20, 2024
b8de54b
Fix error handling
paul1956 Dec 20, 2024
70283e4
Improve WebListener
paul1956 Dec 22, 2024
0fa9cd3
Fix logic in WebListener return 500 for server errors
paul1956 Dec 22, 2024
a6413df
Sort new functions
paul1956 Dec 22, 2024
53bbcac
Fix a;l remaining tests
paul1956 Dec 23, 2024
8449f48
Improve test server and test
paul1956 Dec 23, 2024
feb51c6
Minor formatiting correction
paul1956 Dec 23, 2024
6ee4575
Fix large file manual test
paul1956 Dec 23, 2024
6e3b58e
Improve a couple of Skip comments
paul1956 Dec 23, 2024
d3e5523
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 23, 2024
4a1e562
Merge
paul1956 Dec 23, 2024
c9f8d7c
Improove responsiveness of upload and download and sync the code
paul1956 Dec 25, 2024
ad1bab1
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Dec 25, 2024
86a3a05
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Dec 25, 2024
c67d2a9
Simplify DownloadFileAsync
paul1956 Jan 1, 2025
c67f9cf
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 2, 2025
3c103d7
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 2, 2025
4d3c165
Shorten long lines in Network.DownloadFileAsync
paul1956 Jan 2, 2025
134f52f
Cleanup comments without space after single quote
paul1956 Jan 2, 2025
553b886
FIX comments in Network files
paul1956 Jan 2, 2025
51e23d3
Fix a few more missing spaces
paul1956 Jan 2, 2025
758772a
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 6, 2025
9ad4e16
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 6, 2025
b8a8516
Fix some cancel's of DownloadFile and UploadFile being ignored.
paul1956 Jan 6, 2025
ac82c9f
PR feedback
paul1956 Jan 8, 2025
e2ff073
PR Feedback Cleanup files in Separate PR
paul1956 Jan 8, 2025
5f956f4
Merge branch 'Cleanup-review-first' into Code-Coverage-DownloadFile-R…
paul1956 Jan 8, 2025
f24382a
Prevent Merge issues
paul1956 Jan 8, 2025
4f963cf
Merge
paul1956 Jan 8, 2025
0b70c5d
Merge branch 'master' into Cleanup-review-first
paul1956 Jan 8, 2025
6f59c93
Merge branch 'Cleanup-review-first' into Code-Coverage-DownloadFile-R…
paul1956 Jan 8, 2025
ee82ec8
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 8, 2025
3f71dd5
Fix merge error
paul1956 Jan 8, 2025
a36b059
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 9, 2025
f6fe268
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 9, 2025
6509c30
Fix merge error
paul1956 Jan 9, 2025
e46d87e
Fix merge error
paul1956 Jan 9, 2025
395de61
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 10, 2025
54315ae
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 10, 2025
bf4d70a
PR Feedback Don't create new exceptions.
paul1956 Jan 11, 2025
dced84d
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 11, 2025
d4d4b6b
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 11, 2025
b7ad7ae
Sort Unauthorized Access tests together
paul1956 Jan 12, 2025
a084485
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 12, 2025
4fed93b
Fix merge issues
paul1956 Jan 12, 2025
253b185
Make it easier to test with real web server instead of WebListener
paul1956 Jan 12, 2025
7ddc1b2
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 12, 2025
127c7ef
Make FileName for Transfer match size
paul1956 Jan 13, 2025
fde921e
Fix logic for ServerThrowsPasswordErrors
paul1956 Jan 13, 2025
3ed66c3
Add ServerConfiguratio,json file to allow manual testing using privat…
paul1956 Jan 13, 2025
c94a16f
Fix issues found in testing on File servers
paul1956 Jan 14, 2025
b674593
Fix upload and download tests to handle both possible cancelations ex…
paul1956 Jan 14, 2025
e8b912e
Correct skip download test on GitHub
paul1956 Jan 14, 2025
846ae50
Improve code coverage
paul1956 Jan 15, 2025
abeb4f7
Fix spelling error
paul1956 Jan 15, 2025
bb1b65a
Fix default values in ServerConfiguration.json
paul1956 Jan 15, 2025
96e7834
Correct default password for local testing
paul1956 Jan 15, 2025
9faf31e
Make CreateTempFile more robust by making size a FileSize Enum
paul1956 Jan 15, 2025
0efa368
Prevent merge issue
paul1956 Jan 16, 2025
efa5e04
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 16, 2025
74abf89
Merge
paul1956 Jan 16, 2025
1f5dd80
Fix test failures
paul1956 Jan 16, 2025
bbd01fe
Cleanup VbFileCleanupTestBase
paul1956 Jan 16, 2025
3594993
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 16, 2025
74bb4b8
Change Getter in ServerConfiguration to be private to avoid exposing …
paul1956 Jan 18, 2025
8d46198
Add tests for ServerConfiguration
paul1956 Jan 22, 2025
3eb681c
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 22, 2025
b22aa91
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 23, 2025
caaeb54
Cleanup ServerConfigurationTests
paul1956 Jan 23, 2025
b9fcf21
Update broken test
paul1956 Jan 23, 2025
4ea5f9e
Fix failing test
paul1956 Jan 23, 2025
0be8d2e
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 24, 2025
79c12e5
Restore WebClientCopy, remove incorrect fix
paul1956 Jan 24, 2025
69199fa
Merge
paul1956 Jan 24, 2025
12364c0
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 25, 2025
1188123
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 25, 2025
db6e9a5
Fix error message text for file upload/download operations
paul1956 Jan 25, 2025
fd55d2b
Fix exception messages for uploadFile and downloadFile
paul1956 Jan 25, 2025
8a51d7e
Improve code coverage
paul1956 Jan 27, 2025
3dce1a7
Improve test coverage
paul1956 Jan 27, 2025
11df186
Improve coverage for invalid connectionTimeout
paul1956 Jan 27, 2025
9ee75a8
Rename filing tests to end with Throw
paul1956 Jan 27, 2025
69f2695
Rename filing tests to end with Throw
paul1956 Jan 27, 2025
bbf0622
Improve test coverage
paul1956 Jan 27, 2025
cdcb4e7
Improve code coverage
paul1956 Jan 27, 2025
a0b06af
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 27, 2025
3edb205
Fix encoding in SR.resx file
paul1956 Jan 27, 2025
1ac03f1
Merge
paul1956 Jan 27, 2025
1c1341b
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 27, 2025
24f15c5
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 27, 2025
1d94bd5
Undo changes to WebClientCopy
paul1956 Jan 27, 2025
6a44666
Update changes to SingleInstanceHe;perTests to match master
paul1956 Jan 27, 2025
bfc3deb
Merge
paul1956 Jan 27, 2025
4674ca3
Fix a couple of comments
paul1956 Jan 27, 2025
16a9c62
Add test for missing file to be downloaded on server
paul1956 Jan 29, 2025
25972f9
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 29, 2025
8d45a2f
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 29, 2025
ff4ce61
Handle File not found on server
paul1956 Jan 29, 2025
65f8638
Improve HttpResponse handling
paul1956 Jan 29, 2025
d5a4723
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Jan 31, 2025
da4e9c9
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Jan 31, 2025
513fe71
Handle more HttpStatusCode(s)
paul1956 Jan 31, 2025
63f9b0c
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Feb 10, 2025
571371f
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Feb 10, 2025
a2aeffe
Merge branch 'master' into Code-Coverage-DownloadFile-Review-1St
paul1956 Mar 2, 2025
f373d22
Merge branch 'Code-Coverage-DownloadFile-Review-1St' into FixIssue#98…
paul1956 Mar 2, 2025
435a8fb
Remove unneccessary imports
paul1956 Mar 2, 2025
2465ab0
Use Path.Join
paul1956 Mar 13, 2025
74e9b92
Merge
paul1956 Mar 13, 2025
ebb4b83
Fix merge issues
paul1956 Mar 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.Net
Imports System.Net.Http
Imports System.Threading
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.CompilerServices
Imports Microsoft.VisualBasic.FileIO
Imports Microsoft.VisualBasic.MyServices.Internal
Expand Down Expand Up @@ -262,6 +265,7 @@ Namespace Microsoft.VisualBasic.Devices
connectionTimeout As Integer,
onUserCancel As UICancelOption)

' Construct the local file. This will validate the full name and path
sourceFileName = FileSystemUtils.NormalizeFilePath(sourceFileName, NameOf(sourceFileName))

' Make sure the file exists
Expand All @@ -280,15 +284,13 @@ Namespace Microsoft.VisualBasic.Devices
Throw GetArgumentNullException(NameOf(address))
End If

Using client As New WebClientExtended()
client.Timeout = connectionTimeout

' Set credentials if we have any
If networkCredentials IsNot Nothing Then
client.Credentials = networkCredentials
End If

Dim dialog As ProgressDialog = Nothing
Dim dialog As ProgressDialog = Nothing
Try
' Get network credentials
Dim clientHandler As HttpClientHandler =
If(networkCredentials Is Nothing,
New HttpClientHandler,
New HttpClientHandler With {.Credentials = networkCredentials})
If InteractiveEnvironment(showUI) Then
dialog = New ProgressDialog With {
.Text = GetResourceString(SR.ProgressDialogUploadingTitle, sourceFileName),
Expand All @@ -299,19 +301,39 @@ Namespace Microsoft.VisualBasic.Devices
}
End If

' Create the copier
Dim copier As New WebClientCopy(client, dialog)

' Download the file
copier.UploadFile(sourceFileName, address)

' Handle a dialog cancel
If InteractiveEnvironment(showUI) Then
If onUserCancel = UICancelOption.ThrowException And dialog.UserCanceledTheDialog Then
Throw New OperationCanceledException()
Dim t As Task = UploadFileAsync(
sourceFileName,
addressUri:=address,
clientHandler,
dialog,
connectionTimeout,
onUserCancel)

If t.IsFaulted Then
' IsFaulted will be true if any parameters are bad
Throw t.Exception
Else
dialog?.ShowProgressDialog()
Do While Not (t.IsCompleted OrElse t.IsFaulted OrElse t.IsCanceled)
' prevent UI freeze
Thread.Sleep(10)
Application.DoEvents()
Loop
If t.IsFaulted Then
Throw t.Exception
End If
If t.IsCanceled Then
Throw New OperationCanceledException
End If
End If
Catch ex As Exception
If ex.InnerException IsNot Nothing Then
Throw ex.InnerException
End If
End Using
Throw
Finally
CloseProgressDialog(dialog)
End Try

End Sub

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
' Licensed to the .NET Foundation under one or more agreements.
' The .NET Foundation licenses this file to you under the MIT license.

Imports System.Net
Imports System.Net.Http
Imports System.Threading
Imports Microsoft.VisualBasic.CompilerServices
Imports Microsoft.VisualBasic.FileIO
Imports Microsoft.VisualBasic.MyServices.Internal

Imports VbUtils = Microsoft.VisualBasic.CompilerServices.ExceptionUtils

Namespace Microsoft.VisualBasic.Devices

Partial Public Class Network
''' <summary>
''' Uploads a file to the network to the specified path.
''' </summary>
''' <param name="sourceFileName">Name and path of file to be uploaded.</param>
''' <param name="addressUri">Uri to the remote file</param>
''' <param name="clientHandler">An HttpClientHandler of the user performing the download.</param>
''' <param name="dialog">Progress Dialog.</param>
''' <param name="connectionTimeout">Time allotted before giving up on a connection.</param>
''' <param name="onUserCancel">Indicates what to do if user cancels dialog (either throw or do nothing).</param>
''' <param name="cancelToken"><see cref="CancellationToken"/></param>
''' <remarks>Calls to all the other overloads will come through here.</remarks>
Friend Shared Async Function UploadFileAsync(
sourceFileName As String,
addressUri As Uri,
clientHandler As HttpClientHandler,
dialog As ProgressDialog,
connectionTimeout As Integer,
onUserCancel As UICancelOption,
Optional cancelToken As CancellationToken = Nothing) As Task

If cancelToken = Nothing Then
cancelToken = New CancellationTokenSource().Token
End If

If connectionTimeout <= 0 Then
Throw VbUtils.GetArgumentExceptionWithArgName(NameOf(connectionTimeout), SR.Network_BadConnectionTimeout)
End If

If addressUri Is Nothing Then
Throw VbUtils.GetArgumentNullException(NameOf(addressUri))
End If

Dim normalizedFilePath As String = FileSystemUtils.NormalizeFilePath(sourceFileName, NameOf(sourceFileName))

' Make sure we have a meaningful file.
If String.IsNullOrEmpty(normalizedFilePath) Then
Throw VbUtils.GetInvalidOperationException(SR.Network_DownloadNeedsFilename)
End If

Dim client As HttpClient = If(clientHandler Is Nothing,
New HttpClient(),
New HttpClient(clientHandler))
client.Timeout = New TimeSpan(0, 0, 0, 0, connectionTimeout)

' Create the copier
Dim copier As New HttpClientCopy(client, dialog)

' Upload the file
Try
Await copier.UploadFileWorkerAsync(
filePath:=normalizedFilePath,
requestURI:=addressUri,
externalToken:=cancelToken).ConfigureAwait(continueOnCapturedContext:=False)
Catch ioEx As IO.IOException
Throw

Catch ex As Exception
If onUserCancel = UICancelOption.ThrowException OrElse (dialog IsNot Nothing AndAlso Not dialog.UserCanceledTheDialog) Then
If ex.Message.Contains("401") Then
Throw New WebException(SR.net_webstatus_Unauthorized, WebExceptionStatus.ProtocolError)
End If
Throw
End If
If ex.Message.Contains("401") Then
Throw New WebException(SR.net_webstatus_Unauthorized)
End If
Finally
CloseProgressDialog(dialog)
End Try

End Function

End Class
End Namespace
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Namespace Microsoft.VisualBasic.Devices
showUI As Boolean) As ProgressDialog

If InteractiveEnvironment(showUI) Then
'Construct the local file. This will validate the full name and path
' Construct the local file. This will validate the full name and path
Dim fullFilename As String = FileSystemUtils.NormalizeFilePath(
path:=destinationFileName,
paramName:=NameOf(destinationFileName))
Expand All @@ -95,7 +95,7 @@ Namespace Microsoft.VisualBasic.Devices
Try
Return New Uri(address)
Catch ex As UriFormatException
'Throw an exception with an error message more appropriate to our API
' Throw an exception with an error message more appropriate to our API
Throw GetArgumentExceptionWithArgName(
argumentName:=NameOf(address),
resourceKey:=SR.Network_InvalidUriString,
Expand Down

This file was deleted.

Loading