Skip to content

Commit

Permalink
Merge pull request #251 from solarwinds/feature/dotnet-format-and-ref…
Browse files Browse the repository at this point in the history
…actor

dotnet format and automated refactoring
  • Loading branch information
danjagnow committed Sep 23, 2020
2 parents e218e0f + 074ee7a commit 3726b44
Show file tree
Hide file tree
Showing 137 changed files with 452 additions and 442 deletions.
12 changes: 12 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"dotnet-format": {
"version": "4.1.131201",
"commands": [
"dotnet-format"
]
}
}
}
17 changes: 8 additions & 9 deletions Src/Contract/Bindings/GZipMessageEncoderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ namespace SolarWinds.InformationService.Contract2.Bindings
internal class GZipMessageEncoderFactory : MessageEncoderFactory
{
private static readonly Log _log = new Log();

readonly MessageEncoder encoder;
private readonly MessageEncoder encoder;

//The GZip encoder wraps an inner encoder
//We require a factory to be passed in that will create this inner encoder
public GZipMessageEncoderFactory(MessageEncoderFactory messageEncoderFactory)
{
if (messageEncoderFactory == null)
throw new ArgumentNullException("messageEncoderFactory", "A valid message encoder factory must be passed to the GZipEncoder");
throw new ArgumentNullException(nameof(messageEncoderFactory), "A valid message encoder factory must be passed to the GZipEncoder");
encoder = new GZipMessageEncoder(messageEncoderFactory.Encoder);

}
Expand All @@ -35,22 +34,22 @@ public override MessageVersion MessageVersion
}

//This is the actual GZip encoder
class GZipMessageEncoder : MessageEncoder
private class GZipMessageEncoder : MessageEncoder
{
static string GZipContentType = "application/x-gzip";
private static readonly string GZipContentType = "application/x-gzip";

//This implementation wraps an inner encoder that actually converts a WCF Message
//into textual XML, binary XML or some other format. This implementation then compresses the results.
//The opposite happens when reading messages.
//This member stores this inner encoder.
readonly MessageEncoder innerEncoder;
private readonly MessageEncoder innerEncoder;

//We require an inner encoder to be supplied (see comment above)
internal GZipMessageEncoder(MessageEncoder messageEncoder)
: base()
{
if (messageEncoder == null)
throw new ArgumentNullException("messageEncoder", "A valid message encoder must be passed to the GZipEncoder");
throw new ArgumentNullException(nameof(messageEncoder), "A valid message encoder must be passed to the GZipEncoder");
innerEncoder = messageEncoder;
}

Expand All @@ -76,7 +75,7 @@ public override MessageVersion MessageVersion
}

//Helper method to compress an array of bytes
static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager, int messageOffset)
private static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager, int messageOffset)
{
MemoryStream memoryStream = new MemoryStream();

Expand All @@ -100,7 +99,7 @@ static ArraySegment<byte> CompressBuffer(ArraySegment<byte> buffer, BufferManage
}

//Helper method to decompress an array of bytes
static ArraySegment<byte> DecompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager)
private static ArraySegment<byte> DecompressBuffer(ArraySegment<byte> buffer, BufferManager bufferManager)
{
MemoryStream memoryStream = new MemoryStream(buffer.Array, buffer.Offset, buffer.Count);
MemoryStream decompressedStream = new MemoryStream();
Expand Down
10 changes: 5 additions & 5 deletions Src/Contract/Bindings/GZipMessageEncodingBindingElement.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

using System;
using System.Xml;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.Xml;

namespace SolarWinds.InformationService.Contract2.Bindings
{
Expand Down Expand Up @@ -62,7 +62,7 @@ public override T GetProperty<T>(BindingContext context)
public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingContext context)
{
if (context == null)
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));

context.BindingParameters.Add(this);
return context.BuildInnerChannelFactory<TChannel>();
Expand All @@ -71,7 +71,7 @@ public override IChannelFactory<TChannel> BuildChannelFactory<TChannel>(BindingC
public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context)
{
if (context == null)
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));

context.BindingParameters.Add(this);
return context.BuildInnerChannelListener<TChannel>();
Expand All @@ -80,7 +80,7 @@ public override IChannelListener<TChannel> BuildChannelListener<TChannel>(Bindin
public override bool CanBuildChannelListener<TChannel>(BindingContext context)
{
if (context == null)
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));

