コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: Cube_BSO.cs プロジェクト: Chriz-ONeill/PxStat
        /// <summary>
        /// Get the collection with metadata
        /// </summary>
        /// <param name="theAdo"></param>
        /// <param name="theCubeDTO"></param>
        /// <param name="theResponse"></param>
        /// <returns></returns>
        internal dynamic ExecuteReadCollection(ADO theAdo, Cube_DTO_ReadCollection DTO)
        {
            var ado = new Cube_ADO(theAdo);

            var dbData = ado.ReadCollectionMetadata(DTO.language, DTO.datefrom, DTO.product);


            List <dynamic> jsonStatCollection = new List <dynamic>();

            //Get a list of individual matrix data entities
            List <dynamic> releases = getReleases(dbData);


            var theJsonStatCollection = new JsonStatCollection();

            theJsonStatCollection.Link      = new JsonStatCollectionLink();
            theJsonStatCollection.Link.Item = new List <Item>();

            List <Format_DTO_Read> formats = new List <Format_DTO_Read>();

            using (Format_BSO format = new Format_BSO(new ADO("defaultConnection")))
            {
                formats = format.Read(new Format_DTO_Read()
                {
                    FrmDirection = Utility.GetCustomConfig("APP_FORMAT_DOWNLOAD_NAME")
                });
            };

            //For each of these, get a list of statistics and a list of classifications
            //Then get the JSON-stat for that metadata and add to jsonStatCollection
            foreach (var rls in releases)
            {
                List <dynamic> thisReleaseMetadata = dbData.Where(x => x.RlsCode == rls.RlsCode).Where(x => x.LngIsoCode == rls.LngIsoCode).ToList <dynamic>();

                List <dynamic> stats           = getStatistics(thisReleaseMetadata);
                List <dynamic> classifications = getClassifications(thisReleaseMetadata);
                List <dynamic> periods         = getPeriods(thisReleaseMetadata);
                theJsonStatCollection.Link.Item.Add(GetJsonStatRelease(thisReleaseMetadata, stats, classifications, periods, formats));
            }

            //Get the minimum next release date. The cache can only live until then.
            //If there's no next release date then the cache will live for the maximum configured amount.

            DateTime minDateItem = default;


            dynamic minimum = null;

            if (dbData != null)
            {
                minimum     = dbData.Where(x => x.RlsLiveDatetimeFrom > DateTime.Now).Min(x => x.RlsLiveDatetimeFrom);
                minDateItem = minimum ?? default(DateTime);
            }

            if (minDateItem < DateTime.Now)
            {
                minDateItem = default(DateTime);
            }

            var result = new JRaw(Serialize.ToJson(theJsonStatCollection));

            MemCacheD.Store_BSO <dynamic>("PxStat.Data", "Cube_API", "ReadCollection", DTO, result, minDateItem, Constants.C_CAS_DATA_CUBE_READ_COLLECTION);


            // return the formatted data. This is an array of JSON-stat objects.
            return(result);
        }
コード例 #3
0
 public static string ToJson(this JsonStatCollection self) => JsonConvert.SerializeObject(self, CollectionConverter.Settings);