コード例 #1
0
        /// <summary>
        /// Removes all entries from the webhookWebhookParameters table with a reference to the given webhookId.
        /// </summary>
        /// <param name="webhookId">The ID to filter by.</param>
        /// <returns></returns>
        public async Task DeleteWebhookJoinEntriesAsync(long webhookId)
        {
            List <WebhookWebhookParameter> webhookWebhookParameters = await _context.WebhookWebhookParameters.Where(x => x.WebhookId == webhookId).ToListAsync();

            _context.WebhookWebhookParameters.RemoveRange(webhookWebhookParameters);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(WebhookWebhookParameter).Name, $"webhookId={webhookId}"));
        }
コード例 #2
0
        private async Task UpdateWebhookParameters(Offer offer, Webhook webhook, long webhookId)
        {
            List <WebhookParameter>        incompleteParams = ParseWebhookParameters(webhook);
            List <WebhookWebhookParameter> joinEntries      = await _webhookWebhookParameterService.GetAllJoinEntries(webhookId);

            Dictionary <string, WebhookParameter> paramsDb = new Dictionary <string, WebhookParameter>();
            HashSet <string> usedParamNames = new HashSet <string>();

            // Populate paramsDb so that it maps the WebhookParameter name to the WebhookParameter object
            foreach (WebhookWebhookParameter entry in joinEntries)
            {
                WebhookParameter webhookParameter = await _context.WebhookParameters.FindAsync(entry.WebhookParameterId);

                if (!paramsDb.ContainsKey(webhookParameter.Name))
                {
                    paramsDb.Add(webhookParameter.Name, webhookParameter);
                }
            }

            foreach (WebhookParameter incompleteParam in incompleteParams)
            {
                // Check if a param with the same name as the incompleteParam already exists
                if (!paramsDb.ContainsKey(incompleteParam.Name))
                {
                    // A param with the same name as the incompleteParam does not exist, so create it
                    await _webhookParameterService.CreateAsync(offer.OfferName, webhookId, incompleteParam);
                }

                // Keep track of all the new parameters we are using in usedParamNames
                if (!usedParamNames.Contains(incompleteParam.Name))
                {
                    usedParamNames.Add(incompleteParam.Name);
                }
            }

            foreach (KeyValuePair <string, WebhookParameter> paramDb in paramsDb)
            {
                // Check if there is a param in the db that we are no longer using
                if (!usedParamNames.Contains(paramDb.Key))
                {
                    WebhookWebhookParameter webhookWebhookParameter = await _context.WebhookWebhookParameters.FindAsync(webhookId, paramDb.Value.Id);

                    // Remove the join entry for any unused params
                    _context.WebhookWebhookParameters.Remove(webhookWebhookParameter);
                    await _context._SaveChangesAsync();

                    _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(
                                               nameof(WebhookWebhookParameter),
                                               $"(webhookId={webhookId}, webhookParameterId={webhookWebhookParameter.WebhookParameter})",
                                               offerName: offer.OfferName));
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Deletes a subscriptionCustomMeterUsage.
        /// </summary>
        /// <param name="subscriptionId">The subscription id.</param>
        /// <param name="meterName">The name of the customMeter to delete.</param>
        /// <returns>The deleted subscriptionCustomMeterUsage.</returns>
        public async Task <SubscriptionCustomMeterUsage> DeleteAsync(Guid subscriptionId, string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, subscriptionId: subscriptionId));

            // Get the customMeter that matches the meterName provide
            var subscriptionCustomMeterUsage = await GetAsync(subscriptionId, meterName);

            // Update and save changes in db
            _context.SubscriptionCustomMeterUsages.Remove(subscriptionCustomMeterUsage);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(SubscriptionCustomMeterUsage).Name, meterName, subscriptionId: subscriptionId));

            return(subscriptionCustomMeterUsage);
        }
コード例 #4
0
        /// <summary>
        /// Deletes an aadSecretTmp object within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the aadSecretTmp to delete.</param>
        /// <returns>The deleted aadSecretTmp object.</returns>
        public async Task <AadSecretTmp> DeleteAsync(string offerName, string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(AadSecretTmp).Name, name, offerName: offerName));

            // Get the aadSecretTmp that matches the name provided
            var aadSecretTmp = await GetAsync(offerName, name);

            // Remove the aadSecretTmp from the db
            _context.AadSecretTmps.Remove(aadSecretTmp);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(AadSecretTmp).Name, name, offerName: offerName));

            return(aadSecretTmp);
        }
