mirror of
https://github.com/BDDSM/YY.EventLogReaderAssistant.git
synced 2024-11-26 18:11:45 +02:00
Сделал возможным добавить в тесты внутрение вспомогательные классы
This commit is contained in:
parent
e5967a9230
commit
223789c1d9
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal static class DateTimeExtensions
|
||||
|
@ -1,5 +1,7 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal static class IntExtensions
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.Data.SQLite;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal static class SQLiteExtensions
|
||||
|
@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal class StreamLineReader : IDisposable
|
||||
|
@ -1,6 +1,8 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal static class StreamReaderExtensions
|
||||
|
@ -1,20 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
[assembly: InternalsVisibleTo("YY.EventLogAssistant.Tests")]
|
||||
namespace YY.EventLogAssistant.Services
|
||||
{
|
||||
internal static class StringExtensions
|
||||
{
|
||||
public static long From16To10(this string Str)
|
||||
#region Private Member Variables
|
||||
|
||||
private static readonly Dictionary<int, char> CharactersToMap = new Dictionary<int, char>
|
||||
{
|
||||
return Convert.ToInt64(Str.ToUpper(), 16);
|
||||
{130, '‚'},
|
||||
{131, 'ƒ'},
|
||||
{132, '„'},
|
||||
{133, '…'},
|
||||
{134, '†'},
|
||||
{135, '‡'},
|
||||
{136, 'ˆ'},
|
||||
{137, '‰'},
|
||||
{138, 'Š'},
|
||||
{139, '‹'},
|
||||
{140, 'Œ'},
|
||||
{145, '‘'},
|
||||
{146, '’'},
|
||||
{147, '“'},
|
||||
{148, '”'},
|
||||
{149, '•'},
|
||||
{150, '–'},
|
||||
{151, '—'},
|
||||
{152, '˜'},
|
||||
{153, '™'},
|
||||
{154, 'š'},
|
||||
{155, '›'},
|
||||
{156, 'œ'},
|
||||
{159, 'Ÿ'},
|
||||
{173, '-'}
|
||||
};
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
|
||||
public static long From16To10(this string sourceValue)
|
||||
{
|
||||
return Convert.ToInt64(sourceValue.ToUpper(), 16);
|
||||
}
|
||||
|
||||
public static string RemoveQuotes(this string s)
|
||||
public static string RemoveQuotes(this string sourceValue)
|
||||
{
|
||||
string functionReturnValue = s;
|
||||
string functionReturnValue = sourceValue;
|
||||
|
||||
if (functionReturnValue.StartsWith("\""))
|
||||
{
|
||||
@ -44,110 +81,32 @@ namespace YY.EventLogAssistant.Services
|
||||
return Convert.ToInt64(sourceString);
|
||||
}
|
||||
|
||||
public static string ConvertEncoding(this string s, Encoding source, Encoding result)
|
||||
public static string FromWin1251ToUTF8(this string sourceValue)
|
||||
{
|
||||
byte[] souceBytes = source.GetBytes(s);
|
||||
byte[] resultBytes = Encoding.Convert(source, result, souceBytes);
|
||||
return result.GetString(resultBytes);
|
||||
//return result.GetString(source.GetBytes(s));
|
||||
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
||||
Encoding utf8 = Encoding.GetEncoding("UTF-8");
|
||||
Encoding win1251 = Encoding.GetEncoding("windows-1251");
|
||||
|
||||
return ConvertEncoding(sourceValue, win1251, utf8);
|
||||
}
|
||||
|
||||
public static string FromAnsiToUTF8(this string s)
|
||||
{
|
||||
return ConvertEncoding(s,
|
||||
Encoding.GetEncoding(1252),
|
||||
Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static string FromWIN1251ToUTF8(this string s)
|
||||
{
|
||||
Encoding win1251 = CodePagesEncodingProvider.Instance.GetEncoding(1251);
|
||||
return ConvertEncoding(s, win1251, Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static string FromWIN1252ToUTF8(this string s)
|
||||
{
|
||||
return ConvertEncoding(s,
|
||||
Encoding.GetEncoding("windows-1252"),
|
||||
Encoding.UTF8);
|
||||
}
|
||||
|
||||
public static Guid ToGuid(this string s)
|
||||
public static Guid ToGuid(this string sourceValue)
|
||||
{
|
||||
Guid guidFromString = Guid.Empty;
|
||||
Guid.TryParse(s, out guidFromString);
|
||||
Guid.TryParse(sourceValue, out guidFromString);
|
||||
return guidFromString;
|
||||
}
|
||||
|
||||
public static bool IsLike(this string s, string pattern)
|
||||
#endregion
|
||||
|
||||
#region Private Methods
|
||||
|
||||
private static string ConvertEncoding(this string sourceString, Encoding source, Encoding result)
|
||||
{
|
||||
// Characters matched so far
|
||||
int matched = 0;
|
||||
byte[] souceBytes = source.GetBytes(sourceString);
|
||||
byte[] resultBytes = Encoding.Convert(result, source, souceBytes);
|
||||
|
||||
// Loop through pattern string
|
||||
for (int i = 0; i < pattern.Length; )
|
||||
{
|
||||
// Check for end of string
|
||||
if (matched > s.Length)
|
||||
return false;
|
||||
|
||||
// Get next pattern character
|
||||
char c = pattern[i++];
|
||||
if (c == '[') // Character list
|
||||
{
|
||||
// Test for exclude character
|
||||
bool exclude = (i < pattern.Length && pattern[i] == '!');
|
||||
if (exclude)
|
||||
i++;
|
||||
// Build character list
|
||||
int j = pattern.IndexOf(']', i);
|
||||
if (j < 0)
|
||||
j = s.Length;
|
||||
HashSet<char> charList = CharListToSet(pattern.Substring(i, j - i));
|
||||
i = j + 1;
|
||||
|
||||
if (charList.Contains(s[matched]) == exclude)
|
||||
return false;
|
||||
matched++;
|
||||
}
|
||||
else if (c == '?') // Any single character
|
||||
{
|
||||
matched++;
|
||||
}
|
||||
else if (c == '#') // Any single digit
|
||||
{
|
||||
if (!Char.IsDigit(s[matched]))
|
||||
return false;
|
||||
matched++;
|
||||
}
|
||||
else if (c == '*') // Zero or more characters
|
||||
{
|
||||
if (i < pattern.Length)
|
||||
{
|
||||
// Matches all characters until
|
||||
// next character in pattern
|
||||
char next = pattern[i];
|
||||
int j = s.IndexOf(next, matched);
|
||||
if (j < 0)
|
||||
return false;
|
||||
matched = j;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Matches all remaining characters
|
||||
matched = s.Length;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else // Exact character
|
||||
{
|
||||
if (matched >= s.Length || c != s[matched])
|
||||
return false;
|
||||
matched++;
|
||||
}
|
||||
}
|
||||
// Return true if all characters matched
|
||||
return (matched == s.Length);
|
||||
return source.GetString(resultBytes);
|
||||
}
|
||||
|
||||
private static HashSet<char> CharListToSet(string charList)
|
||||
@ -172,60 +131,6 @@ namespace YY.EventLogAssistant.Services
|
||||
return set;
|
||||
}
|
||||
|
||||
public static string GetHashMD5(this string input)
|
||||
{
|
||||
MD5 md5 = System.Security.Cryptography.MD5.Create();
|
||||
byte[] inputBytes = System.Text.Encoding.ASCII.GetBytes(input);
|
||||
byte[] hash = md5.ComputeHash(inputBytes);
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < hash.Length; i++)
|
||||
sb.Append(hash[i].ToString("X2"));
|
||||
|
||||
return sb.ToString();
|
||||
|
||||
}
|
||||
|
||||
private static readonly Dictionary<int, char> CharactersToMap = new Dictionary<int, char>
|
||||
{
|
||||
{130, '‚'},
|
||||
{131, 'ƒ'},
|
||||
{132, '„'},
|
||||
{133, '…'},
|
||||
{134, '†'},
|
||||
{135, '‡'},
|
||||
{136, 'ˆ'},
|
||||
{137, '‰'},
|
||||
{138, 'Š'},
|
||||
{139, '‹'},
|
||||
{140, 'Œ'},
|
||||
{145, '‘'},
|
||||
{146, '’'},
|
||||
{147, '“'},
|
||||
{148, '”'},
|
||||
{149, '•'},
|
||||
{150, '–'},
|
||||
{151, '—'},
|
||||
{152, '˜'},
|
||||
{153, '™'},
|
||||
{154, 'š'},
|
||||
{155, '›'},
|
||||
{156, 'œ'},
|
||||
{159, 'Ÿ'},
|
||||
{173, '-'}
|
||||
};
|
||||
|
||||
public static string ConvertFromWindowsToUnicode(this string txt)
|
||||
{
|
||||
Encoding utf8 = Encoding.GetEncoding("utf-8");
|
||||
Encoding win1251 = Encoding.GetEncoding("windows-1252");
|
||||
|
||||
byte[] utf8Bytes = win1251.GetBytes(txt);
|
||||
byte[] win1251Bytes = Encoding.Convert(win1251, utf8, utf8Bytes);
|
||||
string result = win1251.GetString(win1251Bytes);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user