//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); } }
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); }
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++; } }
//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); } }
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); }