/// <summary> /// Returns the dataset in JSON-stat format /// </summary> /// <param name="collection"></param> /// <returns></returns> private static JsonStatCollection GetJsonStatCollectionObject(List <dynamic> collection) { var theJsonStatCollection = new JsonStatCollection(); var theCollectionLink = new JsonStatCollectionLink() { Item = new List <Item>() }; theJsonStatCollection.Link = theCollectionLink; if (collection == null) { return(theJsonStatCollection); } if (collection.Count == 0) { return(theJsonStatCollection); } foreach (var element in collection) { var aItem = new Item() { Href = new Uri(string.Format("{0}/{1}/{2}", Configuration_BSO.GetCustomConfig("url.application"), Utility.GetCustomConfig("APP_COOKIELINK_TABLE"), element.MtrCode)), Class = ItemClass.Dataset, Label = element.MtrTitle, Updated = DataAdaptor.ConvertToString(element.RlsLiveDatetimeFrom), Extension = new Dictionary <string, object>() }; var Frequency = new { name = element.FrqValue, code = element.FrqCode }; aItem.Extension.Add("copyright", new { name = element.CprValue, code = element.CprCode, href = element.CprUrl }); aItem.Extension.Add("exceptional", element.ExceptionalFlag); aItem.Extension.Add("language", new { code = element.LngIsoCode, name = element.LngIsoName }); aItem.Extension.Add("matrix", element.MtrCode); aItem.Extension.Add("frequency", Frequency); theCollectionLink.Item.Add(aItem); } return(theJsonStatCollection); }
/// <summary> /// Get a JSON-stat metadata based on a database read of collections /// </summary> /// <param name="collection"></param> /// <param name="statistics"></param> /// <param name="classifications"></param> /// <returns></returns> private Item GetJsonStatRelease(List <dynamic> collection, List <dynamic> statistics, List <dynamic> classifications, List <dynamic> periods, List <Format_DTO_Read> formats) { var jsStat = new Item(); // jsStat.Class = Class.Dataset; //jsStat.Version = Version.The20; jsStat.Id = new List <string>(); jsStat.Size = new List <long>(); var thisItem = collection.FirstOrDefault(); jsStat.Extension = new Dictionary <string, object>(); var Frequency = new { name = thisItem.FrqValue, code = thisItem.FrqCode }; jsStat.Extension.Add("copyright", new { name = thisItem.CprValue, code = thisItem.CprCode, href = thisItem.CprUrl }); jsStat.Extension.Add("exceptional", thisItem.ExceptionalFlag); jsStat.Extension.Add("language", new { code = thisItem.LngIsoCode, name = thisItem.LngIsoName }); jsStat.Extension.Add("matrix", thisItem.MtrCode); Format_DTO_Read fDtoMain = formats.Where(x => x.FrmType == Constants.C_SYSTEM_JSON_STAT_NAME).FirstOrDefault();// new Format_DTO_Read() { FrmDirection = Utility.GetCustomConfig("APP_FORMAT_DOWNLOAD_NAME"), FrmType = Constants.C_SYSTEM_JSON_STAT_NAME }; jsStat.Href = new Uri(Configuration_BSO.GetCustomConfig("url.restful") + string.Format(Utility.GetCustomConfig("APP_RESTFUL_DATASET"), Utility.GetCustomConfig("APP_READ_DATASET_API"), thisItem.MtrCode, fDtoMain.FrmType, fDtoMain.FrmVersion, thisItem.LngIsoCode)); jsStat.Label = thisItem.MtrTitle; jsStat.Updated = DataAdaptor.ConvertToString(thisItem.RlsLiveDatetimeFrom); jsStat.Dimension = new Dictionary <string, Dimension>(); formats.Remove(fDtoMain); var link = new DimensionLink { Alternate = new List <Alternate>() }; foreach (var f in formats) { link.Alternate.Add(new Alternate() { Href = Configuration_BSO.GetCustomConfig("url.restful") + string.Format(Utility.GetCustomConfig("APP_RESTFUL_DATASET"), Utility.GetCustomConfig("APP_READ_DATASET_API"), thisItem.MtrCode, f.FrmType, f.FrmVersion, thisItem.LngIsoCode) }); } jsStat.Link = link; formats.Add(fDtoMain); var statDimension = new Dimension() { Label = Utility.GetCustomConfig("APP_CSV_STATISTIC"), Category = new Category() { } }; jsStat.Dimension.Add(Utility.GetCustomConfig("APP_CSV_STATISTIC"), statDimension); jsStat.Id.Add(Frequency.code); List <PeriodRecordDTO_Create> plist = new List <PeriodRecordDTO_Create>(); foreach (var per in periods) { plist.Add(new PeriodRecordDTO_Create() { Code = per.PrdCode, Value = per.PrdValue }); } var timeDimension = new Dimension() { Label = Frequency.name, Category = new Category() { Index = plist.Select(v => v.Code).ToList(), Label = plist.ToDictionary(v => v.Code, v => v.Value) } }; jsStat.Dimension.Add(Frequency.code, timeDimension); foreach (var s in classifications) { Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add(s.ClsCode, s.ClsValue); var clsDimension = new Dimension() { Label = s.ClsValue, Category = new Category() { } }; jsStat.Dimension.Add(s.ClsCode, clsDimension); } jsStat.Role = new Role(); jsStat.Role.Metric = new List <string> { Utility.GetCustomConfig("APP_CSV_STATISTIC") }; jsStat.Role.Time = new List <string> { thisItem.FrqCode }; //Values will be blank in this case, all we want is metadata //jsStat.Value = new JsonStatValue() { AnythingArray = new List<ValueElement>() }; return(jsStat); }