Ejemplo n.º 1
0
 private async Task <string> TrySendImport(string filePath, string groupId, string targetReportName, string nameConflict)
 {
     try
     {
         return(await SaaSController.SendImport(filePath, groupId, targetReportName, nameConflict));
     }
     catch (Exception e)
     {
         MessageBox.Show(e.ToString());
         return(null);
     }
 }
Ejemplo n.º 2
0
        private async Task <O365Group> TryCreateGroup(string groupName)
        {
            try
            {
                O365Group createdO365Group = await SaaSController.CreateGroup(groupName);

                return(createdO365Group);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
                return(null);
            }
        }
Ejemplo n.º 3
0
        private async Task CreateMissingGroups(List <ReportMigrationData> selectedReports)
        {
            if (!selectedReports.Any())
            {
                return;
            }

            var groups = SaaSController.GetGroups();

            foreach (var report in selectedReports)
            {
                report.SaaSTargetGroupCreationStatus = "In Progress";
                RunInUIContext(UpdateGroupsGrid);

                var group = groups.Value.FirstOrDefault(g => string.Equals(g.Name, report.SaaSTargetGroupName, StringComparison.OrdinalIgnoreCase));

                if (group == null)
                {
                    group = await SaaSController.CreateGroupAsync(report.SaaSTargetGroupName);

                    if (group == null)
                    {
                        report.SaaSTargetGroupCreationStatus = Errors.GroupCreation.FailedToCreateGroup;
                        continue;
                    }

                    foreach (var same_group_report in MigrationPlan.ReportsMigrationData.Where(r => string.Equals(r.SaaSTargetGroupName, report.SaaSTargetGroupName, StringComparison.OrdinalIgnoreCase)))
                    {
                        same_group_report.SaaSTargetGroupId             = group.Id;
                        same_group_report.SaaSTargetGroupCreationStatus = "Done";
                    }
                }
                else  // group is found by GetGroups
                {
                    report.SaaSTargetGroupCreationStatus = "Done";
                    report.SaaSTargetGroupId             = group.Id;
                }
            }
            RunInUIContext(UpdateGroupsGrid);
            SaveMigrationPlan();
        }
Ejemplo n.º 4
0
        private async Task Import(List <ReportMigrationData> selectedReports, string selectedNameConflict)
        {
            if (!selectedReports.Any())
            {
                return;
            }

            var groups = SaaSController.GetGroups();

            foreach (var report in selectedReports)
            {
                Microsoft.PowerBI.Api.V2.Models.ODataResponseListImport imports = null;

                if (!string.IsNullOrWhiteSpace(report.SaaSReportId))
                {
                    // The report was already imported. Do nothing.
                    continue;
                }

                // We are ready for import if
                // 1. Get Group retuns the group
                // 2. The group Id is the same as expected
                var group = groups.Value.FirstOrDefault(g => string.Equals(g.Name, report.SaaSTargetGroupName, StringComparison.OrdinalIgnoreCase));

                report.SaaSImportState = ImportState.InProgress;
                RunInUIContext(UpdateImportGrid);

                if (group == null)
                {
                    report.SaaSImportState = ImportState.Failed;
                    report.SaaSImportError = Errors.Import.GroupWasNotFound;
                    continue;
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(report.SaaSTargetGroupId))
                    {
                        report.SaaSTargetGroupId = group.Id;
                    }
                    else if (!string.Equals(report.SaaSTargetGroupId, group.Id, StringComparison.OrdinalIgnoreCase))
                    {
                        report.SaaSImportError = Errors.Import.GroupIdsMismatch;
                        report.SaaSImportState = ImportState.Failed;
                        continue;
                    }
                }

                imports = await SaaSController.GetImports(report.SaaSTargetGroupId);

                string nameConflict = null;

                var existing_reports = await SaaSController.GetReports(report.SaaSTargetGroupId);

                if (existing_reports != null && existing_reports.Value.Where(r => string.Equals(r.Name, report.SaaSTargetReportName, StringComparison.OrdinalIgnoreCase)).Any())
                {
                    // report with the same name exists
                    if (selectedNameConflict == "Abort")
                    {
                        report.SaaSImportError = Errors.Import.DuplicateReport;
                        report.SaaSImportState = ImportState.Failed;
                        RunInUIContext(UpdateImportGrid);
                        continue;
                    }
                    else
                    {
                        nameConflict = selectedNameConflict;
                    }
                }
                else // report with the same name does not exist
                {
                    nameConflict = "Abort";
                }

                report.SaaSImportState = ImportState.Publishing;
                RunInUIContext(UpdateImportGrid);
                var importId = await TrySendImport(report.PbixPath, report.SaaSTargetGroupId, report.SaaSTargetReportName, nameConflict);

                if (importId == null)
                {
                    report.SaaSImportError = Errors.Import.UploadFailed;
                    report.SaaSImportState = ImportState.Failed;
                    RunInUIContext(UpdateImportGrid);
                    continue;
                }

                // polling
                Microsoft.PowerBI.Api.V2.Models.Import import = null;
                do
                {
                    imports = await SaaSController.GetImports(report.SaaSTargetGroupId);

                    if (imports != null)
                    {
                        import = imports.Value.FirstOrDefault(i => string.Equals(i.Id, importId, StringComparison.OrdinalIgnoreCase));
                    }
                } while (import == null || (import.ImportState != "Succeeded" && import.ImportState != "Failed"));

                report.SaaSImportState = import.ImportState == "Succeeded" ? ImportState.Done : ImportState.Failed;
                if (import.ImportState == "Succeeded" && import.Reports.Count == 1)
                {
                    report.SaaSReportId    = import.Reports[0].Id;
                    report.SaaSImportError = null;
                }
                else
                {
                    report.SaaSImportError = Errors.Import.UploadFailed;
                }
            }

            RunInUIContext(UpdateImportGrid);
        }
