Skip to content

Commit

Permalink
Upgrade to C# 7.1 (#145)
Browse files Browse the repository at this point in the history
* Change csproj files to C# 7.1

* Update SWAN version

* Applying C# 7.1 specs

* Change SWAN to SWAN Lite

* Fix build
  • Loading branch information
geoperez authored Feb 22, 2018
1 parent 7b7cc86 commit ebb69cd
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/Unosquare.Labs.EmbedIO.Command/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ private static void Main(string[] args)

using (var server = new WebServer($"http://localhost:{options.Port}/"))
{
// TODO: Add AppSettings file
//if (Properties.Settings.Default.UseLocalSessionModule)
server.WithLocalSession();

server.EnableCors().WithStaticFolderAt(options.RootPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<AssemblyName>Unosquare.Labs.EmbedIO.Command</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Labs.EmbedIO.Command</PackageId>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<OutputType>Exe</OutputType>
<PackageId>Unosquare.Labs.EmbedIO.Samples</PackageId>
<ContentSQLiteInteropFiles>true</ContentSQLiteInteropFiles>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO.Samples/WebSocketsSample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected override void OnClientConnected(WebSocketContext context)
protected override void OnFrameReceived(WebSocketContext context, byte[] rxBuffer,
WebSocketReceiveResult rxResult)
{
return;
// placeholder
}

/// <inheritdoc />
Expand Down
6 changes: 3 additions & 3 deletions src/Unosquare.Labs.EmbedIO/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public static bool JsonResponse(this HttpListenerContext context, string json)
public static Task<bool> JsonResponseAsync(
this HttpListenerContext context,
string json,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
return context.StringResponseAsync(json, cancellationToken: cancellationToken);
}
Expand All @@ -433,7 +433,7 @@ public static Task<bool> HtmlResponseAsync(
this HttpListenerContext context,
string htmlContent,
System.Net.HttpStatusCode statusCode = System.Net.HttpStatusCode.OK,
CancellationToken cancellationToken = default(CancellationToken))
CancellationToken cancellationToken = default)
{
context.Response.StatusCode = (int) statusCode;
return context.StringResponseAsync(htmlContent, Responses.HtmlContentType, cancellationToken);
Expand Down Expand Up @@ -484,7 +484,7 @@ public static async Task<bool> StringResponseAsync(
this HttpListenerContext context,
string content,
string contentType = "application/json",
CancellationToken cancellationToken = default(CancellationToken),
CancellationToken cancellationToken = default,
Encoding encoding = null)
{
var buffer = (encoding ?? Encoding.UTF8).GetBytes(content);
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO/Modules/WebSocketsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public abstract class WebSocketsServer : IDisposable
private readonly int _maximumMessageSize;
#endif
private bool _isDisposing;
private CancellationToken _ct = default(CancellationToken);
private CancellationToken _ct = default;

/// <summary>
/// Initializes a new instance of the <see cref="WebSocketsServer" /> class.
Expand Down
24 changes: 24 additions & 0 deletions src/Unosquare.Labs.EmbedIO/System.Net/CloseEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ internal CloseEventArgs(CloseStatusCode code, string reason = null)

internal PayloadData PayloadData { get; }
}

/// <summary>
/// The event arguments for connection failure events
/// </summary>
/// <seealso cref="System.EventArgs" />
public class ConnectionFailureEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the <see cref="ConnectionFailureEventArgs"/> class.
/// </summary>
/// <param name="ex">The ex.</param>
public ConnectionFailureEventArgs(Exception ex)
{
Error = ex;
}

/// <summary>
/// Gets the error.
/// </summary>
/// <value>
/// The error.
/// </value>
public Exception Error { get; }
}
}

