예제 #1
0
 /// <summary>
 /// Gets multiple LinkedIn member details asynchronously
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInGetMultipleMembersOptions"/> representing retrieval options</param>
 /// <param name="action">Action to be invoked when retrieval process ends</param>
 /// <returns>Status of asynchronus 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 collection for holding members
 /// private readonly List (LinkedInMember) _Members = new List&lt;LinkedInMember&gt;();
 /// 
 /// ...
 /// 
 /// // define retrieval options
 /// var options = new LinkedInGetMultipleMembersOptions();
 /// options.BasicProfileOptions.SelectAll();
 /// options.EmailProfileOptions.SelectAll();
 /// options.FullProfileOptions.SelectAll();
 /// // add retrieval parameters
 /// var parameters = new List&lt;LinkedInGetMemberParameters&gt;()
 /// // add currently logged in user
 /// parameters.Add(new LinkedInGetMemberParameters
 /// {
 ///     GetBy = LinkedInGetMemberBy.Self
 /// });
 /// // add additional user id
 /// parameters.Add(new LinkedInGetMemberParameters
 /// {
 ///     GetBy = LinkedInGetMemberBy.Id,
 ///     RequestBy = "12345"
 /// });
 /// // assign parameters and call the method where processMultipleProfiles is application defined callback function
 /// options.Params = parameters;
 /// _client.GetMembers(options, processMultipleProfiles);
 /// 
 /// ...
 /// 
 /// // application defined function
 /// private void processMultipleProfiles(LinkedInResponse&lt;IEnumerable&lt;LinkedInMember&gt;&gt; response)
 /// {
 ///     // always check response.Result and response.Status before processing
 ///     if (response.Result != null &amp;&amp; response.Status == LinkedInResponseStatus.OK)
 ///     {
 ///         _Members.Clear();
 ///         _Members.AddRange(response.Result);
 ///     }
 ///     else
 ///     {
 ///         // show possible error message LinkedIn response
 ///         MessageBox.Show(response.Message);
 ///     }
 /// }
 /// </code>
 /// </example>
 public IAsyncResult GetMembers(LinkedInGetMultipleMembersOptions options,
                                Action<LinkedInResponse<IEnumerable<LinkedInMember>>> action)
 {
     GetMembersDelegate _delegate = GetMembers;
     return _delegate.BeginInvoke(options, getMembersCallback, action);
 }
예제 #2
0
 /// <summary>
 /// Gets multiple LinkedIn members details
 /// </summary>
 /// <param name="options">The object of type <see cref="LinkedInGetMultipleMembersOptions"/> representing retrieval options</param>
 /// <returns>Value containing collection of <see cref="LinkedInMember"/> objects and response status</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 collection for holding members
 /// private readonly List (LinkedInMember) _Members = new List&lt;LinkedInMember&gt;();
 /// 
 /// ...
 /// 
 /// // define retrieval options
 /// var options = new LinkedInGetMultipleMembersOptions();
 /// options.BasicProfileOptions.SelectAll();
 /// options.EmailProfileOptions.SelectAll();
 /// options.FullProfileOptions.SelectAll();
 /// // add retrieval parameters
 /// var parameters = new List&lt;LinkedInGetMemberParameters&gt;()
 /// // add currently logged in user
 /// parameters.Add(new LinkedInGetMemberParameters
 /// {
 ///     GetBy = LinkedInGetMemberBy.Self
 /// });
 /// // add additional user id
 /// parameters.Add(new LinkedInGetMemberParameters
 /// {
 ///     GetBy = LinkedInGetMemberBy.Id,
 ///     RequestBy = "12345"
 /// });
 /// // assign parameters and call the method
 /// options.Params = parameters;
 /// var response = _client.GetMembers(options);
 /// // always check response.Result and response.Status before processing
 /// if (response.Result != null &amp;&amp; response.Status == LinkedInResponseStatus.OK)
 /// {
 ///     _Members.Clear();
 ///     _Members.AddRange(response.Result);
 /// }
 /// else
 /// {
 ///     // show possible error message LinkedIn response
 ///     MessageBox.Show(response.Message);
 /// }
 /// </code>
 /// </example>
 public LinkedInResponse<IEnumerable<LinkedInMember>> GetMembers(LinkedInGetMultipleMembersOptions options)
 {
     return RequestRunner.GetMembers(options);
 }
예제 #3
0
        internal static LinkedInResponse<IEnumerable<LinkedInMember>> GetMembers(
            LinkedInGetMultipleMembersOptions options)
        {
            MethodInfo getSyntax = null;
            FieldInfo flagsField = null;
            try
            {
                getSyntax = typeof(UriParser).GetMethod("GetSyntax", BindingFlags.Static | BindingFlags.NonPublic);
                flagsField = typeof(UriParser).GetField("m_Flags", BindingFlags.Instance | BindingFlags.NonPublic);
                setCompressionFlag(getSyntax, flagsField, false);

                var fieldsParams = RequestFields.PrepareMemberFields(options);
                var sb = new StringBuilder(Utils.PROFILE_MULTIPLE_URL);
                sb.Append("(");
                foreach (var p in options.Params)
                {
                    switch (p.GetBy)
                    {
                        case LinkedInGetMemberBy.Self:
                            sb.Append("~");
                            break;
                        case LinkedInGetMemberBy.Id:
                            sb.Append("id=");
                            sb.Append(p.RequestBy);
                            break;
                        case LinkedInGetMemberBy.Url:
                            sb.Append("url=");
                            sb.Append(Utils.NormalizeUrl(p.RequestBy));
                            break;
                    }
                    sb.Append(",");
                }
                if (sb.Length > 1) sb.Length -= 1;
                sb.Append(")");
                
                if (!string.IsNullOrEmpty(fieldsParams))
                    sb.Append(fieldsParams);

                sb.Append("?oauth2_access_token=");
                sb.Append(Singleton.Instance.AccessToken);
                var responseString = Utils.MakeRequest(sb.ToString(), "GET");
                var xdoc = XDocument.Parse(responseString);

                var members = new List<LinkedInMember>();
                if (xdoc.Root != null)
                {
                    members.AddRange(xdoc.Root.Elements("person").Select(Utils.BuildMember));
                }

                return new LinkedInResponse<IEnumerable<LinkedInMember>>(members.AsEnumerable(),
                    LinkedInResponseStatus.OK, null);
            }
            catch (WebException wex)
            {
                return Utils.GetResponse<IEnumerable<LinkedInMember>>(null, wex, null);
            }
            catch (Exception ex)
            {
                return new LinkedInResponse<IEnumerable<LinkedInMember>>(null, LinkedInResponseStatus.OtherException, null, ex);
            }
            finally
            {
                setCompressionFlag(getSyntax, flagsField, true);
            }
        }