Beispiel #1
0
 private LinkedInResponse<IEnumerable<LinkedInGroupPost>> getPosts(LinkedInGetGroupPostsOptions options)
 {
     try
     {
         return new LinkedInResponse<IEnumerable<LinkedInGroupPost>>(RequestRunner.GetGroupPosts(options),
                 LinkedInResponseStatus.OK, options.GroupId);
     }
     catch (WebException wex)
     {
         return Utils.GetResponse<IEnumerable<LinkedInGroupPost>>(null, wex, null);
     }
     catch (Exception ex)
     {
         return new LinkedInResponse<IEnumerable<LinkedInGroupPost>>(null, LinkedInResponseStatus.OtherException, null, ex);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Asynchronously gets group's posts
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInGetGroupPostsOptions"/> 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 LinkedInGetGroupPostsOptions();
 /// options.PostOptions.SelectAll();
 /// options.GroupId = 12345;
 /// _Client.GetGroupPosts(options, postsMemberReceived);
 /// ...
 /// // application defined function
 /// private void postsMemberReceived(LinkedInResponse&lt;IEnumerable&lt;LinkedInGroupPost&gt;&gt; response)
 /// {
 ///     // always check response.Result and response.Status before processing 
 ///     if (response.Result != null &amp;&amp; response.Status == LinkedInResponseStatus.OK)
 ///     {
 ///         foreach (var post in response.Result)
 ///         {
 ///             Console.WriteLine(post.Summary);
 ///         }
 ///     }
 ///     else
 ///     {
 ///         // show possible error message LinkedIn response
 ///         MessageBox.Show(response.Message);
 ///     }
 ///  }
 /// </code>
 /// </example>
 public IAsyncResult GetGroupPosts(LinkedInGetGroupPostsOptions options, Action<LinkedInResponse<IEnumerable<LinkedInGroupPost>>> action)
 {
     ListPostsDelegate _delegate = getPosts;
     return _delegate.BeginInvoke(options, getPostsCallback, action);
 }
Beispiel #3
0
 /// <summary>
 /// Loads group's posts
 /// </summary>
 /// <param name="options"><see cref="LinkedInGetGroupPostsOptions"/> object representing posts 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 posts. If you want to load group's posts asynchronously, consider to use <see cref="LinkedInClient.GetGroupPosts"/> function instead</remarks>
 public LinkedInResponse<bool> LoadPosts(LinkedInGetGroupPostsOptions options)
 {
     try
     {
         if (_Posts == null)
             _Posts = new List<LinkedInGroupPost>();
         else
             _Posts.Clear();
         options.GroupId = Id;
         _Posts.AddRange(RequestRunner.GetGroupPosts(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);
     }
 }
Beispiel #4
0
        internal static IEnumerable<LinkedInGroupPost> GetGroupPosts(LinkedInGetGroupPostsOptions options)
        {
            var posts = new List<LinkedInGroupPost>();

            var sb = new StringBuilder();
            sb.Append(options.Role == LinkedInGroupPostRole.NotDefined
                ? Utils.GROUP_POSTS_URL.Replace("{GROUP_ID}", options.GroupId)
                : Utils.GROUP_MEMBER_POSTS_URL.Replace("{GROUP_ID}", options.GroupId));
            var postParameters = RequestFields.PrepareGroupPostFields(options);
            if (!string.IsNullOrEmpty(postParameters))
                sb.Append(postParameters);
            sb.Append("?");

            switch (options.Role)
            {
                case LinkedInGroupPostRole.Creator:
                    sb.Append("role=creator&");
                    break;
                case LinkedInGroupPostRole.Commenter:
                    sb.Append("role=commenter&");
                    break;
                case LinkedInGroupPostRole.Follower:
                    sb.Append("role=follower&");
                    break;
            }

            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("post").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;

                posts.AddRange(xroot.Elements("post").Select(Utils.BuildGroupPost));

                if (fetched >= total)
                    break;

                start += count;
            }
            return posts.AsEnumerable();
        }
Beispiel #5
0
		protected async void GetPosts(string groupId)
		{
			LinkedInGroup group = groups[groupId];
			LinkedInGetGroupPostsOptions postOptions = new LinkedInGetGroupPostsOptions();
			postOptions.PostOptions.SelectAll();
			postOptions.GroupId = group.Id;
			await Task.Run(()=>group.LoadPosts(postOptions));

			foreach (LinkedInGroupPost post in group.Posts)
			{
				if (!posts.ContainsKey(post.Id))
				{
					posts[post.Id] = post;
					postGroup[post.Id] = group;
				}

				CreateCarrier("LinkedInPost", signal=>
					{
						signal.LinkedInGroup.Name.Text.Value = group.Name;
						signal.LinkedInGroup.Id = group.Id;
						signal.Id = post.Id;
						signal.CreationTime = post.CreationTime;
						signal.Summary.Text.Value = post.Summary;
						signal.Title.Text.Value = post.Title;
						signal.LinkedInPostCreator.PersonName.Name.Text.Value = post.Creator.FirstName +" " + post.Creator.LastName;
					});
			}
		}
Beispiel #6
0
 internal static string PrepareGroupPostFields(LinkedInGetGroupPostsOptions options)
 {
     var sb = new StringBuilder();
     var gp = options.PostOptions;
     if (!gp.HasValues) return sb.ToString();
     sb.Append(":(");
     if (gp[LinkedInGroupPostFields.Id])
         sb.Append("id,");
     if (gp[LinkedInGroupPostFields.PostType])
         sb.Append("type,");
     if (gp[LinkedInGroupPostFields.Category])
         sb.Append("category,");
     if (gp[LinkedInGroupPostFields.Creator])
         sb.Append("creator,");
     if (gp[LinkedInGroupPostFields.Title])
         sb.Append("title,");
     if (gp[LinkedInGroupPostFields.Summary])
         sb.Append("summary,");
     if (gp[LinkedInGroupPostFields.CreationTime])
         sb.Append("creation-timestamp,");
     if (gp[LinkedInGroupPostFields.RelationToViewer])
         sb.Append("relation-to-viewer,");
     if (gp[LinkedInGroupPostFields.Likes])
         sb.Append("likes,");
     if (gp[LinkedInGroupPostFields.Attachment])
         sb.Append("attachment,");
     if (gp[LinkedInGroupPostFields.SiteGroupPostUrl])
         sb.Append("site-group-post-url,");
     sb.Length -= 1;
     sb.Append(")");
     return sb.ToString();
 }