예제 #1
0
        /// <summary>
        /// Map RESTful parameters to JsonRpc parameters
        /// </summary>
        /// <param name="restfulParameters"></param>
        /// <returns></returns>
        internal dynamic ReadMetadata_MapParameters(dynamic restfulParameters)
        {
            Format_DTO_Read format;

            using (Format_BSO bso = new Format_BSO(new ADO("defaultConnection")))
            {
                format = bso.Read(new Format_DTO_Read()
                {
                    FrmType = Constants.C_SYSTEM_JSON_STAT_NAME, FrmDirection = Format_DTO_Read.FormatDirection.DOWNLOAD.ToString()
                }).FirstOrDefault();
            }

            //Create a null format if one is not found. This will be caught in validation
            if (format == null)
            {
                format = new Format_DTO_Read();
            }

            var prm = JObject.FromObject(new
            {
                matrix   = restfulParameters.Count >= 2 ? restfulParameters[1] : null,
                language = restfulParameters.Count >= 3 ? restfulParameters[2] : null,
                format   = new { type = format.FrmType, version = format.FrmVersion }
            });

            // To make the parameters agnostic of trailing slashes:
            if (restfulParameters.Count >= 2)
            {
                if (restfulParameters[1].ToString().Length == 0)
                {
                    prm["matrix"] = null;
                }
            }
            if (restfulParameters.Count >= 3)
            {
                if (restfulParameters[2].ToString().Length == 0)
                {
                    prm["language"] = null;
                }
            }

            return(prm);
        }
예제 #2
0
        /// <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);
        }