示例#1
0
        /// <summary>
        /// Gets the <see cref="ResourceGroupCostResultKey"/> instance.
        /// </summary>
        /// <param name="result"><see cref="ResourceGroupCostResult"/> instance.</param>
        /// <returns>Returns the <see cref="ResourceGroupCostResultKey"/> instance.</returns>
        public static ResourceGroupCostResultKey GetResourceGroupCostResultKey(ResourceGroupCostResult result)
        {
            var key = new ResourceGroupCostResultKey()
            {
                ResourceGroupName = result.ResourceGroupName,
                OwnerEmails       = result.OwnerEmails,
                TotalSpendLimit   = result.TotalSpendLimit,
                DailySpendLimit   = result.DailySpendLimit,
                OverspendAction   = result.OverspendAction,
                DateStart         = result.DateStart,
                DateEnd           = result.DateEnd
            };

            return(key);
        }
示例#2
0
        /// <summary>
        /// Gets the <see cref="ResourceGroupCostResult"/> instance.
        /// </summary>
        /// <param name="group"><see cref="ResourceGroupCostResultKey"/> instance.</param>
        /// <param name="records">List of <see cref="ResourceGroupCostResult"/> instances.</param>
        /// <returns>Returns the <see cref="ResourceGroupCostResult"/> instance.</returns>
        public static ResourceGroupCostResult GetResourceGroupCostResult(ResourceGroupCostResultKey group, IEnumerable <ResourceGroupCostResult> records)
        {
            var result = new ResourceGroupCostResult()
            {
                ResourceGroupName = group.ResourceGroupName,
                OwnerEmails       = group.OwnerEmails,
                Cost            = records.Sum(q => q.Cost),
                DateStart       = group.DateStart,
                DateEnd         = group.DateEnd,
                TotalSpendLimit = group.TotalSpendLimit,
                DailySpendLimit = group.DailySpendLimit,
                OverspendAction = group.OverspendAction
            };

            return(result);
        }
示例#3
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);
        }