public async Task <ActionResult> Index()
        {
            List <Employee> employees = new List <Employee>();

            employees.Add(new Employee()
            {
                Id = 1, EmployeeName = "Andrew Ma", IsSelected = false
            });
            employees.Add(new Employee()
            {
                Id = 2, EmployeeName = "Annelie Zubar", IsSelected = false
            });
            employees.Add(new Employee()
            {
                Id = 3, EmployeeName = "Carlos Grilo", IsSelected = false
            });
            employees.Add(new Employee()
            {
                Id = 4, EmployeeName = "Tina Lassila", IsSelected = false
            });
            employees.Add(new Employee()
            {
                Id = 5, EmployeeName = "Valery Ushakov", IsSelected = false
            });
            // Generate Embed Configuration.
            var embedConfig = new EmbedConfig()
            {
                Employees = employees
            };

            return(View(embedConfig));
        }
Esempio n. 2
0
        public async Task <ActionResult> GetDashboards(string username, string roles)
        {
            var result = new EmbedConfig();

            try
            {
                TokenCredentials tokenCredentials = await CreateCredentials();

                if (tokenCredentials == null)
                {
                    var error = "Authentication Failed";
                    return(Json(error, JsonRequestBehavior.AllowGet));
                }

                // Create a Power BI Client object. It will be used to call Power BI APIs.
                using (var client = new PowerBIClient(new Uri(powerbiSettings.ApiUrl), tokenCredentials))
                {
                    // Get a list of dashboards.
                    var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(powerbiSettings.WorkspaceId);

                    return(Json(dashboards.Value, JsonRequestBehavior.AllowGet));
                }
            }
            catch (HttpOperationException exc)
            {
                result.ErrorMessage = string.Format("Status: {0} ({1})\r\nResponse: {2}\r\nRequestId: {3}", exc.Response.StatusCode, (int)exc.Response.StatusCode, exc.Response.Content, exc.Response.Headers["RequestId"].FirstOrDefault());
            }
            catch (Exception exc)
            {
                result.ErrorMessage = exc.ToString();
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Esempio n. 3
0
 public EmbedService(AzureAdOptions azureAdOptions)
 {
     m_tokenCredentials = null;
     m_embedConfig      = new EmbedConfig();
     m_tileEmbedConfig  = new TileEmbedConfig();
     ApplicationSecret  = azureAdOptions.ClientSecret;
 }
Esempio n. 4
0
        public static EmbedConfig InviteLinkConfig()
        {
            EmbedConfig config = FindConfig <EmbedConfig>("invite");

            if (config == null)
            {
                config = new EmbedConfig
                {
                    AuthorName    = "Recruiter Hat",
                    Title         = "Invitation",
                    ReactionEmoji = ":email:",
                    Description   = "Spread the word! Get your fellow classmates to join us!",
                    Contents      = "Spread the word, our trusted scout! Spread the word " +
                                    "of our kingdom! Amass an army of knowledge seeking minions! Lay waste " +
                                    "to the legions of doubt and uncertainty!!",
                    Fields = new List <string>()
                    {
                        "Invite|https://discord.io/unofficial-DevryIT"
                    },
                    Footer           = "Minions of knowledge! Assembblleeee!",
                    IgnoreHelpWizard = false
                }
            }
            ;

            return(config);
        }
Esempio n. 5
0
 public EmbedService()
 {
     m_tokenCredentials = null;
     m_embedConfig      = new EmbedConfig();
     m_tileEmbedConfig  = new TileEmbedConfig();
     m_ReportList       = new List <ReportDefinition>();
 }
        public async Task <ActionResult> EmbedDashboard()
        {
            var error = GetWebConfigErrors();

            if (error != null)
            {
                return(View(new EmbedConfig()
                {
                    ErrorMessage = error
                }));
            }

            // Create a user password cradentials.
            var credential = new UserPasswordCredential(Username, Password);

            // Authenticate using created credentials
            var authenticationContext = new AuthenticationContext(AuthorityUrl);
            var authenticationResult  = await authenticationContext.AcquireTokenAsync(ResourceUrl, ClientId, credential);

            if (authenticationResult == null)
            {
                return(View(new EmbedConfig()
                {
                    ErrorMessage = "Authentication Failed."
                }));
            }

            var tokenCredentials = new TokenCredentials(authenticationResult.AccessToken, "Bearer");

            // Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials))
            {
                // Get a list of dashboards.
                var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(GroupId);

                // Get the first report in the group.
                var dashboard = dashboards.Value.FirstOrDefault();

                if (dashboard == null)
                {
                    return(View(new EmbedConfig()
                    {
                        ErrorMessage = "Group has no dashboards."
                    }));
                }



                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = authenticationResult.AccessToken,
                    EmbedUrl   = dashboard.EmbedUrl,
                    Id         = dashboard.Id
                };

                return(View(embedConfig));
            }
        }
Esempio n. 7
0
        public async Task OnGet()
        {
//            await _embedService.EmbedReport("*****@*****.**", "User_Read");
            await _embedService.EmbedReport("89bc4df8-0d2b-4f78-ad55-e4a0e200a5d0", "User_Read");

//            await _embedService.EmbedReport("", "");

            EmbedConfig = _embedService.EmbedConfig;
        }
Esempio n. 8
0
        public async Task <ActionResult> EmbedDashboard(string dashboardId, string workspaceId)
        {
            if (string.IsNullOrWhiteSpace(workspaceId))
            {
                workspaceId = powerbiSettings.WorkspaceId;
            }
            TokenCredentials tokenCredentials = await CreateCredentials();

            if (tokenCredentials == null)
            {
                var error = "Authentication Failed";
                return(Json(error, JsonRequestBehavior.AllowGet));
            }

            // Create a Power BI Client object. It will be used to call Power BI APIs.
            using (var client = new PowerBIClient(new Uri(powerbiSettings.ApiUrl), tokenCredentials))
            {
                // Get a list of dashboards.
                var dashboards = await client.Dashboards.GetDashboardsInGroupAsync(workspaceId);

                // Get the first report in the workspace.
                var dashboard = dashboards.Value.Where(x => x.Id == dashboardId).FirstOrDefault();

                if (dashboard == null)
                {
                    return(Json(new EmbedConfig()
                    {
                        ErrorMessage = "Workspace has no dashboards."
                    }, JsonRequestBehavior.AllowGet));
                }

                // Generate Embed Token.
                var generateTokenRequestParameters = new GenerateTokenRequest(accessLevel: "view");
                var tokenResponse = await client.Dashboards.GenerateTokenInGroupAsync(powerbiSettings.WorkspaceId, dashboard.Id, generateTokenRequestParameters);

                if (tokenResponse == null)
                {
                    return(Json(new EmbedConfig()
                    {
                        ErrorMessage = "Failed to generate embed token."
                    }, JsonRequestBehavior.AllowGet));
                }

                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse,
                    EmbedUrl   = dashboard.EmbedUrl,
                    Id         = dashboard.Id
                };

                return(Json(embedConfig, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 9
0
        public async Task <ActionResult> EmbedReport()
        {
            string tenantID = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/tenantid").Value;

            string reportId = Request.Form["SelectedReport"].ToString();

            using (var client = await CreatePowerBIClientForISV())
            {
                var report = client.Reports.GetReportInGroup(GroupId, reportId);
                // map user for RLS
                var salesUser = new EffectiveIdentity(
                    username: "******",
                    roles: new List <string> {
                    "Sales"
                },
                    datasets: new List <string> {
                    report.DatasetId
                });

                // Generate Embed Token.
                var generateTokenRequestParameters = tenantID.StartsWith("1") || report.Name.ToLower().CompareTo("adventureworks") != 0 ?
                                                     new GenerateTokenRequest(
                    accessLevel: "edit", allowSaveAs: true) :
                                                     new GenerateTokenRequest(
                    accessLevel: "edit", allowSaveAs: true,
                    identities: new List <EffectiveIdentity> {
                    salesUser
                });
                var tokenResponse = await client.Reports.GenerateTokenInGroupAsync(GroupId, reportId, generateTokenRequestParameters);

                // Refresh the dataset
                // await client.Datasets.RefreshDatasetInGroupAsync(GroupId, report.DatasetId);

                // Generate Embed Configuration.
                var embedConfig = new EmbedConfig()
                {
                    EmbedToken = tokenResponse,
                    EmbedUrl   = report.EmbedUrl,
                    Id         = reportId,
                    Name       = report.Name
                };

                return(View(embedConfig));
            }
        }