From 88524047ffee964a0e414a19ea1e6289edc86a89 Mon Sep 17 00:00:00 2001 From: schedpas Date: Wed, 27 Oct 2021 10:04:34 +0200 Subject: [PATCH 1/7] Interface for UniquieID - IUniquieID --- Pilz.Cryptography/IUniquieID.cs | 15 +++++++++++++++ Pilz.Cryptography/UniquieID.cs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Pilz.Cryptography/IUniquieID.cs diff --git a/Pilz.Cryptography/IUniquieID.cs b/Pilz.Cryptography/IUniquieID.cs new file mode 100644 index 0000000..dbfc87e --- /dev/null +++ b/Pilz.Cryptography/IUniquieID.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Pilz.Cryptography +{ + interface IUniquieID + { + bool HasID { get; } + string ID { get; } + + void GenerateIfNull(); + void Generate(); + } +} diff --git a/Pilz.Cryptography/UniquieID.cs b/Pilz.Cryptography/UniquieID.cs index 16efa58..6655afc 100644 --- a/Pilz.Cryptography/UniquieID.cs +++ b/Pilz.Cryptography/UniquieID.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace Pilz.Cryptography { - public class UniquieID + public class UniquieID : IUniquieID { private static int currentSimpleID = 0; From 2415feaca38078502fcaddbcd1abd05b169ea8d4 Mon Sep 17 00:00:00 2001 From: schedpas Date: Wed, 27 Oct 2021 10:11:58 +0200 Subject: [PATCH 2/7] public IUniquieID --- Pilz.Cryptography/IUniquieID.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pilz.Cryptography/IUniquieID.cs b/Pilz.Cryptography/IUniquieID.cs index dbfc87e..87e606c 100644 --- a/Pilz.Cryptography/IUniquieID.cs +++ b/Pilz.Cryptography/IUniquieID.cs @@ -4,7 +4,7 @@ using System.Text; namespace Pilz.Cryptography { - interface IUniquieID + public interface IUniquieID { bool HasID { get; } string ID { get; } From 4ca12b19dafef532e74959685a1b970e9dea3343 Mon Sep 17 00:00:00 2001 From: schedpas Date: Wed, 27 Oct 2021 10:16:58 +0200 Subject: [PATCH 3/7] Euqlas for IUniquieID --- Pilz.Cryptography/IUniquieID.cs | 1 + Pilz.Cryptography/UniquieID.cs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Pilz.Cryptography/IUniquieID.cs b/Pilz.Cryptography/IUniquieID.cs index 87e606c..34bc49e 100644 --- a/Pilz.Cryptography/IUniquieID.cs +++ b/Pilz.Cryptography/IUniquieID.cs @@ -11,5 +11,6 @@ namespace Pilz.Cryptography void GenerateIfNull(); void Generate(); + bool Equals(object obj); } } diff --git a/Pilz.Cryptography/UniquieID.cs b/Pilz.Cryptography/UniquieID.cs index 6655afc..ff7ee07 100644 --- a/Pilz.Cryptography/UniquieID.cs +++ b/Pilz.Cryptography/UniquieID.cs @@ -92,7 +92,7 @@ namespace Pilz.Cryptography { var iD = obj as UniquieID; return iD != null && - _iD == iD._iD; + _iD.Equals(iD._iD); } public override int GetHashCode() From daf0e8f4a3b95517cc54bc2c617b851bb3e66f2c Mon Sep 17 00:00:00 2001 From: schedpas Date: Wed, 27 Oct 2021 10:34:25 +0200 Subject: [PATCH 4/7] optimize equals for UniquieID --- Pilz.Cryptography/UniquieID.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Pilz.Cryptography/UniquieID.cs b/Pilz.Cryptography/UniquieID.cs index ff7ee07..5437b1f 100644 --- a/Pilz.Cryptography/UniquieID.cs +++ b/Pilz.Cryptography/UniquieID.cs @@ -91,8 +91,13 @@ namespace Pilz.Cryptography public override bool Equals(object obj) { var iD = obj as UniquieID; - return iD != null && - _iD.Equals(iD._iD); + var leftHasID = (iD?.HasID ?? false); + var rightHasID = HasID; + + if (leftHasID && rightHasID) + return _iD.Equals(iD._iD); + else + return false; } public override int GetHashCode() @@ -104,7 +109,7 @@ namespace Pilz.Cryptography public static implicit operator UniquieID(string id) => new UniquieID() { ID = id }; public static implicit operator UniquieID(int id) => new UniquieID() { ID = Convert.ToString(id) }; - public static bool operator ==(UniquieID left, UniquieID right) => left.ID == right.ID; - public static bool operator !=(UniquieID left, UniquieID right) => left.ID != right.ID; + public static bool operator ==(UniquieID left, UniquieID right) => left.ID.Equals(right.ID); + public static bool operator !=(UniquieID left, UniquieID right) => !left.ID.Equals(right.ID); } } From a7de6c7bd614cea06d44497f33b6a2f51ef3e579 Mon Sep 17 00:00:00 2001 From: schedpas Date: Tue, 30 Nov 2021 11:14:49 +0100 Subject: [PATCH 5/7] prevent ReferenceNullException for equalizing UniquieID --- Pilz.Cryptography/UniquieID.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pilz.Cryptography/UniquieID.cs b/Pilz.Cryptography/UniquieID.cs index 5437b1f..bf09edd 100644 --- a/Pilz.Cryptography/UniquieID.cs +++ b/Pilz.Cryptography/UniquieID.cs @@ -91,7 +91,7 @@ namespace Pilz.Cryptography public override bool Equals(object obj) { var iD = obj as UniquieID; - var leftHasID = (iD?.HasID ?? false); + var leftHasID = iD != null && iD.HasID; var rightHasID = HasID; if (leftHasID && rightHasID) From 1f12af2a68ff60ad623ede4b5af5ad416b2c61fd Mon Sep 17 00:00:00 2001 From: schedpas Date: Tue, 30 Nov 2021 11:46:59 +0100 Subject: [PATCH 6/7] d --- Pilz.Cryptography/UniquieID.cs | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/Pilz.Cryptography/UniquieID.cs b/Pilz.Cryptography/UniquieID.cs index bf09edd..ddf2c08 100644 --- a/Pilz.Cryptography/UniquieID.cs +++ b/Pilz.Cryptography/UniquieID.cs @@ -90,14 +90,36 @@ namespace Pilz.Cryptography public override bool Equals(object obj) { + var res = false; var iD = obj as UniquieID; - var leftHasID = iD != null && iD.HasID; - var rightHasID = HasID; - if (leftHasID && rightHasID) - return _iD.Equals(iD._iD); - else - return false; + if (iD is object) + { + if (ReferenceEquals(res, iD)) + res = true; + else + { + var leftHasID = iD.HasID; + var rightHasID = HasID; + + if (!leftHasID && iD.GenerateOnGet) + { + iD.Generate(); + leftHasID = iD.HasID; + } + + if (!rightHasID && GenerateOnGet) + { + Generate(); + rightHasID = HasID; + } + + if (leftHasID && rightHasID) + res = _iD.Equals(iD._iD); + } + } + + return res; } public override int GetHashCode() From 8c74ca9553fbddc00797586ef2d74d432cbad5f4 Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 31 Jan 2022 14:04:12 +0000 Subject: [PATCH 7/7] recursive SuspendDrawing and ResumeDrawing --- Pilz.UI/Utilities/DrawingControl.vb | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/Pilz.UI/Utilities/DrawingControl.vb b/Pilz.UI/Utilities/DrawingControl.vb index 02b44a8..9dd45a4 100644 --- a/Pilz.UI/Utilities/DrawingControl.vb +++ b/Pilz.UI/Utilities/DrawingControl.vb @@ -1,4 +1,4 @@ -Imports System.Runtime.CompilerServices +Imports System.Runtime.CompilerServices Imports System.Windows.Forms Namespace Utils @@ -6,10 +6,19 @@ Namespace Utils Public Module DrawingControl Private Const WM_SETREDRAW = 11 + Private ReadOnly dicSuspendCount As New Dictionary(Of IntPtr, Integer) Public Sub SuspendDrawing(control As Control) - SendMessage(control.Handle, WM_SETREDRAW, False, 0) + If Not dicSuspendCount.ContainsKey(control.Handle) Then + dicSuspendCount.Add(control.Handle, 1) + Else + dicSuspendCount(control.Handle) += 1 + End If + + If dicSuspendCount(control.Handle) = 1 Then + SendMessage(control.Handle, WM_SETREDRAW, False, 0) + End If End Sub @@ -19,8 +28,19 @@ Namespace Utils Public Sub ResumeDrawing(control As Control, redraw As Boolean) - SendMessage(control.Handle, WM_SETREDRAW, True, 0) - If redraw Then control.Refresh() + Dim doRedraw As Boolean = True + + If dicSuspendCount.ContainsKey(control.Handle) Then + dicSuspendCount(control.Handle) -= 1 + If dicSuspendCount(control.Handle) >= 1 Then + doRedraw = False + End If + End If + + If doRedraw Then + SendMessage(control.Handle, WM_SETREDRAW, True, 0) + If redraw Then control.Refresh() + End If End Sub End Module