Esempio n. 1
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. 2
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);
        }
Esempio n. 3
0
        public void PushRowsToPowerBI(List <PBIRow> rows = null, PBIAPIClient powerBiAPI = null)
        {
            if (rows != null)
            {
                DataRows = rows;
            }

            PushRowsToPowerBI(PBIJsonHelper.SerializeObject(DataRows), powerBiAPI);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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. 6
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. 7
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. 8
0
        public void AddGroupMember(PBIGroupMember groupMember)
        {
            if (this is PBIAPIClient) // if the caller is a PBIClient, we do not have a ParentGroup but need to use "My Workspace" instead
            {
                throw new Exception("Cannot add users to 'My Workspace'!");
            }

            using (HttpWebResponse response = ParentPowerBIAPI.SendPOSTRequest(ApiURL, PBIAPI.Users, PBIJsonHelper.SerializeObject(groupMember)))
            {
                string result = response.ResponseToString();
            }
        }