Esempio n. 1
0
        public static bool GetToken(string vstrUser, string vstrPWord, ref string rstrToken, string vstrEndPt = "")
        {
            string  ENDPOINT_TOKEN = APIHelper.BASE_URL + "/Token";
            string  strResult      = "";
            string  strPostdata;
            JObject jobjThis;
            JToken  jtSuccess;
            bool    blnOk = false;

            try
            {
                rstrToken = "";

                if (!string.IsNullOrWhiteSpace(vstrEndPt))
                {
                    ENDPOINT_TOKEN = vstrEndPt + "Token";
                }

                strPostdata = "userName="******"&password="******"&grant_type=password";
                if (WebCallHelper.PostCall(ENDPOINT_TOKEN, strPostdata, ref strResult))
                {
                    jobjThis  = JObject.Parse(strResult);
                    jtSuccess = jobjThis["access_token"];
                    rstrToken = jtSuccess.ToString();
                    blnOk     = true;
                }
            }
            catch (Exception exc)
            {
                rstrToken = exc.Message;
            }

            return(blnOk);
        }
Esempio n. 2
0
        public bool PostInfo <T1, T2>(string vstrEndPoint,
                                      string vstrUser,
                                      T1 vclsPostBody,
                                      ref T2 rclsInfoOut,
                                      ref string rstrErr)
        {
            JavaScriptSerializer jss;
            string strToken  = "";
            string strResult = "";
            string strPostData;
            string strURL;
            bool   blnOk = false;

            try
            {
                if (RedisHelper.GetIt("TP-" + vstrUser, ref strToken))
                {
                    strURL = HttpUtility.UrlPathEncode(vstrEndPoint);

                    jss         = new JavaScriptSerializer();
                    strPostData = jss.Serialize(vclsPostBody);

                    if (WebCallHelper.PostCall(strURL, strPostData, ref strResult, strToken) &&
                        !string.IsNullOrWhiteSpace(strResult))
                    {
                        rclsInfoOut = jss.Deserialize <T2>(strResult);
                        blnOk       = true;
                    }
                    else
                    {
                        rstrErr = "Cannot retrieve events:" + strResult;
                    }
                }
                else
                {
                    rstrErr = "Missing second stage authentication";
                }
            }
            catch (Exception exc)
            {
                rstrErr     = exc.Message;
                rclsInfoOut = default(T2);
            }

            return(blnOk);
        }
Esempio n. 3
0
        public bool GetEntity <T>(string vstrEndPoint,
                                  string vstrUser,
                                  int vintDS,
                                  ref T rclsItem,
                                  ref string rstrErr,
                                  string vstrOtherParams = "")
        {
            JavaScriptSerializer jss;
            string strToken  = "";
            string strResult = "";
            string strURL;
            bool   blnOk = false;

            try
            {
                if (RedisHelper.GetIt("TP-" + vstrUser, ref strToken))
                {
                    strURL = vstrEndPoint + "?dsID=" + HttpUtility.UrlEncode(vintDS.ToString()) + vstrOtherParams;
                    strURL = HttpUtility.UrlPathEncode(strURL);

                    if (WebCallHelper.GetCall(strURL, ref strResult, strToken) &&
                        !string.IsNullOrWhiteSpace(strResult))
                    {
                        jss      = new JavaScriptSerializer();
                        rclsItem = jss.Deserialize <T>(strResult);
                        blnOk    = true;
                    }
                    else
                    {
                        rstrErr = "Cannot retrieve item";
                    }
                }
                else
                {
                    rstrErr = "Missing second stage authentication";
                }
            }
            catch (Exception exc)
            {
                rstrErr  = exc.Message;
                rclsItem = default(T);
            }

            return(blnOk);
        }