Esempio n. 1
0
        private void StreamRowsToPowerBI(string JSON, string apiKey, PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot stream 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;
                }
            }

            if (ParentDataset.PBIDefaultMode == PBIDefaultMode.Push)
            {
                throw new Exception("StreamRowsToPowerBI is only supported for Datasets in DefaultMode 'Streaming' or 'PushStreaming'!");
            }

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

            Task.Factory.StartNew(() =>
            {
                //https://api.powerbi.com/beta/<TenantID>/datasets/<DatasetID>/rows?key={MyKey}
                using (HttpWebResponse response = powerBiAPI.SendGenericWebRequest(string.Format("https://api.powerbi.com/beta/{0}/datasets/{1}/rows?key={2}", powerBiAPI.TenantId, ParentDataset.Id, apiKey), "POST", JSON))
                {
                    string result = response.ResponseToString();
                }
            });
        }
Esempio n. 2
0
        public void UpdateDatatsourceInPowerBI(string newCredentials, PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot update a Gateway Datasource in PowerBI if the GatewayDatasource object 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.SendGenericWebRequest(ApiURL, "PATCH", newCredentials))
            {
                string result = response.ResponseToString();
            }
        }