Esempio n. 1
0
        internal static AgentScheduleInfo ConvertToAgentScheduleInfo(JobSchedule schedule)
        {
            AgentScheduleInfo scheduleInfo = new AgentScheduleInfo();

            scheduleInfo.Id                         = schedule.ID;
            scheduleInfo.Name                       = schedule.Name;
            scheduleInfo.JobName                    = " ";
            scheduleInfo.IsEnabled                  = schedule.IsEnabled;
            scheduleInfo.FrequencyTypes             = (Contracts.FrequencyTypes)schedule.FrequencyTypes;
            scheduleInfo.FrequencySubDayTypes       = (Contracts.FrequencySubDayTypes)schedule.FrequencySubDayTypes;
            scheduleInfo.FrequencySubDayInterval    = schedule.FrequencySubDayInterval;
            scheduleInfo.FrequencyRelativeIntervals = (Contracts.FrequencyRelativeIntervals)schedule.FrequencyRelativeIntervals;
            scheduleInfo.FrequencyRecurrenceFactor  = schedule.FrequencyRecurrenceFactor;
            scheduleInfo.FrequencyInterval          = schedule.FrequencyInterval;
            scheduleInfo.DateCreated                = schedule.DateCreated;
            scheduleInfo.ActiveStartTimeOfDay       = schedule.ActiveStartTimeOfDay;
            scheduleInfo.ActiveStartDate            = schedule.ActiveStartDate;
            scheduleInfo.ActiveEndTimeOfDay         = schedule.ActiveEndTimeOfDay;
            scheduleInfo.ActiveEndDate              = schedule.ActiveEndDate;
            scheduleInfo.JobCount                   = schedule.JobCount;
            scheduleInfo.ScheduleUid                = schedule.ScheduleUid;
            var scheduleData = new JobScheduleData(schedule);

            scheduleInfo.Description = scheduleData.Description;
            return(scheduleInfo);
        }
