public async Task<ResultBase> SendCommentAsync(Feed feed, UserInfo userInfo, string content, SimulateDevice device = SimulateDevice.Android, Comment reviewComment = null) { if (feed == null) { throw new ArgumentNullException(nameof(feed)); } if (userInfo == null) { throw new ArgumentNullException(nameof(userInfo)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } if (content.Length <= 0) { throw new ArgumentException("评论不能为空", nameof(content)); } if (Enum.IsDefined(typeof(SimulateDevice), device) == false) { throw new ArgumentException("模拟设备未定义。", nameof(device)); } Dictionary<string, string> postData = new Dictionary<string, string> { { "id", feed.Id.ToString() }, { "token", userInfo.Token } }; switch (device) { case SimulateDevice.Android: postData.Add("client", "android"); break; case SimulateDevice.IPhone: postData.Add("client", "iphone"); break; } postData.Add("content", content); if (reviewComment != null) { postData.Add("review_id", reviewComment.Id.ToString()); } string json; using (HttpClient client = new HttpClient()) { using (IHttpContent httpContent = new HttpFormUrlEncodedContent(postData)) { HttpResponseMessage response = await client.PostAsync(new Uri(SendCommentTemplate), httpContent); json = await response.Content.ReadAsStringAsync(); } } return JsonConvert.DeserializeObject<ResultBase>(json); }
protected override void ReceiveFromView(dynamic parameter) { Feed feed = parameter as Feed; if (feed != null) { this.Feed = feed; this.LoadArticleAsync(feed); } }
public async Task<DataResultBase<Article>> GetArticleAsync(Feed feed) { if (feed == null) { throw new ArgumentNullException(nameof(feed)); } string url = string.Format(ArticleTemplate, feed.Id); using (HttpClient client = new HttpClient()) { return await client.GetJsonAsync<DataResultBase<Article>>(new Uri(url)); } }
private async void LoadArticleAsync(Feed feed) { this.IsLoading = true; try { DataResultBase<Article> result = await this._service.GetArticleAsync(feed); if (result.Code == 0) { this.Article = result.Data; this.SendToView(this.Article); } } catch { } this.IsLoading = false; }
public async Task<DataResultBase<ResultList<Comment>>> GetCommentsAsync(Feed feed, int page = 1) { if (feed == null) { throw new ArgumentNullException(nameof(feed)); } if (page <= 0) { throw new ArgumentOutOfRangeException(nameof(page), "page should greater than zero."); } string url = string.Format(GetCommentTemplate, feed.Id, page); url = url + "?t=" + DateTime.Now.Ticks; using (HttpClient client = new HttpClient()) { return await client.GetJsonAsync<DataResultBase<ResultList<Comment>>>(new Uri(url)); } }
protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); Messenger.Register(this); if (Frame.CanGoBack) { NavigationHelper.Register(Frame, () => { GoBack(); }); } if (e.NavigationMode != NavigationMode.Back) { _domReadyTcs = new TaskCompletionSource<object>(); TypedEventHandler<WebView, WebViewDOMContentLoadedEventArgs> handler = null; handler = (sender, args) => { webView.DOMContentLoaded -= handler; _domReadyTcs.SetResult(null); }; webView.DOMContentLoaded += handler; webView.Navigate(new Uri("ms-appx-web:///Web/Views/app.html")); Feed feed = e.Parameter as Feed; if (feed != null) { _feed = feed; this.SendToViewModel(feed); } } }