#endif
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO/System.Net/HttpBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected static async Task<T> ReadAsync<T>(
Stream stream,
Func<string[], T> parser,
int millisecondsTimeout = 90000,
CancellationToken ct = default(CancellationToken))
CancellationToken ct = default)
where T : HttpBase
{
var timeout = false;
Expand Down
10 changes: 5 additions & 5 deletions src/Unosquare.Labs.EmbedIO/System.Net/WebSocket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ internal bool HasMessage
/// <returns>
/// A task that represents the asynchronous closes websocket connection
/// </returns>
public async Task CloseAsync(CloseStatusCode code = CloseStatusCode.Undefined, string reason = null, CancellationToken ct = default(CancellationToken))
public async Task CloseAsync(CloseStatusCode code = CloseStatusCode.Undefined, string reason = null, CancellationToken ct = default)
{
if (!_validator.CheckIfAvailable(out var msg))
{
Expand Down Expand Up @@ -532,7 +532,7 @@ internal bool HasMessage
/// <para>
/// This method isn't available in a server.
/// </para></remarks>
public async Task ConnectAsync(CancellationToken ct = default(CancellationToken))
public async Task ConnectAsync(CancellationToken ct = default)
{
if (!_validator.CheckIfAvailable(out string msg, true, false, true, false, false))
{
Expand Down Expand Up @@ -622,7 +622,7 @@ public async Task<bool> PingAsync(string message)
/// A task that represents the asynchronous of send
/// binary data using websocket
/// </returns>
public async Task SendAsync(byte[] data, Opcode opcode, CancellationToken ct = default(CancellationToken))
public async Task SendAsync(byte[] data, Opcode opcode, CancellationToken ct = default)
{
var msg = WebSocketValidator.CheckIfAvailable(_readyState) ??
WebSocketValidator.CheckSendParameter(data);
Expand Down Expand Up @@ -714,7 +714,7 @@ internal async Task CloseAsync(HttpResponse response)
}

// As server
internal async Task CloseAsync(CloseEventArgs e, byte[] frameAsBytes, bool receive, CancellationToken ct = default(CancellationToken))
internal async Task CloseAsync(CloseEventArgs e, byte[] frameAsBytes, bool receive, CancellationToken ct = default)
{
lock (_forState)
{
Expand Down Expand Up @@ -825,7 +825,7 @@ private async Task InternalCloseAsync(
bool send = true,
bool receive = true,
bool received = false,
CancellationToken ct = default(CancellationToken))
CancellationToken ct = default)
{
lock (_forState)
{
Expand Down
3 changes: 2 additions & 1 deletion src/Unosquare.Labs.EmbedIO/Unosquare.Labs.EmbedIO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
<RepositoryUrl>https://github.com/unosquare/embedio/</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>webserver websocket webapi http</PackageTags>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.DotNet.Analyzers.Compatibility" Version="0.1.2-alpha" />
<PackageReference Include="StyleCop.Analyzers" Version="1.0.2">
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Unosquare.Swan" Version="0.24.0" />
<PackageReference Include="Unosquare.Swan.Lite" Version="0.25.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' ">
Expand Down
2 changes: 1 addition & 1 deletion src/Unosquare.Labs.EmbedIO/WebServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ await context.HtmlResponseAsync(
/// Both the server and client requests are queued separately on the thread pool,
/// so it is safe to call <see cref="Task.Wait()" /> in a synchronous method.
/// </remarks>
public async Task RunAsync(CancellationToken ct = default(CancellationToken))
public async Task RunAsync(CancellationToken ct = default)
{
Listener.IgnoreWriteExceptions = true;
Listener.Start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFrameworks>net46;net47;netcoreapp2.0</TargetFrameworks>
<TestProjectType>UnitTest</TestProjectType>
<CodeAnalysisRuleSet>..\..\StyleCop.Analyzers.ruleset</CodeAnalysisRuleSet>
<LangVersion>7.1</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -30,6 +31,10 @@
<DefineConstants>$(DefineConstants);NET47</DefineConstants>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net47' ">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net46' ">
<Reference Include="System.Net.Http" />
<Reference Include="System.Threading.Tasks" />
Expand Down

0 comments on commit ebb69cd

Please sign in to comment.