Beispiel #1
0
        /// <summary>
        /// Returns strong typed page of data.
        /// </summary>
        /// <param name="pageIndex">Page number.</param>
        /// <param name="pageSize">Size of page.</param>
        /// <param name="cancellationToken">Cancellation token.</param>
        /// <returns>Strong typed page of data.</returns>
        public async Task <IEnumerable <T> > GetPagedItemsAsync(int pageIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (_isFirstCall)
            {
                var result = await _paginatedArray.FirstAsync();

                return(ProcessResult(result));
            }
            else
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }

                if (_paginatedArray.HasNext && (pageIndex < _maxPages))
                {
                    var result = await _paginatedArray.NextAsync();

                    return(ProcessResult(result));
                }
                else
                {
                    return(null);
                }
            }
        }
Beispiel #2
0
        public async Task <IReadOnlyList <Object> > getListOfTestUsers()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();
            string      path       = "/" + TestAppId + FBSDKTestUsersPath;

            //Assert.IsNotNull(token);

            parameters.Add("access_token", Uri.EscapeUriString(token));

            FBPaginatedArray arr = new FBPaginatedArray(path, parameters,
                                                        new FBJsonClassFactory(FBTestUser.FromJson));

            FBResult result = await arr.FirstAsync();

            //Assert.IsTrue(result.Succeeded);

            IReadOnlyList <Object> users = null;

            try
            {
                users = (IReadOnlyList <Object>)result.Object;
            }
            catch (InvalidCastException)
            {
                Assert.IsTrue(false, "Item returned is not expected type" +
                              " (IReadOnlyList<Object>)");
            }

            return(users);
        }
Beispiel #3
0
        public async void GetUserLikes()
        {
            if (FBSession.ActiveSession.LoggedIn)
            {
                string graphPath = FBSession.ActiveSession.User.Id + "/likes";

                FBJsonClassFactory fact = new FBJsonClassFactory(
                    (JsonText) => MyFBPage.FromJson(JsonText));

                _likes = new FBPaginatedArray(graphPath, null, fact);
                FBResult result = await _likes.FirstAsync();

                if (result.Succeeded)
                {
                    BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
                    LikesListView.Visibility       = Windows.UI.Xaml.Visibility.Visible;
                    if (_likes.Current.Count > 0)
                    {
                        AddLikes(_likes.Current);
                    }
                    else
                    {
                        LikesListView.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                        BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
                        BadResultsTextBlock.Text       = "No User likes found";
                    }
                }
                else
                {
                    LikesListView.Visibility       = Windows.UI.Xaml.Visibility.Collapsed;
                    BadResultsTextBlock.Visibility = Windows.UI.Xaml.Visibility.Visible;
                    BadResultsTextBlock.Text       = result.ErrorInfo.Message;
                }
            }
        }
Beispiel #4
0
        public async Task testListTestUsers()
        {
            string token = await getAppToken();

            PropertySet parameters = new PropertySet();
            string      path       = "/" + TestAppId + FBSDKTestUsersPath;

            Assert.IsNotNull(token);
            bool found = false;

            parameters.Add("access_token", Uri.EscapeUriString(token));

            //Ensure we have at least one test user!
            FBTestUser user = await createTestUser(parameters);

            FBPaginatedArray arr = new FBPaginatedArray(path, parameters,
                                                        new FBJsonClassFactory(FBTestUser.FromJson));

            FBResult result = await arr.FirstAsync();

            Assert.IsTrue(result.Succeeded);

            IReadOnlyList <Object> users =
                (IReadOnlyList <Object>)result.Object;

            Assert.IsTrue(users.Count > 0);

            for (int i = 0; i < users.Count; i++)
            {
                try
                {
                    FBTestUser testuser = (FBTestUser)users[i];
                    if (string.CompareOrdinal(testuser.Id, user.Id) == 0)
                    {
                        found = true;
                    }
                }
                catch (InvalidCastException)
                {
                    Assert.IsTrue(false, "Item returned is not expected type" +
                                  " (FBTestUser)");
                }
            }

            Assert.IsTrue(found);

            await deleteTestUser(user);
        }
Beispiel #5
0
        public async void GetUserLikes()
        {
            if (FBSession.ActiveSession.LoggedIn)
            {
                string graphPath = FBSession.ActiveSession.User.Id + "/likes";

                FBJsonClassFactory fact = new FBJsonClassFactory(
                    (JsonText) => MyFBPage.FromJson(JsonText));

                _likes = new FBPaginatedArray(graphPath, null, fact);
                FBResult result = await _likes.FirstAsync();

                if (result.Succeeded)
                {
                    IReadOnlyList <object> pages =
                        (IReadOnlyList <object>)result.Object;
                    AddLikes(pages);
                }
            }
        }
Beispiel #6
0
        public async Task testFBPaginatedArray()
        {
            MockHttpClient mockHttpClient = new MockHttpClient();

            HttpManager.Instance.SetHttpClient(mockHttpClient);
            // test no values returned from request
            mockHttpClient.ResponseData = @"{""data"":[]}";
            String graphPath = @"/12345/likes";
            Func <string, string> dumbFunc = (string a) => { return(a); };

            FBJsonClassFactory fact = new FBJsonClassFactory(
                (JsonText) => dumbFunc(JsonText));

            FBPaginatedArray likes  = new FBPaginatedArray(graphPath, null, fact);
            FBResult         result = await likes.FirstAsync();

            Assert.IsTrue(likes.HasCurrent);
            Assert.IsFalse(likes.HasNext);
            Assert.IsFalse(likes.HasPrevious);
            // test with next but no previous
        }
