Esempio n. 1
0
        /// <summary>
        /// Get SubscriptionMeterUsage by meter id
        /// </summary>
        /// <param name="meterId">The meter id</param>
        /// <returns>The SubscriptionMeterUsage</returns>
        public async Task <List <SubscriptionCustomMeterUsage> > GetAllByMeterIdAsync(long meterId)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(SubscriptionCustomMeterUsage).Name));

            // Get all customMeters from db
            var subscriptionCustomMeterUsages = await _context.SubscriptionCustomMeterUsages.Where(s => s.MeterId == meterId).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(SubscriptionCustomMeterUsage).Name, subscriptionCustomMeterUsages.Count()));

            return(subscriptionCustomMeterUsages);
        }
        /// <summary>
        /// Gets all TelemetryDataConnector.
        /// </summary>
        /// <returns>A list of TelemetryDataConnector.</returns>
        public async Task <List <TelemetryDataConnector> > GetAllAsync()
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(TelemetryDataConnector).Name));

            // Get all TelemetryDataConnectors from db
            var connectors = _context.TelemetryDataConnectors;

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(TelemetryDataConnector).Name, connectors.Count()));

            return(connectors.ToList());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets all offers.
        /// </summary>
        /// <returns>A list of offers.</returns>
        public async Task <List <Offer> > GetAllAsync()
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(Offer).Name));

            // Get all offers that have not been deleted
            var offers = await _context.Offers.Where(o => o.DeletedTime == null).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(Offer).Name, offers.Count()));

            return(offers);
        }
        /// <summary>
        /// Gets all customMeters.
        /// </summary>
        /// <returns>A list of customMeters.</returns>
        public async Task <List <CustomMeter> > GetAllAsync()
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(CustomMeter).Name));

            // Get all customMeters from db
            var customMeters = await _context.CustomMeters.ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(CustomMeter).Name, customMeters.Count()));

            return(customMeters);
        }
Esempio n. 5
0
        public async Task <List <SubscriptionParameter> > GetAllAsync(Guid subscriptionId)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(SubscriptionParameter).Name));

            var subscription = await _subscriptionService.GetAsync(subscriptionId);

            var parameters = await _context.SubscriptionParameters.Where(p => p.SubscriptionId == subscriptionId).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(SubscriptionParameter).Name, parameters.Count()));

            return(parameters);
        }
Esempio n. 6
0
        /// <summary>
        /// Gets all aadSecretTmps within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of aadSecretTmp objects.</returns>
        public async Task <List <AadSecretTmp> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(AadSecretTmp).Name, offerName: offerName));

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

            // Get all aadSecretTmps with a FK to the offer
            var aadSecretTmps = await _context.AadSecretTmps.Where(a => a.OfferId == offer.Id).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(AadSecretTmp).Name, aadSecretTmps.Count()));

            return(aadSecretTmps);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets all webhookParameter within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of webhookParameter objects.</returns>
        public async Task <List <WebhookParameter> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(WebhookParameter).Name));

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

            // Get all webhookParameter with a FK to the offer
            var webhookParameters = await _context.WebhookParameters.Where(a => a.OfferId == offer.Id).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(WebhookParameter).Name, webhookParameters.Count()));

            return(webhookParameters);
        }
Esempio n. 8
0
        /// <summary>
        /// Gets all restrictedUsers within a plan within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planUniqueName">The name of the plan.</param>
        /// <returns>A list of restrictedUsers.</returns>
        public async Task <List <RestrictedUser> > GetAllAsync(string offerName, string planUniqueName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(RestrictedUser).Name, offerName: offerName, planName: planUniqueName));

            // Get the plan associated with the offerName and planUniqueName provided
            var plan = await _planService.GetAsync(offerName, planUniqueName);

            // Get all restrictedUsers with a FK to the plan
            var restrictedUsers = await _context.RestrictedUsers.Where(r => r.PlanId == plan.Id).ToListAsync();

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(RestrictedUser).Name, restrictedUsers.Count(), offerName: offerName, planName: planUniqueName));

            return(restrictedUsers);
        }
Esempio n. 9
0
        /// <summary>
        /// Gets all armTemplateParameters within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of armTemplateParameter objects.</returns>
        public async Task <List <ArmTemplateParameter> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(ArmTemplateParameter).Name, offerName: offerName));
            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Get all armTemplateParameters with a FK to the offer
            var armTemplateParameters = await _context.ArmTemplateParameters.Where(a => a.OfferId == offer.Id).ToListAsync();

            // TODO: Delete unused parameters

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(ArmTemplateParameter).Name, armTemplateParameters.Count()));

            return(armTemplateParameters);
        }
