Esempio n. 1
0
        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());
                }
            }));
        }
Esempio n. 2
0
        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());
                }
            }));
        }
Esempio n. 3
0
        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());
                }
            }));
        }
Esempio n. 4
0
        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());
                }
            }));
        }
Esempio n. 5
0
        internal async Task <Tuple <bool, string> > ConfigureAgentJobStep(
            string ownerUri,
            AgentJobStepInfo stepInfo,
            ConfigAction configAction,
            RunType runType)
        {
            return(await Task <Tuple <bool, string> > .Run(() =>
            {
                try
                {
                    if (string.IsNullOrWhiteSpace(stepInfo.JobName))
                    {
                        return new Tuple <bool, string>(false, "JobId cannot be null");
                    }

                    JobData jobData;
                    CDataContainer dataContainer;
                    CreateJobData(ownerUri, stepInfo.JobName, out dataContainer, out jobData);

                    using (var jobStep = new JobStepsActions(dataContainer, jobData, stepInfo, configAction))
                    {
                        var executionHandler = new ExecutonHandler(jobStep);
                        executionHandler.RunNow(runType, this);
                    }

                    return new Tuple <bool, string>(true, string.Empty);
                }
                catch (Exception ex)
                {
                    // log exception here
                    return new Tuple <bool, string>(false, ex.ToString());
                }
            }));
        }
Esempio n. 6
0
        internal async Task <Tuple <bool, string> > ConfigureAgentJob(
            string ownerUri,
            AgentJobInfo jobInfo,
            ConfigAction configAction,
            RunType runType)
        {
            return(await Task <Tuple <bool, string> > .Run(() =>
            {
                try
                {
                    JobData jobData;
                    CDataContainer dataContainer;
                    CreateJobData(ownerUri, jobInfo.Name, out dataContainer, out jobData, jobInfo);

                    using (JobActions jobActions = new JobActions(dataContainer, jobData, configAction))
                    {
                        var executionHandler = new ExecutonHandler(jobActions);
                        executionHandler.RunNow(runType, this);
                    }

                    return new Tuple <bool, string>(true, string.Empty);
                }
                catch (Exception ex)
                {
                    return new Tuple <bool, string>(false, ex.ToString());
                }
            }));
        }
Esempio n. 7
0
        internal void ExecuteAction(ManagementActionBase action, RunType runType)
        {
            var executionHandler = new ExecutonHandler(action);

            executionHandler.RunNow(runType, this);
            if (executionHandler.ExecutionResult == ExecutionMode.Failure)
            {
                if (executionHandler.ExecutionFailureException != null)
                {
                    throw executionHandler.ExecutionFailureException;
                }
                else
                {
                    throw new Exception("Failed to execute action");
                }
            }
        }