Beispiel #1
0
        public void Execute(Bot bot)
        {
            if (string.IsNullOrWhiteSpace(IpAddressOrHostNameOfCCServer) || !Projects.Any())
            {
                return;
            }

            _client = new TeamCityClient(IpAddressOrHostNameOfCCServer);
            _client.Connect("teamcitysharpuser", "qwerty");

            var allProjects     = _client.AllProjects();
            var allBuildConfigs = _client.AllBuildConfigs();

            foreach (var proj in allProjects)
            {
                Project currentProject = proj;
                var     buildConfigs   = allBuildConfigs.Where(buildConfig => currentProject.Id == buildConfig.Project.Id);

                foreach (var currentBuildConfig in buildConfigs)
                {
                    var build = _client.LastBuildByBuildConfigId(currentBuildConfig.Id);

                    var project = new ProjectModel(currentProject.Name, currentProject.Id, currentBuildConfig.Name, build.StartDate,
                                                   build.Status, build.StatusText);
                    Update(bot, project);
                }
            }
        }
        public BuildStatus Poll()
        {
            FileLogger.Logger.LogVerbose("Polling Monitor: {0}", Name);
            var runningBuilds = _client.BuildsByBuildLocator(BuildLocator.RunningBuilds());

            foreach (var build in _builds)
            {
                // Mark the current last state for the Build.
                // ------------------------------------------------------------------------------
                DateTime dateTime;
                try {
                    var lastbuild = _client.LastBuildByBuildConfigId(build.ID);
                    switch (lastbuild.Status)
                    {
                    case "SUCCESS":
                        build.Status = Status.Success;
                        break;

                    case "ERROR":
                    case "FAILURE":
                        build.Status = Status.Failed;
                        break;

                    case "UNKNOWN":
                        build.Status = Status.Unknown;
                        break;

                    default:
                        Console.WriteLine(lastbuild.Status);
                        break;
                    }
                    if (!string.IsNullOrEmpty(lastbuild.FinishDate))
                    {
                        DateTime.TryParse(lastbuild.FinishDate, out dateTime);
                        build.DateTime = dateTime;
                    }
                } catch {
                    // LastBuildByBuildID will throw an exception if no builds have occurred.
                    // So we need to catch this and simulate an SUCCESS state.
                    build.Status = Status.Success;
                }

                // Update any which are "RUNNING" Now
                // --------------------------------------------------------------------
                if (runningBuilds != null)
                {
                    foreach (var runningBuild in runningBuilds)
                    {
                        if (build.ID.Equals(runningBuild.BuildTypeId))
                        {
                            switch (build.Status)
                            {
                            case Status.Success:
                                build.Status = Status.SuccessInProgress;
                                break;

                            case Status.Failed:
                                build.Status = Status.FailedInProgress;
                                break;

                            default:
                                build.Status = Status.InProgress;
                                break;
                            }

                            if (!string.IsNullOrEmpty(runningBuild.FinishDate))
                            {
                                DateTime.TryParse(runningBuild.FinishDate, out dateTime);
                                build.DateTime = dateTime;
                            }
                        }
                    }
                }
            }
            return(DetermineMonitorState());
        }