internal async Task <Tuple <bool, string> > ConfigureAgentAlert( string ownerUri, AgentAlertInfo alert, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("alert", alert.JobName); if (alert != null && !string.IsNullOrWhiteSpace(alert.JobName)) { using (AgentAlertActions agentAlert = new AgentAlertActions(dataContainer, alert, configAction)) { var executionHandler = new ExecutonHandler(agentAlert); executionHandler.RunNow(runType, this); } } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
/// <summary> /// Constructor /// </summary> public AgentOperator(CDataContainer dataContainer, AgentOperatorInfo operatorInfo) { try { if (dataContainer == null) { throw new ArgumentNullException("dataContainer"); } if (operatorInfo == null) { throw new ArgumentNullException("operatorInfo"); } this.operatorInfo = operatorInfo; this.DataContainer = dataContainer; STParameters parameters = new STParameters(); parameters.SetDocument(dataContainer.Document); string agentOperatorName = null; if (parameters.GetParam("operator", ref agentOperatorName)) { this.operatorsData = new AgentOperatorsData(dataContainer, agentOperatorName); } else { throw new ArgumentNullException("agentOperatorName"); } } catch (Exception e) { throw new ApplicationException("AgentOperatorsSR.FailedToCreateInitializeAgentOperatorDialog", e); } }
internal async Task <Tuple <bool, string> > ConfigureAgentProxy( string ownerUri, string accountName, AgentProxyInfo proxy, ConfigAction configAction, RunType runType) { return(await Task <bool> .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("proxyaccount", accountName); using (AgentProxyAccountActions agentProxy = new AgentProxyAccountActions(dataContainer, proxy, configAction)) { var executionHandler = new ExecutonHandler(agentProxy); executionHandler.RunNow(runType, this); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
/// <summary> /// Handle request to delete an alert /// </summary> internal async Task HandleDeleteAgentAlertRequest(DeleteAgentAlertParams parameters, RequestContext <DeleteAgentAlertResult> requestContext) { await Task.Run(async() => { var result = new DeleteAgentAlertResult(); ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); AgentAlertInfo alert = parameters.Alert; if (connInfo != null && ValidateAgentAlertInfo(alert)) { CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("alert", alert.JobName); using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert)) { agentAlert.Drop(); } } await requestContext.SendResult(result); }); }
private void CreateJobData( string ownerUri, string jobName, out CDataContainer dataContainer, out JobData jobData, ConfigAction configAction = ConfigAction.Create, AgentJobInfo jobInfo = null) { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); XmlDocument jobDoc = CreateJobXmlDocument(dataContainer.Server.Name.ToUpper(), jobName); dataContainer.Init(jobDoc.InnerXml); STParameters param = new STParameters(dataContainer.Document); string originalName = jobInfo != null && !string.Equals(jobName, jobInfo.Name) ? jobName : string.Empty; param.SetParam("job", configAction == ConfigAction.Update ? jobName : string.Empty); param.SetParam("jobid", string.Empty); jobData = new JobData(dataContainer, jobInfo, configAction); }
internal async Task <Tuple <bool, string> > ConfigureAgentOperator( string ownerUri, AgentOperatorInfo operatorInfo, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("operator", operatorInfo.Name); using (AgentOperatorActions actions = new AgentOperatorActions(dataContainer, operatorInfo, configAction)) { ExecuteAction(actions, runType); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
internal async Task <Tuple <bool, string> > ConfigureAgentSchedule( string ownerUri, AgentScheduleInfo schedule, ConfigAction configAction, RunType runType) { return(await Task <bool> .Run(() => { try { JobData jobData; CDataContainer dataContainer; CreateJobData(ownerUri, schedule.JobName, out dataContainer, out jobData); const string UrnFormatStr = "Server[@Name='{0}']/JobServer[@Name='{0}']/Job[@Name='{1}']/Schedule[@Name='{2}']"; string serverName = dataContainer.Server.Name.ToUpper(); string scheduleUrn = string.Format(UrnFormatStr, serverName, jobData.Job.Name, schedule.Name); STParameters param = new STParameters(dataContainer.Document); param.SetParam("urn", scheduleUrn); using (JobSchedulesActions actions = new JobSchedulesActions(dataContainer, jobData, schedule, configAction)) { var executionHandler = new ExecutonHandler(actions); executionHandler.RunNow(runType, this); } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
private static string GetAlertName(CDataContainer container) { string alertName = null; STParameters parameters = new STParameters(); parameters.SetDocument(container.Document); if (parameters.GetParam("alert", ref alertName) == false || string.IsNullOrWhiteSpace(alertName)) { throw new Exception(SR.AlertNameCannotBeBlank); } return(alertName.Trim()); }
private void CreateOrUpdateAgentAlert(ConnectionInfo connInfo, AgentAlertInfo alert) { if (connInfo != null && ValidateAgentAlertInfo(alert)) { CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("alert", alert.JobName); using (AgentAlert agentAlert = new AgentAlert(dataContainer, alert)) { agentAlert.CreateOrUpdate(); } } }
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); }
private void LoadData() { STParameters parameters = new STParameters(this.context.Document); string urn = String.Empty; string jobIdString = null; parameters.GetParam("urn", ref urn); parameters.GetParam("jobid", ref jobIdString); Job job = null; // If JobID is passed in look up by jobID if (!String.IsNullOrEmpty(jobIdString)) { job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString)); } else { // or use urn path to query job job = this.context.Server.GetSmoObject(urn) as Job; } // load the data if (job != null) { AlertCollection alerts = job.Parent.Alerts; // allocate the array list this.jobAlerts = new ArrayList(); for (int i = 0; i < alerts.Count; i++) { // only get alerts that point to this job. if (alerts[i].JobID == job.JobID) { //Since this job was just return from SMO, it is an existing object //Flag it with true to indicate is has already been created. this.jobAlerts.Add(new JobAlertData(alerts[i], true)); } } } else { SetDefaults(); } }
internal async Task <bool> ConfigureAgentProxy( string ownerUri, string accountName, AgentProxyInfo proxy, AgentConfigAction configAction) { return(await Task <bool> .Run(() => { try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( ownerUri, out connInfo); CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("proxyaccount", accountName); using (AgentProxyAccount agentProxy = new AgentProxyAccount(dataContainer, proxy)) { if (configAction == AgentConfigAction.Create) { return agentProxy.Create(); } else if (configAction == AgentConfigAction.Update) { return agentProxy.Update(); } else if (configAction == AgentConfigAction.Drop) { return agentProxy.Drop(); } else { return false; } } } catch (Exception) { // log exception here return false; } })); }
internal async Task <Tuple <bool, string> > ConfigureAgentAlert( string ownerUri, string alertName, AgentAlertInfo alert, ConfigAction configAction, RunType runType) { return(await Task <Tuple <bool, string> > .Run(() => { try { CDataContainer dataContainer; JobData jobData = null; // If the alert is being created outside of a job if (string.IsNullOrWhiteSpace(alert.JobName)) { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(ownerUri, out connInfo); dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); } else { // If the alert is being created inside a job CreateJobData(ownerUri, alert.JobName, out dataContainer, out jobData); } STParameters param = new STParameters(dataContainer.Document); param.SetParam("alert", alertName); if (alert != null) { using (AgentAlertActions actions = new AgentAlertActions(dataContainer, alertName, alert, configAction, jobData)) { ExecuteAction(actions, runType); } } return new Tuple <bool, string>(true, string.Empty); } catch (Exception ex) { return new Tuple <bool, string>(false, ex.ToString()); } })); }
public AgentAction(XmlDocument document, IServiceProvider source, object actionObject) { // parameter check if (document == null) { throw new ArgumentNullException("document"); } if (source == null) { throw new ArgumentNullException("source"); } if (actionObject != null) { this.ActionObject = actionObject; } // get the managed connection managedConnection = source.GetService(typeof(IManagedConnection)) as IManagedConnection; // get the connection SqlOlapConnectionInfoBase ci = managedConnection.Connection; // get the server connection ServerConnection serverConnection = ((SqlConnectionInfoWithConnection)managedConnection.Connection).ServerConnection; smoServer = new Microsoft.SqlServer.Management.Smo.Server(serverConnection); // get the list or urn's that have been passed in param = new STParameters(document); StringCollection urnStrings = new StringCollection(); // get a list of urns that have been passed in. param.GetParam("urn", urnStrings); // store the Urn's as real Urns urnParameters = new Urn[urnStrings.Count]; for (int i = 0; i < urnStrings.Count; i++) { urnParameters[i] = new Urn(urnStrings[i]); } }
/// <summary> /// reads context - ensures we have /// valid context /// valid server connection /// valid schedule name /// </summary> private void LoadData() { System.Diagnostics.Debug.Assert(DataContainer != null); System.Diagnostics.Debug.Assert(DataContainer.Server != null); System.Diagnostics.Debug.Assert(m_scheduleName != null); System.Diagnostics.Debug.Assert(m_scheduleId != -1); string urnString = String.Empty; STParameters param = new STParameters(); param.SetDocument(DataContainer.Document); param.GetParam("joburn", ref urnString); if (urnString != null) { this.jobUrn = new Urn(urnString); } }
/// <summary> /// Get the list of any schedules that should not be shown in the UI. /// </summary> private void InitializeExcludedSchedules() { if (DataContainer == null) { throw new InvalidOperationException(); } string excludedIdList = string.Empty; string removedIdList = string.Empty; STParameters param = new STParameters(); param.SetDocument(DataContainer.Document); param.GetParam("excludedschedules", ref excludedIdList); param.GetParam("removedschedules", ref removedIdList); excludedScheduleId = ConvertCommaSeparatedIdList(excludedIdList); removedScheduleId = ConvertCommaSeparatedIdList(removedIdList); }
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; } }
internal async Task HandleCreateAgentOperatorRequest(CreateAgentOperatorParams parameters, RequestContext <CreateAgentOperatorResult> requestContext) { await Task.Run(async() => { var result = new CreateAgentOperatorResult(); ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); AgentOperatorInfo operatorInfo = parameters.Operator; CDataContainer dataContainer = AdminService.CreateDataContainer(connInfo, databaseExists: true); STParameters param = new STParameters(dataContainer.Document); param.SetParam("operator", operatorInfo.Name); using (AgentOperator agentOperator = new AgentOperator(dataContainer, operatorInfo)) { agentOperator.CreateOrUpdate(); } await requestContext.SendResult(result); }); }
/// <summary> /// Retrieves a proxy account name from shared data containter. /// </summary> internal static void GetProxyAccountName(CDataContainer dataContainer, ref string proxyAccountName, ref bool duplicate) { STParameters parameters = new STParameters(); parameters.SetDocument(dataContainer.Document); // Get proxy name parameters.GetParam(AgentProxyAccountActions.ProxyAccountPropertyName, ref proxyAccountName); if (proxyAccountName != null && proxyAccountName.Length == 0) { // Reset empty name back to null proxyAccountName = null; } // Get duplicate flag string mode = string.Empty; if (parameters.GetParam(AgentProxyAccountActions.ProxyAccountMode, ref mode) && 0 == string.Compare(mode, AgentProxyAccountActions.ProxyAccountDuplicateMode, StringComparison.Ordinal)) { duplicate = true; } }
/// <summary> /// Constructor /// </summary> public AgentOperatorActions( CDataContainer dataContainer, AgentOperatorInfo operatorInfo, ConfigAction configAction) { if (dataContainer == null) { throw new ArgumentNullException("dataContainer"); } if (operatorInfo == null) { throw new ArgumentNullException("operatorInfo"); } this.operatorInfo = operatorInfo; this.DataContainer = dataContainer; this.configAction = configAction; STParameters parameters = new STParameters(); parameters.SetDocument(dataContainer.Document); string agentOperatorName = null; if (parameters.GetParam("operator", ref agentOperatorName)) { this.operatorsData = new AgentOperatorsData( dataContainer, agentOperatorName, createMode: configAction == ConfigAction.Create); } else { throw new ArgumentNullException("agentOperatorName"); } }
/// <summary> /// Load job steps from the server /// </summary> private void LoadData() { STParameters parameters = new STParameters(this.context.Document); string urn = string.Empty; string jobIdString = string.Empty; parameters.GetParam("urn", ref urn); parameters.GetParam("jobid", ref jobIdString); // save current state of default fields StringCollection originalFields = this.context.Server.GetDefaultInitFields(typeof(JobStep)); // Get all JobStep properties since the JobStepData class is going to use themn this.context.Server.SetDefaultInitFields(typeof(JobStep), true); try { Job job = null; // If JobID is passed in look up by jobID if (!string.IsNullOrEmpty(jobIdString)) { job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString)); } else { // or use urn path to query job job = this.context.Server.GetSmoObject(urn) as Job; } // load the data JobStepCollection steps = job.JobSteps; // allocate the array list this.jobSteps = new ArrayList(steps.Count); for (int i = 0; i < steps.Count; i++) { // add them in step id order int ii = 0; for (; ii < this.jobSteps.Count; ii++) { if (steps[i].ID < ((JobStepData)this.jobSteps[ii]).ID) { break; } } this.jobSteps.Insert(ii, new JobStepData(steps[i], this)); } // figure out the start step this.startStep = GetObjectForStep(job.StartStepID); // fixup all of the jobsteps failure/completion actions foreach (JobStepData jobStep in this.jobSteps) { jobStep.LoadCompletionActions(); } } finally { // revert to initial default fields for this type this.context.Server.SetDefaultInitFields(typeof(JobStep), originalFields); } }
public JobData(CDataContainer data, AgentJobInfo jobInfo = null, ConfigAction configAction = ConfigAction.Create) { this.context = data; // get the job information STParameters parameters = new STParameters(this.context.Document); parameters.GetParam("job", ref this.originalName); parameters.GetParam("jobid", ref this.jobIdString); parameters.GetParam("script", ref this.script); parameters.GetParam("scriptName", ref this.scriptName); // get the Urn string urn = string.Empty; parameters.GetParam("urn", ref urn); if (urn != null && urn.Length > 0) { this.urn = new Urn(urn); } bool isMsxJob = false; parameters.GetParam("msxjob", ref isMsxJob); //If this is an MSX, initially set TargetLocalServers to false; if (isMsxJob) { this.targetLocalServer = false; } // we are in properties mode. if (configAction == ConfigAction.Update) { this.mode = ActionMode.Edit; CheckAndLoadGeneralData(); } else if (this.script.Length > 0) { // we are creating a new job, but prepopulating // one step with the script passed to us this.mode = ActionMode.Create; this.Name = this.scriptName; SetDefaults(); this.jobSteps = new JobStepsData(context, script, this); } // creating a new job else { this.mode = ActionMode.Create; // set defaults that do not involve going to the server to retrieve SetDefaults(); } // load AgentJobInfo data if (jobInfo != null) { this.currentName = jobInfo.Name; this.owner = jobInfo.Owner; this.description = jobInfo.Description; this.enabled = jobInfo.Enabled; } }