Exemple #1
0
        public AnswerDetailPage(int questionId)
        {
            _theAnswer  = new AnswerInfo();
            _questionId = questionId;

            Title = "Possible Answer";

            HtmlWebViewSource webSource = new HtmlWebViewSource();

            webSource.BindingContext = _theAnswer;
            webSource.SetBinding(HtmlWebViewSource.HtmlProperty, new Binding("AnswerBody"));

            _theFullAnswer = new WebView {
                Source          = webSource,
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            Content = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Children        =
                {
                    _theFullAnswer
                }
            };
        }
        public async Task <AnswerInfo> GetAnswerForQuestion(int questionId)
        {
            if (!CrossConnectivity.Current.IsConnected)
            {
                throw new NoInternetException();
            }

            var decompressedContent = await this.CallAndDecompress(string.Format(ANSWER_URL, questionId));

            var deserializedContent = JsonConvert.DeserializeObject <AnswerResponse> (decompressedContent);

            AnswerInfo theAnswer = null;

            if (deserializedContent != null && deserializedContent.items != null && deserializedContent.items.Count > 0)
            {
                var currAnswer = deserializedContent.items [0];

                theAnswer = new AnswerInfo {
                    AnswerID   = currAnswer.answer_id,
                    QuestionID = currAnswer.question_id,
                    AnswerBody = currAnswer.body
                };
            }

            return(theAnswer);
        }
Exemple #3
0
        protected async Task LoadAnswer(int questionId)
        {
            AnswerInfo currentAnswer = await BlobCache.LocalMachine.GetOrFetchObject <AnswerInfo> (
                _questionId.ToString(),
                async() => await new StackOverflowService().GetAnswerForQuestion(questionId),
                DateTime.Now.AddDays(7)
                );

            if (currentAnswer != null)
            {
                _theAnswer.AnswerID   = currentAnswer.AnswerID;
                _theAnswer.QuestionID = currentAnswer.QuestionID;
                _theAnswer.AnswerBody = currentAnswer.AnswerBody;
            }
            else
            {
                // Nothing found on the web or in the cache - so invalidate the cache - don't want null stored
                await BlobCache.LocalMachine.InvalidateObject <AnswerInfo> (_questionId.ToString());

                _theAnswer.AnswerBody = "No answer found on StackOverflow or in cache";
            }
        }