static void Main(string[] args) { string url = "https://opendata.cbs.nl/ODataApi/odata/37296ned/UntypedDataSet?$select=Perioden,+TotaleBevolking_1,+Mannen_2,+Vrouwen_3"; ODataComposer oDataComposer = new ODataComposer(url); SeriesTableViewModel seriesTableViewModel = oDataComposer.GetTable(); Console.WriteLine(seriesTableViewModel.TableInfo.ShortTitle); Console.WriteLine(new String('-', 40)); ConsoleTableBuilder .From(seriesTableViewModel.Data) .ExportAndWriteLine(); }
public SeriesTableViewModel GetTable() { if (string.IsNullOrEmpty(_tableId)) { return(null); } PropertyItems regions = null; string json = GetJson(string.Format("{0}Tables?$format=json&$filter=(Identifier%20eq%20%27{1}%27)", _catalogUrl, _tableId)); TableInfoViewModel tableInfo = Deserialize <TableInfoViewModel>(json); json = GetJson(_url); SeriesTableViewModel seriesTableViewModel = Deserialize <SeriesTableViewModel>(json); string propertiesUrl = string.Format("{0}{1}/DataProperties?$format=json", _baseUrl, _tableId); json = GetJson(propertiesUrl); DataPropertiesViewModel properties = Deserialize <DataPropertiesViewModel>(json); if ((tableInfo == null) || (properties == null) || (seriesTableViewModel == null)) { return(null); } // Parse properties var regionAvailable = properties.DataProperties.FirstOrDefault(s => s.Datatype == "GeoDimension"); if (regionAvailable != null) { string regionKey = regionAvailable.Key; json = GetJson(string.Format("{0}{1}/{2}?$format=json", _baseUrl, _tableId, regionKey)); regions = Deserialize <PropertyItems>(json); } foreach (DataColumn col in seriesTableViewModel.Data.Columns) { var propertyColumn = properties.DataProperties.FirstOrDefault(s => s.Key == col.ColumnName); if (propertyColumn != null) { col.ColumnName = string.Format("{0} {1}", propertyColumn.Title, string.IsNullOrEmpty(propertyColumn.Unit) ? string.Empty : string.Format("({0})", propertyColumn.Unit)); if (propertyColumn.Type == "TimeDimension") { foreach (DataRow row in seriesTableViewModel.Data.Rows) { string periode = row[col.ColumnName].ToString(); row[col.ColumnName] = ParsePeriod(periode); } } if ((propertyColumn.Type == "GeoDimension") && (regions != null)) { foreach (DataRow row in seriesTableViewModel.Data.Rows) { string region = row[col.ColumnName].ToString(); var regionName = regions.Items.FirstOrDefault(x => x.Key == region); if (regionName != null) { row[col.ColumnName] = regionName.Title; } } } } } if (_transpose) { seriesTableViewModel.Data = Transpose(seriesTableViewModel.Data); } if ((tableInfo.TableInfos != null) && (tableInfo.TableInfos.Any())) { seriesTableViewModel.TableInfo = tableInfo.TableInfos[0]; } seriesTableViewModel.TableId = _tableId; return(seriesTableViewModel); }