From 023b3a3e809d2a1f7ca70217bef1cfc8d1da0964 Mon Sep 17 00:00:00 2001 From: Ogoun Date: Fri, 31 Jan 2020 18:47:13 +0300 Subject: [PATCH] 1 --- ZeroLevel/Services/Extensions/EncodingEx.cs | 62 +++++++++++++++++++++ ZeroLevel/Services/Utils/Multiprocessor.cs | 10 +--- 2 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 ZeroLevel/Services/Extensions/EncodingEx.cs diff --git a/ZeroLevel/Services/Extensions/EncodingEx.cs b/ZeroLevel/Services/Extensions/EncodingEx.cs new file mode 100644 index 0000000..3c88bf5 --- /dev/null +++ b/ZeroLevel/Services/Extensions/EncodingEx.cs @@ -0,0 +1,62 @@ +using System; +using System.Text; + +namespace ZeroLevel.Services.Extensions +{ + public class EncodingEx : Encoding + { + private readonly Encoding _baseEncoding; + + public override string BodyName + { + get + { + if (_baseEncoding.CodePage == 1251) + return _baseEncoding.HeaderName; + return _baseEncoding.BodyName; + } + } + + public EncodingEx(string name) + : this(Encoding.GetEncoding(name)) + { + + } + + public EncodingEx(Encoding baseEncoding) : base(baseEncoding.CodePage) + { + if (baseEncoding == null) throw new ArgumentNullException("baseEncoding"); + _baseEncoding = baseEncoding; + } + + public override int GetByteCount(char[] chars, int index, int count) + { + return _baseEncoding.GetByteCount(chars, index, count); + } + + public override int GetBytes(char[] chars, int charIndex, int charCount, byte[] bytes, int byteIndex) + { + return _baseEncoding.GetBytes(chars, charIndex, charCount, bytes, byteIndex); + } + + public override int GetCharCount(byte[] bytes, int index, int count) + { + return _baseEncoding.GetCharCount(bytes, index, count); + } + + public override int GetChars(byte[] bytes, int byteIndex, int byteCount, char[] chars, int charIndex) + { + return _baseEncoding.GetChars(bytes, byteIndex, byteCount, chars, charIndex); + } + + public override int GetMaxByteCount(int charCount) + { + return _baseEncoding.GetMaxByteCount(charCount); + } + + public override int GetMaxCharCount(int byteCount) + { + return _baseEncoding.GetMaxCharCount(byteCount); + } + } +} diff --git a/ZeroLevel/Services/Utils/Multiprocessor.cs b/ZeroLevel/Services/Utils/Multiprocessor.cs index 21c19e0..0c3414d 100644 --- a/ZeroLevel/Services/Utils/Multiprocessor.cs +++ b/ZeroLevel/Services/Utils/Multiprocessor.cs @@ -50,7 +50,7 @@ namespace ZeroLevel.Utils foreach (var t in _threads) t.Start(); } - public void Append(T t) => _queue.Add(t); + public void Append(T t) { if (!_is_disposed) _queue.Add(t); } public bool WaitForEmpty(int timeoutInMs) { @@ -72,12 +72,8 @@ namespace ZeroLevel.Utils public void Dispose() { _is_disposed = true; - try - { - _queue.CompleteAdding(); - _queue.Dispose(); - } - catch { } + _queue.Dispose(); + _threads = null; } } }