private void btnDeleteSchedule_Click(object sender, EventArgs e) { if (jobDefinition != null) { var jobId = jobDefinition.JobId.ToString(); TeamFoundationJobService jobService = GetJobService(); jobService.UpdateJobDefinitions(currentContext, new[] { jobDefinition.JobId }, null); jobDefinition = null; ReadJobSchedule(jobId); MessageBox.Show("Job definition deleted successfully."); } }
private void btnCreateSchedule_Click(object sender, EventArgs e) { TeamFoundationJobService jobService = GetJobService(); if (jobDefinition == null) { // Create new job definition var jobId = (string)lvJobs.SelectedItems[0].Tag; var jobType = jobs[jobId.ToUpper()].Item2; var jobName = jobType.IsDefined(typeof(JobNameAttribute)) ? jobType.GetCustomAttribute <JobNameAttribute>().JobName : jobType.Name; XmlElement jobData = null; if (!string.IsNullOrEmpty(txtJobData.Text)) { var xElem = XElement.Parse(txtJobData.Text); jobData = new XmlDocument().ReadNode(xElem.CreateReader()) as XmlElement; } var timeZone = (from tzi in TimeZoneInfo.GetSystemTimeZones() where tzi.DisplayName == (string)cbTimeZone.SelectedItem select tzi).FirstOrDefault() ?? TimeZoneInfo.Utc; var schedule = new TeamFoundationJobSchedule(); schedule.TimeZoneId = timeZone.Id; schedule.Interval = (int)nudInterval.Value; schedule.ScheduledTime = dtpScheduledTime.Value; var definition = new TeamFoundationJobDefinition(new Guid(jobId), jobName, jobType.FullName, jobData, Microsoft.TeamFoundation.Framework.Common.TeamFoundationJobEnabledState.Enabled); definition.Schedule.Add(schedule); try { jobService.UpdateJobDefinitions(currentContext, null, new[] { definition }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error creating job definition", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ReadJobSchedule(jobId); MessageBox.Show("Job definition created successfully. Please make sure to copy the necessary assemblies to the TFS job agent's plugin folder and restart the job agent!"); } else { // Update existing job definition var timeZone = (from tzi in TimeZoneInfo.GetSystemTimeZones() where tzi.DisplayName == (string)cbTimeZone.SelectedItem select tzi).FirstOrDefault() ?? TimeZoneInfo.Utc; jobDefinition.Schedule[0].ScheduledTime = dtpScheduledTime.Value; jobDefinition.Schedule[0].TimeZoneId = timeZone.Id; jobDefinition.Schedule[0].Interval = (int)nudInterval.Value; XmlElement jobData = null; if (!string.IsNullOrEmpty(txtJobData.Text)) { var xElem = XElement.Parse(txtJobData.Text); jobData = new XmlDocument().ReadNode(xElem.CreateReader()) as XmlElement; } jobDefinition.Data = jobData; try { jobService.UpdateJobDefinitions(currentContext, null, new[] { jobDefinition }); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error updating job definition", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ReadJobSchedule(jobDefinition.JobId.ToString()); MessageBox.Show("Job definition updated successfully."); } }