Example #1
0
        /// <summary>
        /// Checks if a customMeter exists.
        /// </summary>
        /// <param name="subscriptionId">The subscription id.</param>
        /// <param name="meterName">The name of the customMeter to check exists.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(Guid subscriptionId, string meterName)
        {
            var subscription = await _subscriptionService.GetAsync(subscriptionId);

            var customMeter = await _customMeterService.GetAsync(subscription.OfferName, meterName);

            // Check that only one customMeter with this meterName exists
            var count = await _context.SubscriptionCustomMeterUsages
                        .CountAsync(c => c.MeterId == customMeter.Id && c.SubscriptionId.Equals(subscriptionId));

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(SubscriptionCustomMeterUsage).Name,
                                                                                                meterName, subscriptionId: subscriptionId));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, false, subscriptionId: subscriptionId));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, true, subscriptionId: subscriptionId));
                // count = 1
                return(true);
            }
        }
Example #2
0
        /// <summary>
        /// Checks if an aadSecretTmp object exists within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the aadSecretTmp to check exists.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(string offerName, string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(AadSecretTmp).Name, name, offerName: offerName));

            //Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Check that only one aadSecretTmp with this name exists within the offer
            var count = await _context.AadSecretTmps
                        .CountAsync(a => (a.OfferId == offer.Id) && (a.Name == name));

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(AadSecretTmp).Name,
                                                                                                name,
                                                                                                offerName: offerName));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(AadSecretTmp).Name, name, false, offerName: offerName));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(AadSecretTmp).Name, name, true, offerName: offerName));
                // count = 1
                return(true);
            }
        }
Example #3
0
        /// <summary>
        /// Checks if an offer exists.
        /// </summary>
        /// <param name="offerName">The name of the offer to check exists.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(Offer).Name, offerName));

            // Check that only one offer with this offerName exists and has not been deleted
            var count = await _context.Offers
                        .CountAsync(o => (o.OfferName == offerName) && (o.DeletedTime == null));

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(Offer).Name, offerName));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Offer).Name, offerName, false));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Offer).Name, offerName, true));
                // count = 1
                return(true);
            }
        }
Example #4
0
        public async Task <bool> ExistsAsync(Guid subscriptionID, string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(SubscriptionParameter).Name, name));

            // Check that only one armTemplateParameter with this name exists within the offer
            var count = await _context.SubscriptionParameters
                        .CountAsync(p => (p.SubscriptionId == subscriptionID) && (p.Name == name));

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(SubscriptionParameter).Name,
                                                                                                name,
                                                                                                subscriptionId: subscriptionID));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionParameter).Name, name, false));

                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(SubscriptionParameter).Name, name, true));
                // count = 1
                return(true);
            }
        }
Example #5
0
        /// Checks if a customMeter exists.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planName">The name of the plan.</param>
        /// <param name="meterName">The name of the customMeter to check exists.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(string offerName, string planName, string meterName)
        {
            var plan = await _planService.GetAsync(offerName, planName);

            var meter = await _customMeterService.GetAsync(offerName, meterName);

            // Check that only one customMeter with this meterName exists
            var count = await _context.CustomMeterDimensions
                        .CountAsync(c => c.PlanId == plan.Id && c.MeterId == meter.Id);

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(CustomMeterDimension).Name,
                                                                                                meterName));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(CustomMeterDimension).Name, meterName, false));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(CustomMeterDimension).Name, meterName, true));
                // count = 1
                return(true);
            }
        }
        /// <summary>
        /// Checks if a customMeter exists.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(string name)
        {
            // Check that only one customMeter with this meterName exists
            var count = await _context.TelemetryDataConnectors
                        .CountAsync(c => c.Name == name);

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                                name));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(TelemetryDataConnector).Name,
                                                                                      name, false));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(TelemetryDataConnector).Name,
                                                                                      name, true));
                // count = 1
                return(true);
            }
        }
Example #7
0
        public async Task <bool> ExistsAsync(string offerName, string planName, Guid tenantId)
        {
            _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName));

            var plan = await _planService.GetAsync(offerName, planName);

            // Check that only one restructed user with this templateName exists within the offer
            var count = await _context.RestrictedUsers
                        .CountAsync(a => (a.PlanId == plan.Id) && (a.TenantId == tenantId));

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(RestrictedUser).Name,
                                                                                                tenantId.ToString(),
                                                                                                offerName: offerName,
                                                                                                planName: planName));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(RestrictedUser).Name, tenantId.ToString(), false, offerName: offerName, planName: planName));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(RestrictedUser).Name, tenantId.ToString(), true, offerName: offerName, planName: planName));
                // count = 1
                return(true);
            }
        }
        /// <summary>
        /// Checks to see if an webhookWebhookParameters entry already exists with the same given IDs.
        /// </summary>
        /// <param name="webhookId">The webhookId to check against.</param>
        /// <param name="webhookParameterId">The webhookParameterId to check against.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(long webhookId, long webhookParameterId)
        {
            var count = await _context.WebhookWebhookParameters.Where(x => x.WebhookParameterId == webhookParameterId && x.WebhookId == webhookId).CountAsync();

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(WebhookWebhookParameterService).Name, $"(webhookId={webhookId}, webhookParameterId={webhookParameterId})"));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(WebhookWebhookParameterService).Name, $"(webhookId={webhookId}, webhookParameterId={webhookParameterId})", false));
                return(false);
            }
            else
            {
                // count = 1
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(WebhookWebhookParameterService).Name, $"(webhookId={webhookId}, webhookParameterId={webhookParameterId})", false));
                return(true);
            }
        }
Example #9
0
        /// <summary>
        /// Checks if a subscription exists.
        /// </summary>
        /// <param name="subscriptionId">The id of the subscription to check exists.</param>
        /// <returns>True if exists, false otherwise.</returns>
        public async Task <bool> ExistsAsync(Guid subscriptionId)
        {
            _logger.LogInformation(LoggingUtils.ComposeCheckResourceExistsMessage(typeof(Subscription).Name, subscriptionId.ToString()));
            // Check that only one subscription with this subscriptionId exists
            var count = await _context.Subscriptions
                        .CountAsync(s => s.SubscriptionId == subscriptionId);

            // More than one instance of an object with the same name exists, this should not happen
            if (count > 1)
            {
                throw new NotSupportedException(LoggingUtils.ComposeFoundDuplicatesErrorMessage(typeof(Subscription).Name, subscriptionId.ToString()));
            }
            else if (count == 0)
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Subscription).Name, subscriptionId.ToString(), false));
                return(false);
            }
            else
            {
                _logger.LogInformation(LoggingUtils.ComposeResourceExistsOrNotMessage(typeof(Subscription).Name, subscriptionId.ToString(), true));
                // count = 1
                return(true);
            }
        }