Exemplo n.º 1
0
        /// <summary>
        /// Get max recurrence for the job collection.
        /// </summary>
        /// <param name="frequencyInput">Frequence specified via powershell.</param>
        /// <param name="intervalInput">Interval specified via powershell.</param>
        /// <param name="minRecurrenceQuota">Min reurrence quota.</param>
        /// <param name="errorMessage">Error message for invalid recurrence.</param>
        /// <returns>Maximum recurrence.</returns>
        private JobMaxRecurrence GetMaxRecurrence(string frequencyInput, int?intervalInput, TimeSpan minRecurrenceQuota, string errorMessage)
        {
            int interval = intervalInput.HasValue ? intervalInput.Value : minRecurrenceQuota.GetInterval();
            RecurrenceFrequency frequency = frequencyInput.GetValueOrDefaultEnum <RecurrenceFrequency>(defaultValue: minRecurrenceQuota.GetFrequency());

            TimeSpan recurrenceTimeSpan = SchedulerUtility.ToTimeSpan(frequency, interval);

            if (recurrenceTimeSpan < minRecurrenceQuota)
            {
                throw new PSArgumentException(string.Format(errorMessage, recurrenceTimeSpan, minRecurrenceQuota));
            }

            return(new JobMaxRecurrence(frequency, interval));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Populate quota object with valid values.
        /// </summary>
        /// <param name="quota">Quota object.</param>
        /// <param name="skuDefinition">Sku definition (Free, Standard, P10Premium, and P20Premium</param>
        /// <param name="jobCollectionParams">Job collection parameters set via powershell.</param>
        /// <param name="newQuota">boolean to indicate whether quota object is new or existing.</param>
        private void PopulateJobCollectionQuota(JobCollectionQuota quota, SkuDefinition skuDefinition, PSJobCollectionsParams jobCollectionParams, bool newQuota = true)
        {
            if (quota == null && !newQuota)
            {
                throw new ArgumentOutOfRangeException("quota", "Quota is null.");
            }

            if (quota == null)
            {
                quota = new JobCollectionQuota();
            }

            int      existingMaxCountValue      = Constants.MaxJobCountQuotaStandard;
            TimeSpan existingMinRecurrenceValue = Constants.MinRecurrenceQuotaStandard;

            if (!newQuota)
            {
                existingMaxCountValue      = quota.MaxJobCount.Value;
                existingMinRecurrenceValue = SchedulerUtility.ToTimeSpan(quota.MaxRecurrence.Frequency.Value, quota.MaxRecurrence.Interval.Value);
            }

            switch (skuDefinition)
            {
            case SkuDefinition.Free:
                quota.MaxJobCount = this.GetMaxJobCount(
                    jobCollectionParams.MaxJobCount,
                    newQuota ? Constants.MaxJobCountQuotaFree : existingMaxCountValue,
                    Resources.JobCollectionMaxJobQuotaTooLargeForFree);

                quota.MaxRecurrence = this.GetMaxRecurrence(
                    jobCollectionParams.Frequency,
                    jobCollectionParams.Interval,
                    newQuota ? Constants.MinRecurrenceQuotaFree : existingMinRecurrenceValue,
                    Resources.JobCollectionMaxRecurrenceQuotaTooLargeForFree);
                break;

            case SkuDefinition.Standard:
            case SkuDefinition.P10Premium:
            default:
                quota.MaxJobCount = this.GetMaxJobCount(
                    jobCollectionParams.MaxJobCount,
                    newQuota ? Constants.MaxJobCountQuotaStandard : existingMaxCountValue,
                    Resources.JobCollectionMaxJobQuotaTooLargeForPaid);

                quota.MaxRecurrence = this.GetMaxRecurrence(
                    jobCollectionParams.Frequency,
                    jobCollectionParams.Interval,
                    newQuota ? Constants.MinRecurrenceQuotaStandard : existingMinRecurrenceValue,
                    Resources.JobCollectionMaxJobQuotaTooLargeForPaid);
                break;

            case SkuDefinition.P20Premium:
                quota.MaxJobCount = this.GetMaxJobCount(
                    jobCollectionParams.MaxJobCount,
                    newQuota ? Constants.MaxJobCountQuotaP20Premium : existingMaxCountValue,
                    Resources.JobCollectionMaxJobQuotaTooLargeForPaid);

                quota.MaxRecurrence = this.GetMaxRecurrence(
                    jobCollectionParams.Frequency,
                    jobCollectionParams.Interval,
                    newQuota ? Constants.MinRecurrenceQuotaP20Premium : existingMinRecurrenceValue,
                    Resources.JobCollectionMaxJobQuotaTooLargeForPaid);
                break;
            }
        }
Exemplo n.º 3
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);
        }