Esempio n. 1
0
        private static void Test_Serialization(PBIAPIClient pbic)
        {
            PBIDataset dataset = new PBIDataset("myDataset", PBIDefaultMode.Streaming);

            dataset.ParentPowerBIAPI = pbic;
            dataset.SyncFromPowerBI();                   // check if a Dataset with the same ID or Name already exists in the PowerBI-Service

            PBITable salesTable = new PBITable("Facts"); // create a PBI table manually

            salesTable.AddColumn(new PBIColumn("ProductKey", PBIDataType.Int64)
            {
                IsHidden = true
            });                                                                                       // hiding a column
            salesTable.AddColumn(new PBIColumn("SalesDate", PBIDataType.DateTime)
            {
                FormatString = "yyyy-MM-dd"
            });                                                                                                     // setting the Formatstring
            salesTable.AddColumn(new PBIColumn("Amount_BASE", PBIDataType.Double)
            {
                FormatString = "$ #,##0.00", IsHidden = true
            });


            string x = PBIJsonHelper.SerializeObject(dataset);
        }
 public void DeleteRowsFromPowerBI(PBIAPIClient powerBiAPI)
 {
     foreach (PBITable table in Tables)
     {
         table.DeleteRowsFromPowerBI(powerBiAPI);
     }
 }
Esempio n. 3
0
        public void StreamRowToPowerBI(PBIRow row, string apiKey, PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot add row to PowerBI table as the table is not linked to a DataSet in PowerBI!");
            }

            if (powerBiAPI == null)
            {
                if (ParentDataset.ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentDataset.ParentPowerBIAPI;
                }
            }

            PBIRows rows = new PBIRows();

            rows.ParentTable = this;
            rows.Rows        = new List <PBIRow>(1);
            rows.Rows.Add(row);

            StreamRowsToPowerBI(rows, apiKey, powerBiAPI);
        }
Esempio n. 4
0
        public void DeleteRowsFromPowerBI(PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot delete rows from PowerBI table as the table is not linked to a DataSet in PowerBI!");
            }

            if (Name == null)
            {
                throw new Exception("Cannot add row to PowerBI table as the table does not have a name!");
            }

            if (powerBiAPI == null)
            {
                if (ParentDataset.ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentDataset.ParentPowerBIAPI;
                }
            }

            using (HttpWebResponse response = powerBiAPI.SendDELETERequest(ApiURL, PBIAPI.Rows))
            {
                string result = response.ResponseToString();
            }
        }
Esempio n. 5
0
        public void PublishToPowerBI(PBIAPIClient powerBiAPI = null, bool pushRows = false)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot Publish Table to PowerBI as it is not linked to a DataSet in PowerBI!");
            }

            if (powerBiAPI == null)
            {
                if (ParentDataset.ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentDataset.ParentPowerBIAPI;
                }
            }

            using (HttpWebResponse response = powerBiAPI.SendPUTRequest(ApiURL, PBIJsonHelper.SerializeObject(this)))
            {
                string result = response.ResponseToString();
            }

            if (pushRows)
            {
                PushRowsToPowerBI(DataRows, powerBiAPI);
            }
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            string ApplicationID = ConfigurationManager.AppSettings["PBI_ApplicationID"];

            PBIAPIClient pbic = new PBIAPIClient(ApplicationID);

            //Test_Parameters(pbic);
            //Test_Import(pbic);
            //Test_GetImports(pbic);
            //Test_GetImports(pbic);
            //Test_RemoveGroupMember(pbic);
            //Test_AddGroupMember(pbic);
            //Test_GetGroupMembers(pbic);
            //Test_CreateGroup(pbic);
            Test_GetDashboard(pbic);
            //Test_Rebind(pbic);
            //Test_Export(pbic);
            //Test_Serialization(pbic);
            //Test_Tiles(pbic);
            //Sample_Create_Model(pbic);

            //Sample_DataTable(pbic);

            //Sample_Dataset_Refresh(pbic);

            //Sample_Dataset_Rebind(pbic);
            //Sample_PushDataset(pbic);

            Console.Write("Press <ENTER> to quit. ");
            Console.ReadLine();
        }
