This commit is contained in:
schedpas
2021-10-27 10:04:43 +02:00
12 changed files with 136 additions and 25 deletions

View File

@@ -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;
}
}

View File

@@ -22,12 +22,13 @@ namespace Pilz.Json.Converters
var idString = serializer.Deserialize<string>(reader);
SecureString id;
if (existingValue is object)
if (existingValue is SecureString)
{
id = (SecureString)existingValue;
else
id = new SecureString();
id.EncryptedValue = idString;
}
else
id = new SecureString(idString, true);
return id;
}

View File

@@ -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);
return array;
for (int i = 0; i < lowerLength; i++)
output[i] = array[i];
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)

View File

@@ -2,6 +2,12 @@
Public Class PluginManager
''' <summary>
''' Gets or sets an indicator if an exception should throw on error while loading a plugin.
''' </summary>
''' <returns></returns>
Public Property ThrowOnError As Boolean = False
''' <summary>
''' The name of the type where to search for Methods when loading a new Plugin.
''' </summary>
@@ -79,7 +85,11 @@ Public Class PluginManager
If addToList Then Plugins.Add(filePath, plugin)
Return plugin
Catch ex As Exception
If ThrowOnError Then
Throw
Else
Return Nothing
End If
End Try
End Function

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -0,0 +1,7 @@
Imports System.Drawing
Public MustInherit Class LineCapProps
Friend MustOverride Function Configure() As LineCapConfigurationArgs
End Class

View File

@@ -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

View File

@@ -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
<JsonProperty>
Private _Text As String = ""
Public Property TextPosition As TextPosition = TextPosition.FullCenter
@@ -40,7 +42,8 @@ Imports Newtonsoft.Json
<JsonIgnore> Public Property BufferedImage As Image = Nothing
Public Property ImageSizeMode As ImageSizeMode
Public Property ImageProperties As New PaintingObjectImageProperties
Public Property Tag As String = Nothing
<JsonIgnore>
Public Property Tag As Object = Nothing
Public Property Name As String = ""
Public ReadOnly Property PinnedObjects As New List(Of PaintingObject)
<JsonIgnore>
@@ -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
<JsonProperty>
Private _Visible As Boolean = True
<JsonProperty>
@@ -181,6 +185,15 @@ Imports Newtonsoft.Json
End Set
End Property
<JsonIgnore> Public Property LocationDirect As PointF
Get
Return _Location
End Get
Set(value As PointF)
_Location = value
End Set
End Property
<JsonIgnore> Public Property Size As SizeF
Get
If Parent IsNot Nothing Then
@@ -419,6 +432,20 @@ Imports Newtonsoft.Json
End Set
End Property
<JsonProperty(NameOf(Tag))>
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)

View File

@@ -2,7 +2,7 @@
Public Class PaintingObjectLayering
<JsonProperty(NameOf(PaintingObject))>
'<JsonProperty(NameOf(PaintingObject))>
Private ReadOnly _PaintingObject As PaintingObject
<JsonIgnore>