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); }
public CommentItemReviewEventArgs(Comment comment, string content, TextBox textBox) { if (comment == null) { throw new ArgumentNullException(nameof(comment)); } if (content == null) { throw new ArgumentNullException(nameof(content)); } if (textBox == null) { throw new ArgumentNullException(nameof(textBox)); } if (content.Length <= 0) { throw new ArgumentException("评论不能为空。", nameof(content)); } Comment = comment; Content = content; TextBox = textBox; }