Moved files
Added DownloadClient to Connector
This commit is contained in:
parent
45713b868d
commit
d6ec91c896
@ -1,9 +0,0 @@
|
|||||||
namespace Tranga;
|
|
||||||
|
|
||||||
public abstract class Connector
|
|
||||||
{
|
|
||||||
public abstract string name { get; }
|
|
||||||
public abstract bool GetPublications(out Publication[] publications);
|
|
||||||
public abstract bool GetChapters(Publication publication, out Chapter[] chapters);
|
|
||||||
public abstract bool DownloadChapter(Chapter chapter); //where to?
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", "Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tranga", ".\Tranga\Tranga.csproj", "{545E81B9-D96B-4C8F-A97F-2C02414DE566}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
35
Tranga/Connector.cs
Normal file
35
Tranga/Connector.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
using System.Net;
|
||||||
|
|
||||||
|
namespace Tranga;
|
||||||
|
|
||||||
|
public abstract class Connector
|
||||||
|
{
|
||||||
|
public abstract string name { get; }
|
||||||
|
public abstract bool GetPublications(out Publication[] publications);
|
||||||
|
public abstract bool GetChapters(Publication publication, out Chapter[] chapters);
|
||||||
|
public abstract bool DownloadChapter(Chapter chapter); //where to?
|
||||||
|
|
||||||
|
internal class DownloadClient
|
||||||
|
{
|
||||||
|
static readonly HttpClient client = new HttpClient();
|
||||||
|
public RequestResult GetPage(string url)
|
||||||
|
{
|
||||||
|
HttpRequestMessage requestMessage = new HttpRequestMessage(HttpMethod.Get, url);
|
||||||
|
HttpResponseMessage response = client.Send(requestMessage);
|
||||||
|
Stream resultString = response.IsSuccessStatusCode ? response.Content.ReadAsStream() : Stream.Null;
|
||||||
|
return new RequestResult(response.StatusCode, resultString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public struct RequestResult
|
||||||
|
{
|
||||||
|
public HttpStatusCode statusCode { get; }
|
||||||
|
public Stream result { get; }
|
||||||
|
|
||||||
|
public RequestResult(HttpStatusCode statusCode, Stream result)
|
||||||
|
{
|
||||||
|
this.statusCode = statusCode;
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user