Skip to content
This repository has been archived by the owner on May 8, 2019. It is now read-only.

Commit

Permalink
Reduce HttpClient.
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Jun 5, 2018
1 parent 6011e1f commit f4edbe1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
37 changes: 22 additions & 15 deletions TsinghuaNet/MainViewModel.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Imports System.Collections.ObjectModel
Imports System.Globalization
Imports System.Net.Http
Imports Berrysoft.Tsinghua.Net

Class MainViewModel
Expand Down Expand Up @@ -106,13 +107,7 @@ Class MainViewModel
Private auth4 As Auth4Helper
Private auth6 As Auth6Helper
Private net As NetHelper
Private Function InitHelper(Of T As {New, NetHelperBase})(ByRef helper As T) As T
If helper Is Nothing Then
helper = New T()
End If
UpdateHelper(helper)
Return helper
End Function
Private client As New HttpClient()
Private Sub UpdateHelper(helper As NetHelperBase)
helper.Username = Username
helper.Password = Password
Expand All @@ -121,11 +116,26 @@ Class MainViewModel
Get
Select Case State
Case NetState.Auth4
Return InitHelper(auth4)
If auth4 Is Nothing Then
auth4 = New Auth4Helper(Username, Password, client)
Else
UpdateHelper(auth4)
End If
Return auth4
Case NetState.Auth6
Return InitHelper(auth6)
If auth6 Is Nothing Then
auth6 = New Auth6Helper(Username, Password, client)
Else
UpdateHelper(auth6)
End If
Return auth6
Case NetState.Net
Return InitHelper(net)
If net Is Nothing Then
net = New NetHelper(Username, Password, client)
Else
UpdateHelper(net)
End If
Return net
Case Else
Return Nothing
End Select
Expand Down Expand Up @@ -166,7 +176,7 @@ Class MainViewModel
Public ReadOnly Property UseregHelper As UseregHelper
Get
If usereg Is Nothing Then
usereg = New UseregHelper(Username, Password)
usereg = New UseregHelper(Username, Password, client)
Else
UpdateHelper(usereg)
End If
Expand All @@ -175,10 +185,7 @@ Class MainViewModel
End Property

Public Sub DisposeHelpers()
net?.Dispose()
auth4?.Dispose()
auth6?.Dispose()
usereg?.Dispose()
client.Dispose()
End Sub
End Class

Expand Down
4 changes: 2 additions & 2 deletions TsinghuaNet/My Project/AssemblyInfo.vb
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,5 @@ Imports System.Windows
' 方法是按如下所示使用“*”: :
' <Assembly: AssemblyVersion("1.0.*")>

<Assembly: AssemblyVersion("2.3.83.0")>
<Assembly: AssemblyFileVersion("2.3.83.0")>
<Assembly: AssemblyVersion("2.4.86.0")>
<Assembly: AssemblyFileVersion("2.4.86.0")>

0 comments on commit f4edbe1

Please sign in to comment.