Exemplo n.º 1
0
        internal static dynamic GetBusinessDataFromNewAPI(string websiteName, string schemaName, string customerId, string developerId)
        {
            try
            {
                var fpDataRequest = (HttpWebRequest)WebRequest.Create(new Uri(String.Format(GetWebsiteDataEndPointFromNewAPI, KitsuneServerUrl, customerId, schemaName.ToLower())));
                fpDataRequest.Method      = "GET";
                fpDataRequest.ContentType = "application/json";
                fpDataRequest.Headers.Add(HttpRequestHeader.Authorization, developerId);


                var          ws       = fpDataRequest.GetResponse();
                StreamReader sr       = new StreamReader(ws.GetResponseStream());
                var          response = sr.ReadToEnd().ToString();
                if (!String.IsNullOrEmpty(response))
                {
                    var output = JsonConvert.DeserializeObject <dynamic>(response);
                    return(output["Data"][0]);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "KLM exception occured while GetBusinessData: " + websiteName);
            }

            return(null);
        }
Exemplo n.º 2
0
        internal static dynamic GetMetaInfoFromAPI(string projectId, string sourcePath, string developerId)
        {
            try
            {
                var fpDataRequest = (HttpWebRequest)WebRequest.Create(new Uri(String.Format(GetMetaInfoAPI, KitsuneServerUrl, projectId, sourcePath.ToLower())));
                fpDataRequest.Method      = "GET";
                fpDataRequest.ContentType = "application/json";
                fpDataRequest.Headers.Add(HttpRequestHeader.Authorization, developerId);


                var          ws       = fpDataRequest.GetResponse();
                StreamReader sr       = new StreamReader(ws.GetResponseStream());
                var          response = sr.ReadToEnd().ToString();
                if (!String.IsNullOrEmpty(response))
                {
                    var output = JsonConvert.DeserializeObject <dynamic>(response);
                    return(output);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "KLM exception occured while GetMetaInfoFromAPI SourcePath: " + sourcePath + " , ProjectId: " + projectId);
            }

            return(null);
        }
Exemplo n.º 3
0
        internal static dynamic GetBusinessDataWithMetaInfo(string projectId, string websiteName, string schemaName, string filePath, string currentPageNumber, string developerId)
        {
            try
            {
                var fpDataRequest = (HttpWebRequest)WebRequest.Create(new Uri(String.Format(GetBusinessDataWithMetaInfoAPI, KitsuneServerUrl, schemaName.ToLower(), projectId.ToLower(), websiteName.ToLower(), filePath.ToLower(), currentPageNumber.ToLower())));
                fpDataRequest.Method      = "GET";
                fpDataRequest.ContentType = "application/json";
                fpDataRequest.Headers.Add(HttpRequestHeader.Authorization, developerId);


                var          ws       = fpDataRequest.GetResponse();
                StreamReader sr       = new StreamReader(ws.GetResponseStream());
                var          response = sr.ReadToEnd().ToString();
                if (!String.IsNullOrEmpty(response))
                {
                    //JavaScriptSerializer responseJsonData = new JavaScriptSerializer();
                    //var output = responseJsonData.Deserialize<dynamic>(response);
                    var output = JsonConvert.DeserializeObject <dynamic>(response);
                    return(output["Data"][0]);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "KLM exception occured while GetBusinessData: " + websiteName);
            }

            return(null);
        }
        private bool DynamicFieldExists(dynamic obj, int field)
        {
            bool retval = false;

            try
            {
                dynamic finalObject = null;
                finalObject = obj;
                var temp = finalObject[field];
                retval = true;
            }
            catch (RuntimeBinderException) { }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "Kitsune Helper :: DynamicFieldExists ", null);
            }
            return(retval);
        }
Exemplo n.º 5
0
        internal static string GetSchemaForWebsiteFromNewAPI(string name)
        {
            try
            {
                var fpDataRequest = (HttpWebRequest)WebRequest.Create(new Uri(String.Format(GetSchemaForWebsiteEndPointFromNewAPI, KitsuneServerUrl, name)));
                fpDataRequest.Method      = "GET";
                fpDataRequest.ContentType = "application/json";


                var          ws       = fpDataRequest.GetResponse();
                StreamReader sr       = new StreamReader(ws.GetResponseStream());
                var          response = sr.ReadToEnd().ToString();
                if (!String.IsNullOrEmpty(response))
                {
                    return(response);
                }
            }
            catch (Exception ex)
            {
                EventLogger.Write(ex, "KLM exception occured while GetSchemaForWebsite: " + name);
            }

            return(null);
        }
Exemplo n.º 6
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);
        }