diff --git a/framework-dotnet/src/lib/MBS.Core/Application.cs b/framework-dotnet/src/lib/MBS.Core/Application.cs index 9c1bcb3..a7b0ca0 100644 --- a/framework-dotnet/src/lib/MBS.Core/Application.cs +++ b/framework-dotnet/src/lib/MBS.Core/Application.cs @@ -240,9 +240,21 @@ public class Application */ } + public event EventHandler BeforeStartInternal; + protected virtual void OnBeforeStartInternal(CancelEventArgs e) + { + BeforeStartInternal?.Invoke(this, e); + } + public int Start() { Instance = this; + + CancelEventArgs e = new CancelEventArgs(); + OnBeforeStartInternal(e); + if (e.Cancel) + return 2; + int exitCode = StartInternal(); Instance = null; diff --git a/framework-dotnet/src/lib/MBS.Core/NanoId.cs b/framework-dotnet/src/lib/MBS.Core/NanoId.cs index 8349238..967d4f8 100755 --- a/framework-dotnet/src/lib/MBS.Core/NanoId.cs +++ b/framework-dotnet/src/lib/MBS.Core/NanoId.cs @@ -163,7 +163,10 @@ namespace MBS.Core public const string DefaultAlphabet = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string DefaultAlphabetNoSpecialChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + public const string CapitalAlphabetNoSpecialChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + + public const string CapitalAlphanumeric = "_-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public const string CapitalAlphanumericNoSpecialChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; private static readonly CryptoRandom Random = new CryptoRandom(); diff --git a/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs b/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs new file mode 100644 index 0000000..b7930ed --- /dev/null +++ b/framework-dotnet/src/lib/MBS.Core/Reflection/TypeExtensions.cs @@ -0,0 +1,32 @@ +namespace MBS.Core.Reflection; + +public static class TypeExtensions +{ + public static bool IsSubclassOfGeneric(this Type toCheck, Type generic) + { + // thanks https://stackoverflow.com/a/457708 + + while (toCheck != null && toCheck != typeof(object)) + { + var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck; + if (generic == cur) + { + return true; + } + + Type[] intfs = toCheck.GetInterfaces(); + foreach (Type intf in intfs) + { + // !!! HACK HACK HACK !!! + bool hack = intf.Namespace.Equals(generic.Namespace) && intf.Name.Equals(generic.Name); + if (hack) + { + return true; + } + } + toCheck = toCheck.BaseType; + } + return false; + } + +} \ No newline at end of file diff --git a/framework-dotnet/src/lib/MBS.Core/StreamExtensions.cs b/framework-dotnet/src/lib/MBS.Core/StreamExtensions.cs index 9568243..9b3f51f 100644 --- a/framework-dotnet/src/lib/MBS.Core/StreamExtensions.cs +++ b/framework-dotnet/src/lib/MBS.Core/StreamExtensions.cs @@ -98,27 +98,33 @@ public static class StreamExtensions } _streamPositions[st].Push(st.Position); } - + + private const long BUFFER_SIZE=4096; public static byte[] ReadToEnd(this Stream st) { - byte[] retval = new byte[0]; - byte[] buffer = new byte[4096]; - - long j = 0; - bool remaining = true; - while (remaining) + byte[] buffer = new byte[BUFFER_SIZE]; + byte[] output = new byte[0]; + int i = 0; + bool done = false; + while (!done) { - int count = st.Read(buffer, 0, buffer.Length); - if (count < buffer.Length) + int length = st.Read(buffer, 0, buffer.Length); + if (length == 0) { - Array.Resize(ref buffer, count); - remaining = false; + done = true; + break; + } + + if (length < BUFFER_SIZE) + { + Array.Resize(ref buffer, length); + done = true; } - Array.Resize(ref retval, retval.Length + buffer.Length); - Array.Copy(buffer, 0, retval, j, buffer.Length); - j += buffer.Length; + Array.Resize(ref output, output.Length + buffer.Length); + Array.Copy(buffer, 0, output, i, buffer.Length); + i += buffer.Length; } - return retval; + return output; } -} \ No newline at end of file +}