Ejemplo n.º 1
0
        public async Task Handle(HealthCheckRequest <JenkinsView_v1> request, CancellationToken cancellationToken)
        {
            var jenkinsClient = new JenkinsClient(_logger);

            var jenkinsViewResponse = await jenkinsClient.GetViewAsync(request.DataContext).ConfigureAwait(false);

            var prevJobs = request.DataContext.Items.OfType <JenkinsJob_v1>();

            var dispatcher = Application.Current != null ? Application.Current.Dispatcher : Dispatcher.CurrentDispatcher;

            dispatcher.Invoke(() =>
            {
                // Add Jobs
                var newJobs = jenkinsViewResponse.Jobs.Where(x => prevJobs.All(y => y.URL != x.URL)).OrderBy(x => x.Name);

                foreach (var job in newJobs)
                {
                    AddJob(request.DataContext, job);
                }

                // Remove Jobs
                foreach (var job in prevJobs.Where(x => jenkinsViewResponse.Jobs.All(y => y.URL != x.URL)))
                {
                    request.DataContext.Remove(job);
                }
            });
        }
Ejemplo n.º 2
0
        public async Task Handle(HealthCheckRequest <JenkinsJob_v1> request, CancellationToken cancellationToken)
        {
            var jenkinsClient = new JenkinsClient(_logger);

            var jenkinsJob = await jenkinsClient.GetJobAsync(request.DataContext).ConfigureAwait(false);

            if (jenkinsJob.IsRunning)
            {
                OnBuildRunning(request.DataContext, jenkinsJob.Executor.Progress);
                return;
            }

            if (request.DataContext.ProgressEnabled)
            {
                request.DataContext.ProgressEnabled = false;
                request.DataContext.Progress        = 0;
            }

            if (jenkinsJob.Result == null)
            {
                throw new Exception("Jenkins job result is null.");
            }

            request.DataContext.State = ConvertBuildResultToState(jenkinsJob.Result);
        }
Ejemplo n.º 3
0
        public async Task Handle(StartRequest <JenkinsJob_v1> request, CancellationToken cancellationToken)
        {
            var dialog = new ConfirmationDialog($"Are you sure you want to start {request.DataContext.Name}?");

            var result = _dialogService.ShowDialog(dialog);

            if (result != DialogResult.Yes)
            {
                return;
            }

            var jenkinsClient = new JenkinsClient(_logger);

            await jenkinsClient.TriggerJobAsync(request.DataContext).ConfigureAwait(false);

            _logger.Info($"\"{request.DataContext.Name}\" has been triggered.");
        }