wasSharpNET

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 22  →  ?path2? @ 21
/IO/Utilities/IOExtensions.cs
@@ -4,6 +4,7 @@
// rights of fair usage, the disclaimer and warranty conditions. //
///////////////////////////////////////////////////////////////////////////
 
using System;
using System.IO;
 
namespace wasSharpNET.IO.Utilities
/IO/SafeFileStream.cs
@@ -6,6 +6,8 @@
 
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Threading;
 
namespace wasSharpNET.IO
/Diagnostics/ExceptionExtensions.cs
@@ -9,6 +9,7 @@
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.IO;
 
namespace wasSharpNET.Diagnostics
{
/Network/HTTP/HTTPServer.cs
@@ -25,7 +25,6 @@
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)
{
@@ -47,10 +46,9 @@
return ThreadPool.QueueUserWorkItem(Listen, new HTTPServerCallbackState(HTTPListener));
}
 
public bool Stop(int timeout)
public void Stop()
{
stopListen.Set();
return listenStop.Wait(timeout);
}
 
private void Listen(object state)
@@ -59,20 +57,12 @@
 
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();
}
callbackState.Listener.Stop();
break;
}
}
@@ -113,7 +103,7 @@
 
public void Dispose()
{
stopListen.Set();
Stop();
}
 
private class HTTPServerCallbackState
/Platform/Windows/Commands/NetSH/URLACL.cs
@@ -6,19 +6,21 @@
 
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 readonly string domain;
private readonly string URL;
private string domain;
private string URL;
 
private readonly Regex URLReservationRegex;
private readonly string username;
private readonly int timeout;
private string username;
private int timeout;
 
public URLACL(string URL, string username, string domain, int timeout)
{
@@ -29,7 +31,7 @@
 
URLReservationRegex =
new Regex(
$@"{Regex.Escape(URL)}.*{Regex.Escape($@"{domain}\{username}")}",
$@"{Regex.Escape(URL)}.*{Regex.Escape(string.Format(@"{0}\{1}", domain, username))}",
RegexOptions.Singleline | RegexOptions.CultureInvariant | RegexOptions.IgnoreCase |
RegexOptions.Compiled);
}
@@ -39,15 +41,13 @@
get
{
var netSHOutput = new StringBuilder();
var checkProcess = new System.Diagnostics.Process
var checkProcess = new System.Diagnostics.Process();
checkProcess.StartInfo = new ProcessStartInfo("netsh", @"http show urlacl")
{
StartInfo = new ProcessStartInfo("netsh", @"http show urlacl")
{
RedirectStandardOutput = true,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
}
RedirectStandardOutput = true,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
UseShellExecute = false
};
 
checkProcess.OutputDataReceived += (sender, output) =>
/Serialization/XmlSerializerCache.cs
@@ -8,18 +8,19 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
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 readonly ReaderWriterLockSlim SerializerCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private static readonly Dictionary<string, XmlSerializer> SerializerCache = new Dictionary<string, XmlSerializer>();
private static ReaderWriterLockSlim SerializerCacheLock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);
private static Dictionary<string, XmlSerializer> SerializerCache = new Dictionary<string, XmlSerializer>();
 
public static XmlSerializer GetSerializer<T>()
{
@@ -38,14 +39,15 @@
 
public static XmlSerializer GetSerializer(Type MainTypeForSerialization, Type[] ExtraTypes)
{
var Signature = MainTypeForSerialization.FullName;
string Signature = MainTypeForSerialization.FullName;
if (ExtraTypes != null)
{
Signature = ExtraTypes.Aggregate(Signature, (current, tp) => current + ("-" + tp.FullName));
foreach (Type Tp in ExtraTypes)
Signature += "-" + Tp.FullName;
}
 
SerializerCacheLock.EnterReadLock();
XmlSerializer XmlEventSerializer;
XmlSerializer XmlEventSerializer = null;
if (SerializerCache.TryGetValue(Signature, out XmlEventSerializer))
{
SerializerCacheLock.ExitReadLock();
@@ -75,7 +77,7 @@
{
using (var XmlReader = XmlData.Root.CreateReader())
{
return (T) GetSerializer<T>(ExtraTypes).Deserialize(XmlReader);
return (T)GetSerializer<T>(ExtraTypes).Deserialize(XmlReader);
}
}
catch (Exception ex)
@@ -120,7 +122,7 @@
{
using (var xmlWriter = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true }))
{
var ns = new XmlSerializerNamespaces();
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add(string.Empty, string.Empty);
GetSerializer<T>(ExtraTypes).Serialize(xmlWriter, Object, ns);
xmlWriter.Flush();
@@ -148,7 +150,7 @@
 
public static T Deserialize<T>(Stream stream)
{
using (var memoryStream = new MemoryStream())
using (MemoryStream memoryStream = new MemoryStream())
{
stream.CopyTo(memoryStream);
memoryStream.Position = 0L;
/Console/ConsoleExtensions.cs
@@ -119,10 +119,9 @@
switch (alignment)
{
case ConsoleTextAlignment.TOP_CENTER:
var enumerable = data as IList<object> ?? data.ToList();
var textBlock = enumerable.Select(o => o.ToString()).ToArray();
var textBlock = data.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 enumerable)
foreach (var line in data)
{
System.Console.CursorLeft = padding;
WriteLine(line, System.Console.ForegroundColor);
/Syndication/ObservableSyndication.cs
@@ -29,11 +29,13 @@
 
private readonly Timer syndicationPoll;
private TimeSpan _defaultUpdateTime;
private string URL;
 
public ObservableSyndication(string URL, TimeSpan defaultUpdateTime)
{
// Assign update variables.
_defaultUpdateTime = defaultUpdateTime;
this.URL = URL;
 
// Forward the collection change event.
syndicationItems.CollectionChanged += (o, p) => { CollectionChanged?.Invoke(this, p); };