コード例 #1
0
        /// <summary>
        /// Executes the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var httpJobAction = new PSHttpJobActionParams()
            {
                RequestMethod         = this.Method,
                Uri                   = this.Uri,
                RequestBody           = this.RequestBody,
                RequestHeaders        = this.Headers,
                RequestAuthentication = GetAuthenticationParams(),
            };

            JobActionType jobActionType;

            if (this.Uri.Scheme.Equals(Constants.HttpScheme, StringComparison.InvariantCultureIgnoreCase) ||
                this.Uri.Scheme.Equals(Constants.HttpsScheme, StringComparison.InvariantCultureIgnoreCase))
            {
                jobActionType = (JobActionType)Enum.Parse(typeof(JobActionType), this.Uri.Scheme, ignoreCase: true);
            }
            else
            {
                throw new PSArgumentException(string.Format(Resources.SchedulerInvalidUriScheme, this.Uri.Scheme));
            }

            var jobAction = new PSJobActionParams()
            {
                JobActionType = jobActionType,
                HttpJobAction = httpJobAction
            };

            var jobRecurrence = new PSJobRecurrenceParams()
            {
                Interval       = this.Interval,
                Frequency      = this.Frequency,
                EndTime        = this.EndTime,
                ExecutionCount = this.ExecutionCount
            };

            var jobParams = new PSJobParams()
            {
                ResourceGroupName = this.ResourceGroupName,
                JobCollectionName = this.JobCollectionName,
                JobName           = this.JobName,
                JobState          = this.JobState,
                StartTime         = this.StartTime,
                JobAction         = jobAction,
                JobRecurrence     = jobRecurrence,
                JobErrorAction    = this.GetErrorActionParamsValue(this.ErrorActionType)
            };

            this.ConfirmAction(
                processMessage: string.Format(Resources.NewHttpJobResourceDescription, this.JobName),
                target: this.JobCollectionName,
                action: () =>
            {
                this.WriteObject(this.SchedulerClient.CreateJob(jobParams));
            }
                );
        }
