This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static T DeSerializer<T>(Dictionary<string, IStorageElement> element) | |
{ | |
var o = (T)Activator.CreateInstance<T>(); | |
var props = o.GetType().GetProperties(); | |
foreach (var prop in props) | |
{ | |
// match element name with property name set value | |
if (element.TryGetValue(prop.Name, out var e)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string Serializer<T>(this T obj) | |
{ | |
var sb = new StringBuilder(); | |
sb.AppendLine($"<record>"); | |
var props = obj.GetType().GetProperties(); | |
// add values | |
foreach (var prop in props) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static readonly RNGCryptoServiceProvider random = new RNGCryptoServiceProvider(); | |
private string GenerateUniqueID(int length) | |
{ | |
// We chose an encoding that fits 6 bits into every character, | |
// so we can fit length*6 bits in total. | |
// Each byte is 8 bits, so... | |
int sufficientBufferSizeInBytes = (length * 6 + 7) / 8; | |
var buffer = new byte[sufficientBufferSizeInBytes]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetUniqueId() | |
{ | |
// get unique id | |
var builder = new StringBuilder(); | |
Enumerable | |
.Range(65, 26) | |
.Select(e => ((char)e).ToString()) | |
.Concat(Enumerable.Range(97, 26).Select(e => ((char)e).ToString())) | |
.Concat(Enumerable.Range(0, 10).Select(e => e.ToString())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string ToDateTime(this string datestring, string format="ddd dd") | |
{ | |
var dstring = datestring; | |
if (System.DateTime.TryParse(datestring, out System.DateTime dTime)) | |
{ | |
dstring = dTime.ToString(format); | |
} | |
return dstring; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<List<T>> ChunkInto<T>(this IList<T> source, int chunkSize) | |
{ | |
return source | |
.Select((x, i) => new { Index = i, Value = x }) | |
.GroupBy(x => x.Index / chunkSize) | |
.Select(x => x.Select(v => v.Value).ToList()) | |
.ToList(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void Delay(TimeSpan ts) | |
{ | |
var stopwatch = Stopwatch.StartNew(); | |
stopwatch.Start(); | |
while (stopwatch.Elapsed.TotalSeconds <= ts.Seconds) { } | |
stopwatch.Stop(); | |
} | |
public static bool IsVisible(this IWebDriver webDriver, By locator, TimeSpan timeOut) | |
{ |