context.BindingParameters.Add(this);
return context.CanBuildInnerChannelListener<TChannel>();
Expand All @@ -90,7 +90,7 @@ void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConver
{
if (policyContext == null)
{
throw new ArgumentNullException("policyContext");
throw new ArgumentNullException(nameof(policyContext));
}
XmlDocument document = new XmlDocument();
policyContext.GetBindingAssertions().Add(document.CreateElement(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

using System;
using System.Xml;
using System.ServiceModel.Description;
using System.Collections.Generic;
using System.ServiceModel.Description;
using System.Xml;

namespace SolarWinds.InformationService.Contract2.Bindings
{
Expand All @@ -16,12 +16,12 @@ void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConver
{
if (importer == null)
{
throw new ArgumentNullException("importer");
throw new ArgumentNullException(nameof(importer));
}

if (context == null)
{
throw new ArgumentNullException("context");
throw new ArgumentNullException(nameof(context));
}

ICollection<XmlElement> assertions = context.GetBindingAssertions();
Expand Down
2 changes: 1 addition & 1 deletion Src/Contract/Bindings/GZipMessageEncodingElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ protected override BindingElement CreateBindingElement()
return bindingElement;
}
}
}
}
4 changes: 2 additions & 2 deletions Src/Contract/Bindings/GZipMessageEncodingPolicyConstants.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
namespace SolarWinds.InformationService.Contract2.Bindings
{
// This is constants for GZip message encoding policy.
static class GZipMessageEncodingPolicyConstants
internal static class GZipMessageEncodingPolicyConstants
{
public const string GZipEncodingName = "GZipEncoding";
public const string GZipEncodingNamespace = "http://schemas.microsoft.com/ws/06/2004/mspolicy/netgzip1";
public const string GZipEncodingPrefix = "gzip";
}
}
}
2 changes: 1 addition & 1 deletion Src/Contract/Bindings/IdentityVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SolarWinds.InformationService.Contract2.Bindings
{
class SWIdentityVerifier : IdentityVerifier
internal class SWIdentityVerifier : IdentityVerifier
{
public override bool CheckAccess(EndpointIdentity identity, AuthorizationContext authContext)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/Contract/Bindings/ReaderQuotaHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SolarWinds.InformationService.Contract2.Bindings
{
class ReaderQuotaHelper
internal class ReaderQuotaHelper
{
public static void SetReaderQuotas(XmlDictionaryReaderQuotas readerQuotas)
{
Expand Down
6 changes: 3 additions & 3 deletions Src/Contract/EntityCollectionResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IEnumerable<ErrorMessage> ErrorMessages
public T ReadNextEntity(XmlReader reader)
{
if (reader == null)
throw new ArgumentNullException("reader");
throw new ArgumentNullException(nameof(reader));

while (reader.Read())
{
Expand Down Expand Up @@ -78,7 +78,7 @@ public T ReadNextEntity(XmlReader reader)
throw new InvalidOperationException("Only one root entity is supported at this time");

StackFrame state = new StackFrame();
state.entity = new EntityInfo(reader["name"], reader["type"], Boolean.Parse(reader["dynamic"]));
state.entity = new EntityInfo(reader["name"], reader["type"], bool.Parse(reader["dynamic"]));
stack.Push(state);

entityInfo = state.entity;
Expand All @@ -100,7 +100,7 @@ public T ReadNextEntity(XmlReader reader)
else if (string.CompareOrdinal(reader.LocalName, "entity") == 0)
{
StackFrame state = new StackFrame();
state.entity = new EntityInfo(reader["name"], reader["type"], Boolean.Parse(reader["dynamic"]));
state.entity = new EntityInfo(reader["name"], reader["type"], bool.Parse(reader["dynamic"]));

stack.Peek().entitySet.Entities.Add(state.entity.EntityName, state.entity);

Expand Down
46 changes: 23 additions & 23 deletions Src/Contract/EntityPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ namespace SolarWinds.InformationService.Contract2
{
internal class EntityPropertyInfo
{
private TypeInfo typeInfo;
private static Dictionary<string, TypeInfo> typeMap = new Dictionary<string, TypeInfo>(StringComparer.Ordinal);
private readonly TypeInfo typeInfo;
private static readonly Dictionary<string, TypeInfo> typeMap = new Dictionary<string, TypeInfo>(StringComparer.Ordinal);

static EntityPropertyInfo()
{
typeMap.Add("Blob", new TypeInfo() { Type = typeof(byte[]), PropertyType = EntityPropertyType.Blob });
typeMap.Add("Boolean", new TypeInfo() { Type = typeof(Boolean), PropertyType = EntityPropertyType.Boolean });
typeMap.Add("Byte", new TypeInfo() { Type = typeof(byte), PropertyType = EntityPropertyType.Byte });
typeMap.Add("Char", new TypeInfo() { Type = typeof(char), PropertyType = EntityPropertyType.Char });
typeMap.Add("DateTime", new TypeInfo() { Type = typeof(DateTime), PropertyType = EntityPropertyType.DateTime });
typeMap.Add("Decimal", new TypeInfo() { Type = typeof(Decimal), PropertyType = EntityPropertyType.Decimal });
typeMap.Add("Double", new TypeInfo() { Type = typeof(Double), PropertyType = EntityPropertyType.Double });
typeMap.Add("Guid", new TypeInfo() { Type = typeof(Guid), PropertyType = EntityPropertyType.Guid });
typeMap.Add("Int16", new TypeInfo() { Type = typeof(Int16), PropertyType = EntityPropertyType.Int16 });
typeMap.Add("Int32", new TypeInfo() { Type = typeof(Int32), PropertyType = EntityPropertyType.Int32 });
typeMap.Add("Int64", new TypeInfo() { Type = typeof(Int64), PropertyType = EntityPropertyType.Int64 });
typeMap.Add("Single", new TypeInfo() { Type = typeof(Single), PropertyType = EntityPropertyType.Single });
typeMap.Add("String", new TypeInfo() { Type = typeof(String), PropertyType = EntityPropertyType.String });
typeMap.Add("Type", new TypeInfo() { Type = typeof(String), PropertyType = EntityPropertyType.Type });
typeMap.Add("Uri", new TypeInfo() { Type = typeof(String), PropertyType = EntityPropertyType.Uri });
typeMap.Add("Null", new TypeInfo() { Type = typeof(Object), PropertyType = EntityPropertyType.Null });
typeMap.Add("Blob", new TypeInfo { Type = typeof(byte[]), PropertyType = EntityPropertyType.Blob });
typeMap.Add("Boolean", new TypeInfo { Type = typeof(bool), PropertyType = EntityPropertyType.Boolean });
typeMap.Add("Byte", new TypeInfo { Type = typeof(byte), PropertyType = EntityPropertyType.Byte });
typeMap.Add("Char", new TypeInfo { Type = typeof(char), PropertyType = EntityPropertyType.Char });
typeMap.Add("DateTime", new TypeInfo { Type = typeof(DateTime), PropertyType = EntityPropertyType.DateTime });
typeMap.Add("Decimal", new TypeInfo { Type = typeof(decimal), PropertyType = EntityPropertyType.Decimal });
typeMap.Add("Double", new TypeInfo { Type = typeof(double), PropertyType = EntityPropertyType.Double });
typeMap.Add("Guid", new TypeInfo { Type = typeof(Guid), PropertyType = EntityPropertyType.Guid });
typeMap.Add("Int16", new TypeInfo { Type = typeof(short), PropertyType = EntityPropertyType.Int16 });
typeMap.Add("Int32", new TypeInfo { Type = typeof(int), PropertyType = EntityPropertyType.Int32 });
typeMap.Add("Int64", new TypeInfo { Type = typeof(long), PropertyType = EntityPropertyType.Int64 });
typeMap.Add("Single", new TypeInfo { Type = typeof(float), PropertyType = EntityPropertyType.Single });
typeMap.Add("String", new TypeInfo { Type = typeof(string), PropertyType = EntityPropertyType.String });
typeMap.Add("Type", new TypeInfo { Type = typeof(string), PropertyType = EntityPropertyType.Type });
typeMap.Add("Uri", new TypeInfo { Type = typeof(string), PropertyType = EntityPropertyType.Uri });
typeMap.Add("Null", new TypeInfo { Type = typeof(object), PropertyType = EntityPropertyType.Null });

// define array types for all preceding types
var toAdd = new Dictionary<string, TypeInfo>(StringComparer.Ordinal);
foreach (var pair in typeMap)
{
toAdd.Add(pair.Key + "[]", new TypeInfo()
toAdd.Add(pair.Key + "[]", new TypeInfo
{
Type = pair.Value.Type.MakeArrayType(),
PropertyType = pair.Value.PropertyType,
Expand All @@ -48,15 +48,15 @@ public EntityPropertyInfo(string name, string typeName)
{

if (!typeMap.TryGetValue(typeName, out typeInfo))
throw new ArgumentException(String.Format("unsupported type name '{0}'", typeName), "typeName");
throw new ArgumentException(string.Format("unsupported type name '{0}'", typeName), nameof(typeName));

Name = name;
TypeName = typeName;
}

public String Name { get; }
public string Name { get; }

public String TypeName { get; }
public string TypeName { get; }

public Type Type
{
Expand All @@ -82,7 +82,7 @@ public bool IsArray
}
}

class TypeInfo
private class TypeInfo
{
public Type Type;
public EntityPropertyType PropertyType;
Expand Down
2 changes: 1 addition & 1 deletion Src/Contract/IEntityPropertySetter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ public interface IEntityPropertySetter
/// <param name="value">property value</param>
void SetPropertyValue(string name, object value);
}
}
}
2 changes: 1 addition & 1 deletion Src/Contract/IResponseParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ public enum ParserType
{
EntityCollectionResponseParser
}
}
}
2 changes: 1 addition & 1 deletion Src/Contract/Impersonation/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SolarWinds.InformationService.Contract2.Impersonation
{
static class Constants
internal static class Constants
{
public const string Namespace = "http://schemas.solarwinds.com/2007/08/informationservice";
public const string HeaderName = "Impersonation";
Expand Down
2 changes: 1 addition & 1 deletion Src/Contract/Impersonation/ImpersonationAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace SolarWinds.InformationService.Contract2.Impersonation
{
class ImpersonationAttribute : Attribute, IContractBehavior
internal class ImpersonationAttribute : Attribute, IContractBehavior
{
public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
Expand Down
2 changes: 1 addition & 1 deletion Src/Contract/Impersonation/ImpersonationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ImpersonationContext : IDisposable
public ImpersonationContext(string targetUsername)
{
if (targetUsername == null)
throw new ArgumentNullException("targetUsername");
throw new ArgumentNullException(nameof(targetUsername));

TargetUsername = targetUsername;
current = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SolarWinds.InformationService.Contract2.Impersonation
{
class ImpersonationMessageInspector : IClientMessageInspector, IDispatchMessageInspector
internal class ImpersonationMessageInspector : IClientMessageInspector, IDispatchMessageInspector
{
public object BeforeSendRequest(ref Message request, IClientChannel channel)
{
Expand Down
12 changes: 6 additions & 6 deletions Src/Contract/IndicationReporterProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.ServiceModel.Security;
using SolarWinds.Logging;
using SolarWinds.InformationService.Contract2.PubSub;
using SolarWinds.Logging;

namespace SolarWinds.InformationService.Contract2
{
public class IndicationReporterProxy : IIndicationReporter, IDisposable
{
private readonly static Log log = new Log();

private ChannelFactory<IIndicationReporter> channelFactory;
private readonly ChannelFactory<IIndicationReporter> channelFactory;

private IIndicationReporter reporter;

Expand All @@ -32,7 +32,7 @@ private IndicationReporterProxy(string endpointName)
{
if (endpointName == null)
{
throw new ArgumentNullException("endpointName");
throw new ArgumentNullException(nameof(endpointName));
}

channelFactory = new ChannelFactory<IIndicationReporter>(endpointName);
Expand All @@ -57,12 +57,12 @@ private IndicationReporterProxy(Uri address, X509Certificate2 cert)
{
if (address == null)
{
throw new ArgumentNullException("address");
throw new ArgumentNullException(nameof(address));
}

if (cert == null)
{
throw new ArgumentNullException("cert");
throw new ArgumentNullException(nameof(cert));
}

var binding = new NetMsmqBinding(NetMsmqSecurityMode.Message);
Expand All @@ -80,7 +80,7 @@ private IndicationReporterProxy(Uri address, X509Certificate2 cert)
public IndicationReporterProxy(Uri address)
{
if (address == null)
throw new ArgumentNullException("address");
throw new ArgumentNullException(nameof(address));

NetMsmqBinding binding = new NetMsmqBinding(NetMsmqSecurityMode.None);
//TODO set security mode, provide other constructors like InfoServiceProxy has
Expand Down

0 comments on commit 3726b44

Please sign in to comment.