/// <summary>
        /// Gets the <see cref="ResourceGroupCost"/> instance.
        /// </summary>
        /// <param name="group"><see cref="ResourceGroupDateKey"/> instance.</param>
        /// <param name="records">List of <see cref="ResourceCosts"/> instances.</param>
        /// <returns>Returns the <see cref="ResourceGroupCost"/> instance.</returns>
        public static ResourceGroupCost GetResourceGroupCost(ResourceGroupDateKey group, IEnumerable <ResourceCosts> records)
        {
            var cost = new ResourceGroupCost()
            {
                ResourceGroupName = group.ResourceGroupName,
                Cost = records.Sum(p => p.CalculatedCosts)
            };

            return(cost);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the <see cref="ResourceGroupCostResult"/> instance.
        /// </summary>
        /// <param name="cost"><see cref="ResourceGroupCost"/> instance.</param>
        /// <param name="groups">List of <see cref="ResourceGroup"/> instances.</param>
        /// <param name="tagSettings"><see cref="TagSettings"/> instance.</param>
        /// <returns>Returns the <see cref="ResourceGroupCostResult"/> instance.</returns>
        public static ResourceGroupCostResult GetResourceGroupCostResult(ResourceGroupCost cost, IEnumerable <ResourceGroup> groups, TagSettings tagSettings)
        {
            var group = groups.SingleOrDefault(p => p.Name.IsEquivalentTo(cost.ResourceGroupName));
            var tags  = group?.Tags;

            var result = new ResourceGroupCostResult()
            {
                ResourceGroupName = cost.ResourceGroupName,
                Cost            = Convert.ToDecimal(cost.Cost),
                OwnerEmails     = tags?.SingleOrDefault(p => p.Key.IsEquivalentTo(tagSettings.OwnerEmailsKey)).Value,
                TotalSpendLimit = tags?.SingleOrDefault(p => p.Key.IsEquivalentTo(tagSettings.TotalSpendLimitKey)).Value,
                DailySpendLimit = tags?.SingleOrDefault(p => p.Key.IsEquivalentTo(tagSettings.DailySpendLimitKey)).Value,
                OverspendAction = tags?.SingleOrDefault(p => p.Key.IsEquivalentTo(tagSettings.OverspendActionKey)).Value,
                DateStart       = cost.DateStart,
                DateEnd         = cost.DateEnd
            };

            return(result);
        }