2

这是我获取到 TeamCitySharp 服务器的 Json 连接的代码。本地主机是我的 Json 连接。现在,我试图在我转到本地主机时显示开始日期,但它显示为空。有想法该怎么解决这个吗?

 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();        

这是在单独项目中的另一个控制器上调用 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);
    }
4

1 回答 1

0

我不确定这个问题是否仍然与提出问题的人相关。我会为可能遇到相同问题的其他人回答。

有一个 FluentTc 库,可通过其 REST API 轻松访问 TeamCity。有一种方法可以检索带有开始和/或结束日期的构建:

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());

该库以 nuget 包的形式提供:https ://www.nuget.org/packages/fluenttc

于 2016-09-20T21:47:04.663 回答