Exemplo n.º 1
0
        /// <summary>
        /// Generate Token
        /// </summary>
        /// <returns></returns>
        private string GenerateToken()
        {
            IConfiguration ConfigurationData = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();

            string[]       getUserNamePwd = DbFunction.GetUserNamePassword();
            HttpWebRequest request        = (HttpWebRequest)HttpWebRequest.Create(ConfigurationData.GetValue <string>("BasicUrl") + Constants.GenerateUserToken);

            request.Method      = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var postData = "username="******"&password="******"&scope=openid offline_access";
            postData += "&client_id=ro.angular";
            postData += "&grant_type=password";
            postData += "&client_secret=secret";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            request.ContentLength = byteArray.Length;
            Stream dataStream = request.GetRequestStream();

            dataStream.Write(byteArray, 0, byteArray.Length);
            dataStream.Close();
            HttpWebResponse response      = null;
            var             access_token  = "";
            var             refresh_token = "";

            try
            {
                response = (HttpWebResponse)request.GetResponse();
                var     responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                JObject objects        = JObject.Parse(responseString);
                foreach (var kv in objects)
                {
                    if (kv.Key == "access_token")
                    {
                        access_token = kv.Value.ToString();
                    }
                    if (kv.Key == "refresh_token")
                    {
                        refresh_token = kv.Value.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Info("Error while getting file from GenerateToken  " + ex);
            }
            return(access_token);
        }
Exemplo n.º 2
0
        private void sendbitePointsCreditedNotificaion(string id, string amount, string PointsAdded, string PointsBalance, string PointsThreshold, string PercentProgress, int UserID, string Key)
        {
            //IConfiguration ConfigurationData = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true).AddEnvironmentVariables().Build();
            string[] getUserNamePwd = DbFunction.GetUserNamePassword();
            // string ApiUrl = ConfigurationData.GetValue<string>("BiteNotifictionBasicUrl") + ConstantsBitenotification.PointsCredited;
            string         ApiUrl  = GetBitePushUrl(Key) + ConstantsBitenotification.PointsCredited;
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ApiUrl);

            request.Method      = "POST";
            request.ContentType = "application/json";

            string json;

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                json = "{ \"UserObjectId\": \"" + id + "\", \"TransactionAmount\": \"" + amount + "\", \"PointsAdded\": \"" + PointsAdded
                       + "\", \"PointsBalance\": \"" + PointsBalance + "\", \"PointsThreshold\": \"" + PointsThreshold + "\", \"PercentProgress\": \"" + PercentProgress + "\"   } ";

                streamWriter.Write(json);
            }
            HttpWebResponse response = null;

            try
            {
                using (response = (HttpWebResponse)request.GetResponse())
                {
                    var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
                    var rescode        = response.StatusCode.ToString();
                    using (StreamWriter sw = File.AppendText(path))
                    {
                        sw.WriteLine("Notification :" + rescode);
                    }
                    InsertPartnerNotificationsLog("PointsCredited", ApiUrl, json, responseString, rescode, UserID);
                }
            }
            catch (Exception ex)
            {
                using (StreamWriter sw = File.AppendText(path))
                {
                    sw.WriteLine("Error : sendbitePointsCreditedNotificaion :" + ex.Message.ToString());
                    InsertPartnerNotificationsLog("PointsCredited", ApiUrl, json, ex.Message.ToString(), "Error", UserID);
                }
            }
            //            return access_token;
        }