Exemplo n.º 1
0
        private async Task <ListResultBase> GetAnswerCommentsMethod(String requestUri)
        {
            if (CommentsLoading)
            {
                return(null);
            }

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

            CommentsLoading = true;

            var result = await _answerService.GetCommentsAsync(LoginUser.Current.Token, requestUri, true);

            CommentsLoading = false;

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

                Debug.WriteLine(Regex.Unescape(result.Error.Message));
                return(null);
            }

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

            var cachePagesCount = CacheCommentsCount / 20;

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

                Debug.WriteLine(request);

                await Task.Delay(10);

                var comments = await _answer.GetCommentsAsync(LoginUser.Current.Token, request, true);

                await Task.Delay(10);

                if (comments.Result != null)
                {
                    iCachePageCount++;

                    nextPaging = comments.Result.Paging;

                    var commentsCount = comments.Result.GetItems().Length;

                    lock (_commentsSync)
                    {
                        CommentsCount += commentsCount;
                    }

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