From 1756d32c799830469ff7144ed9c35347574f1e20 Mon Sep 17 00:00:00 2001 From: zmjack Date: Tue, 6 Dec 2022 17:14:02 +0800 Subject: [PATCH] v1.3.2 --- PortProxyGUI/Data/ApplicationDbScope.cs | 14 +++++++++++--- PortProxyGUI/PortProxyGUI.cs | 7 ++++++- PortProxyGUI/PortProxyGUI.csproj | 2 +- README.md | 2 +- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/PortProxyGUI/Data/ApplicationDbScope.cs b/PortProxyGUI/Data/ApplicationDbScope.cs index 24800df..856dd3f 100644 --- a/PortProxyGUI/Data/ApplicationDbScope.cs +++ b/PortProxyGUI/Data/ApplicationDbScope.cs @@ -41,9 +41,11 @@ namespace PortProxyGUI.Data public void Add(T obj) where T : class { var newid = Guid.NewGuid().ToString(); - if (obj is Rule rule) + { Sql($"INSERT INTO Rules (Id, Type, ListenOn, ListenPort, ConnectTo, ConnectPort, Comment, `Group`) VALUES ({newid}, {rule.Type}, {rule.ListenOn}, {rule.ListenPort}, {rule.ConnectTo}, {rule.ConnectPort}, {rule.Comment ?? ""}, {rule.Group ?? ""});"); + rule.Id = newid; + } else throw new NotSupportedException($"Adding {obj.GetType().FullName} is not supported."); } public void AddRange(IEnumerable objs) where T : class @@ -53,7 +55,10 @@ namespace PortProxyGUI.Data public void Update(T obj) where T : class { - if (obj is Rule rule) Sql($"UPDATE Rules SET Type={rule.Type}, ListenOn={rule.ListenOn}, ListenPort={rule.ListenPort}, ConnectTo={rule.ConnectTo}, ConnectPort={rule.ConnectPort} WHERE Id={rule.Id};"); + if (obj is Rule rule) + { + Sql($"UPDATE Rules SET Type={rule.Type}, ListenOn={rule.ListenOn}, ListenPort={rule.ListenPort}, ConnectTo={rule.ConnectTo}, ConnectPort={rule.ConnectPort} WHERE Id={rule.Id};"); + } else throw new NotSupportedException($"Updating {obj.GetType().FullName} is not supported."); } public void UpdateRange(IEnumerable objs) where T : class @@ -63,7 +68,10 @@ namespace PortProxyGUI.Data public void Remove(T obj) where T : class { - if (obj is Rule rule) Sql($"DELETE FROM Rules WHERE Id={rule.Id};"); + if (obj is Rule rule) + { + Sql($"DELETE FROM Rules WHERE Id={rule.Id};"); + } else throw new NotSupportedException($"Removing {obj.GetType().FullName} is not supported."); } public void RemoveRange(IEnumerable objs) where T : class diff --git a/PortProxyGUI/PortProxyGUI.cs b/PortProxyGUI/PortProxyGUI.cs index 636a17e..2722ab1 100644 --- a/PortProxyGUI/PortProxyGUI.cs +++ b/PortProxyGUI/PortProxyGUI.cs @@ -182,7 +182,12 @@ namespace PortProxyGUI } var pendingAdds = proxies.Where(x => x.Valid && x.Id == null); - var pendingUpdates = proxies.Where(x => x.Valid && x.Id != null && !x.Equals(rules.First(r => r.Id == x.Id))); + var pendingUpdates = + from proxy in proxies + let exsist = rules.FirstOrDefault(r => r.Id == proxy.Id) + where exsist is not null + where proxy.Valid && proxy.Id is not null + select proxy; Program.SqliteDbScope.AddRange(pendingAdds); Program.SqliteDbScope.UpdateRange(pendingUpdates); diff --git a/PortProxyGUI/PortProxyGUI.csproj b/PortProxyGUI/PortProxyGUI.csproj index 0a05177..abb7977 100644 --- a/PortProxyGUI/PortProxyGUI.csproj +++ b/PortProxyGUI/PortProxyGUI.csproj @@ -14,7 +14,7 @@ portproxy TCP/IP redirector LICENSE.md Copyright © nstandard.net 2020 - 1.3.1 + 1.3.2 icon.ico Microsoft Sans Serif, 8pt PPGUI diff --git a/README.md b/README.md index b54547a..5c95bcb 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ A manager for netsh interface portproxy, which is to evaluate TCP/IP port redire ## Upgrade -- **v1.3.1** +- **v1.3.1 - v1.3.2** - Fix program crash caused by wrong rules. - **v1.3.0** - Update display, provide comments and grouping.