Esempio n. 10
0
        /// <summary>
        /// Gets all subscriptions.
        /// </summary>
        /// <param name="status">The list of status of the subscription.</param>
        /// <param name="owner">The owner of the subscription.</param>
        /// <returns>A list of all subsrciptions.</returns>
        public async Task <List <Subscription> > GetAllAsync(string[] status = null, string owner = "")
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(Subscription).Name));

            // Gets all subscriptions that have the provided status.
            List <Subscription> allSub = await _context.Subscriptions.ToListAsync();

            List <Subscription> subscriptionList = allSub.Where(s => (status == null || status.Contains(s.Status)) &&
                                                                (string.IsNullOrEmpty(owner) || s.Owner.Equals(owner, StringComparison.InvariantCultureIgnoreCase))).ToList();

            foreach (var sub in subscriptionList)
            {
                sub.PlanName  = (await _context.Plans.FindAsync(sub.PlanId)).PlanName;
                sub.OfferName = (await _context.Offers.FindAsync(sub.OfferId)).OfferName;
            }
            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(Subscription).Name, subscriptionList.Count()));

            return(subscriptionList);
        }
        /// <summary>
        /// Gets all customMeterDimensions within a plan within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <param name="planUniqueName">The name of the plan.</param>
        /// <returns>A list of customMeterDimensions.</returns>
        public async Task <List <CustomMeterDimension> > GetAllAsync(string offerName, string planUniqueName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(CustomMeterDimension).Name, offerName: offerName));

            // Get the plan associated with the offerName and planUniqueName provided
            var plan = await _planService.GetAsync(offerName, planUniqueName);

            // Get all customMeterDimensions with a FK to the plan
            var customMeterDimensions = await _context.CustomMeterDimensions.Where(c => c.PlanId == plan.Id).ToListAsync();

            // Set each customMeterDimension's meterName
            foreach (CustomMeterDimension customMeterDimension in customMeterDimensions)
            {
                customMeterDimension.MeterName = (await _context.CustomMeters.FindAsync(customMeterDimension.MeterId)).MeterName;
            }
            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(CustomMeterDimension).Name, customMeterDimensions.Count()));

            return(customMeterDimensions);
        }
Esempio n. 12
0
        /// <summary>
        /// Gets all ipConfigs within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of ipConfigs.</returns>
        public async Task <List <IpConfig> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(IpConfig).Name, offerName: offerName));

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

            // Get all ipConfigs with a FK to the offer
            var ipConfigs = await _context.IpConfigs.Where(o => o.OfferId == offer.Id).ToListAsync();

            // Populate the IpBlocks for each IpConfig
            foreach (IpConfig ipConfig in ipConfigs)
            {
                ipConfig.IpBlocks = await GetIpBlocks(ipConfig.Id);
            }
            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(IpConfig).Name, ipConfigs.Count()));

            return(ipConfigs);
        }
Esempio n. 13
0
        /// <summary>
        /// Get all active subscription by offer name
        /// </summary>
        /// <param name="offerName">The offer name</param>
        /// <returns>The list of subscriptions</returns>
        public async Task <List <Subscription> > GetAllActiveByOfferName(string offerName)
        {
            var offer = await _offerService.GetAsync(offerName);

            //TODO: error handling

            List <Subscription> allSub = await _context.Subscriptions.ToListAsync();

            List <Subscription> subscriptionList = allSub.Where(s => s.OfferId == offer.Id).ToList();

            foreach (var sub in subscriptionList)
            {
                sub.PlanName  = (await _context.Plans.FindAsync(sub.PlanId)).PlanName;
                sub.OfferName = offerName;
            }

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(Subscription).Name, subscriptionList.Count()));

            return(subscriptionList);
        }
Esempio n. 14
0
        /// <summary>
        /// Gets all armTemplates within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of armTemplates.</returns>
        public async Task <List <ArmTemplate> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(ArmTemplate).Name, offerName: offerName));
            // Get the offer associated with the offerName provided
            var offer = await _offerService.GetAsync(offerName);

            // Get all armTemplates with a FK to the offer
            var armTemplates = await _context.ArmTemplates.Where(a => a.OfferId == offer.Id).ToListAsync();

            foreach (var armTemplate in armTemplates)
            {
                // Generate Sas key
                armTemplate.TemplateFilePath = await _storageUtility.GetFileReferenceWithSasKeyAsync(armTemplate.TemplateFilePath);
            }

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(ArmTemplate).Name, armTemplates.Count()));


            return(armTemplates);
        }
Esempio n. 15
0
        /// <summary>
        /// Gets all plans within an offer.
        /// </summary>
        /// <param name="offerName">The name of the offer.</param>
        /// <returns>A list of plans.</returns>
        public async Task <List <Plan> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(Plan).Name, offerName: offerName));

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

            // Get all plans with a FK to the offer
            var plans = await _context.Plans.Where(p => p.OfferId == offer.Id).ToListAsync();

            List <Plan> result = new List <Plan>();

            // Set each plan's ARM template Names
            foreach (Plan plan in plans)
            {
                result.Add(await SetArmTemplateAndWebhookNames(plan));
            }
            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(Plan).Name, plans.Count()));

            return(result);
        }
Esempio n. 16
0
        /// <summary>
        /// Gets all customMeters.
        /// </summary>
        /// <param name="offerName">The offer name of the customMeter.</param>
        /// <returns>A list of customMeters.</returns>
        public async Task <List <CustomMeter> > GetAllAsync(string offerName)
        {
            _logger.LogInformation(LoggingUtils.ComposeGetAllResourcesMessage(typeof(CustomMeter).Name, offerName: offerName));

            var offer = await _offerService.GetAsync(offerName);

            // Get all customMeters from db
            var customMeters = await _context.CustomMeters.Where(c => c.OfferId == offer.Id).ToListAsync();

            foreach (var meter in customMeters)
            {
                meter.OfferName = offerName;
                var connector = await _context.TelemetryDataConnectors.FindAsync(meter.TelemetryDataConnectorId);

                meter.TelemetryDataConnectorName = connector.Name;
            }

            _logger.LogInformation(LoggingUtils.ComposeReturnCountMessage(typeof(CustomMeter).Name, customMeters.Count()));

            return(customMeters);
        }