private async Task <FacebookCollection <T> > CreateNewCollectionAsync(FacebookCursor.Direction direction) { var collectionType = GetType(); var collection = (FacebookCollection <T>)Activator.CreateInstance(collectionType, _fbClient, _query, _token, Cursor); await collection.LoadToCollectionAsync(Cursor, direction); return(collection); }
private async Task <bool> LoadToCollectionAsync(FacebookCursor cursor = null, FacebookCursor.Direction direction = FacebookCursor.Direction.None) { try { var response = await _fbClient.GetAsync(_query, _token, cursor, direction); var results = response["data"]; if (!results.Any()) { return(false); } foreach (var result in results) { var mappedResult = Mapper(result); Add(mappedResult); } var newCursor = response["paging"]["cursors"]; var before = newCursor["before"]?.ToString(); var after = newCursor["after"]?.ToString(); Cursor = new FacebookCursor(before, after); return(true); } catch (Exception ex) { throw new FacebookCollectionException($"There was a problem loading additional items to Facebook collection {typeof(T)}", ex); } }