コード例 #1
0
        public async Task <PBIDataSet> CreateDataSet(string authToken, PBIDataSet dataSet, bool includeData = false)
        {
            if (authToken == null)
            {
                throw new ArgumentNullException("authToken");
            }
            if (dataSet == null)
            {
                throw new ArgumentNullException("dataSet");
            }

            using (var client = new HttpClient())
            {
                client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", authToken));
                client.DefaultRequestHeaders.Add("Accept", "application/json");

                var jObj = JObject.FromObject(dataSet, GetJSONSerializer());

                jObj.Remove("id");
                jObj.Remove("defaultRetentionPolicy");

                var jObjText = jObj.ToString();

                var bodyContent = new StringContent(jObjText, System.Text.Encoding.Default, "application/json");

                using (var response = await client.PostAsync(String.Format("{0}/datasets", baseAddress), bodyContent))
                {
                    response.EnsureSuccessStatusCode();

                    var responseString = await response.Content.ReadAsStringAsync();

                    var oResponse = JObject.Parse(responseString);

                    dataSet.Id = oResponse.SelectToken("id").ToString();
                }
            }

            if (includeData)
            {
                foreach (var table in dataSet.Tables)
                {
                    await AddTableRows(authToken, dataSet.Id, table.Name, table.Rows, 500);
                }
            }

            return(dataSet);
        }
コード例 #2
0
ファイル: PBIProvider.cs プロジェクト: ninocrudele/Aziverso
        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();
            }
        }