Ejemplo n.º 5
0
        private async Task CreateMissingGroups(List <ReportMigrationData> selectedReports)
        {
            Dictionary <string, string> createdGroupIds = new Dictionary <string, string>();
            HashSet <string>            confirmedGroups = new HashSet <string>();

            if (!selectedReports.Any())
            {
                return;
            }

            var groups = SaaSController.GetGroups();

            foreach (var report in selectedReports)
            {
                report.SaaSTargetGroupCreationStatus = "In Progress";
                RunInUIContext(UpdateGroupsGrid);

                if (createdGroupIds.ContainsKey(report.SaaSTargetGroupName))
                {
                    report.SaaSTargetGroupId = createdGroupIds[report.SaaSTargetGroupName];
                    if (confirmedGroups.Contains(report.SaaSTargetGroupId))
                    {
                        report.SaaSTargetGroupCreationStatus = "Confirmed";
                    }
                    continue;
                }

                var group = groups.Value.FirstOrDefault(g => string.Equals(g.Name, report.SaaSTargetGroupName, StringComparison.OrdinalIgnoreCase));

                if (group == null)
                {
                    if (string.IsNullOrWhiteSpace(report.SaaSTargetGroupId))
                    {
                        var createdO365Group = await TryCreateGroup(report.SaaSTargetGroupName);

                        if (createdO365Group == null)
                        {
                            report.SaaSTargetGroupCreationStatus = "Failed to Create Group";
                            continue;
                        }

                        report.SaaSTargetGroupId = createdO365Group.Id;
                        createdGroupIds[report.SaaSTargetGroupName] = createdO365Group.Id;
                    }

                    // The created group is not found by GetGroups untill it is refreshed.
                    // So, try to get imports from the newly created group untill the result is not null
                    // This code will be removed once PowerBI API for Group Creation is implemented.
                    report.SaaSTargetGroupCreationStatus = "Created. Not Confirmed";
                    RunInUIContext(UpdateGroupsGrid);

                    Microsoft.PowerBI.Api.V2.Models.ODataResponseListImport imports = null;
                    for (int i = 0; i < 15 && imports == null; i++)
                    {
                        try
                        {
                            imports = await SaaSController.GetImports(report.SaaSTargetGroupId);
                        }
                        catch (Microsoft.Rest.HttpOperationException)
                        {
                            if (imports == null)
                            {
                                Thread.Sleep(1000);
                            }
                        }
                    }

                    if (imports != null)
                    {
                        report.SaaSTargetGroupCreationStatus = "Confirmed";
                        confirmedGroups.Add(report.SaaSTargetGroupId);
                    }
                }
                else  // group is found by GetGroups
                {
                    confirmedGroups.Add(group.Id);
                    report.SaaSTargetGroupCreationStatus = "Confirmed";
                    report.SaaSTargetGroupId             = group.Id;
                }
            }
            RunInUIContext(UpdateGroupsGrid);
            SaveMigrationPlan();
        }