Example #1
0
        public static async Task <Gateway> GetWorkspaceGatewaysAsync(string gatewayName)
        {
            Gateway returnVal = null;

            if (string.IsNullOrEmpty(gatewayName))
            {
                throw new ArgumentException("no gateway name specified on the request . Value is required");
            }

            using (PowerBIClient client = await CreateClient())
            {
                ODataResponseListGateway gateways = await client.Gateways.GetGatewaysAsync();

                IEnumerable <Gateway> gatewayquery = gateways.Value.Where(x => x.Name.Contains(gatewayName));

                try
                {
                    returnVal = gatewayquery.First();
                }
                catch (InvalidOperationException ex)
                {
                    throw new ArgumentException($"Specified gateway '{gatewayName}' not found. Please check the name of the gateway and try again. Details: {ex.Message}");
                }

                return(returnVal);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                // Create a user password cradentials.
                credential = new UserPasswordCredential(username, Secrets.Password);

                // Authenticate using created credentials
                Authorize().Wait();

                using (var client = new PowerBIClient(new Uri(apiUrl), tokenCredentials))
                {
                    EmbedToken embedToken = client.Reports.GenerateTokenInGroup(groupId, "<REPORT ID>", new GenerateTokenRequest(accessLevel: "View", datasetId: "<DATASET ID>"));

                    Report report = client.Reports.GetReportInGroup(groupId, "<REPORT ID>");

                    #region Output Embed Token
                    Console.WriteLine("\r*** EMBED TOKEN ***\r");

                    Console.Write("Report Id: ");

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("<REPORT ID>");
                    Console.ResetColor();

                    Console.Write("Report Embed Url: ");

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(report.EmbedUrl);
                    Console.ResetColor();

                    Console.WriteLine("Embed Token Expiration: ");

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(embedToken.Expiration.Value.ToString());
                    Console.ResetColor();


                    Console.WriteLine("Report Embed Token: ");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(embedToken.Token);
                    Console.ResetColor();
                    #endregion

                    #region Output Datasets
                    Console.WriteLine("\r*** DATASETS ***\r");

                    // List of Datasets
                    // This method calls for items in a Group/App Workspace. To get a list of items within your "My Workspace"
                    // call GetDatasets()
                    ODataResponseListDataset datasetList = client.Datasets.GetDatasetsInGroup(groupId);

                    foreach (Dataset ds in datasetList.Value)
                    {
                        Console.WriteLine(ds.Id + " | " + ds.Name);
                    }
                    #endregion

                    #region Output Reports
                    Console.WriteLine("\r*** REPORTS ***\r");

                    // List of reports
                    // This method calls for items in a Group/App Workspace. To get a list of items within your "My Workspace"
                    // call GetReports()
                    ODataResponseListReport reportList = client.Reports.GetReportsInGroup(groupId);

                    foreach (Report rpt in reportList.Value)
                    {
                        Console.WriteLine(rpt.Id + " | " + rpt.Name + " | DatasetID = " + rpt.DatasetId);
                    }
                    #endregion

                    #region Output Dashboards
                    Console.WriteLine("\r*** DASHBOARDS ***\r");

                    // List of reports
                    // This method calls for items in a Group/App Workspace. To get a list of items within your "My Workspace"
                    // call GetReports()
                    ODataResponseListDashboard dashboards = client.Dashboards.GetDashboardsInGroup(groupId);

                    foreach (Dashboard db in dashboards.Value)
                    {
                        Console.WriteLine(db.Id + " | " + db.DisplayName);
                    }
                    #endregion

                    #region Output Gateways
                    Console.WriteLine("\r*** Gateways ***\r");

                    ODataResponseListGateway gateways = client.Gateways.GetGateways();

                    Console.WriteLine(gateways.Value[0].Name);

                    //foreach (Gateway g in gateways)
                    //{
                    //    Console.WriteLine(g.Name + " | " + g.GatewayStatus);
                    //}
                    #endregion
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.ToString());
                Console.ResetColor();
            }
        }