コード例 #5
0
        /// <summary>
        /// Deletes a customMeterDimension.
        /// </summary>
        /// <param name="id">The id of the customMeterDimension to delete.</param>
        /// <returns>The deleted customMeterDimension.</returns>
        public async Task <CustomMeterDimension> DeleteAsync(long id)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(CustomMeterDimension).Name, id.ToString()));

            // Get the customMeterDimension that matches the id provided
            var customMeterDimension = await GetAsync(id);

            // Remove the customMeterDimension from the db
            _context.CustomMeterDimensions.Remove(customMeterDimension);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(CustomMeterDimension).Name, id.ToString()));

            return(customMeterDimension);
        }
コード例 #6
0
        /// <summary>
        /// Deletes a customMeter.
        /// </summary>
        /// <param name="meterName">The name of the customMeter to delete.</param>
        /// <returns>The deleted customMeter.</returns>
        public async Task <CustomMeter> DeleteAsync(string meterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(CustomMeter).Name, meterName));

            // Get the customMeter that matches the meterName provide
            var customMeter = await GetAsync(meterName);

            // Update and save changes in db
            _context.CustomMeters.Remove(customMeter);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(CustomMeter).Name, meterName));

            return(customMeter);
        }
コード例 #7
0
        /// <summary>
        /// Deletes a webhook within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="webhookName">The name of the webhook to delete.</param>
        /// <returns>The deleted webhook.</returns>
        public async Task <Webhook> DeleteAsync(string offerName, string webhookName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(Webhook).Name, webhookName, offerName: offerName));

            // Get the webhook that matches the webhook provided
            var webhook = await GetAsync(offerName, webhookName);

            // Remove the webhook from the db
            _context.Webhooks.Remove(webhook);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(nameof(Webhook), webhookName, offerName: offerName));

            return(webhook);
        }
コード例 #8
0
        /// <summary>
        /// Deletes an offerParameter within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="parameterName">The name of the offerParameter to delete.</param>
        /// <returns>The deleted offerParameter.</returns>
        public async Task <OfferParameter> DeleteAsync(string offerName, string parameterName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(OfferParameter).Name, parameterName, offerName: offerName));

            // Get the offerParameter that matches the parameterName provided
            var offerParameter = await GetAsync(offerName, parameterName);

            // Remove the offerParameter from the db
            _context.OfferParameters.Remove(offerParameter);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(OfferParameter).Name, parameterName, offerName: offerName));

            return(offerParameter);
        }
コード例 #9
0
        /// <summary>
        /// Removes any WebhookParameters from the db that are not associated with any Webhooks.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns></returns>
        public async Task DeleteUnusedAsync(string offerName)
        {
            List <WebhookParameter> webhookParameters = await GetAllAsync(offerName);

            foreach (WebhookParameter webhookParameter in webhookParameters)
            {
                int usages = await _context.WebhookWebhookParameters.Where(x => x.WebhookParameterId == webhookParameter.Id).CountAsync();

                if (usages == 0)
                {
                    _context.WebhookParameters.Remove(webhookParameter);
                    await _context._SaveChangesAsync();

                    _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(WebhookParameter).Name, webhookParameter.Name, offerName: offerName));
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Deletes a restrictedUser.
        /// </summary>
        /// <param name="offerName">The offer name.</param>
        /// <param name="planName">The plan name.</param>
        /// <param name="tenantId">The tenant id.</param>
        /// <returns>The deleted restrictedUser.</returns>
        public async Task <RestrictedUser> DeleteAsync(string offerName, string planName, Guid tenantId)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName));

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

            // Get all restrictedUsers with a FK to the plan
            var restrictedUser = await _context.RestrictedUsers.SingleOrDefaultAsync(r => r.PlanId == plan.Id && r.TenantId == tenantId);


            // Remove the restrictedUser from the db
            _context.RestrictedUsers.Remove(restrictedUser);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(RestrictedUser).Name, tenantId.ToString(), offerName: offerName, planName: planName));

            return(restrictedUser);
        }
