示例#1
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;
                }
            }
        }
示例#2
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 TakeOver(PBIAPIClient powerBiAPI = null)
 {
     if (powerBiAPI == null)
     {
         if (ParentPowerBIAPI == null)
         {
             throw new Exception("No PowerBI API Object was supplied!");
         }
         else
         {
             powerBiAPI = ParentPowerBIAPI;
         }
     }
     using (HttpWebResponse response = powerBiAPI.SendPOSTRequest(ApiURL + "/takeover", null))
     {
         string result = response.ResponseToString();
     }
 }
示例#4
0
        private void PushRowsToPowerBI(string JSON, PBIAPIClient powerBiAPI = null)
        {
            if (ParentDataset == null)
            {
                throw new Exception("Cannot push 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("PushRowsToPowerBI is only supported for Datasets in DefaultMode 'Push'!");
            }

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

            Task.Factory.StartNew(() =>
            {
                using (HttpWebResponse response = powerBiAPI.SendPOSTRequest(ApiURL, PBIAPI.Rows, JSON))
                {
                    string result = response.ResponseToString();
                }
            });
        }