public void WillGetValueFromJsonDictionary() { var dictionary = new Dictionary <string, object> { { "key1", new Dictionary <string, object> { { "_content", "value1" } } }, { "key2", new Dictionary <string, object> { { "_content", "value2" } } } }; Assert.AreEqual("value1", dictionary.GetSubValue("key1")); Assert.AreEqual("value2", dictionary.GetSubValue("key2")); }
public void WillGetValueFromJsonDictionary() { var dictionary = new Dictionary<string, object> { {"key1", new Dictionary<string, object> {{"_content", "value1"}}}, {"key2", new Dictionary<string, object> {{"_content", "value2"}}} }; Assert.AreEqual("value1", dictionary.GetSubValue("key1")); Assert.AreEqual("value2", dictionary.GetSubValue("key2")); }
private static Photoset BuildPhotoset(Dictionary <string, object> dictionary) { return(new Photoset(dictionary.GetValue("id").ToString(), dictionary.GetValue("primary").ToString(), dictionary.GetValue("secret").ToString(), dictionary.GetValue("server").ToString(), int.Parse(dictionary.GetValue("farm").ToString()), int.Parse(dictionary.GetValue("photos").ToString()), int.Parse(dictionary.GetValue("videos").ToString()), dictionary.GetSubValue("title").ToString(), dictionary.GetSubValue("description").ToString(), PhotosetType.Album, null)); }
public static PhotosetsResponse GetPhotosetsResponseFromDictionary(this Dictionary <string, object> dictionary) { var photosets = new List <Photoset>(); IEnumerable <Dictionary <string, object> > photosetDictionary = ExtractPhotosets(dictionary); photosets.AddRange(photosetDictionary.Select(BuildPhotoset)); return(new PhotosetsResponse( int.Parse(dictionary.GetSubValue("photosets", "page").ToString()), int.Parse(dictionary.GetSubValue("photosets", "pages").ToString()), int.Parse(dictionary.GetSubValue("photosets", "perpage").ToString()), int.Parse(dictionary.GetSubValue("photosets", "total").ToString()), photosets)); }
private static Photo BuildPhoto(Dictionary <string, object> dictionary) { return(new Photo(dictionary.GetValue("id").ToString(), dictionary.GetValue("owner").ToString(), dictionary.GetValue("secret").ToString(), dictionary.GetValue("server").ToString(), int.Parse(dictionary.GetValue("farm").ToString()), dictionary.GetValue("title").ToString(), Convert.ToBoolean(dictionary.GetValue("ispublic")), Convert.ToBoolean(dictionary.GetValue("isfriend")), Convert.ToBoolean(dictionary.GetValue("isfamily")), dictionary.GetSubValue("description").ToString().Trim(), dictionary.GetValue("tags").ToString(), dictionary.GetValue("originalsecret").ToString(), dictionary.GetValue("originalformat").ToString(), dictionary.GetValue("url_sq").ToString(), dictionary.GetValue("url_q").ToString(), dictionary.GetValue("url_t").ToString(), dictionary.GetValue("url_s").ToString(), dictionary.GetValue("url_n").ToString(), dictionary.GetValue("url_m").ToString(), dictionary.GetValue("url_z").ToString(), dictionary.GetValue("url_c").ToString(), dictionary.GetValue("url_l").ToString(), dictionary.GetValue("url_o").ToString())); }
private static Photo BuildPhoto(Dictionary<string, object> dictionary) { return new Photo(dictionary.GetValue("id").ToString(), dictionary.GetValue("owner").ToString(), dictionary.GetValue("secret").ToString(), dictionary.GetValue("server").ToString(), Convert.ToInt32(dictionary.GetValue("farm")), dictionary.GetValue("title").ToString(), Convert.ToBoolean(dictionary.GetValue("ispublic")), Convert.ToBoolean(dictionary.GetValue("isfriend")), Convert.ToBoolean(dictionary.GetValue("isfamily")), dictionary.GetSubValue("description").ToString().Trim(), dictionary.GetValue("tags").ToString(), dictionary.GetValue("originalsecret").ToString(), dictionary.GetValue("originalformat").ToString(), dictionary.GetValue("url_sq").ToString(), dictionary.GetValue("url_q").ToString(), dictionary.GetValue("url_t").ToString(), dictionary.GetValue("url_s").ToString(), dictionary.GetValue("url_n").ToString(), dictionary.GetValue("url_m").ToString(), dictionary.GetValue("url_z").ToString(), dictionary.GetValue("url_c").ToString(), dictionary.GetValue("url_l").ToString(), dictionary.GetValue("url_o").ToString()); }
public static IEnumerable <Dictionary <string, object> > ExtractPhotosets(Dictionary <string, object> dictionary) { IEnumerable <Dictionary <string, object> > photosetDictionary; if (runningOnMono) { var photosetListAsArrayList = (ArrayList)dictionary.GetSubValue("photosets", "photoset"); photosetDictionary = photosetListAsArrayList.Cast <Dictionary <string, object> >(); } else { var photosetListAsIEnumerable = (IEnumerable <object>)dictionary.GetSubValue("photosets", "photoset"); photosetDictionary = photosetListAsIEnumerable.Cast <Dictionary <string, object> >(); } return(photosetDictionary); }
public static PhotosetsResponse GetPhotosetsResponseFromDictionary(this Dictionary <string, object> dictionary) { var photosets = new List <Photoset>(); IEnumerable <Dictionary <string, object> > photosetDictionary; if (runningOnMono) { var photosetListAsArrayList = (ArrayList)dictionary.GetSubValue("photosets", "photoset"); photosetDictionary = photosetListAsArrayList.Cast <Dictionary <string, object> >(); } else { var photosetListAsIEnumerable = (IEnumerable <object>)dictionary.GetSubValue("photosets", "photoset"); photosetDictionary = photosetListAsIEnumerable.Cast <Dictionary <string, object> >(); } photosets.AddRange(photosetDictionary.Select(BuildPhotoset)); return(new PhotosetsResponse( int.Parse(dictionary.GetSubValue("photosets", "page").ToString()), int.Parse(dictionary.GetSubValue("photosets", "pages").ToString()), int.Parse(dictionary.GetSubValue("photosets", "perpage").ToString()), int.Parse(dictionary.GetSubValue("photosets", "total").ToString()), photosets)); }
public static PhotosResponse GetPhotosResponseFromDictionary(this Dictionary <string, object> dictionary, bool isAlbum) { var apiresponseCollectionName = isAlbum ? "photoset" : "photos"; var photos = new List <Photo>(); IEnumerable <Dictionary <string, object> > photoDictionary; if (runningOnMono) { var photoListAsArrayList = (ArrayList)dictionary.GetSubValue(apiresponseCollectionName, "photo"); photoDictionary = photoListAsArrayList.Cast <Dictionary <string, object> >(); } else { var photoListAsIEnumerable = (IEnumerable <object>)dictionary.GetSubValue(apiresponseCollectionName, "photo"); photoDictionary = photoListAsIEnumerable.Cast <Dictionary <string, object> >(); } photos.AddRange(photoDictionary.Select(BuildPhoto)); return(new PhotosResponse( int.Parse(dictionary.GetSubValue(apiresponseCollectionName, "page").ToString()), int.Parse(dictionary.GetSubValue(apiresponseCollectionName, "pages").ToString()), int.Parse(dictionary.GetSubValue(apiresponseCollectionName, "perpage").ToString()), int.Parse(dictionary.GetSubValue(apiresponseCollectionName, "total").ToString()), photos)); }
/* * Here we are going to get all the albums and then we'll filter only the matching names. */ private async Task LoadCacheForMatchingAlbums(string methodName, User user, Preferences preferences, Dictionary <string, object> photosetsResponseDictionary) { preferences.Visited = false; String albumName = preferences.AlbumSearchName.ToLower().Trim(); bool all = albumName.Equals("*"); cachedFilteredPhotosets = new List <Dictionary <string, object> >(); int maxNum = int.Parse(photosetsResponseDictionary.GetSubValue("photosets", "total").ToString()); /* * See the behaviour for the optional 'page' parameter, from "https://www.flickr.com/services/api/explore/flickr.photosets.getList": * - The page of results to get. Currently, if this is not provided, all sets are returned, but this behaviour may change in future. */ var innerParams = new Dictionary <string, string> { { ParameterNames.UserId, user.UserNsId //let's skip the 'page' parameter } }; //we are going to get the list of all the albums, along with their title... var tmpPhotosetsToBeFiltered = (Dictionary <string, object>) await _oAuthManager.MakeAuthenticatedRequestAsync(methodName, innerParams); IEnumerator <Dictionary <string, object> > browser = DictionaryExtensions.ExtractPhotosets(tmpPhotosetsToBeFiltered).GetEnumerator(); //let's cache only the matching albums while (browser.MoveNext()) { Dictionary <string, object> cur = browser.Current; if (all || cur.GetSubValue("title").ToString().ToLower().Contains(albumName)) { cachedFilteredPhotosets.Add(cur); } } }
private static Photoset BuildPhotoset(Dictionary<string, object> dictionary) { return new Photoset(dictionary.GetValue("id").ToString(), dictionary.GetValue("primary").ToString(), dictionary.GetValue("secret").ToString(), dictionary.GetValue("server").ToString(), int.Parse(dictionary.GetValue("farm").ToString()), int.Parse(dictionary.GetValue("photos").ToString()), int.Parse(dictionary.GetValue("videos").ToString()), dictionary.GetSubValue("title").ToString(), dictionary.GetSubValue("description").ToString(), PhotosetType.Album, null); }