Exemplo n.º 1
0
        public static TCBMP getTCBMP(string output)
        {
            TCBMP tcbmp = new TCBMP();
            var   ser   = new DataContractJsonSerializer(typeof(TCBMP));

            using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(output)))
            {
                tcbmp = (TCBMP)ser.ReadObject(ms);
            }
            return(tcbmp);
        }
Exemplo n.º 2
0
        public static TCBMP ValidateTCBMP(string token, string tcbmpid, string inspId)
        {
            var scriptServer = WebConfigurationManager.AppSettings["constServer"] + "/v4/scripts/SO_SEARCH_TCBMP";

            var serializer = new JavaScriptSerializer();

            serializer.MaxJsonLength = int.MaxValue;

            var serializedResult = serializer.Serialize(new Dictionary <string, string>
            {
                ["recordID"] = tcbmpid,
                ["inspId"]   = inspId
            });

            var client  = new RestClient(scriptServer);
            var request = new RestRequest(Method.POST);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("authorization", token);
            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json", serializedResult, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            Message message = serializer.Deserialize <Message>(response.Content);

            log.Info("In SetDetailsRest response Message: " + message.result.Message + " status: " + message.status + " code: " + message.code + " err_message: " + message.message);

            if (message.status == 200)
            {
                string tcbmpData = message.result.Message;
                TCBMP  tcbmpdata = getTCBMP(tcbmpData);
                tcbmpdata.token = token;
                return(tcbmpdata);
            }
            return(null);
        }