/Console/ConsoleExtensions.cs |
@@ -119,9 +119,10 @@ |
switch (alignment) |
{ |
case ConsoleTextAlignment.TOP_CENTER: |
var textBlock = data.Select(o => o.ToString()).ToArray(); |
var enumerable = data as IList<object> ?? data.ToList(); |
var textBlock = enumerable.Select(o => o.ToString()).ToArray(); |
var padding = Math.Max(System.Console.WindowWidth / 2 - textBlock.Select(o => o.Length).Max() / 2, 0); |
foreach (var line in data) |
foreach (var line in enumerable) |
{ |
System.Console.CursorLeft = padding; |
WriteLine(line, System.Console.ForegroundColor); |
/Network/HTTP/HTTPServer.cs |
@@ -25,6 +25,7 @@ |
public bool IsRunning => HTTPListener != null && HTTPListener.IsListening; |
|
private readonly ManualResetEventSlim stopListen = new ManualResetEventSlim(false); |
private readonly ManualResetEventSlim listenStop = new ManualResetEventSlim(false); |
|
public bool Start(List<string> prefixes) |
{ |
@@ -46,9 +47,10 @@ |
return ThreadPool.QueueUserWorkItem(Listen, new HTTPServerCallbackState(HTTPListener)); |
} |
|
public void Stop() |
public bool Stop(int timeout) |
{ |
stopListen.Set(); |
return listenStop.Wait(timeout); |
} |
|
private void Listen(object state) |
@@ -57,12 +59,20 @@ |
|
while (callbackState.Listener.IsListening) |
{ |
callbackState.Listener.BeginGetContext(ContextCallback, callbackState); |
callbackState.Listener?.BeginGetContext(ContextCallback, callbackState); |
|
if (WaitHandle.WaitAny(new[] { callbackState.ContextRetrieved, stopListen.WaitHandle }) != 1) |
continue; |
|
try |
{ |
callbackState.Listener.Stop(); |
callbackState.Listener.Close(); |
} |
finally |
{ |
listenStop.Set(); |
} |
break; |
} |
} |
@@ -103,7 +113,7 @@ |
|
public void Dispose() |
{ |
Stop(); |
stopListen.Set(); |
} |
|
private class HTTPServerCallbackState |
/Platform/Windows/Commands/NetSH/URLACL.cs |
@@ -6,21 +6,19 @@ |
|
using System.ComponentModel; |
using System.Diagnostics; |
using System.IO; |
using System.Text; |
using System.Text.RegularExpressions; |
using Process = System.Diagnostics.Process; |
|
namespace wasSharpNET.Platform.Windows.Commands.NetSH |
{ |
public class URLACL |
{ |
private string domain; |
private string URL; |
private readonly string domain; |
private readonly string URL; |
|
private readonly Regex URLReservationRegex; |
private string username; |
private int timeout; |
private readonly string username; |
private readonly int timeout; |
|
public URLACL(string URL, string username, string domain, int timeout) |
{ |
@@ -31,7 +29,7 @@ |
|
URLReservationRegex = |
new Regex( |
$@"{Regex.Escape(URL)}.*{Regex.Escape(string.Format(@"{0}\{1}", domain, username))}", |
$@"{Regex.Escape(URL)}.*{Regex.Escape($@"{domain}\{username}")}", |
RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | |
RegexOptions.Compiled); |
} |
@@ -41,13 +39,15 @@ |
get |
{ |
var netSHOutput = new StringBuilder(); |
var checkProcess = new System.Diagnostics.Process(); |
checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl") |
var checkProcess = new System.Diagnostics.Process |
{ |
StartInfo = new ProcessStartInfo("netsh", @"http show urlacl") |
{ |
RedirectStandardOutput = true, |
CreateNoWindow = true, |
WindowStyle = ProcessWindowStyle.Hidden, |
UseShellExecute = false |
} |
}; |
|
checkProcess.OutputDataReceived += (sender, output) => |
/Serialization/XmlSerializerCache.cs |
@@ -8,19 +8,18 @@ |
using System; |
using System.Collections.Generic; |
using System.IO; |
using System.Text; |
using System.Linq; |
using System.Threading; |
using System.Xml; |
using System.Xml.Linq; |
using System.Xml.Serialization; |
using wasSharp; |
|
namespace wasSharpNET.Serialization |
{ |
public static class XmlSerializerCache |
{ |
private static ReaderWriterLockSlim SerializerCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
private static Dictionary<string, XmlSerializer> SerializerCache = new Dictionary<string, XmlSerializer>(); |
private static readonly ReaderWriterLockSlim SerializerCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); |
private static readonly Dictionary<string, XmlSerializer> SerializerCache = new Dictionary<string, XmlSerializer>(); |
|
public static XmlSerializer GetSerializer<T>() |
{ |
@@ -39,15 +38,14 @@ |
|
public static XmlSerializer GetSerializer(Type MainTypeForSerialization, Type[] ExtraTypes) |
{ |
string Signature = MainTypeForSerialization.FullName; |
var Signature = MainTypeForSerialization.FullName; |
if (ExtraTypes != null) |
{ |
foreach (Type Tp in ExtraTypes) |
Signature += "-" + Tp.FullName; |
Signature = ExtraTypes.Aggregate(Signature, (current, tp) => current + ("-" + tp.FullName)); |
} |
|
SerializerCacheLock.EnterReadLock(); |
XmlSerializer XmlEventSerializer = null; |
XmlSerializer XmlEventSerializer; |
if (SerializerCache.TryGetValue(Signature, out XmlEventSerializer)) |
{ |
SerializerCacheLock.ExitReadLock(); |
@@ -122,7 +120,7 @@ |
{ |
using (var xmlWriter = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true })) |
{ |
XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); |
var ns = new XmlSerializerNamespaces(); |
ns.Add(string.Empty, string.Empty); |
GetSerializer<T>(ExtraTypes).Serialize(xmlWriter, Object, ns); |
xmlWriter.Flush(); |
@@ -150,7 +148,7 @@ |
|
public static T Deserialize<T>(Stream stream) |
{ |
using (MemoryStream memoryStream = new MemoryStream()) |
using (var memoryStream = new MemoryStream()) |
{ |
stream.CopyTo(memoryStream); |
memoryStream.Position = 0L; |