This is my code to get a Json connection to a TeamCitySharp server. The localhost is my Json connection. Right now, I am trying to get the start date to display when I go to my localhost, but it displays as null. Any ideas on how to fix this?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:81/Status/AllStatuses");
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var responseString = reader.ReadToEnd();
var serializer = new JavaScriptSerializer();
serializer.RegisterConverters((new[] { new DynamicJsonConverter() }));
dynamic obj = serializer.Deserialize(responseString, typeof(object));
foreach (var objects in obj)
{
foreach (var project in client.Projects)
{
foreach (var build in project.Builds)
{
bs.date = project.ProjectStartDate.ToString();
This is on another controller in a separate project to call the Jsonresult.
public JsonResult AllStatuses() //from the json called in the _client view
{
var buildStatuses = new List<BuildStatus>();
var projects = Client.AllProjects();
//var projects = storeDB.Projects.Include("Builds").ToList();
//var buildStatuses = new List<BuildStatus>();
foreach (var project in projects)
{
try
{
var buildConfigs = Client.BuildConfigsByProjectId(project.Id);
foreach (var buildConfig in buildConfigs)
{
var build = Client.LastBuildByBuildConfigId(buildConfig.Id);
var b = new BuildStatus();
b.id = buildConfig.Id.ToString();
if (b.date != null)
b.date = b.date.ToString();
if (b.status != null)
b.status = build.Status.ToString();
buildStatuses.Add(b);
}
} catch { }
}
//var query = buildStatuses.OrderBy(x => x.status); // Create a sorted list from Error - Unknown
return Json(buildStatuses, JsonRequestBehavior.AllowGet);
}
I am not sure this question is still relevant for the person who asked it. I will answer it for others who might encounter the same issue.
There is a FluentTc library, which provides easy access to TeamCity via its REST API. There is a way to retrieve builds with their start and/or finish dates:
IList builds = new RemoteTc().Connect(h => h.ToHost("teamcity.codebetter.com").AsGuest()) .GetBuilds(b => b.BuildConfiguration(c => c.Id("FluentTc_FluentTcDevelop")) .Branch(r => r.Branched()), i => i.IncludeStatusText().IncludeStartDate().IncludeFinishDate());
The library is available as a nuget package: https://www.nuget.org/packages/fluenttc
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.