コード例 #11
0
ファイル: IpConfigService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Deletes an IpConfig within an Offer and all of the IpBlocks and IpAddresses associated
        /// with it. The delete will only occur if all of the IpAddresses associated with the IpConfig
        /// are not being used.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="name">The name of the ipConfig to delete.</param>
        /// <returns>The deleted ipConfig.</returns>
        public async Task <IpConfig> DeleteAsync(string offerName, string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(IpConfig).Name, name, offerName: offerName));

            // Get the ipConfig that matches the name provided
            var ipConfig = await GetAsync(offerName, name);

            // Get the ipBlocks associated with the ipConfig
            var ipBlocks = await _context.IpBlocks.Where(x => x.IpConfigId == ipConfig.Id).ToListAsync();

            foreach (IpBlock block in ipBlocks)
            {
                // Check if there are any IpAddresses in use
                if (await _context.IpAddresses.AnyAsync(x => x.IpBlockId == block.Id && !x.IsAvailable))
                {
                    // TODO - at least one IpAddress is in use so the delete cannot be performed
                    throw new NotSupportedException();
                }
            }

            // Remove entities from db
            foreach (IpBlock block in ipBlocks)
            {
                // Get all IpAddresses in this IpBlock
                var ipAddresses = await _context.IpAddresses.Where(x => x.IpBlockId == block.Id).ToListAsync();

                // Remove all IpAddresses in this IpBlock from the db
                _context.IpAddresses.RemoveRange(ipAddresses);
                await _context._SaveChangesAsync();

                // Remove the IpBlock from the db
                _context.IpBlocks.Remove(block);
                await _context._SaveChangesAsync();
            }

            // Remove the ipConfig from the db
            _context.IpConfigs.Remove(ipConfig);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(IpConfig).Name, name, offerName: offerName));

            return(ipConfig);
        }
コード例 #12
0
ファイル: OfferService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Deletes an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer to delete.</param>
        /// <returns>The deleted offer.</returns>
        public async Task <Offer> DeleteAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(Offer).Name, offerName));

            // Get the offer that matches the offerName provide
            var offer = await GetAsync(offerName);

            // Update the offer status
            offer.Status = nameof(OfferStatus.Deleted);

            // Update the offer deleted time (soft delete)
            offer.DeletedTime = DateTime.UtcNow;

            // Update and save changes in db
            _context.Offers.Update(offer);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(Offer).Name, offerName));

            return(offer);
        }
コード例 #13
0
        /// <summary>
        /// Deletes a plan within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planName">The name of the plan to delete.</param>
        /// <returns>The deleted plan.</returns>
        public async Task <Plan> DeleteAsync(string offerName, string planName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(Plan).Name, planName, offerName: offerName));

            // Get the plan that matches the planUniqueName provided
            var plan = await GetAsync(offerName, planName);

            // Remove restricted user for the plan
            foreach (var restrictedUser in plan.RestrictedUsers)
            {
                _context.RestrictedUsers.Remove(restrictedUser);
            }

            // Remove the plan from the db
            _context.Plans.Remove(plan);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(Plan).Name, planName, offerName: offerName));

            return(plan);
        }
コード例 #14
0
ファイル: ArmTemplateService.cs プロジェクト: Azure/ace-luna
        /// <summary>
        /// Deletes an armTemplate record within an offer and removes the armTemplate file from blob storage.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="templateName">The name of the armTempalte to delete.</param>
        /// <returns>The deleted armTemplate db record.</returns>
        public async Task <ArmTemplate> DeleteAsync(string offerName, string templateName)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName));

            // Get the armTemplate that matches the templateName provided
            var armTemplate = await GetAsync(offerName, templateName, useSaSKey : false);

            // Remove the armTemplate file from blob storage
            await _storageUtility.DeleteFileAsync(new Uri(armTemplate.TemplateFilePath));

            // Remove the join entry form the db
            await _armTemplateArmTemplateParameterService.DeleteArmTemplateJoinEntriesAsync(armTemplate.Id);

            // Remove the armTemplate from the db
            _context.ArmTemplates.Remove(armTemplate);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(ArmTemplate).Name, templateName, offerName: offerName));

            return(armTemplate);
        }
コード例 #15
0
        /// <summary>
        /// Deletes a TelemetryDataConnector.
        /// </summary>
        /// <param name="name">The name of the TelemetryDataConnector to delete.</param>
        /// <returns>The deleted TelemetryDataConnector.</returns>
        public async Task <TelemetryDataConnector> DeleteAsync(string name)
        {
            _logger.LogInformation(LoggingUtils.ComposeDeleteResourceMessage(typeof(TelemetryDataConnector).Name, name));

            if (!await ExistsAsync(name))
            {
                throw new LunaConflictUserException(LoggingUtils.ComposeNotFoundErrorMessage(typeof(TelemetryDataConnector).Name,
                                                                                             name));
            }

            // Get the TelemetryDataConnector that matches the name provide
            var connector = await GetAsync(name);

            // Update and save changes in db
            _context.TelemetryDataConnectors.Remove(connector);
            await _context._SaveChangesAsync();

            _logger.LogInformation(LoggingUtils.ComposeResourceDeletedMessage(typeof(TelemetryDataConnector).Name, name));

            return(connector);
        }