From 43472f962df06715fb630cd2b2d81988abb783d5 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Tue, 11 Feb 2014 05:30:06 +0200 Subject: [PATCH 1/4] add url --- Core/SharpSquare.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Core/SharpSquare.cs b/Core/SharpSquare.cs index 993f269..7ed3510 100644 --- a/Core/SharpSquare.cs +++ b/Core/SharpSquare.cs @@ -50,6 +50,7 @@ private string Request(string url, HttpMethod httpMethod) private string Request(string url, HttpMethod httpMethod, string data) { + url = url + "&v=20140101"; string result = string.Empty; HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url); httpWebRequest.Method = httpMethod.ToString(); From b04ec4555a3ff5d985f2fc8dbe5dc4a6908af337 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Tue, 11 Feb 2014 05:37:55 +0200 Subject: [PATCH 2/4] added code for seeing changes --- Core/SharpSquare.cs | 134 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 133 insertions(+), 1 deletion(-) diff --git a/Core/SharpSquare.cs b/Core/SharpSquare.cs index 7ed3510..2fdcad3 100644 --- a/Core/SharpSquare.cs +++ b/Core/SharpSquare.cs @@ -7,6 +7,9 @@ using System.IO; using System.Web.Script.Serialization; using FourSquare.SharpSquare.Entities; +using System.Collections; +using System.Reflection; +using System.Diagnostics; namespace FourSquare.SharpSquare.Core { @@ -96,7 +99,124 @@ private FourSquareSingleResponse GetSingle(string endpoint, Dictionary(endpoint, parameters, false); } + /// + /// TODO: make this add to global errors to return to the caller + /// + /// + private void InterceptError(string message) + { + var cc = Console.ForegroundColor; + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message); + Console.ForegroundColor = cc; + Debug.WriteLine(message); + } + private object DeserializeObject(Dictionary dictItem, Type tip) + { + var newInstance = Activator.CreateInstance(tip); + var isDictionary = (tip.GetInterface("IDictionary") != null); + PropertyInfo p = null; + foreach (var k in dictItem.Keys) + { + var ser = new JavaScriptSerializer().Serialize(dictItem[k]); + + + Type tipP = null; + if (isDictionary) + { + tipP = tip.GetGenericArguments()[1]; + } + else + { + + try + { + p = tip.GetProperty(k); + if (p == null) + throw new ArgumentNullException(k); + } + catch (Exception) + { + //Console.WriteLine(ex.Message); + InterceptError("missing property:" + k + " to class" + tip.FullName + " value:" + ser); + continue; + } + tipP = p.PropertyType; + } + + + if (tipP.IsClass && tipP.FullName != typeof(string).FullName) + { + + dynamic val = null; + try + { + val = new JavaScriptSerializer().Deserialize(ser, tipP); + } + catch (Exception ex) + { + Console.WriteLine("error for class:" + k + ex.Message); + IList arr = dictItem[k] as object[]; + if (arr == null) + { + arr = dictItem[k] as ArrayList; + } + if (arr == null) + { + var t1 = dictItem[k] as Dictionary; + if (t1 == null) + { + InterceptError("Not a dictionary, not an array - please contact ignatandrei@yahoo.com for " + k); + } + + val = DeserializeObject(dictItem[k] as Dictionary, tipP); + + } + else + { + val = Activator.CreateInstance(tipP); + var tipGen = tipP.GetGenericArguments()[0]; + foreach (var obj in arr) + { + val.Add((dynamic)DeserializeObject(obj as Dictionary, tipGen)); + } + } + + + } + + if (isDictionary) + { + ((IDictionary)newInstance).Add(k, Convert.ChangeType(val, tipP)); + } + else + { + p.SetValue(newInstance, Convert.ChangeType(val, tipP), null); + + } + } + else//simple int , string, + { + try + { + if (isDictionary) + { + ((IDictionary)newInstance).Add(k, Convert.ChangeType(dictItem[k], tipP)); + } + else + { + p.SetValue(newInstance, Convert.ChangeType(dictItem[k], tipP), null); + } + } + catch (Exception ex) + { + InterceptError("!!!not a simple property " + k + " from " + tip + " value:" + ser); + } + } + } + return newInstance; + } private FourSquareSingleResponse GetSingle(string endpoint, Dictionary parameters, bool unauthenticated) where T : FourSquareEntity { string serializedParameters = ""; @@ -116,7 +236,19 @@ private FourSquareSingleResponse GetSingle(string endpoint, Dictionary fourSquareResponse = new JavaScriptSerializer().Deserialize>(json); + FourSquareSingleResponse fourSquareResponse; + try + { + fourSquareResponse = new JavaScriptSerializer().Deserialize>(json); //json parameter is the string content of the api + } + catch (Exception ex) + { + var obj = new JavaScriptSerializer().Deserialize>(json); //json parameter is the string content of the api + fourSquareResponse = DeserializeObject(obj, typeof(FourSquareSingleResponse)) as FourSquareSingleResponse; + //TODO: look into debug in VS to see what it is missing + Debugger.Break(); + throw; + } return fourSquareResponse; } From f6defc74292e00b3410b6f4a6a684cf4ff12a486 Mon Sep 17 00:00:00 2001 From: Andrei Ignat Date: Tue, 11 Feb 2014 05:43:23 +0200 Subject: [PATCH 3/4] added image --- Entities/Category.cs | 9 ++++++++- Entities/User.cs | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Entities/Category.cs b/Entities/Category.cs index c618272..efc069e 100644 --- a/Entities/Category.cs +++ b/Entities/Category.cs @@ -5,8 +5,15 @@ namespace FourSquare.SharpSquare.Entities { + public class ImageNew + { + public string prefix { get; set; } + public string suffix { get; set; } + + } public class Category : FourSquareEntity { + /// /// A unique identifier for this category. /// @@ -48,7 +55,7 @@ public string shortName /// Combine prefix with a size (32, 44, 64, and 88 are available) and suffix, e.g. https://foursquare.com/img/categories/food/default_64.png. /// To get an image with a gray background, use bg_ before the size, e.g. https://foursquare.com/img/categories_v2/food/icecream_bg_32.png. /// - public string icon + public Image icon { get; set; diff --git a/Entities/User.cs b/Entities/User.cs index 2a35860..fdd3747 100644 --- a/Entities/User.cs +++ b/Entities/User.cs @@ -46,7 +46,7 @@ public string gender /// /// URL of a profile picture for this user. /// - public string photo + public ImageNew photo { get; set; From 9f498eca810bdd0a25efa603212973903195e2bd Mon Sep 17 00:00:00 2001 From: "whitesource-bolt-for-github[bot]" Date: Mon, 17 Jun 2019 20:57:40 +0000 Subject: [PATCH 4/4] Initial WhiteSource configuration file --- .whitesource | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .whitesource diff --git a/.whitesource b/.whitesource new file mode 100644 index 0000000..f056952 --- /dev/null +++ b/.whitesource @@ -0,0 +1,8 @@ +{ + "generalSettings": { + "shouldScanRepo": true + }, + "checkRunSettings": { + "vulnerableCheckRunConclusionLevel": "failure" + } +} \ No newline at end of file