From dc2b2f06aec22c5da7b8a77a2bef242527e013cf Mon Sep 17 00:00:00 2001 From: shinichi Date: Wed, 14 Oct 2020 16:28:37 +0200 Subject: [PATCH] move styles to sharedproject and disposed client --- ClientApp/Utils/Client.cs | 20 +++++++++++++++---- ClientApp/ViewModels/MainWindowViewModel.cs | 2 ++ Hashing/Hashing.projitems | 22 +++++++++++++++++++++ {ClientApp => Hashing}/Styles/Buttons.xaml | 0 {ClientApp => Hashing}/Styles/Colors.xaml | 0 {ClientApp => Hashing}/Styles/Fonts.xaml | 0 {ClientApp => Hashing}/Styles/Texts.xaml | 0 {ClientApp => Hashing}/Styles/Windows.xaml | 0 Server/Client.cs | 14 +++++++------ 9 files changed, 48 insertions(+), 10 deletions(-) rename {ClientApp => Hashing}/Styles/Buttons.xaml (100%) rename {ClientApp => Hashing}/Styles/Colors.xaml (100%) rename {ClientApp => Hashing}/Styles/Fonts.xaml (100%) rename {ClientApp => Hashing}/Styles/Texts.xaml (100%) rename {ClientApp => Hashing}/Styles/Windows.xaml (100%) diff --git a/ClientApp/Utils/Client.cs b/ClientApp/Utils/Client.cs index 16527fd..7a4dd03 100644 --- a/ClientApp/Utils/Client.cs +++ b/ClientApp/Utils/Client.cs @@ -10,7 +10,7 @@ using Util; namespace ClientApp.Utils { public delegate void EngineCallback(); - public class Client : IDataReceiver + public class Client : IDataReceiver, IDisposable { public EngineCallback engineConnectFailed; public EngineCallback engineConnectSuccess; @@ -87,6 +87,10 @@ namespace ClientApp.Utils /// the result of the async read private void OnRead(IAsyncResult ar) { + if (ar == null || (!ar.IsCompleted)) + return; + + int receivedBytes = this.stream.EndRead(ar); if (totalBufferReceived + receivedBytes > 1024) @@ -122,7 +126,7 @@ namespace ClientApp.Utils this.LoginViewModel.setLoginStatus(true); this.connected = true; initEngine(); - + } else { @@ -224,7 +228,7 @@ namespace ClientApp.Utils /// the message public void Bike(byte[] bytes) { - + if (!sessionRunning) { return; @@ -266,7 +270,7 @@ namespace ClientApp.Utils /// public void tryLogin(string username, string password) { - + string hashPassword = Util.Hasher.HashString(password); byte[] message = DataParser.getJsonMessage(DataParser.GetLoginJson(username, hashPassword)); @@ -288,5 +292,13 @@ namespace ClientApp.Utils { this.LoginViewModel = loginViewModel; } + + public void Dispose() + { + Debug.WriteLine("client dispose called"); + this.stream.Dispose(); + this.client.Dispose(); + this.handler.stop(); + } } } diff --git a/ClientApp/ViewModels/MainWindowViewModel.cs b/ClientApp/ViewModels/MainWindowViewModel.cs index 56b98c1..b5caccc 100644 --- a/ClientApp/ViewModels/MainWindowViewModel.cs +++ b/ClientApp/ViewModels/MainWindowViewModel.cs @@ -118,6 +118,8 @@ namespace ClientApp.ViewModels this.MenuCommand = new RelayCommand(() => SystemCommands.ShowSystemMenu(this.mWindow, GetMousePosition())); var resizer = new WindowResizer(this.mWindow); + + this.mWindow.Closed += (sender, e) => this.client.Dispose(); } diff --git a/Hashing/Hashing.projitems b/Hashing/Hashing.projitems index a81b09e..662f597 100644 --- a/Hashing/Hashing.projitems +++ b/Hashing/Hashing.projitems @@ -13,4 +13,26 @@ + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + \ No newline at end of file diff --git a/ClientApp/Styles/Buttons.xaml b/Hashing/Styles/Buttons.xaml similarity index 100% rename from ClientApp/Styles/Buttons.xaml rename to Hashing/Styles/Buttons.xaml diff --git a/ClientApp/Styles/Colors.xaml b/Hashing/Styles/Colors.xaml similarity index 100% rename from ClientApp/Styles/Colors.xaml rename to Hashing/Styles/Colors.xaml diff --git a/ClientApp/Styles/Fonts.xaml b/Hashing/Styles/Fonts.xaml similarity index 100% rename from ClientApp/Styles/Fonts.xaml rename to Hashing/Styles/Fonts.xaml diff --git a/ClientApp/Styles/Texts.xaml b/Hashing/Styles/Texts.xaml similarity index 100% rename from ClientApp/Styles/Texts.xaml rename to Hashing/Styles/Texts.xaml diff --git a/ClientApp/Styles/Windows.xaml b/Hashing/Styles/Windows.xaml similarity index 100% rename from ClientApp/Styles/Windows.xaml rename to Hashing/Styles/Windows.xaml diff --git a/Server/Client.cs b/Server/Client.cs index 092fe70..78a1e02 100644 --- a/Server/Client.cs +++ b/Server/Client.cs @@ -34,14 +34,16 @@ namespace Server private void OnRead(IAsyncResult ar) { - + if (ar == null || (!ar.IsCompleted)) + return; + int receivedBytes = this.stream.EndRead(ar); if (totalBufferReceived + receivedBytes > 1024) - if (totalBufferReceived + receivedBytes > 1024) - { - throw new OutOfMemoryException("buffer too small"); - } + if (totalBufferReceived + receivedBytes > 1024) + { + throw new OutOfMemoryException("buffer too small"); + } Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, receivedBytes); totalBufferReceived += receivedBytes; @@ -209,7 +211,7 @@ namespace Server } - + }