/// <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));
            }
                );
        }
Beispiel #2
0
        /// <summary>
        /// Populate job action values.
        /// </summary>
        /// <param name="jobActionParams">Job action properties specified via PowerShell.</param>
        /// <param name="jobAction">JobAction object to be populated.</param>
        private void PopulateJobAction(PSJobActionParams jobActionParams, ref JobAction jobAction)
        {
            switch (jobActionParams.JobActionType)
            {
            case JobActionType.Http:
            case JobActionType.Https:
                jobAction.Type    = jobActionParams.JobActionType;
                jobAction.Request = this.GetHttpJobAction(jobActionParams.HttpJobAction);
                break;

            case JobActionType.StorageQueue:
                jobAction.Type         = JobActionType.StorageQueue;
                jobAction.QueueMessage = this.GetStorageQueue(jobActionParams.StorageJobAction);
                break;

            case JobActionType.ServiceBusQueue:
                jobAction.Type = JobActionType.ServiceBusQueue;
                jobAction.ServiceBusQueueMessage = this.GetServiceBusQueue(jobActionParams.ServiceBusAction);
                break;

            case JobActionType.ServiceBusTopic:
                jobAction.Type = JobActionType.ServiceBusTopic;
                jobAction.ServiceBusTopicMessage = this.GetServiceBusTopic(jobActionParams.ServiceBusAction);
                break;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Get job action.
        /// </summary>
        /// <param name="updateJobActionParams">Job action properties specified via PowerShell.</param>
        /// <param name="existingJobAction">Job action properties from existing job.</param>
        /// <returns>JobAction object.</returns>
        private JobAction GetExistingJobAction(PSJobActionParams updateJobActionParams, JobAction existingJobAction)
        {
            if (updateJobActionParams != null)
            {
                if (existingJobAction != null &&
                    (existingJobAction.Type == updateJobActionParams.JobActionType ||
                     ((existingJobAction.Type == JobActionType.Http || existingJobAction.Type == JobActionType.Https) &&
                      (updateJobActionParams.JobActionType == JobActionType.Http || updateJobActionParams.JobActionType == JobActionType.Https))))
                {
                    switch (updateJobActionParams.JobActionType)
                    {
                    case JobActionType.Http:
                    case JobActionType.Https:
                        PSHttpJobActionParams httpJobAction        = updateJobActionParams.HttpJobAction;
                        HttpRequest           existinghHttpRequest = existingJobAction.Request;
                        if (httpJobAction.Uri != null)
                        {
                            existinghHttpRequest.Uri = httpJobAction.Uri.OriginalString;
                            existingJobAction.Type   = updateJobActionParams.JobActionType;
                        }

                        existinghHttpRequest.Method  = httpJobAction.RequestMethod.GetValueOrDefault(defaultValue: existinghHttpRequest.Method);
                        existinghHttpRequest.Body    = httpJobAction.RequestBody.GetValueOrDefault(defaultValue: existinghHttpRequest.Body);
                        existinghHttpRequest.Headers = httpJobAction.RequestHeaders != null?httpJobAction.RequestHeaders.ToDictionary() : existinghHttpRequest.Headers;

                        existinghHttpRequest.Authentication = this.GetExistingAuthentication(httpJobAction.RequestAuthentication, existinghHttpRequest.Authentication);
                        break;

                    case JobActionType.StorageQueue:
                        PSStorageJobActionParams storageJobAction     = updateJobActionParams.StorageJobAction;
                        StorageQueueMessage      existingStorageQueue = existingJobAction.QueueMessage;
                        storageJobAction.StorageAccount      = storageJobAction.StorageAccount.GetValueOrDefault(defaultValue: existingStorageQueue.StorageAccount);
                        storageJobAction.StorageQueueMessage = storageJobAction.StorageQueueMessage.GetValueOrDefault(defaultValue: existingStorageQueue.Message);
                        storageJobAction.StorageQueueName    = storageJobAction.StorageQueueName.GetValueOrDefault(defaultValue: existingStorageQueue.QueueName);
                        storageJobAction.StorageSasToken     = storageJobAction.StorageSasToken.GetValueOrDefault(defaultValue: existingStorageQueue.SasToken);
                        break;

                    case JobActionType.ServiceBusQueue:
                        PSServiceBusParams     serviceBusQueueParams          = updateJobActionParams.ServiceBusAction;
                        ServiceBusQueueMessage existingServiceBusQueueMessage = existingJobAction.ServiceBusQueueMessage;
                        this.UpdateServiceBus(serviceBusQueueParams, existingServiceBusQueueMessage);
                        existingServiceBusQueueMessage.QueueName = serviceBusQueueParams.QueueName.GetValueOrDefault(defaultValue: existingServiceBusQueueMessage.QueueName);
                        break;

                    case JobActionType.ServiceBusTopic:
                        PSServiceBusParams     serviceBusTopicParams          = updateJobActionParams.ServiceBusAction;
                        ServiceBusTopicMessage existingServiceBusTopicMessage = existingJobAction.ServiceBusTopicMessage;
                        this.UpdateServiceBus(serviceBusTopicParams, existingServiceBusTopicMessage);
                        existingServiceBusTopicMessage.TopicPath = serviceBusTopicParams.TopicPath.GetValueOrDefault(defaultValue: existingServiceBusTopicMessage.TopicPath);
                        break;
                    }
                }
                else
                {
                    this.PopulateJobAction(updateJobActionParams, ref existingJobAction);
                }
            }

            return(existingJobAction);
        }
        /// <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));
            }
                );
        }
        /// <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));
            }
                );
        }
