private LinkedInResponse<IEnumerable<LinkedInGroupComment>> getComments( LinkedInGetGroupPostCommentsOptions options) { try { return new LinkedInResponse<IEnumerable<LinkedInGroupComment>>(RequestRunner.GetPostComments(options), LinkedInResponseStatus.OK, options.PostId); } catch (WebException wex) { return Utils.GetResponse<IEnumerable<LinkedInGroupComment>>(null, wex, null); } catch (Exception ex) { return new LinkedInResponse<IEnumerable<LinkedInGroupComment>>(null, LinkedInResponseStatus.OtherException, null, ex); } }
/// <summary> /// Gets group post's comments asynchronously /// </summary> /// <param name="options">The object of type <see cref="LinkedInGetGroupPostCommentsOptions"/> representing retrieval options</param> /// <param name="action">Action to be invoked when the retrieval process ends</param> /// <returns>Status of asynchronous operation</returns> /// <example> /// This sample shows how to call this method: /// <code> /// using LinkedIn.NET; /// using LinkedIn.NET.Groups; /// using LinkedIn.NET.Members; /// using LinkedIn.NET.Options; /// using LinkedIn.NET.Search; /// using LinkedIn.NET.Updates; /// ... /// // define retrieval options /// var options = new LinkedInGetGroupPostCommentsOptions(); /// options.CommentOptions.SelectAll(); /// options.PostId = 12345; /// _Client.GetPostComments(options, commentsReceived); /// ... /// // application defined function /// private void commentsReceived(LinkedInResponse<IEnumerable<LinkedInGroupComment>> response) /// { /// // always check response.Result and response.Status before processing /// if (response.Result != null && response.Status == LinkedInResponseStatus.OK) /// { /// foreach (var c in response.Result) /// { /// Console.WriteLine(c.Text); /// } /// } /// else /// { /// // show possible error message LinkedIn response /// MessageBox.Show(response.Message); /// } /// } /// </code> /// </example> public IAsyncResult GetPostComments(LinkedInGetGroupPostCommentsOptions options, Action<LinkedInResponse<IEnumerable<LinkedInGroupComment>>> action) { ListCommentsDelegate _delegate = getComments; return _delegate.BeginInvoke(options, getCommentsCallback, action); }
internal static IEnumerable<LinkedInGroupComment> GetPostComments(LinkedInGetGroupPostCommentsOptions options) { var comments = new List<LinkedInGroupComment>(); var sb = new StringBuilder(Utils.POSTS_COMMENTS_URL.Replace("{POST_ID}", options.PostId)); var postParameters = RequestFields.PrepareGroupPostCommentFields(options); if (!string.IsNullOrEmpty(postParameters)) sb.Append(postParameters); sb.Append("?"); var start = 0; var fetched = 0; while (true) { var request = new StringBuilder(sb.ToString()); request.Append("start="); request.Append(start); request.Append("&"); request.Append("count="); request.Append(10); request.Append("&"); request.Append("oauth2_access_token="); request.Append(Singleton.Instance.AccessToken); var responseString = Utils.MakeRequest(request.ToString(), "GET"); var xdoc = XDocument.Parse(responseString); var xroot = xdoc.Root; if (xroot == null || xroot.Attribute("total") == null || !xroot.Elements("comment").Any()) break; var total = Convert.ToInt32(xroot.Attribute("total").Value.Trim()); var count = xroot.Attribute("count") == null ? total : Convert.ToInt32(xroot.Attribute("count").Value.Trim()); fetched += count; comments.AddRange(xroot.Elements("comment").Select(Utils.BuildGroupComment)); if (fetched >= total) break; start += count; } return comments.AsEnumerable(); }
protected async void GetComments(string postId) { LinkedInGroupPost post = posts[postId]; LinkedInGroup group = postGroup[post.Id]; LinkedInGetGroupPostCommentsOptions commentOptions = new LinkedInGetGroupPostCommentsOptions(); commentOptions.CommentOptions.SelectAll(); commentOptions.PostId = post.Id; await Task.Run(() => post.LoadComments(commentOptions)); foreach (LinkedInGroupComment comment in post.Comments) { CreateCarrier("LinkedInComment", signal => { signal.LinkedInGroup.Name.Text.Value = group.Name; signal.LinkedInGroup.Id = group.Id; signal.LinkedInPost.Title.Text.Value = post.Title; signal.LinkedInPost.Id = post.Id; signal.CreationTime = comment.CreationTime; signal.Comment = comment.Text; signal.LinkedInCommentCreator.PersonName.Name.Text.Value = comment.Creator.FirstName + " " + comment.Creator.LastName; }); } }
/// <summary> /// Loads post's comments /// </summary> /// <param name="options"><see cref="LinkedInGetGroupPostCommentsOptions"/> object representing comments retrieval options</param> /// <returns>Request result</returns> /// <remarks>This is synchronous operation, i.e. the current thread will be suspended until it finishes to load all comments. If you want to load post's comments asynchronously, consider to use <see cref="LinkedInClient.GetPostComments"/> function instead</remarks> public LinkedInResponse<bool> LoadComments(LinkedInGetGroupPostCommentsOptions options) { try { if (_Comments == null) _Comments = new List<LinkedInGroupComment>(); else _Comments.Clear(); options.PostId = Id; _Comments.AddRange(RequestRunner.GetPostComments(options)); return new LinkedInResponse<bool>(true, LinkedInResponseStatus.OK, null); } catch (WebException wex) { return Utils.GetResponse(false, wex, null); } catch (Exception ex) { return new LinkedInResponse<bool>(false, LinkedInResponseStatus.OtherException, null, ex); } }
internal static string PrepareGroupPostCommentFields(LinkedInGetGroupPostCommentsOptions options) { var sb = new StringBuilder(); var gc = options.CommentOptions; if (!gc.HasValues) return sb.ToString(); sb.Append(":("); if (gc[LinkedInGroupPostCommentFields.Id]) sb.Append("id,"); if (gc[LinkedInGroupPostCommentFields.Text]) sb.Append("text,"); if (gc[LinkedInGroupPostCommentFields.Creator]) sb.Append("creator,"); if (gc[LinkedInGroupPostCommentFields.CreationTime]) sb.Append("creation-timestamp,"); if (gc[LinkedInGroupPostCommentFields.RelationToViewer]) sb.Append("relation-to-viewer,"); sb.Length -= 1; sb.Append(")"); return sb.ToString(); }