/// <summary> /// Constructor /// </summary> public User() : base() { ContactInfo = new Dictionary<string, string>(); Cameras = new List<string>(); Lenses = new List<string>(); PhotoStream = new FeatureStream("user"); FriendStream = new FeatureStream("user_friends"); FavStream = new FeatureStream("user_favourites"); }
public static List<Photo> PhotosWithJson(FeatureStream stream, string result) { var newPhotos = new List<Photo>(); var evt = new StoragePhotoStreamEventArgs(); try { JObject rootObject = JObject.Parse(result); int page = int.Parse(rootObject["current_page"].ToString()); int totalItems = int.Parse(rootObject["total_items"].ToString()); // Update stream photo count stream.PhotoCount = totalItems; JToken token; if (rootObject.TryGetValue("photos", out token)) { JArray photoArray = JArray.Parse(rootObject["photos"].ToString()); foreach (JObject photoObject in photoArray) { Photo photo = PhotoFactory.PhotoWithJObject(photoObject); if (photo != null && !stream.Photos.Contains(photo)) { stream.Photos.Add(photo); newPhotos.Add(photo); } } } // Dispatch event evt.Stream = stream; evt.Page = page; evt.PhotoCount = totalItems; evt.NewPhotos.AddRange(newPhotos); if (StorageCore.Instance.PhotoStreamUpdated != null) { StorageCore.Instance.PhotoStreamUpdated(StorageCore.Instance, evt); } } catch (Exception ex) { Debug.WriteLine(ex); if (StorageCore.Instance.PhotoStreamUpdated != null) { StorageCore.Instance.PhotoStreamUpdated(StorageCore.Instance, evt); } } return newPhotos; }
/// <summary> /// Constructor /// </summary> public StorageCore() { UserCache = new Dictionary<string, User>(); UserList = new List<User>(); PhotoCache = new Dictionary<string, Photo>(); // Category InitializePhotoCategoryTable(); // Feature streams PopularStream = new FeatureStream("popular"); UpcomingStream = new FeatureStream("upcoming"); EditorChoiceStream = new FeatureStream("editors"); TodayStream = new FeatureStream("fresh_today"); YesterdayStream = new FeatureStream("fresh_yesterday"); WeekStream = new FeatureStream("fresh_week"); // User events APICore.Instance.GetCurrentUserInfoComplete += OnCurrentUserInfoRetrieved; }
public async Task<string> GetPhotoStreamAsync(FeatureStream stream, int page = 1, int perPage = 20, List<KeyValuePair<string, string>> additionalParams = null) { string timestamp = DateTimeUtils.GetTimestamp(); string nonce = GenerateNonce(); // Encode the request string List<KeyValuePair<string, string>> plist = new List<KeyValuePair<string, string>>(); plist.Add(new KeyValuePair<string, string>("feature", stream.Name)); plist.Add(new KeyValuePair<string, string>("oauth_consumer_key", consumerKey)); plist.Add(new KeyValuePair<string, string>("oauth_nonce", nonce)); plist.Add(new KeyValuePair<string, string>("oauth_signature_method", "HMAC-SHA1")); plist.Add(new KeyValuePair<string, string>("oauth_timestamp", timestamp)); plist.Add(new KeyValuePair<string, string>("oauth_token", AccessToken)); plist.Add(new KeyValuePair<string, string>("oauth_version", "1.0")); plist.Add(new KeyValuePair<string, string>("page", page.ToString())); plist.Add(new KeyValuePair<string, string>("rpp", PerPage.ToString())); if (stream.UserId != null) { plist.Add(new KeyValuePair<string, string>("user_id", stream.UserId)); } else if (stream.UserName != null) { plist.Add(new KeyValuePair<string, string>("username", stream.UserName)); } if (additionalParams != null) { foreach (var entry in additionalParams) { plist.Add(entry); } } string paramString = GenerateParamString(plist); string signature = GenerateSignature("GET", AccessTokenSecret, BaseUrl + "/photos", paramString); // Create the http request string requestUrl = BaseUrl + "/photos?" + paramString + "&oauth_signature=" + signature; try { HttpClient client = new HttpClient(); HttpResponseMessage resp = await client.GetAsync(requestUrl); resp.EnsureSuccessStatusCode(); var result = await resp.Content.ReadAsStringAsync(); // Dispatch event if (GetPhotoStreamComplete != null) { GetPhotoStreamComplete(this, new PhotoStreamEventArgs(stream, result)); } return result; } catch (Exception ex) { GetCurrentUserInfoFailed(this, new PhotoStreamEventArgs(stream)); Debug.WriteLine(ex); return null; } }
private void SelectStream(FeatureStream stream) { PhotoListView.Stream = stream; }
public PhotoStreamEventArgs(FeatureStream stream, String result = null) { Stream = stream; Result = result; }