This commit is contained in:
Andreia Gaita 2015-02-17 20:25:33 +01:00
Родитель e4f3ab406b
Коммит 777fd66ccd
2 изменённых файлов: 5 добавлений и 32 удалений

Просмотреть файл

@ -1,52 +1,25 @@
using System;
using System.ComponentModel.Composition;
using System.Net.Http;
using GitHub.Models;
using Octokit;
using Octokit.Internal;
using System.Reactive.Linq;
using System.Threading;
using System.Reactive.Threading.Tasks;
using System.Net;
using System.Threading.Tasks;
namespace GitHub.Services
{
[Export(typeof(IEnterpriseProbe))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class EnterpriseProbe : IEnterpriseProbe
public class EnterpriseProbe : EnterpriseProbeTask, IEnterpriseProbe
{
static readonly Uri endPoint = new Uri("/site/sha", UriKind.Relative);
readonly ProductHeaderValue productHeader;
readonly IHttpClient httpClient;
[ImportingConstructor]
public EnterpriseProbe(IProgram program, IHttpClient httpClient)
: base(program, httpClient)
{
productHeader = program.ProductHeader;
this.httpClient = httpClient;
}
public IObservable<EnterpriseProbeResult> Probe(Uri enterpriseBaseUrl)
{
var request = new Request
{
Method = HttpMethod.Get,
BaseAddress = enterpriseBaseUrl,
Endpoint = endPoint,
Timeout = TimeSpan.FromSeconds(3),
AllowAutoRedirect = false,
};
request.Headers.Add("User-Agent", productHeader.ToString());
return httpClient.Send<object>(request, CancellationToken.None)
.ToObservable()
.Catch(Observable.Return<IResponse<object>>(null))
.Select(resp => resp == null
? EnterpriseProbeResult.Failed
: (resp.StatusCode == HttpStatusCode.OK
? EnterpriseProbeResult.Ok
: EnterpriseProbeResult.NotFound));
return ProbeAsync(enterpriseBaseUrl).ToObservable();
}
}
}

Просмотреть файл

@ -13,14 +13,14 @@ namespace GitHub.Services
{
[Export(typeof(IEnterpriseProbeTask))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class EnterpriseProbe : IEnterpriseProbeTask
public class EnterpriseProbeTask : IEnterpriseProbeTask
{
static readonly Uri endPoint = new Uri("/site/sha", UriKind.Relative);
readonly ProductHeaderValue productHeader;
readonly IHttpClient httpClient;
[ImportingConstructor]
public EnterpriseProbe(IProgram program, IHttpClient httpClient)
public EnterpriseProbeTask(IProgram program, IHttpClient httpClient)
{
productHeader = program.ProductHeader;
this.httpClient = httpClient;