Beispiel #7
0
        /// <summary>
        /// Request generic list data from service provider based upon a given config / query.
        /// </summary>
        /// <typeparam name="T">Strong type of model.</typeparam>
        /// <param name="config">FacebookDataConfig instance.</param>
        /// <param name="maxRecords">Upper limit of records to return.</param>
        /// <param name="fields">A comma seperated string of required fields, which will have strongly typed representation in the model passed in.</param>
        /// <returns>Strongly typed list of data returned from the service.</returns>
        public async Task <List <T> > RequestAsync <T>(FacebookDataConfig config, int maxRecords = 20, string fields = "id,message,from,created_time,link,full_picture")
        {
            if (Provider.LoggedIn)
            {
                var processedResults = new List <T>();

                PropertySet propertySet = new PropertySet {
                    { "fields", fields }
                };

                var factory = new FBJsonClassFactory(s => JsonConvert.DeserializeObject(s, typeof(T)));

                paginatedArray = new FBPaginatedArray(config.Query, propertySet, factory);

                var result = await paginatedArray.FirstAsync();

                if (result.Succeeded)
                {
                    IReadOnlyList <object> results = (IReadOnlyList <object>)result.Object;

                    await ProcessResultsAsync(results, maxRecords, processedResults);

                    return(processedResults);
                }

                throw new Exception(result.ErrorInfo?.Message);
            }

            var isLoggedIn = await LoginAsync();

            if (isLoggedIn)
            {
                return(await RequestAsync <T>(config, maxRecords, fields));
            }

            return(null);
        }
        internal static async Task PopulateUserPages()
        {
            Pages.Clear();
            String graphPath = "me/accounts";

            FBPaginatedArray fbPages = new FBPaginatedArray(graphPath, null, FBPage.Factory);
            FBResult         result  = null;

            do
            {
                if (result == null)
                {
                    result = await fbPages.FirstAsync();
                }
                else
                {
                    result = await fbPages.NextAsync();
                }
                if (result.Succeeded)
                {
                    IReadOnlyList <object> pages = (IReadOnlyList <object>)result.Object;
                    foreach (var p in pages)
                    {
                        FBPage page = (FBPage)p;
                        if (page != null)
                        {
                            Pages.Add(page);
                        }
                    }
                }
                else
                {
                    FBErrorHandler.HandleError(result);
                }
            } while (fbPages.HasNext);
        }
Beispiel #9
0
        public async Task testListTestUsers()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();
            string path = "/" + TestAppId + FBSDKTestUsersPath;
            Assert.IsNotNull(token);
            bool found = false;

            parameters.Add("access_token", Uri.EscapeUriString(token));

            //Ensure we have at least one test user!
            FBTestUser user = await createTestUser(parameters);
            
            FBPaginatedArray arr = new FBPaginatedArray(path, parameters,
                new FBJsonClassFactory(FBTestUser.FromJson));

            FBResult result = await arr.FirstAsync();
            Assert.IsTrue(result.Succeeded);

            IReadOnlyList<Object> users = 
                (IReadOnlyList<Object>)result.Object;

            Assert.IsTrue(users.Count > 0);

            for (int i = 0; i < users.Count; i++)
            {
                try
                {
                    FBTestUser testuser = (FBTestUser)users[i];
                    if (string.CompareOrdinal(testuser.Id, user.Id) == 0)
                    {
                        found = true;
                    }
                }
                catch (InvalidCastException)
                {
                    Assert.IsTrue(false, "Item returned is not expected type" +
                        " (FBTestUser)");
                }
            }

            Assert.IsTrue(found);

            await deleteTestUser(user);
        }
Beispiel #10
0
        public async Task<IReadOnlyList<Object>> getListOfTestUsers()
        {
            string token = await getAppToken();
            PropertySet parameters = new PropertySet();
            string path = "/" + TestAppId + FBSDKTestUsersPath;
            //Assert.IsNotNull(token);

            parameters.Add("access_token", Uri.EscapeUriString(token));

            FBPaginatedArray arr = new FBPaginatedArray(path, parameters,
                new FBJsonClassFactory(FBTestUser.FromJson));

            FBResult result = await arr.FirstAsync();
            //Assert.IsTrue(result.Succeeded);

            IReadOnlyList<Object> users = null;

            try
            {
                users = (IReadOnlyList<Object>)result.Object; 
            }
            catch (InvalidCastException)
            {
                Assert.IsTrue(false, "Item returned is not expected type" +
                    " (IReadOnlyList<Object>)");
            }

            return users;
        }
Beispiel #11
0
        public async void GetUserLikes()
        {
            if (FBSession.ActiveSession.LoggedIn)
            {
                string graphPath = FBSession.ActiveSession.User.Id + "/likes";
                
                FBJsonClassFactory fact = new FBJsonClassFactory(
                    (JsonText) => MyFBPage.FromJson(JsonText));

                _likes = new FBPaginatedArray(graphPath, null, fact);
                FBResult result = await _likes.FirstAsync();
                if (result.Succeeded)
                {
                    IReadOnlyList<object> pages = 
                        (IReadOnlyList<object>)result.Object;
                    AddLikes(pages);
                }
            }
        }