Esempio n. 7
0
        public List <PBISequenceNumber> GetSequenceNumbers(PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot delete rows from PowerBI table as the table is not linked to a DataSet in PowerBI!");
            }

            if (Name == null)
            {
                throw new Exception("Cannot add row to PowerBI table as the table does not have a name!");
            }

            if (powerBiAPI == null)
            {
                if (ParentDataset.ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentDataset.ParentPowerBIAPI;
                }
            }

            PBIObjectList <PBISequenceNumber> objList = JsonConvert.DeserializeObject <PBIObjectList <PBISequenceNumber> >(powerBiAPI.SendGETRequest(ApiURL + "/sequenceNumbers").ResponseToString());

            foreach (var item in objList.Items)
            {
                item.ParentTable = this;
            }

            return(objList.Items);
        }
Esempio n. 8
0
        public void UpdateParameters(PBIAPIClient powerBiAPI, PBIDatasetParameters parameters)
        {
            if (powerBiAPI == null)
            {
                if (ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentPowerBIAPI;
                }
            }

            try
            {
                using (HttpWebResponse response = powerBiAPI.SendPOSTRequest(ApiURL + "/Default.UpdateParameters", PBIJsonHelper.SerializeObject(parameters)))
                {
                    string result = response.ResponseToString();
                }
            }
            catch (Exception e)
            {
                if (!e.Message.Contains("DMTS_MonikerHasNoDatasourcesToBindError"))
                {
                    throw e;
                }
            }
        }
Esempio n. 9
0
        private static void Test_RemoveGroupMember(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic.GetGroupByName("MyTestGroup");

            myGroup.RemoveGroupMember("*****@*****.**");

            Console.WriteLine(myGroup.GroupMembers.Count);
        }
Esempio n. 10
0
        private static void Test_AddGroupMember(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic.GetGroupByName("MyTestGroup");

            myGroup.AddGroupMember("*****@*****.**", PBIGroupAccessRight.Admin);

            Console.WriteLine(myGroup.GroupMembers.Count);
        }
Esempio n. 11
0
        private static void Test_Import(PBIAPIClient pbic)
        {
            PBIImport import = pbic.ImportPBIX("myDataset", @"D:\Desktop\myDataset.pbix", PBIImportConflictHandlerMode.CreateOrOverwrite);

            import = import.GetState();

            int i = 0;
        }
Esempio n. 12
0
        private static void Test_Export(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic; // "My Workspace"

            PBIReport report = myGroup.GetReportByName("MyReport");

            report.Export("D:\\MyReport.pbix");
        }
Esempio n. 13
0
        private static void Test_GetDashboard(PBIAPIClient pbic)
        {
            PBIGroup     group     = pbic.GetGroupByID("75c2b5c8-b698-4480-ad48-97a190cf67ee");
            PBIDashboard dashboard = group.GetDashboardByID("56ce2b48-9e5c-4ecc-a8aa-a65b7b6bfdc4");
            PBITile      tile      = dashboard.Tiles[0];

            Console.WriteLine(dashboard.DisplayName);
        }
