/Console/ConsoleExtensions.cs |
@@ -19,7 +19,6 @@ |
TOP_RIGHT |
} |
|
|
public static void WriteLine(this object data, ConsoleColor foreground, |
ConsoleColor background) |
{ |
@@ -57,9 +56,10 @@ |
switch (alignment) |
{ |
case ConsoleTextAlignment.TOP_CENTER: |
System.Console.CursorLeft = Math.Max(System.Console.WindowWidth/2 - data.ToString().Length/2, 0); |
System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
WriteLine(data, System.Console.ForegroundColor, System.Console.BackgroundColor); |
break; |
|
default: |
throw new NotImplementedException(); |
} |
@@ -73,6 +73,7 @@ |
System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
WriteLine(data, foregroundColor, System.Console.BackgroundColor); |
break; |
|
default: |
throw new NotImplementedException(); |
} |
@@ -83,9 +84,10 @@ |
switch (alignment) |
{ |
case ConsoleTextAlignment.TOP_CENTER: |
System.Console.CursorLeft = Math.Max(System.Console.WindowWidth/2 - data.ToString().Length/2, 0); |
System.Console.CursorLeft = Math.Max(System.Console.WindowWidth / 2 - data.ToString().Length / 2, 0); |
Write(data, System.Console.ForegroundColor, System.Console.BackgroundColor); |
break; |
|
default: |
throw new NotImplementedException(); |
} |
@@ -97,7 +99,7 @@ |
{ |
case ConsoleTextAlignment.TOP_CENTER: |
var textBlock = data.Select(o => o.ToString()).ToArray(); |
var padding = Math.Max(System.Console.WindowWidth/2 - textBlock.Select(o => o.Length).Max()/2, 0); |
var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2, 0); |
foreach (var line in data) |
{ |
System.Console.CursorLeft = padding; |
@@ -104,9 +106,10 @@ |
WriteLine(line, System.Console.ForegroundColor, System.Console.BackgroundColor); |
} |
break; |
|
default: |
throw new NotImplementedException(); |
} |
} |
} |
} |
} |
/Console/ConsoleSpin.cs |
@@ -19,7 +19,7 @@ |
public class ConsoleSpin : IDisposable |
{ |
private static readonly CircularQueue<string> spinArt = |
new CircularQueue<string>(new[] {".oOo", "oOo.", "Oo.o", "o.oO"}); |
new CircularQueue<string>(new[] { ".oOo", "oOo.", "Oo.o", "o.oO" }); |
|
private static readonly ManualResetEvent spinEvent = new ManualResetEvent(false); |
private static Thread spinThread; |
@@ -86,4 +86,4 @@ |
spinEvent.Reset(); |
} |
} |
} |
} |
/Cryptography/AES.cs |
@@ -43,8 +43,8 @@ |
var salt = new byte[AES_KEY_SALT_BYTES]; |
rng.GetBytes(salt); |
var derivedKey = new Rfc2898DeriveBytes(key, salt); |
rijdanelManaged.Key = derivedKey.GetBytes(rijdanelManaged.KeySize/8); |
rijdanelManaged.IV = derivedKey.GetBytes(rijdanelManaged.BlockSize/8); |
rijdanelManaged.Key = derivedKey.GetBytes(rijdanelManaged.KeySize / 8); |
rijdanelManaged.IV = derivedKey.GetBytes(rijdanelManaged.BlockSize / 8); |
|
byte[] encryptedData; |
using (var encryptor = rijdanelManaged.CreateEncryptor(rijdanelManaged.Key, rijdanelManaged.IV)) |
@@ -81,7 +81,7 @@ |
public string wasAESDecrypt(string data, string key, string separator = ":") |
{ |
// retrieve the salt from the data. |
var segments = new List<string>(data.Split(new[] {separator}, StringSplitOptions.None)); |
var segments = new List<string>(data.Split(new[] { separator }, StringSplitOptions.None)); |
if (!segments.Count.Equals(2)) |
throw new ArgumentException("Invalid data."); |
|
@@ -95,8 +95,8 @@ |
|
// Retrieve the key and the IV from the salt. |
var derivedKey = new Rfc2898DeriveBytes(key, Convert.FromBase64String(segments.First().Trim())); |
rijdanelManaged.Key = derivedKey.GetBytes(rijdanelManaged.KeySize/8); |
rijdanelManaged.IV = derivedKey.GetBytes(rijdanelManaged.BlockSize/8); |
rijdanelManaged.Key = derivedKey.GetBytes(rijdanelManaged.KeySize / 8); |
rijdanelManaged.IV = derivedKey.GetBytes(rijdanelManaged.BlockSize / 8); |
|
using (var decryptor = rijdanelManaged.CreateDecryptor(rijdanelManaged.Key, rijdanelManaged.IV)) |
{ |
@@ -115,4 +115,4 @@ |
return plaintext; |
} |
} |
} |
} |
/Network/HTTP/HTTPServer.cs |
@@ -14,10 +14,12 @@ |
public abstract class HTTPServer |
{ |
private int activeRequests; |
|
private readonly HttpListener HTTPListener = new HttpListener() |
{ |
AuthenticationSchemes = AuthenticationSchemes.None |
}; |
|
private int processedRequests; |
|
private readonly AutoResetEvent StopServerEvent = new AutoResetEvent(false); |
@@ -66,12 +68,12 @@ |
|
private void Listen(object state) |
{ |
var callbackState = (HTTPServerCallbackState) state; |
var callbackState = (HTTPServerCallbackState)state; |
|
while (callbackState.Listener.IsListening) |
{ |
callbackState.Listener.BeginGetContext(ContextCallback, callbackState); |
var n = WaitHandle.WaitAny(new WaitHandle[] {callbackState.ContextRetrieved, StopServerEvent}); |
var n = WaitHandle.WaitAny(new WaitHandle[] { callbackState.ContextRetrieved, StopServerEvent }); |
|
if (n.Equals(1)) |
{ |
@@ -87,7 +89,7 @@ |
|
private void ContextCallback(IAsyncResult ar) |
{ |
var callbackState = (HTTPServerCallbackState) ar.AsyncState; |
var callbackState = (HTTPServerCallbackState)ar.AsyncState; |
HttpListenerContext httpContext = null; |
|
Interlocked.Increment(ref processedRequests); |
@@ -135,4 +137,4 @@ |
public AutoResetEvent ContextRetrieved { get; } |
} |
} |
} |
} |
/Network/IPAddressExtensions.cs |
@@ -26,7 +26,7 @@ |
var broadcastAddress = new byte[ipAdressBytes.Length]; |
for (var i = 0; i < broadcastAddress.Length; i++) |
{ |
broadcastAddress[i] = (byte) (ipAdressBytes[i] | (subnetMaskBytes[i] ^ 255)); |
broadcastAddress[i] = (byte)(ipAdressBytes[i] | (subnetMaskBytes[i] ^ 255)); |
} |
return new IPAddress(broadcastAddress); |
} |
@@ -42,7 +42,7 @@ |
var broadcastAddress = new byte[ipAdressBytes.Length]; |
for (var i = 0; i < broadcastAddress.Length; i++) |
{ |
broadcastAddress[i] = (byte) (ipAdressBytes[i] & subnetMaskBytes[i]); |
broadcastAddress[i] = (byte)(ipAdressBytes[i] & subnetMaskBytes[i]); |
} |
return new IPAddress(broadcastAddress); |
} |
@@ -55,4 +55,4 @@ |
return network1.Equals(network2); |
} |
} |
} |
} |
/Network/SubnetMask.cs |
@@ -31,13 +31,13 @@ |
|
for (var i = 0; i < 4; i++) |
{ |
if (i*8 + 8 <= netPartLength) |
if (i * 8 + 8 <= netPartLength) |
binaryMask[i] = 255; |
else if (i*8 > netPartLength) |
else if (i * 8 > netPartLength) |
binaryMask[i] = 0; |
else |
{ |
var oneLength = netPartLength - i*8; |
var oneLength = netPartLength - i * 8; |
var binaryDigit = |
string.Empty.PadLeft(oneLength, '1').PadRight(8, '0'); |
binaryMask[i] = Convert.ToByte(binaryDigit, 2); |
@@ -61,4 +61,4 @@ |
return CreateByHostBitLength(b.Length); |
} |
} |
} |
} |
/Properties/AssemblyInfo.cs |
@@ -2,7 +2,7 @@ |
using System.Resources; |
using System.Runtime.InteropServices; |
|
// General Information about an assembly is controlled through the following |
// General Information about an assembly is controlled through the following |
// set of attributes. Change these attribute values to modify the information |
// associated with an assembly. |
|
@@ -16,8 +16,8 @@ |
[assembly: AssemblyCulture("")] |
[assembly: NeutralResourcesLanguage("en")] |
|
// Setting ComVisible to false makes the types in this assembly not visible |
// to COM components. If you need to access a type in this assembly from |
// Setting ComVisible to false makes the types in this assembly not visible |
// to COM components. If you need to access a type in this assembly from |
// COM, set the ComVisible attribute to true on that type. |
|
[assembly: ComVisible(false)] |
@@ -29,12 +29,12 @@ |
// Version information for an assembly consists of the following four values: |
// |
// Major Version |
// Minor Version |
// Minor Version |
// Build Number |
// Revision |
// |
// You can specify all the values or you can default the Build and Revision Numbers |
// You can specify all the values or you can default the Build and Revision Numbers |
// by using the '*' as shown below: |
// [assembly: AssemblyVersion("1.0.*")] |
|
[assembly: AssemblyVersion("1.6.*")] |
[assembly: AssemblyVersion("1.7.*")] |
/Reflection.cs |
@@ -64,7 +64,7 @@ |
var getMethod = pi.GetGetMethod(); |
if (getMethod.ReturnType.IsArray) |
{ |
var array = (Array) getMethod.Invoke(@object, null); |
var array = (Array)getMethod.Invoke(@object, null); |
foreach (var sp in |
array.Cast<object>().SelectMany(element => wasGetProperties(element, @namespace))) |
{ |
@@ -94,18 +94,18 @@ |
public static void wasSetInfoValue<TK, TV>(TK info, ref TV @object, object value) |
{ |
object o = @object; |
var fi = (object) info as FieldInfo; |
var fi = (object)info as FieldInfo; |
if (fi != null) |
{ |
fi.SetValue(o, value); |
@object = (TV) o; |
@object = (TV)o; |
return; |
} |
var pi = (object) info as PropertyInfo; |
var pi = (object)info as PropertyInfo; |
if (pi != null) |
{ |
pi.SetValue(o, value, null); |
@object = (TV) o; |
@object = (TV)o; |
} |
} |
|
@@ -120,12 +120,12 @@ |
/// <returns>the value of the field or property</returns> |
public static object wasGetInfoValue<T>(T info, object value) |
{ |
var fi = (object) info as FieldInfo; |
var fi = (object)info as FieldInfo; |
if (fi != null) |
{ |
return fi.GetValue(value); |
} |
var pi = (object) info as PropertyInfo; |
var pi = (object)info as PropertyInfo; |
if (pi != null) |
{ |
if (pi.GetIndexParameters().Any()) |
@@ -137,4 +137,4 @@ |
return null; |
} |
} |
} |
} |