Esempio n. 2
0
        private JobScheduleData ExtractScheduleDataFromXml(XmlDocument xmlDoc)
        {
            JobScheduleData jobscheduledata = new JobScheduleData();

            string stringNewScheduleMode = null;
            string serverName            = String.Empty;
            string scheduleUrn           = String.Empty;

            STParameters param   = new STParameters();
            bool         bStatus = true;

            param.SetDocument(xmlDoc);

            bStatus = param.GetParam("servername", ref serverName);
            bStatus = param.GetParam("urn", ref scheduleUrn);
            bStatus = param.GetParam("itemtype", ref stringNewScheduleMode);
            if ((stringNewScheduleMode != null) && (stringNewScheduleMode.Length > 0))
            {
                return(jobscheduledata); // new schedule
            }

            Microsoft.SqlServer.Management.Common.ServerConnection connInfo =
                new Microsoft.SqlServer.Management.Common.ServerConnection(serverName);

            Enumerator en  = new Enumerator();
            Request    req = new Request();

            req.Urn = scheduleUrn;

            DataTable dt = en.Process(connInfo, req);

            if (dt.Rows.Count == 0)
            {
                return(jobscheduledata);
            }

            DataRow dr = dt.Rows[0];

            jobscheduledata.Enabled                    = Convert.ToBoolean(dr["IsEnabled"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.Name                       = Convert.ToString(dr["Name"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.FrequencyTypes             = (FrequencyTypes)Convert.ToInt32(dr["FrequencyTypes"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.FrequencyInterval          = Convert.ToInt32(dr["FrequencyInterval"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.FrequencySubDayTypes       = (FrequencySubDayTypes)Convert.ToInt32(dr["FrequencySubDayTypes"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.FrequencyRelativeIntervals = (FrequencyRelativeIntervals)Convert.ToInt32(dr["FrequencyRelativeIntervals"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.FrequencyRecurranceFactor  = Convert.ToInt32(dr["FrequencyRecurrenceFactor"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.ActiveStartDate            = Convert.ToDateTime(dr["ActiveStartDate"], System.Globalization.CultureInfo.InvariantCulture);
            jobscheduledata.ActiveEndDate              = Convert.ToDateTime(dr["ActiveEndDate"], System.Globalization.CultureInfo.InvariantCulture);
            return(jobscheduledata);
        }
Esempio n. 3
0
        internal async Task HandleAgentSchedulesRequest(AgentSchedulesParams parameters, RequestContext <AgentSchedulesResult> requestContext)
        {
            await Task.Run(async() =>
            {
                var result = new AgentSchedulesResult();
                try
                {
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
                    CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);

                    int scheduleCount = dataContainer.Server.JobServer.SharedSchedules.Count;
                    var schedules     = new AgentScheduleInfo[scheduleCount];
                    for (int i = 0; i < scheduleCount; ++i)
                    {
                        var schedule                            = dataContainer.Server.JobServer.SharedSchedules[i];
                        var scheduleData                        = new JobScheduleData(schedule);
                        schedules[i]                            = new AgentScheduleInfo();
                        schedules[i].Id                         = schedule.ID;
                        schedules[i].Name                       = schedule.Name;
                        schedules[i].IsEnabled                  = schedule.IsEnabled;
                        schedules[i].FrequencyTypes             = (Contracts.FrequencyTypes)schedule.FrequencyTypes;
                        schedules[i].FrequencySubDayTypes       = (Contracts.FrequencySubDayTypes)schedule.FrequencySubDayTypes;
                        schedules[i].FrequencySubDayInterval    = schedule.FrequencySubDayInterval;
                        schedules[i].FrequencyRelativeIntervals = (Contracts.FrequencyRelativeIntervals)schedule.FrequencyRelativeIntervals;
                        schedules[i].FrequencyRecurrenceFactor  = schedule.FrequencyRecurrenceFactor;
                        schedules[i].FrequencyInterval          = schedule.FrequencyInterval;
                        schedules[i].DateCreated                = schedule.DateCreated;
                        schedules[i].ActiveStartTimeOfDay       = schedule.ActiveStartTimeOfDay;
                        schedules[i].ActiveStartDate            = schedule.ActiveStartDate;
                        schedules[i].ActiveEndTimeOfDay         = schedule.ActiveEndTimeOfDay;
                        schedules[i].JobCount                   = schedule.JobCount;
                        schedules[i].ActiveEndDate              = schedule.ActiveEndDate;
                        schedules[i].ScheduleUid                = schedule.ScheduleUid;
                        schedules[i].Description                = scheduleData.Description;
                    }
                    result.Schedules = schedules;
                    result.Success   = true;
                }
                catch (Exception ex)
                {
                    result.Success      = false;
                    result.ErrorMessage = ex.ToString();
                }

                await requestContext.SendResult(result);
            });
        }
 /// <summary>
 /// delete a schedule from JobScheduleData list - this does not apply changes on server
 /// </summary>
 /// <param name="schedule"></param>
 public void DeleteSchedule(JobScheduleData schedule)
 {
     if (schedule == null)
     {
         throw new ArgumentNullException("schedule");
     }
     if (this.jobSchedules.Contains(schedule))
     {
         this.jobSchedules.Remove(schedule);
         // if it exists on the server then mark it for deletion later. Otherwise just discard the schedule.
         if (schedule.Created)
         {
             this.deletedJobSchedues.Add(schedule);
         }
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Create a new JobScheduleData based on the current structure
        /// </summary>
        /// <returns>JobScheduleData object</returns>
        public JobScheduleData ToJobScheduleData()
        {
            JobScheduleData data = new JobScheduleData();

            data.Name                       = this.Name;
            data.Enabled                    = this.IsEnabled;
            data.ActiveStartDate            = SimpleJobSchedule.ConvertIntToDateLocalized(this.ActiveStartDate);
            data.ActiveStartTime            = SimpleJobSchedule.ConvertIntToTimeSpan(this.ActiveStartTimeOfDay);
            data.ActiveEndDate              = SimpleJobSchedule.ConvertIntToDateLocalized(this.ActiveEndDate);
            data.ActiveEndTime              = SimpleJobSchedule.ConvertIntToTimeSpan(this.ActiveEndTimeOfDay);
            data.FrequencyTypes             = this.FrequencyTypes;
            data.FrequencyInterval          = this.FrequencyInterval;
            data.FrequencyRecurranceFactor  = this.FrequencyRecurrenceFactor;
            data.FrequencyRelativeIntervals = this.FrequencyRelativeIntervals;
            data.FrequencySubDayInterval    = this.FrequencySubDayInterval;
            data.FrequencySubDayTypes       = this.FrequencySubDayTypes;

            return(data);
        }
        /// <summary>
        /// Add a schedule to JobScheduleData list - this does not apply changes on server
        /// </summary>
        /// <param name="schedule"></param>
        public void AddSchedule(JobScheduleData schedule)
        {
            if (schedule == null)
            {
                throw new ArgumentNullException("schedule");
            }

            this.jobSchedules.Add(schedule);

            // check to see if it has been previously removed, if so delete it from the
            // removed schedules list
            for (int i = deletedJobSchedues.Count - 1; i >= 0; i--)
            {
                JobScheduleData removedSchedule = this.deletedJobSchedues[i] as JobScheduleData;
                if (removedSchedule.ID == schedule.ID)
                {
                    this.deletedJobSchedues.RemoveAt(i);
                }
            }
        }
        /// <summary>
        /// check if given schedule data is shared schedule or not
        /// </summary>
        /// <param name="js"></param>
        /// <param name="jobScheduleData"></param>
        /// <returns></returns>
        private bool IsSharedSchedule(JobServer js, JobScheduleData jobScheduleData)
        {
            if (js == null)
            {
                throw new ArgumentNullException("js");
            }

            SqlServer.Management.Smo.Server srv = js.Parent as SqlServer.Management.Smo.Server;

            if ((srv == null) || (srv.Information.Version.Major < 9))
            {
                // Shared Schedules not supported prior Yukon
                return(false);
            }
            else
            {
                // with Yukon all schedules are now shared
                return(true);
            }
        }
Esempio n. 8
0
        /// <summary>
        /// create a new SimpleJobSchedule structure based upon a JobScheduleData object.
        /// </summary>
        /// <param name="source">JobScheduleData object</param>
        /// <returns>new SimpleJobSchedule</returns>
        public static SimpleJobSchedule FromJobScheduleData(JobScheduleData source)
        {
            SimpleJobSchedule schedule = new SimpleJobSchedule();

            schedule.Name                       = source.Name;
            schedule.ID                         = source.ID;
            schedule.IsEnabled                  = source.Enabled;
            schedule.ActiveStartDate            = SimpleJobSchedule.ConvertDateTimeToInt(source.ActiveStartDate);
            schedule.ActiveStartTimeOfDay       = SimpleJobSchedule.ConvertTimeSpanToInt(source.ActiveStartTime);
            schedule.ActiveEndDate              = SimpleJobSchedule.ConvertDateTimeToInt(source.ActiveEndDate);
            schedule.ActiveEndTimeOfDay         = SimpleJobSchedule.ConvertTimeSpanToInt(source.ActiveEndTime);
            schedule.FrequencyTypes             = source.FrequencyTypes;
            schedule.FrequencyInterval          = source.FrequencyInterval;
            schedule.FrequencyRecurrenceFactor  = source.FrequencyRecurranceFactor;
            schedule.FrequencyRelativeIntervals = source.FrequencyRelativeIntervals;
            schedule.FrequencySubDayInterval    = source.FrequencySubDayInterval;
            schedule.FrequencySubDayTypes       = source.FrequencySubDayTypes;

            schedule.Description = schedule.ComputeDescription();
            return(schedule);
        }
        public JobSchedulesActions(CDataContainer dataContainer, JobData data, AgentScheduleInfo scheduleInfo, ConfigAction configAction)
        {
            this.DataContainer            = dataContainer;
            this.data                     = data;
            this.configAction             = configAction;
            this.scheduleInfo             = scheduleInfo;
            this.sharedSchedulesSupported = this.DataContainer.Server.Information.Version.Major >= 9;

            if (configAction == ConfigAction.Create)
            {
                this.scheduleData = new JobScheduleData(this.data.Job);
                this.scheduleData.SetJobSchedule(new JobSchedule());
            }
            else
            {
                // get the JobScheduleData from the urn
                string       urn        = null;
                STParameters parameters = new STParameters();
                parameters.SetDocument(this.DataContainer.Document);
                parameters.GetParam("urn", ref urn);

                JobSchedule jobStep = this.data.Job.Parent.Parent.GetSmoObject(urn) as JobSchedule;
                if (jobStep != null)
                {
                    this.scheduleData = new JobScheduleData(jobStep);
                }

                if (configAction == ConfigAction.Update && this.scheduleData == null)
                {
                    throw new Exception("Schedule urn parameter cannot be null");
                }
            }

            // copy properties from AgentScheduelInfo
            if (this.scheduleData != null)
            {
                this.scheduleData.Name = scheduleInfo.Name;
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Constructs a new Schedule dialog based upon a SimpleJobSchedule structure
 /// </summary>
 /// <param name="source"></param>
 public ScheduleScriptExecution(SimpleJobSchedule source)
 {
     this.scheduleData = source.ToJobScheduleData();
 }
Esempio n. 11
0
 /// <summary>
 /// Constructs a new ScheduleDialog based upon a JobScheduleData object.
 /// </summary>
 /// <param name="source"></param>
 public ScheduleScriptExecution(JobScheduleData source, SqlConnectionInfo ci)
 {
     this.scheduleData = source;
     this.ci           = ci;
 }
Esempio n. 12
0
 /// <summary>
 /// Constructs a new ScheduleDialog based upon an existing smo Job. Will
 /// automatically save changes on ok.
 /// </summary>
 /// <param name="source">source schedule</param>
 public ScheduleScriptExecution(Job source)
 {
     this.scheduleData = new JobScheduleData(source);
 }
Esempio n. 13
0
 /// <summary>
 ///  constructs an empty schedule dialog.
 /// </summary>
 public ScheduleScriptExecution()
 {
     this.scheduleData = new JobScheduleData();
 }
Esempio n. 14
0
        private CDataContainer dataContainerContext = null; // must be non-null to display JobsInSchedule

        #region Constructors / Dispose



        /// <summary>
        /// Constructs a new ScheduleDialog based upon a JobScheduleData object
        /// And provides context for that dialog so it can enable 'JobsInSchedule' button
        /// </summary>
        /// <param name="source"></param>
        /// <param name="context"></param>
        public ScheduleDialog(JobScheduleData source, CDataContainer context)
        {
            this.dataContainerContext = context;
            this.scheduleData         = source;
        }