public virtual string EnsureParam(string param, string desc, bool onlyFillIfEmpty = false, bool forceReEnter = false, bool isPassword = false) { bool available = !string.IsNullOrWhiteSpace(param); if (onlyFillIfEmpty && available) { return(param); } if (available) { ConsoleHelper.WriteColoredValue(desc, param, ConsoleColor.Magenta, forceReEnter ? ". Re-Enter same, or new value:" : ". Press enter to use, or give new value:"); } else { Console.Write(desc + " is required. Enter value:"); } var entered = isPassword ? ConsoleHelper.ReadPassword() : Console.ReadLine(); if (!string.IsNullOrWhiteSpace(entered)) { param = entered; } return(param); }
/// <summary> /// Updates the Power BI dataset connection info for datasets with direct query connections /// </summary> /// <param name="workspaceCollectionName">The Power BI workspace collection name</param> /// <param name="workspaceId">The Power BI workspace id that contains the dataset</param> /// <param name="id"></param> /// <returns></returns> static async Task UpdateConnection(string workspaceCollectionName, string workspaceId, string datasetId) { if (string.IsNullOrWhiteSpace(username)) { Console.Write("Username: "******"Password: "******"Connection String (enter to skip): "); connectionString = Console.ReadLine(); Console.WriteLine(); using (var client = await CreateClient()) { // Optionally udpate the connectionstring details if preent if (!string.IsNullOrWhiteSpace(connectionString)) { var connectionParameters = new Dictionary <string, object> { { "connectionString", connectionString } }; await client.Datasets.SetAllConnectionsAsync(workspaceCollectionName, workspaceId, datasetId, connectionParameters); } // Get the datasources from the dataset var datasources = await client.Datasets.GetGatewayDatasourcesAsync(workspaceCollectionName, workspaceId, datasetId); // Reset your connection credentials var delta = new GatewayDatasource { CredentialType = "Basic", BasicCredentials = new BasicCredentials { Username = username, Password = password } }; if (datasources.Value.Count != 1) { Console.Write("Expected one datasource, updating the first"); } // Update the datasource with the specified credentials await client.Gateways.PatchDatasourceAsync(workspaceCollectionName, workspaceId, datasources.Value[0].GatewayId, datasources.Value[0].Id, delta); } }