Esempio n. 14
0
        public void SyncFromPowerBI(PBIAPIClient powerBiAPI = null)
        {
            if (powerBiAPI == null)
            {
                if (ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentPowerBIAPI;
                }
            }

            PBIDataset temp;

            try
            {
                if (string.IsNullOrEmpty(this.Id))
                {
                    if (ParentGroup == null)
                    {
                        temp = powerBiAPI.GetDatasetByName(this.Name);
                    }
                    else
                    {
                        temp = ParentGroup.GetDatasetByName(this.Name);
                    }
                }
                else
                if (ParentGroup == null)
                {
                    temp = powerBiAPI.GetDatasetByID(this.Id);
                }
                else
                {
                    temp = ParentGroup.GetDatasetByID(this.Id);
                }

                if (temp != null)
                {
                    this.Id = temp.Id;
                    this.AddRowsAPIEnabled  = temp.AddRowsAPIEnabled;
                    this.ConfiguredBy       = temp.ConfiguredBy;
                    this.DefaultMode        = temp.DefaultMode;
                    this.Relationships      = temp.Relationships;
                    this.Datasources        = temp.Datasources;
                    this.GatewayDatasources = temp.GatewayDatasources;

                    this.LoadTablesFromPowerBI();
                    this.LoadDatasourcesFromPowerBI();
                }
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 15
0
        private static void Test_GetReports(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic; // "My Workspace"
            //var x = pbic.Groups;
            //x.Count();
            PBIReport report = myGroup.GetReportByID("9ff0b4cd-2105-4405-857b-d51ffb06c14a");

            report.Export("D:\\Desktop\\MyReport.pdf");
        }
Esempio n. 16
0
        public void PublishToPowerBI(PBIAPIClient powerBiAPI = null)
        {
            if (ParentTable == null)
            {
                throw new Exception("Cannot add row to PowerBI table as the object is not linked to a Table in PowerBI!");
            }

            ParentTable.PushRowToPowerBI(this, powerBiAPI);
        }
Esempio n. 17
0
        public void PushRowsToPowerBI(List <PBIRow> rows = null, PBIAPIClient powerBiAPI = null)
        {
            if (rows != null)
            {
                DataRows = rows;
            }

            PushRowsToPowerBI(PBIJsonHelper.SerializeObject(DataRows), powerBiAPI);
        }
Esempio n. 18
0
        private static void Sample_Dataset_Rebind(PBIAPIClient pbic)
        {
            PBIGroup powerBIGroup = pbic.GetGroupByName("ApiClient Test");

            PBIReport  powerBIReport     = powerBIGroup.GetReportByName("Test Rebind");
            PBIDataset newPowerBIDataset = powerBIGroup.GetDatasetByName("AdventureWorksDW2016");

            powerBIReport.Rebind(newPowerBIDataset);
        }
Esempio n. 19
0
        public void PushRowToPowerBI(PBIRow row, PBIAPIClient powerBiAPI = null)
        {
            PBIRows rows = new PBIRows();

            rows.ParentTable = this;
            rows.Rows        = new List <PBIRow>(1);
            rows.Rows.Add(row);

            PushRowsToPowerBI(rows, powerBiAPI);
        }
Esempio n. 20
0
        private static void Test_Tiles(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic.Groups[0];

            PBIDashboard dashboard = myGroup.Dashboards[0];

            PBITile tile = dashboard.Tiles[0];

            Console.WriteLine(tile.ToString());
        }
 public void DeleteFromPowerBI(PBIAPIClient powerBiAPI)
 {
     using (HttpWebResponse response = powerBiAPI.SendDELETERequest(ApiURL))
     {
         using (StreamReader streamReader = new StreamReader(response.GetResponseStream(), true))
         {
             string json = streamReader.ReadToEnd();
         }
     }
 }
Esempio n. 22
0
        public string PublishToPowerBI(PBIAPIClient powerBiAPI, PBIDefaultRetentionPolicy defaultRetentionPolicy)
        {
            if (powerBiAPI == null)
            {
                if (ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentPowerBIAPI;
                }
            }
            if (string.IsNullOrEmpty(Id)) // Dataset was not loaded from PowerBI Service
            {
                string json = PBIJsonHelper.SerializeObject(this);

                using (HttpWebResponse response = powerBiAPI.SendPOSTRequest(ApiURL + "?defaultRetentionPolicy=" + defaultRetentionPolicy.ToString(), json))
                {
                    using (StreamReader streamReader = new StreamReader(response.GetResponseStream(), true))
                    {
                        json = streamReader.ReadToEnd();

                        JObject jObj = JObject.Parse(json);


                        Id           = jObj.GetValue("id", StringComparison.InvariantCultureIgnoreCase).ToString();
                        ODataContext = jObj.GetValue("@odata.context", StringComparison.InvariantCultureIgnoreCase).ToString();

                        if (jObj.Property("defaultRetentionPolicy") != null)
                        {
                            PBIDefaultRetentionPolicy = (PBIDefaultRetentionPolicy)Enum.Parse(typeof(PBIDefaultRetentionPolicy), jObj.GetValue("defaultRetentionPolicy", StringComparison.InvariantCultureIgnoreCase).ToString(), true);
                        }

                        if (jObj.Property("addRowsAPIEnabled") != null)
                        {
                            AddRowsAPIEnabled = bool.Parse(jObj.GetValue("addRowsAPIEnabled", StringComparison.InvariantCultureIgnoreCase).ToString());
                        }
                    }
                }
            }
            else
            {
                if (PBIDefaultMode != PBIDefaultMode.Streaming)// Update is not supported for Streaming-Datasets
                {
                    foreach (PBITable table in Tables)
                    {
                        table.PublishToPowerBI(powerBiAPI);
                    }
                }
                // Other DefaultModes do not support updating a Table-Definition?!?
            }

            return(Id);
        }
        public void SyncFromPowerBI(PBIAPIClient powerBiAPI = null)
        {
            if (powerBiAPI == null)
            {
                if (ParentPowerBIAPI == null)
                {
                    throw new Exception("No PowerBI API Object was supplied!");
                }
                else
                {
                    powerBiAPI = ParentPowerBIAPI;
                }
            }

            PBIDataset temp;

            try
            {
                if (string.IsNullOrEmpty(this.Id))
                {
                    if (ParentGroup == null)
                    {
                        temp = powerBiAPI.GetDatasetByName(this.Name);
                    }
                    else
                    {
                        temp = ParentGroup.GetDatasetByName(this.Name);
                    }
                }
                else
                if (ParentGroup == null)
                {
                    temp = powerBiAPI.GetDatasetByID(this.Id);
                }
                else
                {
                    temp = ParentGroup.GetDatasetByID(this.Id);
                }

                if (temp != null)
                {
                    this.Id = temp.Id;
                    this.AddRowsAPIEnabled = temp.AddRowsAPIEnabled;

                    foreach (PBITable table in temp.Tables)
                    {
                        this.AddOrUpdateTable(table);
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Esempio n. 24
0
        private static void Test_GetGroupMembers(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic.GetGroupByName("MyTestGroup");

            foreach (PBIGroupMember gm in myGroup.GroupMembers)
            {
                Console.WriteLine(PBIJsonHelper.SerializeObject(gm));
            }

            Console.WriteLine(myGroup.GroupMembers.Count);
        }
Esempio n. 25
0
        private static void Sample_Dataset_Refresh()
        {
            // AppID: the ID of the Azure AD Application
            string ApplicationID = ConfigurationManager.AppSettings["PBI_ApplicationID"];

            PBIAPIClient powerBIClient = new PBIAPIClient(ApplicationID);

            PBIDataset powerBIDataset = powerBIClient.GetDatasetByName("TestRefresh");

            powerBIDataset.Refresh();
        }
Esempio n. 26
0
        private static void Test_Parameters(PBIAPIClient pbic)
        {
            PBIDatasetParameters parameters = new PBIDatasetParameters();

            parameters.Items.Add(new PBIDatasetParameter("myTextParameter", "myUpdatedValue2"));
            parameters.Items.Add(new PBIDatasetParameter("myIntParameter", "789"));

            PBIDataset dataset = pbic.GetDatasetByName("myDataset");

            dataset.UpdateParameters(parameters);
        }
Esempio n. 27
0
        private static void Test_Rebind(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic; // "My Workspace"

            PBIReport srcReport = myGroup.GetReportByName("asdf");

            PBIDataset targetDataset = myGroup.GetDatasetByName("Adobe Analytics Traffic Analysis");

            srcReport.Clone("asdf2", myGroup, targetDataset);

            srcReport.Rebind(targetDataset);
        }
Esempio n. 28
0
        private static void Test_Rebind(PBIAPIClient pbic)
        {
            PBIGroup myGroup = pbic.GetGroupByName("RebindAPI"); // "My Workspace"

            PBIReport srcReport = myGroup.GetReportByName("Report");

            PBIDataset targetDataset = myGroup.GetDatasetByName("Dataset1_Copy");

            //srcReport.Clone("Report_Cloned", myGroup, targetDataset);

            srcReport.Rebind(targetDataset);
        }
Esempio n. 29
0
        public void PushRowsToPowerBI(PBIRows rows, PBIAPIClient powerBiAPI = null)
        {
            if (DataRows == null)
            {
                DataRows = new List <PBIRow>();
            }

            if (rows != null)
            {
                DataRows.AddRange(rows.Rows);
            }

            PushRowsToPowerBI(PBIJsonHelper.SerializeObject(DataRows), powerBiAPI);
        }
Esempio n. 30
0
        private static void Sample_DataTable(PBIAPIClient pbic)
        {
            PBIDataset dataset = new PBIDataset("MyPushDataset", PBIDefaultMode.Push);

            dataset.ParentPowerBIAPI = pbic;
            dataset.SyncFromPowerBI(); // check if a Dataset with the same ID or Name already exists in the PowerBI-Service

            // create a regular DataTable - but could also be derived from a SQL Database!
            DataTable dataTable = new DataTable();
            /* populate the dataTable */
            // create a PBI table from a regular DataTable object
            PBITable productsTable = new PBITable(dataTable);

            // publish the table and push the rows from the dataTable to the PowerBI table
            productsTable.PublishToPowerBI(true);
        }