Skip to content

Commit

Permalink
Merge pull request #322 from ably/code-cleanup
Browse files Browse the repository at this point in the history
Code cleanup
  • Loading branch information
withakay committed Apr 28, 2019
2 parents c89b183 + 616b3ef commit 0941fb1
Show file tree
Hide file tree
Showing 85 changed files with 385 additions and 351 deletions.
Binary file modified src/CommonAssemblyInfo.cs
Binary file not shown.
9 changes: 7 additions & 2 deletions src/IO.Ably.NETFramework/IO.Ably.NETFramework.csproj
Expand Up @@ -52,6 +52,9 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'package|AnyCPU'">
<OutputPath>bin\package\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<RuntimeIdentifiers>win</RuntimeIdentifiers>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Win32.Primitives, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll</HintPath>
Expand Down Expand Up @@ -164,7 +167,9 @@
<ItemGroup>
<None Include="app.config" />
<None Include="IO.Ably.snk" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\StyleCop.Analyzers.1.0.2\analyzers\dotnet\cs\StyleCop.Analyzers.CodeFixes.dll" />
Expand Down Expand Up @@ -192,4 +197,4 @@
</ItemGroup>
<ILRepack KeyFile="..\..\IO.Ably.snk" Parallel="true" Internalize="true" InputAssemblies="@(InputAssemblies)" LibraryPath="@(LibraryPaths)" XmlDocumentation="true" TargetKind="DLL" OutputFile="$(OutputPath)\Packaged\$(AssemblyName).dll" />
</Target>
</Project>
</Project>
5 changes: 4 additions & 1 deletion src/IO.Ably.NETStandard20/IO.Ably.NETStandard20.csproj
Expand Up @@ -28,7 +28,10 @@
<ItemGroup>
<PackageReference Include="MsgPack.Cli" Version="0.9.2" />
<PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta006" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-rc.114">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
</ItemGroup>

<Target Name="AfterBuild" Condition="$(NCrunch) != '1'">
Expand Down
3 changes: 2 additions & 1 deletion src/IO.Ably.Shared/AblyAuth.cs
Expand Up @@ -246,7 +246,8 @@ public virtual async Task<TokenDetails> RequestTokenAsync(TokenParams tokenParam

throw new AblyException(
new ErrorInfo(
"Error calling AuthCallback, token request failed. See inner exception for details.", 80019,
"Error calling AuthCallback, token request failed. See inner exception for details.",
80019,
statusCode), ex);
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/IO.Ably.Shared/AblyAuthUpdatedEventArgs.cs
Expand Up @@ -19,7 +19,8 @@ public AblyAuthUpdatedEventArgs()
CompletedTask = new TaskCompletionSource<bool>();
}

public AblyAuthUpdatedEventArgs(TokenDetails token) : this()
public AblyAuthUpdatedEventArgs(TokenDetails token)
: this()
{
Token = token;
}
Expand Down
8 changes: 2 additions & 6 deletions src/IO.Ably.Shared/AblyException.cs
Expand Up @@ -17,10 +17,6 @@ public InsecureRequestException()
/// </summary>
public class AblyException : Exception
{
/* public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
base.GetObjectData(info, context);
} */
public AblyException()
{
}
Expand All @@ -41,8 +37,8 @@ public AblyException(string reason)
/// <param name="ex">Original exception to be wrapped.</param>
public AblyException(Exception ex)
: this(new ErrorInfo("Unexpected error :" + ex.Message, 50000), ex)
{
}
{
}

/// <summary>
/// Creates an AblyException and populates ErrorInfo with the supplied parameters.
Expand Down
12 changes: 7 additions & 5 deletions src/IO.Ably.Shared/AblyRest.cs
Expand Up @@ -3,10 +3,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using IO.Ably.MessageEncoders;
using IO.Ably.Rest;
using System.Threading.Tasks;

using IO.Ably;
using IO.Ably.MessageEncoders;
using IO.Ably.Rest;

using Newtonsoft.Json.Linq;

namespace IO.Ably
Expand All @@ -20,8 +22,8 @@ public sealed class AblyRest : IRestClient

internal string CustomHost
{
get { return HttpClient.CustomHost; }
set { HttpClient.CustomHost = value; }
get => HttpClient.CustomHost;
set => HttpClient.CustomHost = value;
}

internal AblyAuth AblyAuth { get; private set; }
Expand Down Expand Up @@ -82,7 +84,7 @@ private void InitializeAbly()
throw new AblyException("Invalid options");
}

Logger = Options.Logger ?? IO.Ably.DefaultLogger.LoggerInstance;
Logger = Options.Logger ?? DefaultLogger.LoggerInstance;

