public void TestBuildingSecureStringFromNullPassword() { string password = null; var secureString = CDataContainer.BuildSecureStringFromPassword(password); Assert.Equal(0, secureString.Length); }
/// <summary> /// Main constructor. Creates all pages and adds them /// to the tree control. /// </summary> public AgentProxyAccountActions(CDataContainer dataContainer, AgentProxyInfo proxyInfo, ConfigAction configAction) { this.DataContainer = dataContainer; this.proxyInfo = proxyInfo; this.configAction = configAction; if (configAction != ConfigAction.Drop) { // Create data structures int length = Enum.GetValues(typeof(ProxyPrincipalType)).Length; this.principals = new ArrayList[length]; for (int i = 0; i < length; ++i) { this.principals[i] = new ArrayList(); } if (configAction == ConfigAction.Update) { RefreshData(); } } // Find out if we are creating a new proxy account or // modifying an existing one. GetProxyAccountName(dataContainer, ref this.proxyAccountName, ref this.duplicate); }
/// <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); } }
public void TestBuildingSecureStringFromPassword() { string password = "******"; var secureString = CDataContainer.BuildSecureStringFromPassword(password); Assert.Equal(password.Length, secureString.Length); }
internal async Task HandleAgentProxiesRequest(AgentProxiesParams parameters, RequestContext <AgentProxiesResult> requestContext) { await Task.Run(async() => { var result = new AgentProxiesResult(); try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); int proxyCount = dataContainer.Server.JobServer.ProxyAccounts.Count; var proxies = new AgentProxyInfo[proxyCount]; for (int i = 0; i < proxyCount; ++i) { var proxy = dataContainer.Server.JobServer.ProxyAccounts[i]; proxies[i] = new AgentProxyInfo { AccountName = proxy.Name, Description = proxy.Description, CredentialName = proxy.CredentialName }; } result.Proxies = proxies; result.Success = true; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.ToString(); } await requestContext.SendResult(result); }); }
private string GetDefaultBackupFolderPath(CDataContainer dataContainer, SqlConnection sqlConn) { DisasterRecoveryService service = new DisasterRecoveryService(); BackupConfigInfo backupConfigInfo = service.GetBackupConfigInfo(dataContainer, sqlConn, sqlConn.Database); return(backupConfigInfo.DefaultBackupFolder); }
private BackupOperation CreateBackupOperation(CDataContainer dataContainer, SqlConnection sqlConnection) { BackupOperation backupOperation = new BackupOperation(); backupOperation.Initialize(dataContainer, sqlConnection); return(backupOperation); }
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()); } })); }
public JobAlertsData(CDataContainer context, JobData parent) { if (context == null) { throw new ArgumentNullException("context"); } if (parent == null) { throw new ArgumentNullException("parent"); } this.context = context; this.parent = parent; this.deletedJobAlerts = new ArrayList(); // if we're creating a new job if (this.parent.Mode != JobData.ActionMode.Edit) { SetDefaults(); } else { // load the JobStep objects LoadData(); } IsReadOnly = parent.IsReadOnly; }
internal BackupOperation CreateBackupOperation(CDataContainer dataContainer, SqlConnection sqlConnection, BackupInfo input) { BackupOperation backupOperation = CreateBackupOperation(dataContainer, sqlConnection); backupOperation.SetBackupInput(input); return(backupOperation); }
public JobStepsActions( CDataContainer dataContainer, JobData jobData, AgentJobStepInfo stepInfo, ConfigAction configAction) { this.configAction = configAction; this.DataContainer = dataContainer; this.jobData = jobData; if (configAction == ConfigAction.Create) { this.data = new JobStepData(jobData.JobSteps); } else { JobStep jobStep = GetJobStep(this.jobData, stepInfo.StepName); this.data = new JobStepData(jobStep, jobData.JobSteps); } // load properties from AgentJobStepInfo this.data.ID = stepInfo.Id; this.data.Name = stepInfo.StepName; this.data.Command = stepInfo.Command; this.data.Subsystem = AgentUtilities.ConvertToAgentSubSytem(stepInfo.SubSystem); }
internal BackupConfigInfo GetBackupConfigInfo(CDataContainer dataContainer, SqlConnection sqlConnection, string databaseName) { BackupOperation backupOperation = new BackupOperation(); backupOperation.Initialize(dataContainer, sqlConnection); return(backupOperation.CreateBackupConfigInfo(databaseName)); }
public JobSchedulesData(CDataContainer context, JobData parent) { if (context == null) { throw new ArgumentNullException("context"); } if (parent == null) { throw new ArgumentNullException("parent"); } this.context = context; this.parent = parent; this.isReadOnly = parent.IsReadOnly; this.allowEnableDisable = parent.AllowEnableDisable; // if we're creating a new job if (this.parent.Mode != JobData.ActionMode.Edit) { this.SetDefaults(); } else { // load the schedule data from server to local copy this.LoadData(); } }
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()); } })); }
internal async Task <Tuple <bool, string> > ConfigureCredential( string ownerUri, CredentialInfo credential, 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); using (CredentialActions actions = new CredentialActions(dataContainer, credential, 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 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); }
/// <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); }); }
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()); } })); }
/// <summary> /// Handle request to get Agent Job history /// </summary> internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext <AgentJobHistoryResult> requestContext) { await Task.Run(async() => { try { var result = new AgentJobHistoryResult(); ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection( parameters.OwnerUri, out connInfo); if (connInfo != null) { ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); var jobs = dataContainer.Server.JobServer.Jobs; Tuple <SqlConnectionInfo, DataTable, ServerConnection> tuple = CreateSqlConnection(connInfo, parameters.JobId); SqlConnectionInfo sqlConnInfo = tuple.Item1; DataTable dt = tuple.Item2; ServerConnection connection = tuple.Item3; int count = dt.Rows.Count; List <AgentJobHistoryInfo> jobHistories = new List <AgentJobHistoryInfo>(); if (count > 0) { var job = dt.Rows[0]; string jobName = Convert.ToString(job[AgentUtilities.UrnJobName], System.Globalization.CultureInfo.InvariantCulture); Guid jobId = (Guid)job[AgentUtilities.UrnJobId]; int runStatus = Convert.ToInt32(job[AgentUtilities.UrnRunStatus], System.Globalization.CultureInfo.InvariantCulture); var t = new LogSourceJobHistory(jobName, sqlConnInfo, null, runStatus, jobId, null); var tlog = t as ILogSource; tlog.Initialize(); var logEntries = t.LogEntries; // Send Steps, Alerts and Schedules with job history in background JobStepCollection steps = jobs[jobName].JobSteps; JobScheduleCollection schedules = jobs[jobName].JobSchedules; List <Alert> alerts = new List <Alert>(); foreach (Alert alert in dataContainer.Server.JobServer.Alerts) { if (alert.JobID == jobId && alert.JobName == jobName) { alerts.Add(alert); } } jobHistories = AgentUtilities.ConvertToAgentJobHistoryInfo(logEntries, job, steps, schedules, alerts); tlog.CloseReader(); } result.Jobs = jobHistories.ToArray(); result.Success = true; connection.Disconnect(); await requestContext.SendResult(result); } } catch (Exception e) { await requestContext.SendError(e); } }); }
internal BackupOperation SetBackupInput(CDataContainer dataContainer, SqlConnection sqlConnection, BackupInfo input) { BackupOperation backupOperation = new BackupOperation(); backupOperation.Initialize(dataContainer, sqlConnection); backupOperation.SetBackupInput(input); return(backupOperation); }
/// <summary> /// Ctor /// </summary> /// <param name="dataContainer"></param> /// <param name="sqlConnection"></param> public CommonUtilities(CDataContainer dataContainer, ServerConnection sqlConnection) { this.dataContainer = dataContainer; this.sqlConnection = sqlConnection; this.excludedDatabases = new ArrayList(); this.excludedDatabases.Add("master"); this.excludedDatabases.Add("tempdb"); }
/// <summary> /// Default constructor that will be used to create dialog /// </summary> /// <param name="dataContainer"></param> public AgentAlertActions( CDataContainer dataContainer, string originalAlertName, AgentAlertInfo alertInfo, ConfigAction configAction) { this.originalAlertName = originalAlertName; this.alertInfo = alertInfo; this.DataContainer = dataContainer; this.configAction = configAction; }
/// <summary> /// Main constructor. Creates all pages and adds them /// to the tree control. /// </summary> public AgentProxyAccount(CDataContainer dataContainer, AgentProxyInfo proxyInfo) { this.DataContainer = dataContainer; this.proxyInfo = proxyInfo; // Find out if we are creating a new proxy account or // modifying an existing one. GetProxyAccountName(dataContainer, ref this.proxyAccountName, ref this.duplicate); }
/// <summary> /// Handle request to get the alerts list /// </summary> internal async Task HandleAgentAlertsRequest(AgentAlertsParams parameters, RequestContext <AgentAlertsResult> requestContext) { await Task.Run(async() => { var result = new AgentAlertsResult(); try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); int alertsCount = dataContainer.Server.JobServer.Alerts.Count; var alerts = new AgentAlertInfo[alertsCount]; for (int i = 0; i < alertsCount; ++i) { var alert = dataContainer.Server.JobServer.Alerts[i]; alerts[i] = new AgentAlertInfo { Id = alert.ID, Name = alert.Name, DelayBetweenResponses = alert.DelayBetweenResponses, EventDescriptionKeyword = alert.EventDescriptionKeyword, EventSource = alert.EventSource, HasNotification = alert.HasNotification, IncludeEventDescription = (Contracts.NotifyMethods)alert.IncludeEventDescription, IsEnabled = alert.IsEnabled, JobId = alert.JobID.ToString(), JobName = alert.JobName, LastOccurrenceDate = alert.LastOccurrenceDate.ToString(), LastResponseDate = alert.LastResponseDate.ToString(), MessageId = alert.MessageID, NotificationMessage = alert.NotificationMessage, OccurrenceCount = alert.OccurrenceCount, PerformanceCondition = alert.PerformanceCondition, Severity = alert.Severity, DatabaseName = alert.DatabaseName, CountResetDate = alert.CountResetDate.ToString(), CategoryName = alert.CategoryName, AlertType = (Contracts.AlertType)alert.AlertType, WmiEventNamespace = alert.WmiEventNamespace, WmiEventQuery = alert.WmiEventQuery }; } result.Alerts = alerts; result.Success = true; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.ToString(); } await requestContext.SendResult(result); }); }
/// <summary> /// Create a new jobsteps data object /// </summary> /// <param name="context">server context</param> /// <param name="parent">owning data object</param> public JobStepsData(CDataContainer context, JobData parent) { if (context == null) { throw new ArgumentNullException("context"); } if (parent == null) { throw new ArgumentNullException("parent"); } CommonInit(context, parent, null); }
/// <summary> /// required when loading from Object Explorer context /// </summary> /// <param name="context"></param> public CredentialActions( CDataContainer context, CredentialInfo credential, ConfigAction configAction) { this.DataContainer = context; this.credential = credential; this.configAction = configAction; this.credentialData = new CredentialData(context, credential); this.credentialData.Initialize(); }
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()); }
/// <summary> /// Default constructor that will be used to create dialog /// </summary> /// <param name="dataContainer"></param> public AgentAlertActions( CDataContainer dataContainer, string originalAlertName, AgentAlertInfo alertInfo, ConfigAction configAction, JobData jobData = null) { this.originalAlertName = originalAlertName; this.alertInfo = alertInfo; this.DataContainer = dataContainer; this.configAction = configAction; if (jobData != null) { this.jobData = jobData; } }
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(); } } }
internal async Task HandleAgentOperatorsRequest(AgentOperatorsParams parameters, RequestContext <AgentOperatorsResult> requestContext) { await Task.Run(async() => { var result = new AgentOperatorsResult(); try { ConnectionInfo connInfo; ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo); CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true); int operatorCount = dataContainer.Server.JobServer.Operators.Count; var operators = new AgentOperatorInfo[operatorCount]; for (int i = 0; i < operatorCount; ++i) { var item = dataContainer.Server.JobServer.Operators[i]; operators[i] = new AgentOperatorInfo { Name = item.Name, Id = item.ID, EmailAddress = item.EmailAddress, Enabled = item.Enabled, LastEmailDate = item.LastEmailDate.ToString(), LastNetSendDate = item.LastNetSendDate.ToString(), LastPagerDate = item.LastPagerDate.ToString(), PagerAddress = item.PagerAddress, CategoryName = item.CategoryName, PagerDays = (Contracts.WeekDays)item.PagerDays, SaturdayPagerEndTime = item.SaturdayPagerEndTime.ToString(), SaturdayPagerStartTime = item.SaturdayPagerEndTime.ToString(), SundayPagerEndTime = item.SundayPagerEndTime.ToString(), SundayPagerStartTime = item.SundayPagerStartTime.ToString(), NetSendAddress = item.NetSendAddress, WeekdayPagerStartTime = item.WeekdayPagerStartTime.ToString(), WeekdayPagerEndTime = item.WeekdayPagerEndTime.ToString() }; } result.Operators = operators; result.Success = true; } catch (Exception ex) { result.Success = false; result.ErrorMessage = ex.ToString(); } await requestContext.SendResult(result); }); }