Skip to content
This repository was archived by the owner on Feb 12, 2019. It is now read-only.

Custom Http Timeout. #87

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/TeamCitySharp/ActionTypes/Changes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using TeamCitySharp.Connection;
using TeamCitySharp.DomainEntities;
Expand All @@ -14,33 +14,58 @@ internal Changes(TeamCityCaller caller)
_caller = caller;
}

public List<Change> All()
public List<Change> All(int aHttpTimeOut=-1)
{
if (aHttpTimeOut > -1)
_caller.httpTimeOut = aHttpTimeOut;
var changeWrapper = _caller.Get<ChangeWrapper>("/app/rest/changes");

return changeWrapper.Change;
}

public Change ByChangeId(string id)
public Change ByChangeId(string id, int aHttpTimeOut = -1)
{
if (aHttpTimeOut > -1)
_caller.httpTimeOut = aHttpTimeOut;
var change = _caller.GetFormat<Change>("/app/rest/changes/id:{0}", id);

return change;
}

public List<Change> ByBuildConfigId(string buildConfigId)
public List<Change> ByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1)
{
if (aHttpTimeOut > -1)
_caller.httpTimeOut = aHttpTimeOut;
var changeWrapper = _caller.GetFormat<ChangeWrapper>("/app/rest/changes?buildType={0}", buildConfigId);

return changeWrapper.Change;
}

public Change LastChangeDetailByBuildConfigId(string buildConfigId)
public Change LastChangeDetailByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1)
{
if (aHttpTimeOut > -1)
_caller.httpTimeOut = aHttpTimeOut;
var changes = ByBuildConfigId(buildConfigId);

return changes.FirstOrDefault();
}

public List<Change> ByBuild(Build aBuild, int aHttpTimeOut = -1)
{
int buildId;
if (!int.TryParse(aBuild.Id, out buildId))
buildId = -1;
return ByBuildId(buildId, aHttpTimeOut);
}

public List<Change> ByBuildId(int aBuildId, int aHttpTimeOut = -1)
{
if (aHttpTimeOut > -1)
_caller.httpTimeOut = aHttpTimeOut;
var changeWrapper = _caller.GetFormat<ChangeWrapper>("/app/rest/changes?build=id:{0}", aBuildId);

return changeWrapper.Change;
}

}
}
}
12 changes: 7 additions & 5 deletions src/TeamCitySharp/ActionTypes/IChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ namespace TeamCitySharp.ActionTypes
{
public interface IChanges
{
List<Change> All();
Change ByChangeId(string id);
Change LastChangeDetailByBuildConfigId(string buildConfigId);
List<Change> ByBuildConfigId(string buildConfigId);
List<Change> All(int aHttpTimeOut = -1);
Change ByChangeId(string id, int aHttpTimeOut = -1);
Change LastChangeDetailByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1);
List<Change> ByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1);
List<Change> ByBuild(Build aBuild, int aHttpTimeOut = -1);
List<Change> ByBuildId(int aBuildId, int aHttpTimeOut = -1);
}
}
}
10 changes: 6 additions & 4 deletions src/TeamCitySharp/Connection/TeamCityCaller.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.Net;
using System.Security.Authentication;
Expand All @@ -12,13 +12,15 @@ namespace TeamCitySharp.Connection
{
internal class TeamCityCaller : ITeamCityCaller
{
public int httpTimeOut { get; set; }
private readonly Credentials _configuration = new Credentials();

public TeamCityCaller(string hostName, bool useSsl)
{
if (string.IsNullOrEmpty(hostName))
throw new ArgumentNullException("hostName");


httpTimeOut = 10000;
_configuration.UseSSL = useSsl;
_configuration.HostName = hostName;
}
Expand Down Expand Up @@ -67,7 +69,6 @@ public void GetDownloadFormat(Action<string> downloadHandler, string urlPart, pa
throw new ArgumentException("If you are not acting as a guest you must supply userName and password");
}

urlPart = System.Web.HttpUtility.UrlEncode(urlPart);
if (string.IsNullOrEmpty(urlPart))
{
throw new ArgumentException("Url must be specfied");
Expand Down Expand Up @@ -123,7 +124,7 @@ public T Get<T>(string urlPart)
var response = GetResponse(urlPart);
return response.StaticBody<T>();
}

public void Get(string urlPart)
{
GetResponse(urlPart);
Expand Down Expand Up @@ -248,6 +249,7 @@ private HttpClient CreateHttpClient(string userName, string password, string acc
{
var httpClient = new HttpClient(new TeamcityJsonEncoderDecoderConfiguration());
httpClient.Request.Accept = accept;
httpClient.Request.Timeout = httpTimeOut;
if (!_configuration.ActAsGuest)
{
httpClient.Request.SetBasicAuthentication(userName, password);
Expand Down