protected ICollection <MetadataRecord> MetadataRecords(Datasource datasource) { ICollection <MetadataRecord> metadataRecords = new List <MetadataRecord>(); if (datasource.XML.Element("connection").Element("metadata-records") != null) { IEnumerable <XElement> metadataXMls; if (datasource.XML.Elements("extract").Where(e => e.Attribute("enabled").Value == "true").SingleOrDefault() != null) { metadataXMls = datasource.XML.Element("extract").Element("connection").Element("metadata-records").Elements().Where(e => e.Attribute("class").Value != "capability"); } else { metadataXMls = datasource.XML.Element("connection").Element("metadata-records").Elements().Where(e => e.Attribute("class").Value != "capability"); } foreach (var record in metadataXMls) { MetadataRecord mr = new MetadataRecord(); mr.LocalName = record.Element("local-name") == null ? "" : record.Element("local-name").Value; mr.RemoteName = record.Element("remote-name") == null ? "" : record.Element("remote-name").Value; mr.ParentName = record.Element("parent-name") == null ? "" : record.Element("parent-name").Value; mr.Family = record.Element("family") == null ? "" : record.Element("family").Value; if (datasource.Relations != null) { var nameWithSchema = datasource.Relations.Where(x => x.Name == mr.Family).SingleOrDefault(); if (nameWithSchema != null) { mr.Family = nameWithSchema.Table; } } mr.ApproxCount = record.Element("approx-count") == null ? "" : record.Element("approx-count").Value; if (record.Element("statistics") != null) { var min = record.Element("statistics").Elements().SingleOrDefault(e => e.Attribute("aggregation").Value == "Min"); var max = record.Element("statistics").Elements().SingleOrDefault(e => e.Attribute("aggregation").Value == "Max"); mr.StatisticMin = min == null ? "" : min.Value; mr.StatisticMax = max == null ? "" : max.Value; } metadataRecords.Add(mr); } } return(metadataRecords); }
protected ICollection <Column> Columns(Datasource datasource) { ICollection <Column> columns = new List <Column>(); var columnsXml = datasource.XML.Elements("column"); foreach (var col in columnsXml) { columns.Add(new Column { Name = col.Attribute("name") == null ? "" : col.Attribute("name").Value, Caption = col.Attribute("caption") == null ? col.Attribute("name") == null ? "" : col.Attribute("name").Value : col.Attribute("caption").Value, Formula = col.Element("calculation") == null ? "" : col.Element("calculation").Attribute("formula") == null ? "" : col.Element("calculation").Attribute("formula").Value }); } foreach (var c in columns.Where(i => i.Name.StartsWith("[Calculation_"))) { foreach (var f in columns.Where(x => x.Formula != null)) { f.Formula = f.Formula.Replace(c.Name, c.Caption); } } var hiddenColumnsXml = datasource.XML.Elements("column").Where(e => e.Attribute("hidden") != null && e.Attribute("hidden").Value == "true"); var hiddenColumns = new HashSet <String>(); foreach (var col in hiddenColumnsXml) { hiddenColumns.Add(col.Attribute("name") == null ? "" : col.Attribute("name").Value); } for (int i = 0; i < columns.Count(); i++) { var column = columns.ElementAt(i); if (hiddenColumns.Contains(column.Name)) { column.Hidden = true; } } return(columns); }
protected ICollection <DatasourceFilter> DatasourceFilters(Datasource datasource) { ICollection <DatasourceFilter> filters = new List <DatasourceFilter>(); var filtersXml = datasource.XML.Elements("filter"); foreach (var col in filtersXml) { filters.Add(new DatasourceFilter { Column = col.Attribute("column") == null ? "" : col.Attribute("column").Value }); } return(filters); }
protected ICollection <ColumnMap> ColumnMaps(Datasource datasource) { ICollection <ColumnMap> columnMaps = new List <ColumnMap>(); if (datasource.XML.Element("connection").Element("cols") == null) { return(columnMaps); } var maps = datasource.XML.Element("connection").Element("cols").Elements("map"); var relations = datasource.XML.Element("connection").Descendants("relation").Where(x => x.Attribute("type").Value == "table"); if (relations != null) { foreach (var col in maps) { var key = col.Attribute("key") == null ? "" : col.Attribute("key").Value; var value = col.Attribute("value") == null ? "" : col.Attribute("value").Value; var searchTable = value.Split('.')[0].Replace("[", "").Replace("]", ""); var table = relations.Where(x => x.Attribute("name").Value == searchTable).FirstOrDefault(); var columnMap = new ColumnMap { Key = key, Value = value }; if (table != null) { columnMap.Table = table.Attribute("table").Value; } columnMaps.Add(columnMap); } } return(columnMaps); }