Exemplo n.º 1
0
        private void ReadJobSchedule(string jobId)
        {
            var job     = jobs[jobId.ToUpper()];
            var jobType = job.Item2;

            if (jobType.IsDefined(typeof(JobContextAttribute)))
            {
                var context = jobType.GetCustomAttribute <JobContextAttribute>().Context;
                switch (context)
                {
                case JobContext.Server:
                    if (!rbServer.Checked)
                    {
                        rbServer.Enabled     = true;
                        rbServer.Checked     = true;
                        rbCollection.Enabled = false;
                        return;
                    }
                    break;

                case JobContext.Collection:
                    if (!rbCollection.Checked)
                    {
                        rbCollection.Enabled = true;
                        rbCollection.Checked = true;
                        rbServer.Enabled     = false;
                        return;
                    }
                    break;

                case JobContext.Any:
                    rbCollection.Enabled = true;
                    rbServer.Enabled     = true;
                    break;

                default:
                    break;
                }
            }
            TeamFoundationJobService jobService = GetJobService();

            jobDefinition = jobService.QueryJobDefinition(currentContext, new Guid(jobId));
            if (jobDefinition != null && jobDefinition.Schedule.Count > 0)
            {
                UpdateJobDataInUI();
            }
            else
            {
                ClearJobDataInUI(job, jobType);
            }
            txtJobData.Enabled = !string.IsNullOrEmpty(txtJobData.Text);
            UpdateRegistryInfo(job.Item1, jobType.GetCustomAttribute <RegistryInfoResourceAttribute>());
            tpSchedule.Enabled = true;
        }
Exemplo n.º 2
0
        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.");
            }
        }
Exemplo n.º 3
0
        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.");
            }
        }