/// <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> /// Update service bus properties. /// </summary> /// <param name="serviceBusParams">Service bus message properties specified via PowerShell.</param> /// <param name="existingServiceBusMessage">Existing job's service bus message properties.</param> private void UpdateServiceBus(PSServiceBusParams serviceBusParams, ServiceBusMessage existingServiceBusMessage) { if (existingServiceBusMessage != null) { existingServiceBusMessage.TransportType = serviceBusParams.TransportType.GetValueOrDefaultEnum <ServiceBusTransportType?>(defaultValue: existingServiceBusMessage.TransportType); existingServiceBusMessage.NamespaceProperty = serviceBusParams.NamespaceProperty.GetValueOrDefault(defaultValue: existingServiceBusMessage.NamespaceProperty); existingServiceBusMessage.Message = serviceBusParams.Message.GetValueOrDefault(defaultValue: existingServiceBusMessage.Message); this.PopulateServiceBusAuthentication(serviceBusParams.Authentication, existingServiceBusMessage.Authentication); } }
/// <summary> /// Get Service bus topic. /// </summary> /// <param name="serviceBusQueueActionParams">Servie bus properities specified via PowerShell.</param> /// <returns>ServiceBusTopicMessage object.</returns> private ServiceBusTopicMessage GetServiceBusTopic(PSServiceBusParams serviceBusQueueActionParams) { if (string.IsNullOrWhiteSpace(serviceBusQueueActionParams.TopicPath)) { throw new PSManagement.PSArgumentException(Resources.SchedulerInvalidServiceBusTopicPath); } var serviceBusTopicMessage = new ServiceBusTopicMessage() { TopicPath = serviceBusQueueActionParams.TopicPath }; this.PopulateServiceBusMessage(serviceBusQueueActionParams, serviceBusTopicMessage); return(serviceBusTopicMessage); }
/// <summary> /// Populates Service bus message object with valid values. /// </summary> /// <param name="serviceBusQueueActionParams">Service bus properties specified via PowerShell.</param> /// <param name="serviceBusMessage">Servce message object to be populated.</param> private void PopulateServiceBusMessage(PSServiceBusParams serviceBusQueueActionParams, ServiceBusMessage serviceBusMessage) { if (string.IsNullOrWhiteSpace(serviceBusQueueActionParams.NamespaceProperty) || string.IsNullOrWhiteSpace(serviceBusQueueActionParams.Message) || string.IsNullOrWhiteSpace(serviceBusQueueActionParams.TransportType)) { throw new PSManagement.PSArgumentException(Resources.SchedulerInvalidServiceBus); } if (serviceBusMessage == null) { throw new ArgumentException("serviceBusMessage: Object must be initialized"); } ServiceBusAuthentication authentication = this.GetServiceBusAuthentication(serviceBusQueueActionParams.Authentication); serviceBusMessage.Authentication = this.GetServiceBusAuthentication(serviceBusQueueActionParams.Authentication); serviceBusMessage.Message = serviceBusQueueActionParams.Message; serviceBusMessage.NamespaceProperty = serviceBusQueueActionParams.NamespaceProperty; serviceBusMessage.TransportType = serviceBusQueueActionParams.TransportType.GetValueOrDefaultEnum <ServiceBusTransportType>(defaultValue: ServiceBusTransportType.NetMessaging); }