Example #1
0
        private static Section CreateCostEstimationSection(
            ref DocumentInfo documentInfo,
            RegionInfo regionInfo,
            CostEstimationResult costEstimationResult)
        {
            // TODO: extract to extension method
            // TODO: move hard code string to resource file.
            var subscriptionName = costEstimationResult.SubscriptionName;

            var costEstimationSection = documentInfo.CreateSection();
            var costTitle             = costEstimationSection.AddParagraph("Cost Estimation", DocumentInfo.TitleStyleName);

            costTitle.AddBookmark("CostEstimation" + subscriptionName);

            if (costEstimationResult.HasError)
            {
                costEstimationSection.AddParagraph(
                    "Failed to retrieve Azure resource usage to build the cost estimation due to insufficient permission. Please check your Azure RBAC role and ensure you have any of the role below for the whole subscription: Reader, Contributor and Owner.",
                    DocumentInfo.TableDesStyleName);

                return(costEstimationSection);
            }

            costEstimationSection.AddParagraph(
                "To best help customer plan and estimate the cost in destination environment, China Cloud Migration & Expansion tool set takes customer’s source service usage of one billing cycle as a reference to perform a cost estimation for the same service usage in the destination. Below is the cost estimation summary report. Please note that the cost only reflects the services that is available in destination environment. For services that is not available in destination, N/A are marked.",
                DocumentInfo.TableDesStyleName);

            // Make Cost Summary Table
            var costSummaryTalbe      = DocumentInfo.CreateTable(ref costEstimationSection);
            var headCostSummaryColumn = costSummaryTalbe.AddColumn("8cm");

            headCostSummaryColumn.Format.Font.Bold = true;
            costSummaryTalbe.AddColumn("8cm");

            var costSummaryRow = costSummaryTalbe.AddRow();

            costSummaryRow.Cells[0].AddParagraph("Reference Environment");
            costSummaryRow.Cells[1].AddParagraph("Microsoft Azure");

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Reference Subscription");
            costSummaryRow.Cells[1].AddParagraph(subscriptionName);

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Target Environment");
            costSummaryRow.Cells[1].AddParagraph(regionInfo.TargetRegionName);

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Usage Collection Period");
            costSummaryRow.Cells[1].AddParagraph(FormattableString.Invariant($"{costEstimationResult.StartTime:r} - {costEstimationResult.EndTime:r}"));

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Target Price Base");
            costSummaryRow.Cells[1].AddParagraph("List Price");

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Currency");
            costSummaryRow.Cells[1].AddParagraph(regionInfo.CurrencyUnit);

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Currency Format");
            costSummaryRow.Cells[1].AddParagraph(regionInfo.CurrencyCulture.EnglishName);

            costSummaryRow = costSummaryTalbe.AddRow();
            costSummaryRow.Cells[0].AddParagraph("Total Cost in Period for Available Resources");

            if (!costEstimationResult.Details.Any())
            {
                costSummaryRow.Cells[1].AddParagraph("N/A");
            }
            else
            {
                costEstimationSection.AddParagraph(
                    "Please check the below cost list with price by Resource Group:",
                    DocumentInfo.TableDesStyleName);

                // Resource Details
                decimal totalCost         = 0;
                decimal totalOriginalCost = 0;

                foreach (var kvp in costEstimationResult.DetailsByResourceGroup)
                {
                    if (!kvp.Value.Any(d => d.EstimatedCost.HasValue))
                    {
                        continue;
                    }

                    var resourceGroup = kvp.Key;
                    var costTable     = DocumentInfo.CreateTable(ref costEstimationSection);
                    costEstimationSection.AddParagraph(string.Empty);
                    AddCostTableHeaders(ref costTable, documentInfo, resourceGroup);
                    foreach (var detail in kvp.Value.Where(d => d.EstimatedCost.HasValue))
                    {
                        AddCostTableRow(ref costTable, documentInfo, regionInfo, detail);
                        totalCost += detail.EstimatedCost.Value;
                    }

                    foreach (var detail in kvp.Value.Where(d => !d.EstimatedCost.HasValue))
                    {
                        AddCostTableRow(ref costTable, documentInfo, regionInfo, detail).Cells[0].Format.Font.Color = Colors.Red;

                        // ToDo: Is it necessary to put on total original costs?
                        if (!string.IsNullOrWhiteSpace(detail.SourceMeterId) && string.IsNullOrWhiteSpace(detail.TargetMeterId))
                        {
                            totalOriginalCost += detail.OriginalCost.Value;
                        }
                    }
                }

                // Add total cost to summary table
                costSummaryRow.Cells[1].AddParagraph(ToCurrencyString(totalCost, regionInfo.CurrencySymbol));
            }

            return(costEstimationSection);
        }
Example #2
0
        private static Section CreateAppendixResouceListSection(
            ref DocumentInfo documentInfo,
            RegionInfo regionInfo,
            CostEstimationResult costEstimationResult)
        {
            // TODO: extract to extension method
            // TODO: move hard code string to resource file.
            var subscriptionName = costEstimationResult.SubscriptionName;

            var appendixResouceListSection = documentInfo.CreateSection();
            var appendixResourceListTitle  =
                appendixResouceListSection.AddParagraph(
                    "Full Resource List For " + subscriptionName,
                    DocumentInfo.TitleStyleName);

            appendixResourceListTitle.AddBookmark("AppendixResourceList" + subscriptionName);

            // Resource List by Resource Group
            appendixResouceListSection.AddParagraph(
                "Here is the full resource list in reference subscription related to this migration: ",
                DocumentInfo.TableDesStyleName);

            var locationMap = costEstimationResult.LocationMap[costEstimationResult.SubscriptionId];

            foreach (var kvp in costEstimationResult.DetailsByResourceGroup)
            {
                var resourceTable = DocumentInfo.CreateTable(ref appendixResouceListSection);
                resourceTable.AddColumn("5cm");
                resourceTable.AddColumn("7cm");
                resourceTable.AddColumn("4.5cm");

                var resourceGroupName = resourceTable.AddRow();
                resourceGroupName.Cells[0].AddParagraph("Resource Group Name");
                resourceGroupName.Cells[0].Format.Font.Bold = true;
                resourceGroupName.Cells[1].MergeRight       = 1;
                documentInfo.AddParagraphWordWrap(resourceGroupName.Cells[1], kvp.Key);

                var resourceProperties = resourceTable.AddRow();
                resourceProperties.Format.Font.Bold = true;
                resourceProperties.Cells[0].AddParagraph("Name");
                resourceProperties.Cells[1].AddParagraph("Type");
                resourceProperties.Cells[2].AddParagraph("Location");

                foreach (var detail in kvp.Value)
                {
                    var resourceRow = resourceTable.AddRow();
                    documentInfo.AddParagraphWordWrap(resourceRow.Cells[0], detail.ResourceName);
                    documentInfo.AddParagraphWordWrap(resourceRow.Cells[1], detail.ResourceType);
                    if (locationMap.TryGetValue(detail.Location, out var locationDisplayName))
                    {
                        documentInfo.AddParagraphWordWrap(resourceRow.Cells[2], locationDisplayName);
                    }
                    else
                    {
                        documentInfo.AddParagraphWordWrap(resourceRow.Cells[2], detail.Location);
                    }
                }

                appendixResouceListSection.AddParagraph(string.Empty);
            }

            return(appendixResouceListSection);
        }