static void EnsureBasicParams(EnsureExtras extras, EnsureExtras forceEntering = EnsureExtras.None) { if ((extras & EnsureExtras.WorkspaceCollection) == EnsureExtras.WorkspaceCollection) { var newWorkspaceCollectionName = userInput.EnsureParam(workspaceCollectionName, "Workspace Collection Name", forceReEnter: ((forceEntering & EnsureExtras.WorkspaceCollection) == EnsureExtras.WorkspaceCollection)); if (!newWorkspaceCollectionName.Equals(workspaceCollectionName)) { accessKeys = null; accessKey = null; } workspaceCollectionName = newWorkspaceCollectionName; } if ((extras & EnsureExtras.WorspaceId) == EnsureExtras.WorspaceId) { workspaceId = userInput.EnsureParam(workspaceId, "Workspace Id", forceReEnter: ((forceEntering & EnsureExtras.WorspaceId) == EnsureExtras.WorspaceId)); } if ((extras & EnsureExtras.DatasetId) == EnsureExtras.DatasetId) { datasetId = userInput.EnsureParam(datasetId, "Dataset Id", forceReEnter: ((forceEntering & EnsureExtras.DatasetId) == EnsureExtras.DatasetId)); } if ((extras & EnsureExtras.Azure) == EnsureExtras.Azure) { subscriptionId = userInput.EnsureParam(subscriptionId, "Azure Subscription Id", onlyFillIfEmpty: true); resourceGroup = userInput.EnsureParam(resourceGroup, "Azure Resource Group", onlyFillIfEmpty: true); } if ((extras & EnsureExtras.CollectionLocation) == EnsureExtras.CollectionLocation) { collectionLocation = userInput.EnsureParam(collectionLocation, "Collection location", forceReEnter: ((forceEntering & EnsureExtras.CollectionLocation) == EnsureExtras.CollectionLocation)); } }
/// <summary> /// Creates a new instance of the PowerBIClient with the specified token /// </summary> /// <returns></returns> static async Task <PowerBIClient> CreateClient() { if (accessKeys == null) { var enteredKey = userInput.EnterOptionalParam("Access Key", "Auto select"); if (!string.IsNullOrWhiteSpace(enteredKey)) { accessKey = enteredKey; accessKeys = new WorkspaceCollectionKeys() { Key1 = accessKey }; } } if (accessKeys == null) { // get the current collection's keys accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); } // Create a token credentials with "AppKey" type var credentials = new TokenCredentials(accessKeys.Key1, "AppKey"); // Instantiate your Power BI client passing in the required credentials var client = new PowerBIClient(credentials); // Override the api endpoint base URL. Default value is https://api.powerbi.com client.BaseUri = new Uri(apiEndpointUri); return(client); }
/// <summary> /// Creates a new instance of the PowerBIClient with the specified token /// </summary> /// <returns></returns> static async Task <PowerBIClient> CreateClient() { if (accessKeys == null) { Console.Write("Access Key: "); accessKey = Console.ReadLine(); Console.WriteLine(); accessKeys = new WorkspaceCollectionKeys() { Key1 = accessKey }; } if (accessKeys == null) { accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); } // Create a token credentials with "AppKey" type var credentials = new TokenCredentials(accessKeys.Key1, "AppKey"); // Instantiate your Power BI client passing in the required credentials var client = new PowerBIClient(credentials); // Override the api endpoint base URL. Default value is https://api.powerbi.com client.BaseUri = new Uri(apiEndpointUri); return(client); }
static async Task ManageCachedMetadata(bool forceReset) { // ManageCachedParam may throw, to quit the management try { workspaceCollectionName = userInput.ManageCachedParam(workspaceCollectionName, "Workspace Collection Name", forceReset); string accessKeysKey1 = accessKeys != null ? accessKeys.Key1 : null; accessKeysKey1 = userInput.ManageCachedParam(accessKeysKey1, "Workspace Collection Access Key1", forceReset); if (accessKeysKey1 == null) { accessKeys = null; } else { accessKeys = new WorkspaceCollectionKeys { Key1 = accessKeysKey1 }; } workspaceId = userInput.ManageCachedParam(workspaceId, "Workspace Id", forceReset); datasetId = userInput.ManageCachedParam(datasetId, "Dataset Id", forceReset); collectionLocation = userInput.ManageCachedParam(collectionLocation, "Collection Location", forceReset); if (forceReset) { Console.WriteLine("Entire cache was reset\n"); } } catch (Exception e) { Console.WriteLine("\n" + e.Message); } }
//Sync VS static void Main(string[] args) { Customers = new string[customersNumber]; workspaceID = new string[customersNumber]; for (int i = 0; i < customersNumber; i++) { Customers[i] = $"Customer{i}"; } if (!string.IsNullOrWhiteSpace(accessKey)) { accessKeys = new WorkspaceCollectionKeys { Key1 = accessKey }; } AsyncPump.Run(async delegate { await Run(); }); Console.ReadKey(true); }
static async Task ListWorkspaceCollectionApiKeys() { EnsureBasicParams(EnsureExtras.WorkspaceCollection | EnsureExtras.Azure); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Key1: {0}", accessKeys.Key1); Console.WriteLine("==============================="); Console.WriteLine("Key2: {0}", accessKeys.Key2); }
static async Task ProvisionNewWorkspaceCollection() { // force new workspaceCollectionName, but if collectionLocation, set to the default, as users may be unaware of options workspaceCollectionName = null; collectionLocation = collectionLocation ?? defaultRegion; EnsureBasicParams(EnsureExtras.WorkspaceCollection | EnsureExtras.Azure | EnsureExtras.CollectionLocation); await CreateWorkspaceCollection(subscriptionId, resourceGroup, workspaceCollectionName, collectionLocation); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Workspace collection created successfully"); }
static void Main(string[] args) { if (!string.IsNullOrWhiteSpace(accessKey)) { accessKeys = new WorkspaceCollectionKeys { Key1 = accessKey }; } AsyncPump.Run(async delegate { await Run(); }); Console.ReadKey(true); }
static void Main(string[] args) { if (!string.IsNullOrWhiteSpace(accessKey)) { accessKeys = new WorkspaceCollectionKeys { Key1 = accessKey }; } SetupCommands(); userInput = new UserInput(); AsyncPump.Run(async delegate { bool execute = true; while (execute) { execute = await Run(); } }); Console.WriteLine("Enter any key to terminate: "); Console.ReadKey(true); }
static async Task Run() { Console.ResetColor(); var exit = false; try { Console.WriteLine(); Console.WriteLine("What do you want to do?"); Console.WriteLine("================================================================="); Console.WriteLine("1. Provision a new workspace collection"); Console.WriteLine("2. Get workspace collection metadata"); Console.WriteLine("3. Retrieve a workspace collection's API keys"); Console.WriteLine("4. Get list of workspaces within a collection"); Console.WriteLine("5. Provision a new workspace in an existing workspace collection"); Console.WriteLine("6. Import PBIX Desktop file into an existing workspace"); Console.WriteLine("7. Update connection string info for an existing dataset"); Console.WriteLine("8. Retrieve a list of Datasets published to a workspace"); Console.WriteLine("9. Delete a published dataset from a workspace"); Console.WriteLine(); var key = Console.ReadKey(true); switch (key.KeyChar) { case '1': if (string.IsNullOrWhiteSpace(subscriptionId)) { Console.Write("Azure Subscription ID:"); subscriptionId = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(resourceGroup)) { Console.Write("Azure Resource Group:"); resourceGroup = Console.ReadLine(); Console.WriteLine(); } Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); await CreateWorkspaceCollection(subscriptionId, resourceGroup, workspaceCollectionName); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Workspace collection created successfully"); await Run(); break; case '2': if (string.IsNullOrWhiteSpace(subscriptionId)) { Console.Write("Azure Subscription ID:"); subscriptionId = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(resourceGroup)) { Console.Write("Azure Resource Group:"); resourceGroup = Console.ReadLine(); Console.WriteLine(); } Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); var metadata = await GetWorkspaceCollectionMetadata(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine(metadata); await Run(); break; case '3': if (string.IsNullOrWhiteSpace(subscriptionId)) { Console.Write("Azure Subscription ID:"); subscriptionId = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(resourceGroup)) { Console.Write("Azure Resource Group:"); resourceGroup = Console.ReadLine(); Console.WriteLine(); } Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Key1: {0}", accessKeys.Key1); Console.WriteLine("==============================="); Console.WriteLine("Key2: {0}", accessKeys.Key2); await Run(); break; case '4': Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); var workspaces = await GetWorkspaces(workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; foreach (var instance in workspaces) { Console.WriteLine("Collection: {0}, ID: {1}", instance.WorkspaceCollectionName, instance.WorkspaceId); } await Run(); break; case '5': if (string.IsNullOrWhiteSpace(workspaceCollectionName)) { Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); } var workspace = await CreateWorkspace(workspaceCollectionName); workspaceId = workspace.WorkspaceId; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Workspace ID: {0}", workspaceId); await Run(); break; case '6': if (string.IsNullOrWhiteSpace(workspaceCollectionName)) { Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(workspaceId)) { Console.Write("Workspace ID:"); workspaceId = Console.ReadLine(); Console.WriteLine(); } Console.Write("Dataset Name:"); var datasetName = Console.ReadLine(); Console.WriteLine(); Console.Write("File Path:"); var filePath = Console.ReadLine(); Console.WriteLine(); var import = await ImportPbix(workspaceCollectionName, workspaceId, datasetName, filePath); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Import: {0}", import.Id); await Run(); break; case '7': if (string.IsNullOrWhiteSpace(workspaceCollectionName)) { Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(workspaceId)) { Console.Write("Workspace ID:"); workspaceId = Console.ReadLine(); Console.WriteLine(); } await UpdateConnection(workspaceCollectionName, workspaceId); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Connection information updated successfully."); await Run(); break; case '8': if (string.IsNullOrWhiteSpace(workspaceCollectionName)) { Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(workspaceId)) { Console.Write("Workspace ID:"); workspaceId = Console.ReadLine(); Console.WriteLine(); } await ListDatasets(workspaceCollectionName, workspaceId); break; case '9': if (string.IsNullOrWhiteSpace(workspaceCollectionName)) { Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); Console.WriteLine(); } if (string.IsNullOrWhiteSpace(workspaceId)) { Console.Write("Workspace ID:"); workspaceId = Console.ReadLine(); Console.WriteLine(); } Console.Write("Dataset ID:"); datasetId = Console.ReadLine(); Console.WriteLine(); await DeleteDataset(workspaceCollectionName, workspaceId, datasetId); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Dataset deleted successfully."); break; default: Console.WriteLine("Press any key to exit.."); exit = true; break; } } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Ooops, something broke: {0}", ex.Message); Console.WriteLine(); } if (!exit) { await Run(); } }
static async Task Run() { Console.ResetColor(); var exit = false; try { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("This application does the following operations:"); Console.WriteLine("1. Provision of a new workspace collection in the specified Azure subscription"); Console.WriteLine("2. Retrieve the workspace collection's API key"); Console.WriteLine("3. Provision a new workspace for each customer in the workspace collection"); Console.WriteLine("4. Import PBIX Desktop file into every workspace created - one foreach customer"); Console.WriteLine("5. Update connection string info for the dataset of the first workspace created"); Console.WriteLine(); Console.WriteLine("1. Provision of a new workspace collection in the specified Azure subscription"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Azure Subscription ID:"); subscriptionId = Console.ReadLine(); //Console.WriteLine(); Console.Write("Azure Resource Group:"); resourceGroup = Console.ReadLine(); //Console.WriteLine(); Console.Write("Workspace Collection Name:"); workspaceCollectionName = Console.ReadLine(); await CreateWorkspaceCollection(subscriptionId, resourceGroup, workspaceCollectionName); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Workspace collection created successfully"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("2. Retrieve the workspace collection's API key"); accessKeys = await ListWorkspaceCollectionKeys(subscriptionId, resourceGroup, workspaceCollectionName); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Key1: {0}", accessKeys.Key1); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("3. Provision a new workspace for each customer in the workspace collection"); //one workspace for each customer for (int i = 0; i < Customers.Length; i++) { var workspace = await CreateWorkspace(workspaceCollectionName); workspaceID[i] = workspace.WorkspaceId; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"WorkspaceID: {workspaceID[i]}"); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("4. Import PBIX Desktop file into every existing workspaces"); Console.ForegroundColor = ConsoleColor.White; Console.Write("Dataset Name:"); var datasetName = Console.ReadLine(); Console.Write("File Folder:"); var filePath = Console.ReadLine(); Console.Write("File Name:"); var fileName = Console.ReadLine(); var oldPath = filePath + fileName + ".pbix"; for (int i = 0; i < Customers.Length; i++) { var newFileName = fileName + "_" + Customers[i] + ".pbix"; var newPath = filePath + newFileName; System.IO.File.Copy(oldPath, newPath); var import = await ImportPbix(workspaceCollectionName, workspaceID[i], datasetName, newPath); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("5. Update connection string info for the dataset of the first workspace created"); Console.ForegroundColor = ConsoleColor.White; await UpdateConnection(workspaceCollectionName, workspaceID[0]); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Connection information updated successfully."); Console.WriteLine("PROCESS COMPLETED"); Console.ReadLine(); //await Run(); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Ooops, something broke: {0}", ex); Console.WriteLine(); } if (!exit) { await Run(); } }