Example #1
0
        /// <summary>
        /// Map RESTful parameters to JsonRpc parameters
        /// </summary>
        /// <param name="restfulParameters"></param>
        /// <returns></returns>
        internal dynamic ReadDataset_MapParameters(dynamic restfulParameters)
        {
            dynamic jsonStatParameters = new ExpandoObject();
            dynamic obj  = new ExpandoObject();
            var     dict = (IDictionary <string, object>)obj;


            dynamic extension = new ExpandoObject();
            dynamic dimension = new ExpandoObject();



            extension.matrix = restfulParameters[1];

            extension.language = restfulParameters.Count >= 5 ? new { code = restfulParameters[4] } : new { code = Configuration_BSO.GetCustomConfig("language.iso.code") };

            if (((string)extension.language.code).Length == 0)
            {
                extension.language = new { code = Configuration_BSO.GetCustomConfig("language.iso.code") }
            }
            ;

            extension.format = new { type = restfulParameters[2], version = restfulParameters[3] };


            jsonStatParameters.extension = extension;
            jsonStatParameters.dimension = dimension;

            dict["class"]     = "query";
            dict["id"]        = new string[] { };
            dict["dimension"] = dimension;
            dict["extension"] = extension;
            dict["version"]   = "2.0";
            dict["m2m"]       = true;


            string suffix;

            using (Format_BSO bso = new Format_BSO(new ADO("defaultConnection")))
            {
                this.MimeType = bso.GetMimetypeForFormat(new Format_DTO_Read()
                {
                    FrmType = restfulParameters[2], FrmVersion = restfulParameters[3]
                });

                suffix = bso.GetFileSuffixForFormat(new Format_DTO_Read()
                {
                    FrmType = restfulParameters[2], FrmVersion = restfulParameters[3]
                });
            };


            if (suffix != null)
            {
                this.FileName = extension.matrix + DateTime.Now.ToString("yyyyMMddHHmmss") + suffix;
            }

            return(Utility.JsonSerialize_IgnoreLoopingReference(dict));
        }
    }
Example #2
0
        /// <summary>
        ///  Returns a Collection of JsonStat items. RESTful version
        /// </summary>
        /// <param name="restfulRequest"></param>
        /// <returns></returns>
        public static dynamic ReadCollection(RESTful_API restfulRequest)
        {
            //A pre-validation. If a validation problem is found then an output containing the error will be created and returned immediately
            var vldOutput = ValidateRest <Cube_VLD_REST_ReadCollection>(restfulRequest, new Cube_VLD_REST_ReadCollection());

            if (vldOutput != null)
            {
                return(vldOutput);
            }

            //Map the RESTful request to an equivalent Json Rpc request
            JSONRPC_API jsonRpcRequest = Map.RESTful2JSONRPC_API(restfulRequest);

            //Map the parameters - this is specific to the function
            Cube_MAP map = new Cube_MAP();

            jsonRpcRequest.parameters = map.ReadCollection_MapParameters(jsonRpcRequest.parameters);

            //Run the request as a Json Rpc call
            JSONRPC_Output rsp = new Cube_BSO_ReadCollection(jsonRpcRequest, true).Read().Response;

            string mimeType;

            using (Format_BSO fbso = new Format_BSO(new ADO("defaultConnection")))
            {
                mimeType = fbso.GetMimetypeForFormat(new Format_DTO_Read()
                {
                    FrmType = Constants.C_SYSTEM_JSON_STAT_NAME
                });
            };

            //Convert the JsonRpc output to RESTful output
            var response = Map.JSONRPC2RESTful_Output(rsp, mimeType);

            if (rsp.data == null)
            {
                response.statusCode = HttpStatusCode.NoContent;
            }
            response.fileName = map.FileName;
            return(response);
        }
Example #3
0
        public static dynamic ReadDataset(RESTful_API restfulRequest)
        {
            try
            {
                //A pre-validation. If a validation problem is found then an output containing the error will be created and returned immediately
                var vldOutput = ValidateRest <Cube_VLD_REST_ReadDataset>(restfulRequest, new Cube_VLD_REST_ReadDataset());
                if (vldOutput != null)
                {
                    return(vldOutput);
                }

                //Map the RESTful request to an equivalent Json Rpc request
                JSONRPC_API jsonRpcRequest = Map.RESTful2JSONRPC_API(restfulRequest);

                //Map the parameters - this is specific to the function
                Cube_MAP map = new Cube_MAP();
                //jsonRpcRequest.parameters = map.ReadDataset_MapParameters(jsonRpcRequest.parameters);

                JsonStatQuery jq = map.ReadMetadata_MapParametersToQuery(restfulRequest.parameters);

                jq.Extension["codes"] = true;

                jsonRpcRequest.parameters = Utility.JsonSerialize_IgnoreLoopingReference(jq);


                //Run the request as a Json Rpc call
                JSONRPC_Output rsp = new Cube_BSO_ReadDataset(jsonRpcRequest).Read().Response;

                if (rsp.error != null)
                {
                    return(Map.JSONRPC2RESTful_Output(rsp, null, HttpStatusCode.NoContent, HttpStatusCode.InternalServerError));
                }

                Format_DTO_Read format = new Format_DTO_Read()
                {
                    FrmType = restfulRequest.parameters[Constants.C_DATA_RESTFUL_FORMAT_TYPE], FrmVersion = restfulRequest.parameters[Constants.C_DATA_RESTFUL_FORMAT_VERSION]
                };

                string mtype = null;
                using (Format_BSO fbso = new Format_BSO(new ADO("defaultConnection")))
                {
                    mtype = fbso.GetMimetypeForFormat(format);
                };
                //Convert the JsonRpc output to RESTful output
                var response = Map.JSONRPC2RESTful_Output(rsp, mtype, rsp.data == null ? HttpStatusCode.NotFound : HttpStatusCode.NoContent);

                string suffix;
                using (Format_BSO bso = new Format_BSO(new ADO("defaultConnection")))
                {
                    suffix = bso.GetFileSuffixForFormat(format);
                };


                response.fileName = restfulRequest.parameters[Constants.C_DATA_RESTFUL_MATRIX] + "." + DateTime.Now.ToString("yyyyMMddHHmmss") + suffix;
                return(response);
            }
            catch (Exception ex)

            {
                RESTful_Output error = new RESTful_Output
                {
                    statusCode = HttpStatusCode.InternalServerError
                };

                Log.Instance.Debug(ex.Message);
                return(error);
            }
        }