diff --git a/Pilz.Cryptography/SecureString.cs b/Pilz.Cryptography/SecureString.cs index 54654c5..56b3a65 100644 --- a/Pilz.Cryptography/SecureString.cs +++ b/Pilz.Cryptography/SecureString.cs @@ -11,20 +11,19 @@ namespace Pilz.Cryptography public class SecureString { public static ICrypter DefaultCrypter { get; set; } - - [JsonIgnore] public ICrypter Crypter { get; set; } - - [JsonProperty] public string EncryptedValue { get; set; } - - [JsonIgnore] public string Value { - get => GetCrypter().Decrypt(EncryptedValue); + get => GetCrypter()?.Decrypt(EncryptedValue); set => EncryptedValue = GetCrypter().Encrypt(value); } + [JsonConstructor] + private SecureString(JsonConstructorAttribute dummyAttribute) + { + } + public SecureString() : this(string.Empty, true) { @@ -73,7 +72,7 @@ namespace Pilz.Cryptography public static implicit operator string(SecureString value) => value?.Value; public static implicit operator SecureString(string value) => new SecureString(value, false); - public static bool operator ==(SecureString left, SecureString right) => left.EncryptedValue == right.EncryptedValue; - public static bool operator !=(SecureString left, SecureString right) => left.EncryptedValue != right.EncryptedValue; + public static bool operator ==(SecureString left, SecureString right) => left?.EncryptedValue == right?.EncryptedValue; + public static bool operator !=(SecureString left, SecureString right) => left?.EncryptedValue != right?.EncryptedValue; } } diff --git a/Pilz.Cryptography/SecureStringJsonConverter.cs b/Pilz.Cryptography/SecureStringJsonConverter.cs index 8a1f1f0..3d4a2ab 100644 --- a/Pilz.Cryptography/SecureStringJsonConverter.cs +++ b/Pilz.Cryptography/SecureStringJsonConverter.cs @@ -22,12 +22,13 @@ namespace Pilz.Json.Converters var idString = serializer.Deserialize(reader); SecureString id; - if (existingValue is object) + if (existingValue is SecureString) + { id = (SecureString)existingValue; + id.EncryptedValue = idString; + } else - id = new SecureString(); - - id.EncryptedValue = idString; + id = new SecureString(idString, true); return id; } diff --git a/Pilz.Cryptography/SimpleStringCrypter.cs b/Pilz.Cryptography/SimpleStringCrypter.cs index 90df652..97a2da9 100644 --- a/Pilz.Cryptography/SimpleStringCrypter.cs +++ b/Pilz.Cryptography/SimpleStringCrypter.cs @@ -35,10 +35,13 @@ namespace Pilz.Cryptography byte[] bytes = TextEncoding.GetBytes(key); byte[] array = sha1CryptoServiceProvider.ComputeHash(bytes); - var output = new byte[checked(length - 1 + 1)]; - array.CopyTo(output, 0); + var output = new byte[length]; + var lowerLength = Math.Min(array.Length, output.Length); + + for (int i = 0; i < lowerLength; i++) + output[i] = array[i]; - return array; + return output; } private string EncryptData(string plaintext) @@ -63,7 +66,7 @@ namespace Pilz.Cryptography public string Encrypt(string plainValue) { - return EncryptData(plainValue); + return EncryptData(plainValue ?? string.Empty); } public string Decrypt(string encryptedValue) diff --git a/Pilz.Reflection.PluginSystem/PluginManager.vb b/Pilz.Reflection.PluginSystem/PluginManager.vb index c7acaa8..9ec8df0 100644 --- a/Pilz.Reflection.PluginSystem/PluginManager.vb +++ b/Pilz.Reflection.PluginSystem/PluginManager.vb @@ -2,6 +2,12 @@ Public Class PluginManager + ''' + ''' Gets or sets an indicator if an exception should throw on error while loading a plugin. + ''' + ''' + Public Property ThrowOnError As Boolean = False + ''' ''' The name of the type where to search for Methods when loading a new Plugin. ''' @@ -79,7 +85,11 @@ Public Class PluginManager If addToList Then Plugins.Add(filePath, plugin) Return plugin Catch ex As Exception - Return Nothing + If ThrowOnError Then + Throw + Else + Return Nothing + End If End Try End Function diff --git a/Pilz.UI/PaintingControl/ArrowLineCapProps.vb b/Pilz.UI/PaintingControl/ArrowLineCapProps.vb new file mode 100644 index 0000000..66b23aa --- /dev/null +++ b/Pilz.UI/PaintingControl/ArrowLineCapProps.vb @@ -0,0 +1,15 @@ +Imports System.Drawing +Imports System.Drawing.Drawing2D + +Public Class ArrowLineCapProps + Inherits LineCapProps + + Public Property Size As New Size(10, 10) + Public Property IsFilles As Boolean = True + + Friend Overrides Function Configure() As LineCapConfigurationArgs + Dim cap As New AdjustableArrowCap(Size.Width, Size.Height, IsFilles) + Return New LineCapConfigurationArgs(cap) + End Function + +End Class diff --git a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb b/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb index b802cb7..f115a31 100644 --- a/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb +++ b/Pilz.UI/PaintingControl/DefaultDrawMethodes.vb @@ -112,7 +112,22 @@ Public Class DefaultDrawMethodes Public Shared Sub DrawLine(e As PaintingObjectPaintEventArgs) Dim obj As PaintingObject = e.PaintingObject - Dim p2 As New Pen(obj.OutlineColor, obj.OutlineThicknes) With {.DashStyle = obj.OutlineDashStyle} + Dim p2 As New Pen(obj.OutlineColor, obj.OutlineThicknes) With { + .DashStyle = obj.OutlineDashStyle + } + + If obj.LineEndCap IsNot Nothing Then + Dim args As LineCapConfigurationArgs = obj.LineEndCap.Configure + p2.StartCap = args.LineCap + p2.CustomStartCap = args.CustomLineCap + End If + + If obj.LineStartCap IsNot Nothing Then + Dim args As LineCapConfigurationArgs = obj.LineStartCap.Configure + p2.EndCap = args.LineCap + p2.CustomEndCap = args.CustomLineCap + End If + p2.Alignment = PenAlignment.Center Dim no As PointF = New PointF(e.X, e.Y) e.Graphics.DrawLine(p2, no, no + obj.Size) diff --git a/Pilz.UI/PaintingControl/DefaultLineCapProps.vb b/Pilz.UI/PaintingControl/DefaultLineCapProps.vb new file mode 100644 index 0000000..eef0c92 --- /dev/null +++ b/Pilz.UI/PaintingControl/DefaultLineCapProps.vb @@ -0,0 +1,13 @@ +Imports System.Drawing.Drawing2D + +Public Class DefaultLineCapProps + Inherits LineCapProps + + Public Property LineCap As LineCap = LineCap.Flat + Public Property CustomLineCap As CustomLineCap = Nothing + + Friend Overrides Function Configure() As LineCapConfigurationArgs + Return New LineCapConfigurationArgs(LineCap, CustomLineCap) + End Function + +End Class diff --git a/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb b/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb new file mode 100644 index 0000000..2369439 --- /dev/null +++ b/Pilz.UI/PaintingControl/LineCapConfigurationArgs.vb @@ -0,0 +1,21 @@ +Imports System.Drawing.Drawing2D + +Public Class LineCapConfigurationArgs + + Public ReadOnly Property LineCap As LineCap + Public ReadOnly Property CustomLineCap As CustomLineCap + + Public Sub New(lineCap As LineCap) + Me.New(lineCap, Nothing) + End Sub + + Public Sub New(customLineCap As CustomLineCap) + Me.New(Nothing, customLineCap) + End Sub + + Public Sub New(lineCap As LineCap, customLineCap As CustomLineCap) + Me.LineCap = lineCap + Me.CustomLineCap = customLineCap + End Sub + +End Class diff --git a/Pilz.UI/PaintingControl/LineCapProps.vb b/Pilz.UI/PaintingControl/LineCapProps.vb new file mode 100644 index 0000000..6d48807 --- /dev/null +++ b/Pilz.UI/PaintingControl/LineCapProps.vb @@ -0,0 +1,7 @@ +Imports System.Drawing + +Public MustInherit Class LineCapProps + + Friend MustOverride Function Configure() As LineCapConfigurationArgs + +End Class diff --git a/Pilz.UI/PaintingControl/PaintingControl.vb b/Pilz.UI/PaintingControl/PaintingControl.vb index 33712b4..0de9a3c 100644 --- a/Pilz.UI/PaintingControl/PaintingControl.vb +++ b/Pilz.UI/PaintingControl/PaintingControl.vb @@ -196,7 +196,7 @@ Public Class PaintingControl End If End If - If pressedControl Then + If pressedAlt Then calcOffset_MouseOnTab = New Point(e.X, e.Y) calcOffset_LastOffset = Offset @@ -281,7 +281,7 @@ Public Class PaintingControl End If If calcOffset_IsActive Then - If pressedControl Then + If pressedAlt Then CalcNewOffset(e.Location) Else calcOffset_IsActive = False @@ -314,7 +314,7 @@ Public Class PaintingControl Private Sub SaveObjectPositions(e As MouseEventArgs, objs As IList) For Each obj As PaintingObject In objs - If Not savedPos.ContainsKey(obj) Then + If Not obj.HardcodedLocation AndAlso Not savedPos.ContainsKey(obj) Then savedPos.Add(obj, New PointF(e.X - obj.Location.X + Offset.X, e.Y - obj.Location.Y + Offset.Y)) SaveObjectPositions(e, obj.PinnedObjects) End If diff --git a/Pilz.UI/PaintingControl/PaintingObject.vb b/Pilz.UI/PaintingControl/PaintingObject.vb index e4c6f29..78f00ca 100644 --- a/Pilz.UI/PaintingControl/PaintingObject.vb +++ b/Pilz.UI/PaintingControl/PaintingObject.vb @@ -19,6 +19,8 @@ Imports Newtonsoft.Json Public Property OutlineColor As Color = Color.DarkBlue Public Property OutlineThicknes As Single = 1 Public Property OutlineDashStyle As DashStyle = DashStyle.Solid + Public Property LineStartCap As LineCapProps = Nothing + Public Property LineEndCap As LineCapProps = Nothing Private _Text As String = "" Public Property TextPosition As TextPosition = TextPosition.FullCenter @@ -40,7 +42,8 @@ Imports Newtonsoft.Json Public Property BufferedImage As Image = Nothing Public Property ImageSizeMode As ImageSizeMode Public Property ImageProperties As New PaintingObjectImageProperties - Public Property Tag As String = Nothing + + Public Property Tag As Object = Nothing Public Property Name As String = "" Public ReadOnly Property PinnedObjects As New List(Of PaintingObject) @@ -49,6 +52,7 @@ Imports Newtonsoft.Json Public ReadOnly Property DrawSelectionMethode As DelegateDrawPaintingObjectMethode = AddressOf DefaultDrawMethodes.DrawSelection Public Property Cursor As Cursor = Cursors.Default Public Property HardcodedSize As Boolean = False + Public Property HardcodedLocation As Boolean = False Private _Visible As Boolean = True @@ -181,6 +185,15 @@ Imports Newtonsoft.Json End Set End Property + Public Property LocationDirect As PointF + Get + Return _Location + End Get + Set(value As PointF) + _Location = value + End Set + End Property + Public Property Size As SizeF Get If Parent IsNot Nothing Then @@ -419,6 +432,20 @@ Imports Newtonsoft.Json End Set End Property + + Public Property TagString As String + Get + If TypeOf Tag Is String Then + Return Tag + Else + Return String.Empty + End If + End Get + Set(value As String) + Tag = value + End Set + End Property + Public Property EnableResize As Boolean Get If resizeEngine Is Nothing Then @@ -454,7 +481,7 @@ Imports Newtonsoft.Json End Sub Public Sub Draw(e As PaintEventArgs) - Draw(e, PointF.Empty) + Draw(e, e.ClipRectangle.Location) End Sub Public Sub Draw(e As PaintEventArgs, offset As PointF) diff --git a/Pilz.UI/PaintingControl/PaintingObjectLayering.vb b/Pilz.UI/PaintingControl/PaintingObjectLayering.vb index 7b4c0a9..45ab4a4 100644 --- a/Pilz.UI/PaintingControl/PaintingObjectLayering.vb +++ b/Pilz.UI/PaintingControl/PaintingObjectLayering.vb @@ -2,7 +2,7 @@ Public Class PaintingObjectLayering - + ' Private ReadOnly _PaintingObject As PaintingObject