Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. // Replace the following placeholder values with the target
  2. // server URL and target user.
  3. const string serverUrl = "http://serverName";
  4. const string targetUser = "domainName\userName";
  5.  
  6. // Get the client context.
  7. clientContext = new ClientContext(serverUrl);
  8.  
  9. // Get the SocialFeedManager instance.
  10. followingManager = new SocialFollowingManager(clientContext);
  11.  
  12. // Create a SocialActorInfo object to represent the target user.
  13. SocialActorInfo actorInfo = new SocialActorInfo();
  14. actorInfo.AccountName = targetUser;
  15.  
  16. // Find out whether the current user is following the target user.
  17. ClientResult<bool> isFollowed = followingManager.IsFollowed(actorInfo);
  18.  
  19. // Get the information from the server.
  20. clientContext.ExecuteQuery();
  21.  
  22. Console.WriteLine("Was the current user following the target user? {0}n", isFollowed.Value);
  23. Console.Write("Initial count: ");
  24.  
  25. // Get the current count of followed people.
  26. WriteFollowedCount();
  27.  
  28. // Try to follow the target user. If the result is OK, then
  29. // the request succeeded.
  30. ClientResult<SocialFollowResult> result = followingManager.Follow(actorInfo);
  31. clientContext.ExecuteQuery();
  32.  
  33. // If the result is AlreadyFollowing, then stop following
  34. // the target user.
  35. if (result.Value == SocialFollowResult.AlreadyFollowing)
  36. {
  37. followingManager.StopFollowing(actorInfo);
  38. clientContext.ExecuteQuery();
  39. }
  40.  
  41. // Handle other SocialFollowResult return values.
  42. else if (result.Value == SocialFollowResult.LimitReached
  43. || result.Value == SocialFollowResult.InternalError)
  44. {
  45. Console.WriteLine(result.Value);
  46. }
  47.  
  48. // Get the updated count of followed people.
  49. Console.Write("Updated count: ");
  50. WriteFollowedCount();
  51. Console.ReadKey();
  52. }
  53.  
  54. // Get the count of the people who the current user is following.
  55. static void WriteFollowedCount()
  56. {
  57. ClientResult<int> followedCount = followingManager.GetFollowedCount(SocialActorTypes.Users);
  58. clientContext.ExecuteQuery();
  59. Console.WriteLine("The current user is following {0} people.", followedCount.Value);
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement