Example #1
0
        public static PBITable FromDataTable(DataTable dataTable, bool onlySchema = false)
        {
            if (dataTable == null)
            {
                throw new ArgumentNullException("dataTable");
            }

            var pbiTable = new PBITable(dataTable.TableName);

            foreach (DataColumn dataColumn in dataTable.Columns)
            {
                pbiTable.Columns.Add(new PBIColumn(dataColumn.ColumnName, dataColumn.DataType));
            }

            if (!onlySchema)
            {
                foreach (DataRow dataRow in dataTable.AsEnumerable())
                {
                    dynamic dyn = new ExpandoObject();

                    foreach (DataColumn column in dataTable.Columns)
                    {
                        var dic = (IDictionary <string, object>)dyn;

                        var obj = dataRow[column];

                        dic[column.ColumnName] = (obj != DBNull.Value ? obj : null);
                    }

                    pbiTable.Rows.Add(dyn);
                }
            }

            return(pbiTable);
        }
Example #2
0
        public PBIProvider(List <dynamic> dataDomain, string dataSetName)
        {
            powerBiService = new PowerBIService();

            authToken = powerBiService.GetAccessToken().Result;
            DataTable dt = PBITable.CreateDynamicDataTable(dataDomain);

            dt.TableName = "TableName";
            var pbiTable = PBITable.FromDataTable(dt);

            dataSet = powerBiService.GetDataSets(authToken).Result.FirstOrDefault(s => s.Name == dataSetName);

            if (dataSet == null)
            {
                dataSet      = new PBIDataSet();
                dataSet.Name = dataSetName;
                dataSet.Tables.Add(pbiTable);

                powerBiService.CreateDataSet(authToken, dataSet, false).Wait();
            }
        }