Example #1
0
        /// <summary>
        /// Create a new job definition for a Warehouse job.
        /// </summary>
        /// <remarks>
        /// This set up the job with the properties required for it to be considered a Warehouse job.
        ///
        /// TeamFoundationJobDefinition is sealed so you cannot derive a strongly typed warehouse job.
        /// </remarks>
        /// <param name="jobName">Job name.</param>
        /// <param name="jobExtensionName">Extension name (assembly.class)</param>
        /// <returns>New job definition for the Warehouse job.</returns>
        private TeamFoundationJobDefinition CreateWarehouseJobDefinition(string jobName, string jobExtensionName)
        {
            // Add data node identifying this as a Warehouse job.
            var document    = new XmlDocument();
            var dataElement = document.CreateElement(JobDataElementName);

            dataElement.InnerText = WarehouseJobDataElementValue;

            // Create a job definition
            var newDefinition = new TeamFoundationJobDefinition(jobName, jobExtensionName, dataElement);

            // Create a default schedule for the job.
            var schedule = new TeamFoundationJobSchedule(DateTime.UtcNow, WarehouseJobDefaultProcessingInterval);

            newDefinition.Schedule.Add(schedule);

            return(newDefinition);
        }
        /// <summary>
        /// Create a new job definition for a Warehouse job.
        /// </summary>
        /// <remarks>
        /// This set up the job with the properties required for it to be considered a Warehouse job.
        /// 
        /// TeamFoundationJobDefinition is sealed so you cannot derive a strongly typed warehouse job.
        /// </remarks>
        /// <param name="jobName">Job name.</param>
        /// <param name="jobExtensionName">Extension name (assembly.class)</param>
        /// <returns>New job definition for the Warehouse job.</returns>
        private TeamFoundationJobDefinition CreateWarehouseJobDefinition(string jobName, string jobExtensionName)
        {
            // Add data node identifying this as a Warehouse job.
            var document = new XmlDocument();
            var dataElement = document.CreateElement(JobDataElementName);
            dataElement.InnerText = WarehouseJobDataElementValue;

            // Create a job definition
            var newDefinition = new TeamFoundationJobDefinition(jobName, jobExtensionName, dataElement);

            // Create a default schedule for the job.  
            var schedule = new TeamFoundationJobSchedule(DateTime.UtcNow, WarehouseJobDefaultProcessingInterval);
            newDefinition.Schedule.Add(schedule);

            return newDefinition;
        }
Example #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.");
            }
        }