if (Options.LogLevel.HasValue)
{
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/ApiKey.cs
Expand Up @@ -36,7 +36,7 @@ public static ApiKey Parse(string key)

if (IsValidFormat(trimmedKey))
{
var parts = trimmedKey.Trim().Split(new[] {':'}, StringSplitOptions.RemoveEmptyEntries);
var parts = trimmedKey.Trim().Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

if (parts.Length == 2)
{
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/AuthOptions.cs
Expand Up @@ -22,7 +22,7 @@ public class AuthOptions
/// This enables a client to obtain token requests from
/// another entity, so tokens can be renewed without the
/// client requiring access to keys.
///</summary>
/// </summary>
public Uri AuthUrl { get; set; }

/// <summary>
Expand Down
5 changes: 1 addition & 4 deletions src/IO.Ably.Shared/CipherParams.cs
Expand Up @@ -52,10 +52,7 @@ public override int GetHashCode()

public int KeyLength => Key?.Length * 8 ?? 0;

public string CipherType
{
get { return $"{Algorithm}-{KeyLength}-{Mode}"; }
}
public string CipherType => $"{Algorithm}-{KeyLength}-{Mode}";

public CipherParams(byte[] key)
: this(Crypto.DefaultAlgorithm, key)
Expand Down
23 changes: 11 additions & 12 deletions src/IO.Ably.Shared/ClientOptions.cs
Expand Up @@ -14,9 +14,6 @@ public class ClientOptions : AuthOptions
private bool _useBinaryProtocol = false;
private string[] _fallbackHosts;

/// <summary>
///
/// </summary>
public bool AutoConnect { get; set; } = true;

/// <summary>
Expand All @@ -28,7 +25,7 @@ public class ClientOptions : AuthOptions
/// </summary>
public string ClientId
{
get { return _clientId; }
get => _clientId;

set
{
Expand Down Expand Up @@ -101,8 +98,10 @@ public string[] FallbackHosts
{
return Defaults.FallbackHosts;
}

return _fallbackHosts;
}

set => _fallbackHosts = value;
}

Expand Down Expand Up @@ -151,20 +150,20 @@ internal string FullRestHost()
}

/// <summary>
/// For development environments only; allows a non-default Ably port to be specified.
/// For development environments only; allows a non-default Ably port to be specified.
/// </summary>
public int Port { get; set; } = 80;

/// <summary>
///Encrypted transport: if true, TLS will be used for all connections (whether REST/HTTP
///or Realtime WebSocket or Comet connections).
/// Encrypted transport: if true, TLS will be used for all connections (whether REST/HTTP
/// or Realtime WebSocket or Comet connections).
/// Default: true
///</summary>
/// </summary>
public bool Tls { get; set; } = true;

public int TlsPort { get; set; } = 443;

///<summary>
/// <summary>
/// If false, forces the library to use the JSON encoding for REST and Realtime operations,
/// If true, the MsgPack binary format is used (if available in the current build
/// Default: true
Expand Down Expand Up @@ -214,7 +213,7 @@ internal Func<DateTimeOffset> NowFunc
set => _nowFunc = value;
}

internal ILogger Logger { get; set; } = IO.Ably.DefaultLogger.LoggerInstance;
internal ILogger Logger { get; set; } = DefaultLogger.LoggerInstance;

internal AuthMethod Method
{
Expand Down Expand Up @@ -243,7 +242,7 @@ internal AuthMethod Method
internal TimeSpan RealtimeRequestTimeout { get; set; } = Defaults.DefaultRealtimeTimeout;

/// <summary>
/// Defaul constructor for ClientOptions
/// Default constructor for ClientOptions
/// </summary>
public ClientOptions()
{
Expand All @@ -269,7 +268,7 @@ private void Init()
internal void SetIdempotentRestPublishingDefault(int majorVersion, int minorVersion)
{
// (TO3n) idempotentRestPublishing defaults to false for clients with version < 1.1, otherwise true.
if (majorVersion == 1 && minorVersion >= 1 || majorVersion > 1)
if ((majorVersion == 1 && minorVersion >= 1) || majorVersion > 1)
{
IdempotentRestPublishing = true;
}
Expand Down
24 changes: 12 additions & 12 deletions src/IO.Ably.Shared/Encryption/Crypto.cs
Expand Up @@ -6,10 +6,10 @@

namespace IO.Ably.Encryption
{
///<summary>Specifies the block cipher mode to use for encryption.</summary>
/// <summary>Specifies the block cipher mode to use for encryption.</summary>
public enum CipherMode
{
///<summary>
/// <summary>
/// The Cipher Block Chaining (CBC) mode introduces feedback. Before each plain text
/// block is encrypted, it is combined with the cipher text of the previous block
/// by a bitwise exclusive OR operation. This ensures that even if the plain text
Expand All @@ -22,7 +22,7 @@ public enum CipherMode
/// </summary>
CBC = 1,

///<summary>
/// <summary>
/// The Electronic Codebook (ECB) mode encrypts each block individually. Any blocks
/// of plain text that are identical and in the same message, or that are in a different
/// message encrypted with the same key, will be transformed into identical cipher
Expand All @@ -33,20 +33,20 @@ public enum CipherMode
/// an active adversary can substitute and exchange individual blocks without detection,
/// which allows blocks to be saved and inserted into the stream at other points
/// without detection.
///</summary>
/// </summary>
ECB = 2,

///<summary>
/// <summary>
/// The Output Feedback (OFB) mode processes small increments of plain text into
/// cipher text instead of processing an entire block at a time. This mode is similar
/// to CFB; the only difference between the two modes is the way that the shift register
/// is filled. If a bit in the cipher text is mangled, the corresponding bit of plain
/// text will be mangled. However, if there are extra or missing bits from the cipher
/// text, the plain text will be mangled from that point on.
///</summary>
/// </summary>
OFB = 3,

///<summary>
/// <summary>
/// The Cipher Feedback (CFB) mode processes small increments of plain text into
/// cipher text, instead of processing an entire block at a time. This mode uses
/// a shift register that is one block in length and is divided into sections. For
Expand All @@ -58,22 +58,22 @@ public enum CipherMode
/// by algorithm, but is typically either 8 bits or the number of bits of the block
/// size. You can alter the number of feedback bits by using the System.Security.Cryptography.SymmetricAlgorithm.FeedbackSize
/// property. Algorithms that support CFB use this property to set the feedback.
///</summary>
/// </summary>
CFB = 4,

///<summary>
/// <summary>
/// The Cipher Text Stealing (CTS) mode handles any length of plain text and produces
/// cipher text whose length matches the plain text length. This mode behaves like
/// the CBC mode for all but the last two blocks of the plain text.
///</summary>
/// </summary>
CTS = 5
}

public static class Crypto
{
public const string DefaultAlgorithm = "AES";
public const int DefaultKeylength = 256; ///bits
public const int DefaultBlocklength = 16; ///bytes
public const int DefaultKeylength = 256; // bits
public const int DefaultBlocklength = 16; // bytes
public const CipherMode DefaultMode = CipherMode.CBC;

public static CipherParams GetDefaultParams(string base64EncodedKey, string base64Iv = null, CipherMode? mode = null)
Expand Down
14 changes: 7 additions & 7 deletions src/IO.Ably.Shared/EventEmitter.cs
Expand Up @@ -29,7 +29,7 @@ public abstract class EventEmitter<TState, TArgs> : IEventEmitter<TState, TArgs>
{
internal EventEmitter(ILogger logger)
{
Logger = logger ?? IO.Ably.DefaultLogger.LoggerInstance;
Logger = logger ?? DefaultLogger.LoggerInstance;
}

internal ILogger Logger { get; set; }
Expand All @@ -39,24 +39,24 @@ internal EventEmitter(ILogger logger)

protected abstract Action<Action> NotifyClient { get; }

private class Emitter<TState, TArgs> where TState : struct
private class Emitter<TStatePrivate, TArgsPrivate> where TStatePrivate : struct
{
public Action<TArgs> Action { get; }
public Action<TArgsPrivate> Action { get; }

public Func<TArgs, Task> AsyncAction { get; }
public Func<TArgsPrivate, Task> AsyncAction { get; }

public bool Once { get; }

public TState? State { get; }
public TStatePrivate? State { get; }

public Emitter(Action<TArgs> action, TState? state = null, bool once = false)
public Emitter(Action<TArgsPrivate> action, TStatePrivate? state = null, bool once = false)
{
Action = action ?? throw new ArgumentException("Cannot pass a null action to the EventEmitter");
State = state;
Once = once;
}

public Emitter(Func<TArgs, Task> asyncAction, TState? state = null, bool once = false)
public Emitter(Func<TArgsPrivate, Task> asyncAction, TStatePrivate? state = null, bool once = false)
{
AsyncAction = asyncAction ?? throw new ArgumentException("Cannot pass a null action to the EventEmitter");
State = state;
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/Extensions/DateExtensions.cs
Expand Up @@ -4,7 +4,7 @@ namespace IO.Ably
{
public static class DateExtensions
{
public readonly static DateTimeOffset Epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
public static readonly DateTimeOffset Epoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);

public static DateTimeOffset FromUnixTimeInMilliseconds(this long unixTime)
{
Expand Down
2 changes: 1 addition & 1 deletion src/IO.Ably.Shared/Extensions/StringExtensions.cs
Expand Up @@ -33,7 +33,7 @@ public static string JoinStrings(this IEnumerable<string> input, string delimite
{
if (input == null)
{
return string.Empty;
return Empty;
}

return string.Join(delimiter, input.Where(IsNotEmpty));
Expand Down

0 comments on commit 0941fb1

Please sign in to comment.