Code cleanup

Fixed code style using CodeMaid.
This commit is contained in:
Kevin Thompson
2017-09-24 01:52:45 -04:00
parent 6ff68d8812
commit 3b189d2865
51 changed files with 523 additions and 743 deletions

View File

@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
</configuration>

View File

@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using NSspi;
@@ -13,7 +9,7 @@ namespace TestProtocol
public class CustomConnection
{
private Thread receiveThread;
private Socket socket;
private bool running;
@@ -24,7 +20,7 @@ namespace TestProtocol
}
public delegate void ReceivedAction( Message message );
public event ReceivedAction Received;
public event Action Disconnected;
@@ -33,7 +29,7 @@ namespace TestProtocol
{
if( this.running )
{
throw new InvalidOperationException("Already running");
throw new InvalidOperationException( "Already running" );
}
this.socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp );
@@ -65,7 +61,7 @@ namespace TestProtocol
throw new InvalidOperationException( "Not connected" );
}
byte[] outBuffer = new byte[ message.Data.Length + 8 ];
byte[] outBuffer = new byte[message.Data.Length + 8];
int position = 0;
ByteWriter.WriteInt32_BE( (int)message.Operation, outBuffer, position );
@@ -124,16 +120,15 @@ namespace TestProtocol
// |--4 bytes--|--4 bytes--|---N--|
// Every command is a TLV - | Operation | Length | Data |
// Read the operation.
this.socket.Receive( readBuffer, 4, SocketFlags.None );
// Check if we popped out of a receive call after we were shut down.
if( this.running == false ) { break; }
operation = (ProtocolOp)ByteWriter.ReadInt32_BE( readBuffer, 0 );
// Read the length
// Read the length
this.socket.Receive( readBuffer, 4, SocketFlags.None );
messageLength = ByteWriter.ReadInt32_BE( readBuffer, 0 );
@@ -153,14 +148,13 @@ namespace TestProtocol
remaining -= chunkLength;
position += chunkLength;
}
}
catch( SocketException e )
{
if( e.SocketErrorCode == SocketError.ConnectionAborted ||
e.SocketErrorCode == SocketError.Interrupted ||
e.SocketErrorCode == SocketError.OperationAborted ||
e.SocketErrorCode == SocketError.Shutdown ||
e.SocketErrorCode == SocketError.Shutdown ||
e.SocketErrorCode == SocketError.ConnectionReset )
{
// Shutting down.
@@ -179,7 +173,7 @@ namespace TestProtocol
byte[] dataCopy = new byte[messageLength];
Array.Copy( readBuffer, 0, dataCopy, 0, messageLength );
Message message = new Message( operation, dataCopy );
try
{
this.Received( message );
@@ -187,8 +181,7 @@ namespace TestProtocol
catch( Exception e )
{ }
}
}
}
}
}
}

View File

@@ -159,7 +159,7 @@ namespace TestProtocol
operation = (ProtocolOp)ByteWriter.ReadInt32_BE( readBuffer, 0 );
// Read the length
// Read the length
this.readSocket.Receive( readBuffer, 4, SocketFlags.None );
messageLength = ByteWriter.ReadInt32_BE( readBuffer, 0 );
@@ -212,7 +212,6 @@ namespace TestProtocol
catch( Exception )
{ }
}
}
try
@@ -225,5 +224,4 @@ namespace TestProtocol
catch { }
}
}
}
}

View File

@@ -1,14 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestProtocol
{
public class Message
{
public Message(ProtocolOp op, byte[] data)
public Message( ProtocolOp op, byte[] data )
{
this.Operation = op;
this.Data = data;
@@ -18,4 +14,4 @@ namespace TestProtocol
public byte[] Data { get; private set; }
}
}
}

View File

@@ -1,8 +1,7 @@
using System.Reflection;
using System.Runtime.CompilerServices;
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.
[assembly: AssemblyTitle( "TestProtocol" )]
@@ -14,8 +13,8 @@ using System.Runtime.InteropServices;
[assembly: AssemblyTrademark( "" )]
[assembly: AssemblyCulture( "" )]
// 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 )]
@@ -25,12 +24,12 @@ using System.Runtime.InteropServices;
// 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.0.0.0" )]
[assembly: AssemblyFileVersion( "1.0.0.0" )]
[assembly: AssemblyFileVersion( "1.0.0.0" )]

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestProtocol
{
@@ -14,4 +10,4 @@ namespace TestProtocol
EncryptedMessage = 3,
SignedMessage = 4,
}
}
}