Skip to content

Commit fc60d78

Browse files
committed
Refactorings and enhancements
1 parent 2c8f1af commit fc60d78

File tree

9 files changed

+72
-42
lines changed

9 files changed

+72
-42
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# 0.13.0
2+
3+
(tbd)
4+
5+
- Added additional configuration extensions
6+
17
# 0.12.1
28

39
Released on Wednesday, May 15 2019.

appveyor.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
version: '{build}'
2+
branches:
3+
only:
4+
- master
5+
- devel
6+
skip_tags: true
7+
image: Visual Studio 2015
8+
configuration: Release
9+
platform: Any CPU
10+
build_script:
11+
- ps: >-
12+
if ($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null -and $env:APPVEYOR_REPO_BRANCH -eq "master") {
13+
.\build.ps1 -Target Publish
14+
} elseif ($env:APPVEYOR_PULL_REQUEST_NUMBER -eq $null -and $env:APPVEYOR_REPO_BRANCH -eq "devel") {
15+
.\build.ps1 -Target PrePublish
16+
} else {
17+
.\build.ps1 -Target AppVeyor
18+
}
19+
test: off
20+
deploy: off

src/AngleSharp.Io/Dom/WebSocket.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Dom
1+
namespace AngleSharp.Io.Dom
22
{
33
using AngleSharp.Attributes;
44
using AngleSharp.Dom;
@@ -320,28 +320,28 @@ private void OnMessage(String message)
320320
{
321321
var evt = new MessageEvent();
322322
evt.Init(EventNames.Message, false, false, message, _url.Origin, String.Empty, _window);
323-
this.Dispatch(evt);
323+
Dispatch(evt);
324324
}
325325

326326
private void OnError(Exception ex)
327327
{
328328
var evt = new ErrorEvent();
329329
evt.Init(EventNames.Error, false, false);
330-
this.Dispatch(evt);
330+
Dispatch(evt);
331331
}
332332

333333
private void OnDisconnected()
334334
{
335335
var evt = new Event();
336336
evt.Init(CloseEvent, false, false);
337-
this.Dispatch(evt);
337+
Dispatch(evt);
338338
}
339339

340340
private void OnConnected()
341341
{
342342
var evt = new Event();
343343
evt.Init(OpenEvent, false, false);
344-
this.Dispatch(evt);
344+
Dispatch(evt);
345345
}
346346

347347
#endregion

src/AngleSharp.Io/IoConfigurationExtensions.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static IConfiguration WithRequesters(this IConfiguration configuration) =
8282
public static IConfiguration WithRequesters(this IConfiguration configuration, HttpMessageHandler httpMessageHandler)
8383
{
8484
var httpClient = new HttpClient(httpMessageHandler);
85-
return configuration.With(new Object[]
85+
return configuration.With(new IRequester[]
8686
{
8787
new HttpClientRequester(httpClient),
8888
new DataRequester(),
@@ -92,6 +92,25 @@ public static IConfiguration WithRequesters(this IConfiguration configuration, H
9292
});
9393
}
9494

95+
/// <summary>
96+
/// Adds the given requester to the configuration.
97+
/// </summary>
98+
/// <typeparam name="T">The type of the requester to add.</typeparam>
99+
/// <param name="configuration">The configuration to use.</param>
100+
/// <param name="requester">The requester instance to add.</param>
101+
/// <returns>The new configuration.</returns>
102+
public static IConfiguration WithRequester<T>(this IConfiguration configuration, T requester)
103+
where T : IRequester => configuration.With(requester);
104+
105+
/// <summary>
106+
/// Adds a new requester of the provided type to the configuration.
107+
/// </summary>
108+
/// <typeparam name="T">The type of the requester to add.</typeparam>
109+
/// <param name="configuration">The configuration to use.</param>
110+
/// <returns>The new configuration.</returns>
111+
public static IConfiguration WithRequester<T>(this IConfiguration configuration)
112+
where T: IRequester, new() => configuration.WithRequester(new T());
113+
95114
#endregion
96115

97116
#region Cookies

src/AngleSharp.Io/Network/AboutRequester.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Network
1+
namespace AngleSharp.Io.Network
22
{
33
using System;
44
using System.Collections.Generic;
@@ -37,8 +37,7 @@ public void SetRoute(String address, Func<Request, CancellationToken, Task<IResp
3737
/// <returns>The route, if any.</returns>
3838
public Func<Request, CancellationToken, Task<IResponse>> GetRoute(String address)
3939
{
40-
var route = default(Func<Request, CancellationToken, Task<IResponse>>);
41-
_routes.TryGetValue(address, out route);
40+
_routes.TryGetValue(address, out var route);
4241
return route;
4342
}
4443

@@ -66,10 +65,8 @@ protected override Task<IResponse> PerformRequestAsync(Request request, Cancella
6665
/// </summary>
6766
/// <param name="protocol">The protocol to check for, e.g. file.</param>
6867
/// <returns>True if the protocol is supported, otherwise false.</returns>
69-
public override Boolean SupportsProtocol(String protocol)
70-
{
71-
return protocol.Equals("about", StringComparison.OrdinalIgnoreCase);
72-
}
68+
public override Boolean SupportsProtocol(String protocol) =>
69+
protocol.Equals("about", StringComparison.OrdinalIgnoreCase);
7370

7471
private static String GetAddress(String data)
7572
{

src/AngleSharp.Io/Network/DataRequester.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Network
1+
namespace AngleSharp.Io.Network
22
{
33
using AngleSharp.Text;
44
using System;
@@ -23,10 +23,8 @@ public sealed class DataRequester : BaseRequester
2323
/// <summary>Checks if the data protocol is given.</summary>
2424
/// <param name="protocol">The protocol to check for data.</param>
2525
/// <returns>True if data is matched, otherwise false..</returns>
26-
public override Boolean SupportsProtocol(String protocol)
27-
{
28-
return protocol.Is(ProtocolNames.Data);
29-
}
26+
public override Boolean SupportsProtocol(String protocol) =>
27+
protocol.Is(ProtocolNames.Data);
3028

3129
/// <summary>
3230
/// Performs an asynchronous request that can be cancelled.

src/AngleSharp.Io/Network/FileRequester.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Network
1+
namespace AngleSharp.Io.Network
22
{
33
using System;
44
using System.Net;
@@ -18,9 +18,7 @@ public class FileRequester : BaseRequester
1818
/// <returns>The task that will eventually give the response data.</returns>
1919
protected override async Task<IResponse> PerformRequestAsync(Request request, CancellationToken cancel)
2020
{
21-
var requester = FileWebRequest.Create(request.Address.Href) as FileWebRequest;
22-
23-
if (requester != null)
21+
if (FileWebRequest.Create(request.Address.Href) is FileWebRequest requester)
2422
{
2523
var response = await requester.GetResponseAsync().ConfigureAwait(false);
2624
var content = response.GetResponseStream();
@@ -33,17 +31,15 @@ protected override async Task<IResponse> PerformRequestAsync(Request request, Ca
3331
};
3432
}
3533

36-
return default(IResponse);
34+
return default;
3735
}
3836

3937
/// <summary>
4038
/// Checks if the given protocol is supported.
4139
/// </summary>
4240
/// <param name="protocol">The protocol to check for, e.g. file.</param>
4341
/// <returns>True if the protocol is supported, otherwise false.</returns>
44-
public override Boolean SupportsProtocol(String protocol)
45-
{
46-
return protocol.Equals(ProtocolNames.File, StringComparison.OrdinalIgnoreCase);
47-
}
42+
public override Boolean SupportsProtocol(String protocol) =>
43+
protocol.Equals(ProtocolNames.File, StringComparison.OrdinalIgnoreCase);
4844
}
4945
}

src/AngleSharp.Io/Network/FtpRequester.cs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Network
1+
namespace AngleSharp.Io.Network
22
{
33
using System;
44
using System.Net;
@@ -18,9 +18,7 @@ public class FtpRequester : BaseRequester
1818
/// <returns>The task that will eventually give the response data.</returns>
1919
protected override async Task<IResponse> PerformRequestAsync(Request request, CancellationToken cancel)
2020
{
21-
var requester = FtpWebRequest.Create(request.Address.Href) as FtpWebRequest;
22-
23-
if (requester != null)
21+
if (FtpWebRequest.Create(request.Address.Href) is FtpWebRequest requester)
2422
{
2523
requester.Method = WebRequestMethods.Ftp.DownloadFile;
2624
requester.Credentials = new NetworkCredential("anonymous", String.Empty);
@@ -36,17 +34,15 @@ protected override async Task<IResponse> PerformRequestAsync(Request request, Ca
3634
};
3735
}
3836

39-
return default(IResponse);
37+
return default;
4038
}
4139

4240
/// <summary>
4341
/// Checks if the given protocol is supported.
4442
/// </summary>
4543
/// <param name="protocol">The protocol to check for, e.g. ftp.</param>
4644
/// <returns>True if the protocol is supported, otherwise false.</returns>
47-
public override Boolean SupportsProtocol(String protocol)
48-
{
49-
return protocol.Equals(ProtocolNames.Ftp, StringComparison.OrdinalIgnoreCase);
50-
}
45+
public override Boolean SupportsProtocol(String protocol) =>
46+
protocol.Equals(ProtocolNames.Ftp, StringComparison.OrdinalIgnoreCase);
5147
}
5248
}

src/AngleSharp.Io/Network/HttpClientRequester.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Io.Network
1+
namespace AngleSharp.Io.Network
22
{
33
using System;
44
using System.Collections.Generic;
@@ -52,11 +52,9 @@ public HttpClientRequester(HttpClient client)
5252
/// <returns>
5353
/// True if the protocol is supported, otherwise false.
5454
/// </returns>
55-
public override Boolean SupportsProtocol(String protocol)
56-
{
57-
return protocol.Equals(ProtocolNames.Http, StringComparison.OrdinalIgnoreCase) ||
58-
protocol.Equals(ProtocolNames.Https, StringComparison.OrdinalIgnoreCase);
59-
}
55+
public override Boolean SupportsProtocol(String protocol) =>
56+
protocol.Equals(ProtocolNames.Http, StringComparison.OrdinalIgnoreCase) ||
57+
protocol.Equals(ProtocolNames.Https, StringComparison.OrdinalIgnoreCase);
6058

6159
/// <summary>
6260
/// Performs an asynchronous request that can be cancelled.

0 commit comments

Comments
 (0)