Beispiel #6
0
        /// <summary>
        /// Populates error action paramenter values to PSJobActionParams.
        /// </summary>
        /// <param name="errorActionType">Error action type e.g. http, https, storage etc</param>
        /// <returns>PSJobActionParams.</returns>
        internal PSJobActionParams GetErrorActionParamsValue(string errorActionType)
        {
            if (!string.IsNullOrWhiteSpace(errorActionType))
            {
                var jobErrorActionType = (SchedulerModels.JobActionType)Enum.Parse(typeof(SchedulerModels.JobActionType), errorActionType, ignoreCase: true);

                var jobErrorAction = new PSJobActionParams()
                {
                    JobActionType = jobErrorActionType,
                };

                switch (jobErrorActionType)
                {
                case SchedulerModels.JobActionType.Http:
                case SchedulerModels.JobActionType.Https:
                    var jobErrorActionAuthentication = new PSHttpJobAuthenticationParams()
                    {
                        HttpAuthType       = this.JobDynamicParameters.ErrorActionHttpAuthenticationType,
                        ClientCertPfx      = string.IsNullOrWhiteSpace(JobDynamicParameters.ErrorActionClientCertificatePfx) ? null : SchedulerUtility.GetCertData(this.ResolvePath(JobDynamicParameters.ErrorActionClientCertificatePfx), JobDynamicParameters.ErrorActionClientCertificatePassword),
                        ClientCertPassword = this.JobDynamicParameters.ErrorActionClientCertificatePassword,
                        Username           = this.JobDynamicParameters.ErrorActionBasicUsername,
                        Password           = this.JobDynamicParameters.ErrorActionBasicPassword,
                        Secret             = this.JobDynamicParameters.ErrorActionOAuthSecret,
                        Tenant             = this.JobDynamicParameters.ErrorActionOAuthTenant,
                        Audience           = this.JobDynamicParameters.ErrorActionOAuthAudience,
                        ClientId           = this.JobDynamicParameters.ErrorActionOAuthClientId
                    };

                    var httpJobErrorAction = new PSHttpJobActionParams()
                    {
                        RequestMethod         = this.JobDynamicParameters.ErrorActionMethod,
                        Uri                   = this.JobDynamicParameters.ErrorActionUri,
                        RequestBody           = this.JobDynamicParameters.ErrorActionRequestBody,
                        RequestHeaders        = this.JobDynamicParameters.ErrorActionHeaders,
                        RequestAuthentication = jobErrorActionAuthentication
                    };

                    jobErrorAction.HttpJobAction = httpJobErrorAction;
                    break;

                case SchedulerModels.JobActionType.StorageQueue:
                    var storageQueueErrorAction = new PSStorageJobActionParams()
                    {
                        StorageAccount      = this.JobDynamicParameters.ErrorActionStorageAccount,
                        StorageQueueName    = this.JobDynamicParameters.ErrorActionStorageQueue,
                        StorageSasToken     = this.JobDynamicParameters.ErrorActionStorageSASToken,
                        StorageQueueMessage = this.JobDynamicParameters.ErrorActionQueueMessageBody,
                    };

                    jobErrorAction.StorageJobAction = storageQueueErrorAction;
                    break;

                case SchedulerModels.JobActionType.ServiceBusQueue:
                    var serviceBusQueueErrorAction = GetServiceBusErrorActionParams();
                    serviceBusQueueErrorAction.QueueName = this.JobDynamicParameters.ErrorActionServiceBusQueueName;
                    jobErrorAction.ServiceBusAction      = serviceBusQueueErrorAction;
                    break;

                case SchedulerModels.JobActionType.ServiceBusTopic:
                    var serviceBusTopicErrorAction = GetServiceBusErrorActionParams();
                    serviceBusTopicErrorAction.TopicPath = this.JobDynamicParameters.ErrorActionServiceBusTopicPath;
                    jobErrorAction.ServiceBusAction      = serviceBusTopicErrorAction;
                    break;
                }

                return(jobErrorAction);
            }

            return(null);
        }