예제 #1
0
        internal static async System.Threading.Tasks.Task <dynamic> GetWebActionsDataAsync(string authId, string widgetName, string fpId, string themeid, bool isCacheEnabled = false)
        {
            try
            {
                if (!String.IsNullOrEmpty(widgetName))
                {
                    //if (isCacheEnabled)
                    //{
                    //    var response = CacheHelper.GetThirdPartyAPIResponseFromCache("WEBACTIONS-" + widgetName.ToUpper() + fpId.ToUpper(), isCacheEnabled);
                    //    if (!string.IsNullOrEmpty(response))
                    //    {
                    //        return JsonConvert.DeserializeObject<dynamic>(response);
                    //    }
                    //}
                    //if (!userMapping.ContainsKey(themeid))
                    //{
                    //    HttpClient listclient = new HttpClient();
                    //    listclient.DefaultRequestHeaders.Add("Authorization", userMapping[themeid]);
                    //    var listresult = listclient.GetAsync(WebActionListEndPoint).Result;
                    //    if (listresult.StatusCode == HttpStatusCode.OK)
                    //    {
                    //        var response = listresult.Content.ReadAsStringAsync().Result;
                    //        if (response != null)
                    //        {
                    //            var finalValue = JObject.Parse(response);
                    //            JToken value = null;
                    //            if (finalValue.TryGetValue("Token", out value))
                    //            {
                    //                userMapping.Add(themeid, value.ToString());
                    //            }

                    //        }
                    //    }
                    //    else
                    //        EventLogger.Write(System.Diagnostics.TraceLevel.Error, "GetWebActionsList api failure : " + listresult.Content.ReadAsStringAsync().Result);
                    //}

                    //if (userMapping.ContainsKey(themeid))
                    if (!String.IsNullOrEmpty(authId))
                    {
                        HttpClient client = new HttpClient();
                        client.DefaultRequestHeaders.Add("Authorization", authId);
                        client.DefaultRequestHeaders.Add("ContentType", "application/json");
                        var url    = string.Format(WebActionEndPoint, widgetName.ToLower(), "query={WebsiteId:'" + fpId + "'}");
                        var result = await client.GetAsync(url);

                        if (result.StatusCode == HttpStatusCode.OK)
                        {
                            var response = await result.Content.ReadAsStringAsync();

                            var finalValue = JsonConvert.DeserializeObject <dynamic>(response);

                            //if (isCacheEnabled)
                            //{
                            //    CacheHelper.UpdateThirdPartyAPI("WEBACTIONS-" + widgetName.ToUpper() + fpId.ToUpper(), response);
                            //}

                            return(finalValue);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "KLM exception occured while GetWebActionsData: " + widgetName);
            }

            return(null);
        }