//Groups: The Add Rows operation adds Rows to a Table in a Dataset in a Group. //POST https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name}/rows //Add Rows operation: https://msdn.microsoft.com/en-US/library/mt203561.aspx static void AddRows(string groupId, string datasetId, string tableName) { //In a production application, use more specific exception handling. try { var datasetClient = new DatasetsClient(pbi); //Create a list of Product List <Product> products = new List <Product> { new Product { ProductID = 1, Name = "Adjustable Race", Category = "Components", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30) }, new Product { ProductID = 2, Name = "LL Crankarm", Category = "Components", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30) }, new Product { ProductID = 3, Name = "HL Mountain Frame - Silver", Category = "Bikes", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30) }, }; var tableRows = new TableRows <Product>(); tableRows.rows = products; //POST request using the json from a list of Product //NOTE: Posting rows to a model that is not created through the Power BI API is not currently supported. // Please create a dataset by posting it through the API following the instructions on http://dev.powerbi.com. datasetClient.AddRows <Product>(groupId, datasetId, tableName, tableRows); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
public static void Main(string[] args) { ReadInData(DataSource); FlattenPopulateTables(); var pbi = new PowerBiAuthentication("007fb3ab-bf10-437b-9bea-1825f1086d00"); var dsClient = new DatasetsClient(pbi); var groupClient = new GroupClient(pbi); var group = groupClient.Get().Result.value.First(t => t.name == "ElastacoudPowerByTheHour"); //BufferedInsert<FlightInfoTableEntry>(dsClient, powerByTheHourDatasetId, flightTable); //BufferedInsert<PositionTableEntry>(dsClient, powerByTheHourDatasetId, positionTable); //BufferedInsert<SensorTableEntry>(dsClient, powerByTheHourDatasetId, sensorTable); try { string powerByTheHourDatasetId = CreateBIDataset(dsClient, group); BufferedInsert <FlattenedFlightInfoTableEntry>(dsClient, group, powerByTheHourDatasetId, flattenedFlightDictionary); } catch (Exception e) { Console.WriteLine(); } Console.WriteLine(); }
private async static Task QueryDatasets() { var dataClient = new DatasetsClient(pbi); var datasets = await dataClient.List(); foreach (var dataset in datasets.value) { Console.WriteLine("{0}\t{1}", dataset.name, dataset.id); } Console.WriteLine("Create a data set?"); Dataset created; if (Console.ReadKey().KeyChar == 'Y') { created = await dataClient.Create<resourceMeasures>("resourceManager", true); } else { created = (await dataClient.List()).value.First(ds => ds.name == "resourceManager"); } var tables = await dataClient.ListTables(created.id); ListTables(tables); //var table = dataClient.GetTable(created.id, tables.value.First().name); //ListColumns(table.columns); var table = await dataClient.UpdateTableSchema<resourceMeasures2>(created.id, tables.value.First().name); }
private async static Task QueryDatasets() { var dataClient = new DatasetsClient(pbi); var datasets = await dataClient.List(); foreach (var dataset in datasets.value) { Console.WriteLine("{0}\t{1}", dataset.name, dataset.id); } Console.WriteLine("Create a data set?"); Dataset created; if (Console.ReadKey().KeyChar == 'Y') { created = await dataClient.Create <resourceMeasures>("resourceManager", true); } else { created = (await dataClient.List()).value.First(ds => ds.name == "resourceManager"); } var tables = await dataClient.ListTables(created.id); ListTables(tables); //var table = dataClient.GetTable(created.id, tables.value.First().name); //ListColumns(table.columns); var table = await dataClient.UpdateTableSchema <resourceMeasures2>(created.id, tables.value.First().name); }
public ApiClient(string apiKey, HttpClient http) { Datasets = new DatasetsClient(apiKey, http); Categories = new CategoriesClient(http); Departments = new DepartmentsClient(http); Features = new FeaturesClient(http); Rows = new RowsClient(http); Structure = new StructureClient(http); Versions = new VersionsClient(http); }
public async Task ListDatasets_AllGood_SetsAuthHeader() { Mock<IPowerBiAuthentication> mockPBi = new Mock<IPowerBiAuthentication>(); mockPBi.Setup(t => t.GetAccessToken()).Returns("hello"); var dashboardClient = new DatasetsClient(mockPBi.Object); await dashboardClient.List(); mockPBi.Verify(pbi => pbi.GetAccessToken(), Times.Once); }
public async Task ListDatasets_AllGood_SetsAuthHeader() { Mock <IPowerBiAuthentication> mockPBi = new Mock <IPowerBiAuthentication>(); mockPBi.Setup(t => t.GetAccessToken()).Returns("hello"); var dashboardClient = new DatasetsClient(mockPBi.Object); await dashboardClient.List(); mockPBi.Verify(pbi => pbi.GetAccessToken(), Times.Once); }
private static string CreateBIDataset(DatasetsClient client, Group g) { var datasets = client.List(g.id).Result; if (datasets.value.All(t => t.name != PowerByTheHour)) { var result = client.Create(g.id, PowerByTheHour, false, /*typeof(Classes.FlightInfoTableEntry), typeof(Classes.PositionTableEntry), typeof(Classes.SensorTableEntry),*/ typeof(Classes.FlattenedFlightInfoTableEntry)).Result; return(result.id); } else { return(datasets.value.First(t => t.name == PowerByTheHour).id); } }
private static void BufferedInsert <T>(DatasetsClient client, Group g, String datasetId, TableRows <T> entries) { var length = entries.rows.Count; var numOfSkips = (int)Math.Ceiling((double)length / Buffer); var count = 0; while (count <= numOfSkips) { TableRows <T> bufferTableEntries = new TableRows <T>(); var numremaining = length - count * Buffer; bufferTableEntries.rows.AddRange(entries.rows.Skip(count).Take(numremaining > Buffer ? Buffer : numremaining)); client.AddRows(g.id, datasetId, typeof(T).Name, bufferTableEntries).Wait(); count++; } }
private async static Task GenerateData() { var dataClient = new DatasetsClient(pbi); var created = (await dataClient.List()).value.First(ds => ds.name == "resourceManager"); var tables = await dataClient.ListTables(created.id); var dataRows = new TableRows <resourceMeasures>(); for (int i = 0; i < 1000; i++) { dataRows.rows.Add(new resourceMeasures() { Id = Guid.NewGuid().ToString("n"), InServiceDate = DateTime.Now.AddYears(-4), IsRunning = true, LastMeasure = DateTime.Now, Name = "Engine" + i.ToString(), RPM = 6000, Temperature = 431.6 }); } await dataClient.ClearRows(created.id, tables.value.First().name); await dataClient.AddRows(created.id, tables.value.First().name, dataRows); while (true) { Console.Write("."); foreach (var row in dataRows.rows) { row.RPM = (int)(6000 * Math.Sin(Math.PI * (DateTime.Now.Second / 59D))); row.Temperature += new Random((int)DateTime.Now.Ticks).Next(-5, 5); row.LastMeasure = DateTime.Now; row.IsRunning = row.RPM > 1; Thread.Sleep(1); } await dataClient.AddRows(created.id, tables.value.First().name, dataRows); } await dataClient.ClearRows(created.id, tables.value.First().name); }
//Groups: The Create Dataset operation can also create a dataset in a group //POST https://api.PowerBI.com/v1.0/myorg/groups/{group_id}/datasets //Create Dataset operation: https://msdn.microsoft.com/en-US/library/mt203562(Azure.100).aspx static async Task CreateDataset(string groupId) { try { var datasetsClient = new DatasetsClient(pbi); Dataset ds = (await datasetsClient.List(groupId)).value.First(d => d.name == datasetName); if (ds == null) { //create a dataset using the schema from Product await datasetsClient.Create <Product>(groupId, datasetName, false); } else { Console.WriteLine("Dataset exists"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//The Create Dataset operation creates a new Dataset from a JSON schema definition and returns the Dataset ID //and the properties of the dataset created. //POST https://api.powerbi.com/v1.0/myorg/datasets //Create Dataset operation: https://msdn.microsoft.com/en-US/library/mt203562(Azure.100).aspx static async Task CreateDataset() { //In a production application, use more specific exception handling. try { var datasetsClient = new DatasetsClient(pbi); Dataset ds = (await datasetsClient.List()).value.FirstOrDefault(d => d.name == datasetName); if (ds == null) { //create a dataset using the schema from Product await datasetsClient.Create <Product>(datasetName, false); } else { Console.WriteLine("Dataset exists"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//Groups: The Update Table Schema operation updates a Table schema in a Dataset in a Group. //PUT https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name} //Update Table Schema operation: https://msdn.microsoft.com/en-US/library/mt203560.aspx static void UpdateTableSchema(string groupId, string datasetId, string tableName) { var datasetsClient = new DatasetsClient(pbi); datasetsClient.UpdateTableSchema<Product2>(groupId, datasetId, tableName); }
//Groups: The Add Rows operation adds Rows to a Table in a Dataset in a Group. //POST https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name}/rows //Add Rows operation: https://msdn.microsoft.com/en-US/library/mt203561.aspx static void AddRows(string groupId, string datasetId, string tableName) { //In a production application, use more specific exception handling. try { var datasetClient = new DatasetsClient(pbi); //Create a list of Product List<Product> products = new List<Product> { new Product{ProductID = 1, Name="Adjustable Race", Category="Components", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30)}, new Product{ProductID = 2, Name="LL Crankarm", Category="Components", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30)}, new Product{ProductID = 3, Name="HL Mountain Frame - Silver", Category="Bikes", IsCompete = true, ManufacturedOn = new DateTime(2014, 7, 30)}, }; var tableRows = new TableRows<Product>(); tableRows.rows = products; //POST request using the json from a list of Product //NOTE: Posting rows to a model that is not created through the Power BI API is not currently supported. // Please create a dataset by posting it through the API following the instructions on http://dev.powerbi.com. datasetClient.AddRows<Product>(groupId, datasetId, tableName, tableRows); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//Groups: The Delete Rows operation deletes Rows from a Table in a Dataset in a Group. //DELETE https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name}/rows //Delete Rows operation: https://msdn.microsoft.com/en-US/library/mt238041.aspx static void DeleteRows(string groupId, string datasetId, string tableName) { var datasetClient = new DatasetsClient(pbi); datasetClient.ClearRows(groupId, datasetId, tableName); }
//Groups: The Get Datasets operation can also get datasets in a group //GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets //Get Dataset operation: https://msdn.microsoft.com/en-US/library/mt203567.aspx static async Task<Datasets> GetDatasets(string groupId) { DatasetsClient client = new DatasetsClient(pbi); return await client.List(groupId); }
//Groups: The Get Tables operation returns a JSON list of Tables for the specified Dataset in a Group. //GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables //Get Tables operation: https://msdn.microsoft.com/en-US/library/mt203556.aspx static async Task<Tables> GetTables(string groupId, string datasetId) { var client = new DatasetsClient(pbi); return await client.ListTables(groupId, datasetId); }
//Groups: The Create Dataset operation can also create a dataset in a group //POST https://api.PowerBI.com/v1.0/myorg/groups/{group_id}/datasets //Create Dataset operation: https://msdn.microsoft.com/en-US/library/mt203562(Azure.100).aspx static async Task CreateDataset(string groupId) { try { var datasetsClient = new DatasetsClient(pbi); Dataset ds = (await datasetsClient.List(groupId)).value.First(d => d.name == datasetName); if (ds == null) { //create a dataset using the schema from Product await datasetsClient.Create<Product>(groupId, datasetName, false); } else { Console.WriteLine("Dataset exists"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
//The Get Datasets operation returns a JSON list of all Dataset objects that includes a name and id. //GET https://api.powerbi.com/v1.0/myorg/datasets //Get Dataset operation: https://msdn.microsoft.com/en-US/library/mt203567.aspx static async Task<Datasets> GetDatasets() { DatasetsClient client = new DatasetsClient(pbi); return await client.List(); }
//The Get Datasets operation returns a JSON list of all Dataset objects that includes a name and id. //GET https://api.powerbi.com/v1.0/myorg/datasets //Get Dataset operation: https://msdn.microsoft.com/en-US/library/mt203567.aspx static async Task <Datasets> GetDatasets() { DatasetsClient client = new DatasetsClient(pbi); return(await client.List()); }
//The Create Dataset operation creates a new Dataset from a JSON schema definition and returns the Dataset ID //and the properties of the dataset created. //POST https://api.powerbi.com/v1.0/myorg/datasets //Create Dataset operation: https://msdn.microsoft.com/en-US/library/mt203562(Azure.100).aspx static async Task CreateDataset() { //In a production application, use more specific exception handling. try { var datasetsClient = new DatasetsClient(pbi); Dataset ds = (await datasetsClient.List()).value.FirstOrDefault(d=>d.name == datasetName); if (ds == null) { //create a dataset using the schema from Product await datasetsClient.Create<Product>(datasetName, false); } else { Console.WriteLine("Dataset exists"); } } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private async static Task GenerateData() { var dataClient = new DatasetsClient(pbi); var created = (await dataClient.List()).value.First(ds => ds.name == "resourceManager"); var tables = await dataClient.ListTables(created.id); var dataRows = new TableRows<resourceMeasures>(); for (int i = 0; i < 1000; i++) { dataRows.rows.Add(new resourceMeasures() { Id = Guid.NewGuid().ToString("n"), InServiceDate = DateTime.Now.AddYears(-4), IsRunning = true, LastMeasure = DateTime.Now, Name = "Engine" + i.ToString(), RPM = 6000, Temperature = 431.6 }); } await dataClient.ClearRows(created.id, tables.value.First().name); await dataClient.AddRows(created.id, tables.value.First().name, dataRows); while (true) { Console.Write("."); foreach (var row in dataRows.rows) { row.RPM = (int)(6000 * Math.Sin(Math.PI * (DateTime.Now.Second / 59D))); row.Temperature += new Random((int)DateTime.Now.Ticks).Next(-5, 5); row.LastMeasure = DateTime.Now; row.IsRunning = row.RPM > 1; Thread.Sleep(1); } await dataClient.AddRows(created.id, tables.value.First().name, dataRows); } await dataClient.ClearRows(created.id, tables.value.First().name); }
//Groups: The Get Datasets operation can also get datasets in a group //GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets //Get Dataset operation: https://msdn.microsoft.com/en-US/library/mt203567.aspx static async Task <Datasets> GetDatasets(string groupId) { DatasetsClient client = new DatasetsClient(pbi); return(await client.List(groupId)); }
//Groups: The Get Tables operation returns a JSON list of Tables for the specified Dataset in a Group. //GET https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables //Get Tables operation: https://msdn.microsoft.com/en-US/library/mt203556.aspx static async Task <Tables> GetTables(string groupId, string datasetId) { var client = new DatasetsClient(pbi); return(await client.ListTables(groupId, datasetId)); }
//Groups: The Update Table Schema operation updates a Table schema in a Dataset in a Group. //PUT https://api.powerbi.com/v1.0/myorg/groups/{group_id}/datasets/{dataset_id}/tables/{table_name} //Update Table Schema operation: https://msdn.microsoft.com/en-US/library/mt203560.aspx static void UpdateTableSchema(string groupId, string datasetId, string tableName) { var datasetsClient = new DatasetsClient(pbi); datasetsClient.UpdateTableSchema <Product2>(groupId, datasetId, tableName); }