Visual Studio Reformat: SocketHttpListener

This commit is contained in:
Erwin de Haan 2019-01-13 20:27:29 +01:00
parent 9014e16037
commit 8fd0bc63b9
53 changed files with 946 additions and 1042 deletions

View file

@ -23,16 +23,16 @@ namespace SocketHttpListener
#region Internal Constructors
internal CloseEventArgs (PayloadData payload)
internal CloseEventArgs(PayloadData payload)
{
var data = payload.ApplicationData;
var len = data.Length;
_code = len > 1
? data.SubArray (0, 2).ToUInt16 (ByteOrder.Big)
: (ushort) CloseStatusCode.NoStatusCode;
? data.SubArray(0, 2).ToUInt16(ByteOrder.Big)
: (ushort)CloseStatusCode.NoStatusCode;
_reason = len > 2
? GetUtf8String(data.SubArray (2, len - 2))
? GetUtf8String(data.SubArray(2, len - 2))
: string.Empty;
}
@ -51,8 +51,10 @@ namespace SocketHttpListener
/// <value>
/// A <see cref="ushort"/> that represents the status code for the close if any.
/// </value>
public ushort Code {
get {
public ushort Code
{
get
{
return _code;
}
}
@ -63,8 +65,10 @@ namespace SocketHttpListener
/// <value>
/// A <see cref="string"/> that represents the reason for the close if any.
/// </value>
public string Reason {
get {
public string Reason
{
get
{
return _reason;
}
}
@ -75,12 +79,15 @@ namespace SocketHttpListener
/// <value>
/// <c>true</c> if the WebSocket connection has been closed cleanly; otherwise, <c>false</c>.
/// </value>
public bool WasClean {
get {
public bool WasClean
{
get
{
return _clean;
}
internal set {
internal set
{
_clean = value;
}
}

View file

@ -20,7 +20,7 @@ namespace SocketHttpListener
#region Internal Constructors
internal ErrorEventArgs (string message)
internal ErrorEventArgs(string message)
{
_message = message;
}
@ -35,8 +35,10 @@ namespace SocketHttpListener
/// <value>
/// A <see cref="string"/> that represents the error message.
/// </value>
public string Message {
get {
public string Message
{
get
{
return _message;
}
}

View file

@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.IO.Compression;
using System.Net;
@ -441,7 +440,8 @@ namespace SocketHttpListener
continue;
}
}
else {
else
{
}
buffer.Append(c);

View file

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using System.Threading;
using MediaBrowser.Model.Services;
namespace SocketHttpListener

View file

@ -1,13 +1,11 @@
using System;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using HttpVersion = SocketHttpListener.Net.HttpVersion;
using System.Linq;
using MediaBrowser.Model.Services;
using SocketHttpListener.Net;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using HttpVersion = SocketHttpListener.Net.HttpVersion;
namespace SocketHttpListener
{

View file

@ -24,18 +24,18 @@ namespace SocketHttpListener
#region Internal Constructors
internal MessageEventArgs (Opcode opcode, byte[] data)
internal MessageEventArgs(Opcode opcode, byte[] data)
{
_opcode = opcode;
_rawData = data;
_data = convertToString (opcode, data);
_data = convertToString(opcode, data);
}
internal MessageEventArgs (Opcode opcode, PayloadData payload)
internal MessageEventArgs(Opcode opcode, PayloadData payload)
{
_opcode = opcode;
_rawData = payload.ApplicationData;
_data = convertToString (opcode, _rawData);
_data = convertToString(opcode, _rawData);
}
#endregion
@ -48,8 +48,10 @@ namespace SocketHttpListener
/// <value>
/// A <see cref="string"/> that contains the received data.
/// </value>
public string Data {
get {
public string Data
{
get
{
return _data;
}
}
@ -60,8 +62,10 @@ namespace SocketHttpListener
/// <value>
/// An array of <see cref="byte"/> that contains the received data.
/// </value>
public byte [] RawData {
get {
public byte[] RawData
{
get
{
return _rawData;
}
}
@ -72,8 +76,10 @@ namespace SocketHttpListener
/// <value>
/// One of the <see cref="Opcode"/> values, indicates the type of the received data.
/// </value>
public Opcode Type {
get {
public Opcode Type
{
get
{
return _opcode;
}
}
@ -82,13 +88,13 @@ namespace SocketHttpListener
#region Private Methods
private static string convertToString (Opcode opcode, byte [] data)
private static string convertToString(Opcode opcode, byte[] data)
{
return data.Length == 0
? string.Empty
: opcode == Opcode.Text
? Encoding.UTF8.GetString (data, 0, data.Length)
: opcode.ToString ();
? Encoding.UTF8.GetString(data, 0, data.Length)
: opcode.ToString();
}
#endregion

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal class AuthenticationTypes
{

View file

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal enum BoundaryType
{

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.IO;

View file

@ -1,8 +1,6 @@
using System;
using System.IO;
using System.Net;
using System.Runtime.InteropServices;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net
{

View file

@ -3,7 +3,6 @@ using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
{

View file

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal enum EntitySendFormat
{

View file

@ -3,19 +3,17 @@ using System.IO;
using System.Net;
using System.Net.Security;
using System.Net.Sockets;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Text;
using Microsoft.Extensions.Logging;
using SocketHttpListener.Primitives;
using System.Security.Authentication;
using System.Threading;
namespace SocketHttpListener.Net
{
sealed class HttpConnection

View file

@ -1,21 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Security.Cryptography.X509Certificates;
using System.Threading;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives;
using ProtocolType = MediaBrowser.Model.Net.ProtocolType;
using SocketType = MediaBrowser.Model.Net.SocketType;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net
{
@ -209,7 +203,7 @@ namespace SocketHttpListener.Net
return;
}
if(accepted == null)
if (accepted == null)
{
return;
}

View file

@ -3,12 +3,7 @@ using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net
{

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal static partial class HttpKnownHeaderNames
{

View file

@ -1,17 +1,15 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives;
using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net
{

View file

@ -1,8 +1,8 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System;
using MediaBrowser.Model.Text;
using SocketHttpListener.Net.WebSockets;

View file

@ -1,12 +1,8 @@
using System;
using System.Net;
using System.Security.Principal;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Text;
using SocketHttpListener.Net.WebSockets;
using System.Threading.Tasks;
using SocketHttpListener.Net.WebSockets;
namespace SocketHttpListener.Net
{

View file

@ -1,12 +1,7 @@
using System;
using System.Text;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Security.Authentication.ExtendedProtection;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Text;
namespace SocketHttpListener.Net
{

View file

@ -1,17 +1,11 @@
using System;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Net;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Text;
using MediaBrowser.Model.Services;
using SocketHttpListener.Net.WebSockets;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net
{

View file

@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Globalization;
using System.Text;
namespace SocketHttpListener.Net
{

View file

@ -1,14 +1,13 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Text;
using SocketHttpListener.Primitives;
using System.Threading;
using MediaBrowser.Model.IO;
namespace SocketHttpListener.Net
{

View file

@ -1,14 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Runtime.InteropServices;
using System.ComponentModel;
using System.Diagnostics;
using Microsoft.Win32.SafeHandles;
namespace SocketHttpListener.Net
{

View file

@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
{

View file

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

View file

@ -1,15 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.System;
using Microsoft.Extensions.Logging;
namespace SocketHttpListener.Net
{

View file

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

View file

@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal static class HttpStatusDescription
{

View file

@ -1,6 +1,5 @@
using System;
using System.Net;
using MediaBrowser.Model.Net;
namespace SocketHttpListener.Net
{

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net
namespace SocketHttpListener.Net
{
internal static class UriScheme
{

View file

@ -1,13 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Text;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.Extensions;
namespace SocketHttpListener.Net
{

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text;
namespace SocketHttpListener.Net
{

View file

@ -1,14 +1,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Net;
using System.Security.Principal;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services;
using SocketHttpListener.Primitives;
namespace SocketHttpListener.Net.WebSockets
{

View file

@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics.CodeAnalysis;
using System.Security.Cryptography;
using System.Text;
using System.Threading;
namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SocketHttpListener.Net.WebSockets
namespace SocketHttpListener.Net.WebSockets
{
public enum WebSocketCloseStatus
{

View file

@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Net;
using System.Security.Principal;
using MediaBrowser.Model.Net;
using MediaBrowser.Model.Services;
namespace SocketHttpListener.Net.WebSockets

View file

@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using MediaBrowser.Model.Net;
using System.Globalization;
using System.Text;
using WebSocketState = System.Net.WebSockets.WebSocketState;
namespace SocketHttpListener.Net.WebSockets

View file

@ -9,8 +9,8 @@ namespace SocketHttpListener
{
#region Private Fields
private byte [] _applicationData;
private byte [] _extensionData;
private byte[] _applicationData;
private byte[] _extensionData;
private bool _masked;
#endregion
@ -23,27 +23,27 @@ namespace SocketHttpListener
#region Public Constructors
public PayloadData ()
: this (new byte [0], new byte [0], false)
public PayloadData()
: this(new byte[0], new byte[0], false)
{
}
public PayloadData (byte [] applicationData)
: this (new byte [0], applicationData, false)
public PayloadData(byte[] applicationData)
: this(new byte[0], applicationData, false)
{
}
public PayloadData (string applicationData)
: this (new byte [0], Encoding.UTF8.GetBytes (applicationData), false)
public PayloadData(string applicationData)
: this(new byte[0], Encoding.UTF8.GetBytes(applicationData), false)
{
}
public PayloadData (byte [] applicationData, bool masked)
: this (new byte [0], applicationData, masked)
public PayloadData(byte[] applicationData, bool masked)
: this(new byte[0], applicationData, masked)
{
}
public PayloadData (byte [] extensionData, byte [] applicationData, bool masked)
public PayloadData(byte[] extensionData, byte[] applicationData, bool masked)
{
_extensionData = extensionData;
_applicationData = applicationData;
@ -54,10 +54,12 @@ namespace SocketHttpListener
#region Internal Properties
internal bool ContainsReservedCloseStatusCode {
get {
internal bool ContainsReservedCloseStatusCode
{
get
{
return _applicationData.Length > 1 &&
_applicationData.SubArray (0, 2).ToUInt16 (ByteOrder.Big).IsReserved ();
_applicationData.SubArray(0, 2).ToUInt16(ByteOrder.Big).IsReserved();
}
}
@ -65,27 +67,35 @@ namespace SocketHttpListener
#region Public Properties
public byte [] ApplicationData {
get {
public byte[] ApplicationData
{
get
{
return _applicationData;
}
}
public byte [] ExtensionData {
get {
public byte[] ExtensionData
{
get
{
return _extensionData;
}
}
public bool IsMasked {
get {
public bool IsMasked
{
get
{
return _masked;
}
}
public ulong Length {
get {
return (ulong) (_extensionData.Length + _applicationData.Length);
public ulong Length
{
get
{
return (ulong)(_extensionData.Length + _applicationData.Length);
}
}
@ -93,17 +103,17 @@ namespace SocketHttpListener
#region Private Methods
private static void mask (byte [] src, byte [] key)
private static void mask(byte[] src, byte[] key)
{
for (long i = 0; i < src.Length; i++)
src [i] = (byte) (src [i] ^ key [i % 4]);
src[i] = (byte)(src[i] ^ key[i % 4]);
}
#endregion
#region Public Methods
public IEnumerator<byte> GetEnumerator ()
public IEnumerator<byte> GetEnumerator()
{
foreach (byte b in _extensionData)
yield return b;
@ -112,36 +122,36 @@ namespace SocketHttpListener
yield return b;
}
public void Mask (byte [] maskingKey)
public void Mask(byte[] maskingKey)
{
if (_extensionData.Length > 0)
mask (_extensionData, maskingKey);
mask(_extensionData, maskingKey);
if (_applicationData.Length > 0)
mask (_applicationData, maskingKey);
mask(_applicationData, maskingKey);
_masked = !_masked;
}
public byte [] ToByteArray ()
public byte[] ToByteArray()
{
return _extensionData.Length > 0
? new List<byte> (this).ToArray ()
? new List<byte>(this).ToArray()
: _applicationData;
}
public override string ToString ()
public override string ToString()
{
return BitConverter.ToString (ToByteArray ());
return BitConverter.ToString(ToByteArray());
}
#endregion
#region Explicitly Implemented Interface Members
IEnumerator IEnumerable.GetEnumerator ()
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator ();
return GetEnumerator();
}
#endregion

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using MediaBrowser.Model.Text;
namespace SocketHttpListener.Primitives

View file

@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace SocketHttpListener
{

View file

@ -3,15 +3,12 @@ using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.Cryptography;
using MediaBrowser.Model.IO;
using SocketHttpListener.Net.WebSockets;
using SocketHttpListener.Primitives;
using HttpStatusCode = SocketHttpListener.Net.HttpStatusCode;
using System.Net.Sockets;
using WebSocketState = System.Net.WebSockets.WebSocketState;
namespace SocketHttpListener

View file

@ -9,33 +9,33 @@ namespace SocketHttpListener
{
#region Internal Constructors
internal WebSocketException ()
: this (CloseStatusCode.Abnormal, null, null)
internal WebSocketException()
: this(CloseStatusCode.Abnormal, null, null)
{
}
internal WebSocketException (string message)
: this (CloseStatusCode.Abnormal, message, null)
internal WebSocketException(string message)
: this(CloseStatusCode.Abnormal, message, null)
{
}
internal WebSocketException (CloseStatusCode code)
: this (code, null, null)
internal WebSocketException(CloseStatusCode code)
: this(code, null, null)
{
}
internal WebSocketException (string message, Exception innerException)
: this (CloseStatusCode.Abnormal, message, innerException)
internal WebSocketException(string message, Exception innerException)
: this(CloseStatusCode.Abnormal, message, innerException)
{
}
internal WebSocketException (CloseStatusCode code, string message)
: this (code, message, null)
internal WebSocketException(CloseStatusCode code, string message)
: this(code, message, null)
{
}
internal WebSocketException (CloseStatusCode code, string message, Exception innerException)
: base (message ?? code.GetMessage (), innerException)
internal WebSocketException(CloseStatusCode code, string message, Exception innerException)
: base(message ?? code.GetMessage(), innerException)
{
Code = code;
}
@ -51,7 +51,8 @@ namespace SocketHttpListener
/// One of the <see cref="CloseStatusCode"/> enum values, represents the status code indicating
/// the cause for the exception.
/// </value>
public CloseStatusCode Code {
public CloseStatusCode Code
{
get; private set;
}

View file

@ -2,7 +2,6 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace SocketHttpListener
{