Esempio n. 1
0
        private async Task <ListResultBase> GetMoreAnswersMethod(String requestUri)
        {
            if (null == _questionService || AnswersLoading)
            {
                return(null);
            }

            AnswersLoading = true;

            var result = await _questionService.GetAnswersAsync(LoginUser.Current.Token, requestUri, true);

            AnswersLoading = false;

            if (result == null)
            {
                return(null);
            }

            if (result.Error != null)
            {
                ToasteIndicator.Instance.Show(String.Empty, result.Error.Message, null, 3);

                Debug.WriteLine(Regex.Unescape(result.Error.Message));

                await Task.Delay(3000);

                return(null);
            }

            return(result);
        }
        private async Task OfflineQuestionAnswers(Int32 questionId)
        {
            var    iCachePageCount = 0;
            Paging nextPaging      = null;

            var cachePagesCount = CacheAnswersCount / 20;

            while (iCachePageCount < cachePagesCount)
            {
                var request = String.Empty;
                if (nextPaging == null)
                {
                    request = String.Format("questions/{0}/answers", questionId);
                }
                else
                {
                    var url = new Uri(nextPaging.Next);
                    request = url.PathAndQuery.Substring(1);
                }

                Debug.WriteLine(request);

                await Task.Delay(10);

                var answers = await _question.GetAnswersAsync(LoginUser.Current.Token, request, true);

                await Task.Delay(10);

                if (answers.Result != null)
                {
                    //var childTasks =
                    //    answers.Result.GetItems()
                    //        .Select(item => item as Answer)
                    //        .Select(answer => OfflineAnswer(answer.Id));

                    //await Task.WhenAll(childTasks);

                    foreach (var answer in answers.Result.GetItems().Select(item => item as Answer))
                    {
                        await OfflineAnswer(answer.Id);
                    }

                    iCachePageCount++;

                    nextPaging = answers.Result.Paging;
                    var answersCount = answers.Result.GetItems().Length;

                    lock (_answersSync)
                    {
                        AnswersCount += answersCount;
                    }

                    if (answersCount < 20)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }
        }