コード例 #2
0
        /// <summary>
        /// Update an existing job.
        /// </summary>
        /// <param name="updateJobParams">Update job properties specified via PowerShell.</param>
        /// <returns>The job definition.</returns>
        public PSSchedulerJobDefinition UpdateJob(PSJobParams updateJobParams)
        {
            if (string.IsNullOrWhiteSpace(updateJobParams.ResourceGroupName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "ResourceGroupName");
            }

            if (string.IsNullOrWhiteSpace(updateJobParams.JobCollectionName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobCollectionName");
            }

            if (string.IsNullOrWhiteSpace(updateJobParams.JobName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobName");
            }

            JobDefinition existingJobDefinition = this.GetJob(updateJobParams.ResourceGroupName, updateJobParams.JobCollectionName, updateJobParams.JobName);

            if (existingJobDefinition == null)
            {
                throw new PSManagement.PSArgumentException(string.Format(Resources.JobDoesnotExist, updateJobParams.ResourceGroupName, updateJobParams.JobCollectionName, updateJobParams.JobName));
            }

            this.PopulateExistingJobParams(updateJobParams, existingJobDefinition);

            var jobDefinitionResult = this.SchedulerManagementClient.Jobs.Patch(updateJobParams.ResourceGroupName, updateJobParams.JobCollectionName, updateJobParams.JobName, existingJobDefinition);

            return(Converter.ConvertJobDefinitionToPS(jobDefinitionResult));
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var serviceBusAuthentication = new PSServiceBusAuthenticationParams()
            {
                SasKey     = this.ServiceBusSasKeyValue,
                SasKeyName = this.ServiceBusSasKeyName,
                Type       = Constants.SharedAccessKey
            };

            var servicBusQueue = new PSServiceBusParams()
            {
                Authentication    = serviceBusAuthentication,
                Message           = this.ServiceBusMessage,
                NamespaceProperty = this.ServiceBusNamespace,
                TopicPath         = this.ServiceBusTopicPath,
                TransportType     = this.ServiceBusTransportType
            };

            var jobAction = new PSJobActionParams()
            {
                JobActionType    = SchedulerModels.JobActionType.ServiceBusTopic,
                ServiceBusAction = servicBusQueue
            };

            var jobRecurrence = new PSJobRecurrenceParams()
            {
                Interval       = this.Interval,
                Frequency      = this.Frequency,
                EndTime        = this.EndTime,
                ExecutionCount = this.ExecutionCount
            };

            var jobParams = new PSJobParams()
            {
                ResourceGroupName = this.ResourceGroupName,
                JobCollectionName = this.JobCollectionName,
                JobName           = this.JobName,
                JobState          = this.JobState,
                StartTime         = this.StartTime,
                JobAction         = jobAction,
                JobRecurrence     = jobRecurrence,
                JobErrorAction    = this.GetErrorActionParamsValue(this.ErrorActionType)
            };

            this.ConfirmAction(
                processMessage: string.Format(Resources.NewServiceBusTopicJobResourceDescription, this.JobName),
                target: this.JobCollectionName,
                action: () =>
            {
                this.WriteObject(this.SchedulerClient.CreateJob(jobParams));
            }
                );
        }
コード例 #4
0
        /// <summary>
        /// Get job properties.
        /// </summary>
        /// <param name="updateJobParams">Job properties specified via PowerShell.</param>
        /// <param name="existingJobProperties">Exsting job properties.</param>
        /// <returns></returns>
        private JobProperties GetExistingJobPropertiesParams(PSJobParams updateJobParams, JobProperties existingJobProperties)
        {
            var newJobProperties = new JobProperties()
            {
                Action     = this.GetExistingJobAction(updateJobParams.JobAction, existingJobProperties.Action),
                Recurrence = this.GetExistingJobRecurrence(updateJobParams.JobRecurrence, existingJobProperties.Recurrence),
                StartTime  = updateJobParams.StartTime ?? existingJobProperties.StartTime,
            };

            newJobProperties.Action.ErrorAction = this.GetExistingJobErrorAction(updateJobParams.JobErrorAction, existingJobProperties.Action.ErrorAction);

            newJobProperties.State = updateJobParams.JobState.GetValueOrDefaultEnum <JobState?>(defaultValue: null);

            return(newJobProperties);
        }
コード例 #5
0
        /// <summary>
        /// Get JobAction instance.
        /// </summary>
        /// <param name="jobParams">Job properties specified via PowerShell.</param>
        /// <returns>JobActio instance.</returns>
        private JobAction GetJobAction(PSJobParams jobParams)
        {
            var jobAction = new JobAction();

            this.PopulateJobAction(jobParams.JobAction, ref jobAction);

            // Populate error job action.
            if (jobParams.JobErrorAction != null)
            {
                var jobErrorAction = new JobErrorAction();
                this.PopulateJobErrorAction(jobParams.JobErrorAction, ref jobErrorAction);
                jobAction.ErrorAction = jobErrorAction;
            }

            return(jobAction);
        }
        /// <summary>
        /// Executes the command.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            base.ExecuteCmdlet();

            var storageJobAction = new PSStorageJobActionParams()
            {
                StorageAccount      = this.StorageQueueAccount,
                StorageQueueMessage = this.StorageQueueMessage,
                StorageQueueName    = this.StorageQueueName,
                StorageSasToken     = this.StorageSASToken
            };

            var jobAction = new PSJobActionParams()
            {
                JobActionType    = SchedulerModels.JobActionType.StorageQueue,
                StorageJobAction = storageJobAction
            };

            var jobRecurrence = new PSJobRecurrenceParams()
            {
                Interval       = this.Interval,
                Frequency      = this.Frequency,
                EndTime        = this.EndTime,
                ExecutionCount = this.ExecutionCount
            };

            var jobParams = new PSJobParams()
            {
                ResourceGroupName = this.ResourceGroupName,
                JobCollectionName = this.JobCollectionName,
                JobName           = this.JobName,
                JobState          = this.JobState,
                StartTime         = this.StartTime,
                JobAction         = jobAction,
                JobRecurrence     = jobRecurrence,
                JobErrorAction    = this.GetErrorActionParamsValue(this.ErrorActionType)
            };

            this.ConfirmAction(
                processMessage: string.Format(Resources.UpdateStorageQueueJobResourceDescription, this.JobName),
                target: this.JobCollectionName,
                action: () =>
            {
                this.WriteObject(this.SchedulerClient.UpdateJob(jobParams));
            }
                );
        }
コード例 #7
0
        /// <summary>
        /// Create a job.
        /// </summary>
        /// <param name="createJobParams">Job properties entered via powershell.</param>
        /// <returns>The Job definition.</returns>
        public PSSchedulerJobDefinition CreateJob(PSJobParams createJobParams)
        {
            if (string.IsNullOrWhiteSpace(createJobParams.ResourceGroupName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "ResourceGroupName");
            }

            if (string.IsNullOrWhiteSpace(createJobParams.JobCollectionName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobCollectionName");
            }

            if (string.IsNullOrWhiteSpace(createJobParams.JobName))
            {
                throw new PSManagement.PSArgumentNullException(paramName: "JobName");
            }

            if (!DoesResourceGroupExists(createJobParams.ResourceGroupName))
            {
                throw new PSManagement.PSArgumentException(Resources.SchedulerInvalidResourceGroup);
            }

            IList <JobCollectionDefinition> jobCollection = ListJobCollection(createJobParams.ResourceGroupName, createJobParams.JobCollectionName);

            if (jobCollection == null || jobCollection.Count < 1)
            {
                throw new PSManagement.PSInvalidOperationException(string.Format(Resources.JobCollectionDoesnotExist, createJobParams.JobCollectionName, createJobParams.ResourceGroupName));
            }
            else
            {
                if (JobExists(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, createJobParams.JobName))
                {
                    throw new PSManagement.PSArgumentException(string.Format(Resources.SchedulerExistingJob, createJobParams.JobName, createJobParams.JobCollectionName));
                }

                IList <JobDefinition> listOfJobs = ListJobs(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, jobState: null);

                if (listOfJobs != null)
                {
                    Validate(jobCollection[0], listOfJobs.Count);
                }
            }

            JobAction jobAction = this.GetJobAction(createJobParams);

            JobRecurrence jobRecurrence = this.GetJobRecurrence(createJobParams.JobRecurrence);

            var properties = new JobProperties()
            {
                Action     = jobAction,
                Recurrence = jobRecurrence,
                StartTime  = createJobParams.StartTime,
                State      = createJobParams.JobState.GetValueOrDefaultEnum <JobState?>(defaultValue: null)
            };

            var jobDefinition = new JobDefinition(name: createJobParams.JobName)
            {
                Properties = properties
            };

            JobDefinition jobDefinitionResult = this.SchedulerManagementClient.Jobs.CreateOrUpdate(createJobParams.ResourceGroupName, createJobParams.JobCollectionName, createJobParams.JobName, jobDefinition);

            return(Converter.ConvertJobDefinitionToPS(jobDefinitionResult));
        }
コード例 #8
0
        /// <summary>
        /// Populates job properties with valid values.
        /// </summary>
        /// <param name="updateJobParams">Job properties specified via PowerShell.</param>
        /// <param name="existingJobDefinition">Existing job definition.</param>
        private void PopulateExistingJobParams(PSJobParams updateJobParams, JobDefinition existingJobDefinition)
        {
            JobProperties jobProperties = this.GetExistingJobPropertiesParams(updateJobParams, existingJobDefinition.Properties);

            existingJobDefinition.Properties = jobProperties;
        }