diff --git a/src/TeamCitySharp/ActionTypes/Changes.cs b/src/TeamCitySharp/ActionTypes/Changes.cs index 5218b4aa..a840d573 100644 --- a/src/TeamCitySharp/ActionTypes/Changes.cs +++ b/src/TeamCitySharp/ActionTypes/Changes.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using TeamCitySharp.Connection; using TeamCitySharp.DomainEntities; @@ -14,33 +14,58 @@ internal Changes(TeamCityCaller caller) _caller = caller; } - public List All() + public List All(int aHttpTimeOut=-1) { + if (aHttpTimeOut > -1) + _caller.httpTimeOut = aHttpTimeOut; var changeWrapper = _caller.Get("/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("/app/rest/changes/id:{0}", id); return change; } - public List ByBuildConfigId(string buildConfigId) + public List ByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1) { + if (aHttpTimeOut > -1) + _caller.httpTimeOut = aHttpTimeOut; var changeWrapper = _caller.GetFormat("/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 ByBuild(Build aBuild, int aHttpTimeOut = -1) + { + int buildId; + if (!int.TryParse(aBuild.Id, out buildId)) + buildId = -1; + return ByBuildId(buildId, aHttpTimeOut); + } + + public List ByBuildId(int aBuildId, int aHttpTimeOut = -1) + { + if (aHttpTimeOut > -1) + _caller.httpTimeOut = aHttpTimeOut; + var changeWrapper = _caller.GetFormat("/app/rest/changes?build=id:{0}", aBuildId); + + return changeWrapper.Change; + } + } -} \ No newline at end of file +} diff --git a/src/TeamCitySharp/ActionTypes/IChanges.cs b/src/TeamCitySharp/ActionTypes/IChanges.cs index 1ae51cd5..e01c5796 100644 --- a/src/TeamCitySharp/ActionTypes/IChanges.cs +++ b/src/TeamCitySharp/ActionTypes/IChanges.cs @@ -5,9 +5,11 @@ namespace TeamCitySharp.ActionTypes { public interface IChanges { - List All(); - Change ByChangeId(string id); - Change LastChangeDetailByBuildConfigId(string buildConfigId); - List ByBuildConfigId(string buildConfigId); + List All(int aHttpTimeOut = -1); + Change ByChangeId(string id, int aHttpTimeOut = -1); + Change LastChangeDetailByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1); + List ByBuildConfigId(string buildConfigId, int aHttpTimeOut = -1); + List ByBuild(Build aBuild, int aHttpTimeOut = -1); + List ByBuildId(int aBuildId, int aHttpTimeOut = -1); } -} \ No newline at end of file +} diff --git a/src/TeamCitySharp/Connection/TeamCityCaller.cs b/src/TeamCitySharp/Connection/TeamCityCaller.cs index 8f2cbadf..6d209fd2 100644 --- a/src/TeamCitySharp/Connection/TeamCityCaller.cs +++ b/src/TeamCitySharp/Connection/TeamCityCaller.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Net; using System.Security.Authentication; @@ -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; } @@ -67,7 +69,6 @@ public void GetDownloadFormat(Action 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"); @@ -123,7 +124,7 @@ public T Get(string urlPart) var response = GetResponse(urlPart); return response.StaticBody(); } - + public void Get(string urlPart) { GetResponse(urlPart); @@ -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);