PageRenderTime 4276ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/HigLaboNet/HigLabo.Net.Facebook/Entity/Object/User/User.cs

#
C# | 359 lines | 236 code | 5 blank | 118 comment | 32 complexity | f161bdcb2a8211f469188dacffa68394 MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Newtonsoft.Json;
  6. using HigLabo.Net;
  7. using HigLabo.Net.Extensions;
  8. namespace HigLabo.Net.Facebook
  9. {
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. public class User : ResponseObject
  14. {
  15. private List<UserSports> _UserSports = new List<UserSports>();
  16. private List<IdName> _FavoriteTeams = new List<IdName>();
  17. private List<IdName> _FavoriteAthletes = new List<IdName>();
  18. private List<String> _InterestedIn = new List<String>();
  19. private List<IdName> _Languages = new List<IdName>();
  20. private List<IdName> _InspirationalPeople = new List<IdName>();
  21. private List<User> _Friends = new List<User>();
  22. private List<Book> _Books = new List<Book>();
  23. private List<Album> _Albums = new List<Album>();
  24. private List<Movie> _Movies = new List<Movie>();
  25. private List<Music> _MusicList = new List<Music>();
  26. private List<Television> _Televisions = new List<Television>();
  27. /// <summary>
  28. ///
  29. /// </summary>
  30. public String ID { get; set; }
  31. /// <summary>
  32. ///
  33. /// </summary>
  34. public String Name { get; set; }
  35. /// <summary>
  36. ///
  37. /// </summary>
  38. public String FirstName { get; set; }
  39. /// <summary>
  40. ///
  41. /// </summary>
  42. public String MiddleName { get; set; }
  43. /// <summary>
  44. ///
  45. /// </summary>
  46. public String LastName { get; set; }
  47. /// <summary>
  48. ///
  49. /// </summary>
  50. public String Gender { get; set; }
  51. /// <summary>
  52. ///
  53. /// </summary>
  54. public String Locale { get; set; }
  55. /// <summary>
  56. ///
  57. /// </summary>
  58. public String Link { get; set; }
  59. /// <summary>
  60. ///
  61. /// </summary>
  62. public String UserName { get; set; }
  63. /// <summary>
  64. ///
  65. /// </summary>
  66. public IdName HomeTown { get; set; }
  67. /// <summary>
  68. ///
  69. /// </summary>
  70. public IdName Location { get; set; }
  71. /// <summary>
  72. ///
  73. /// </summary>
  74. public List<IdName> FavoriteTeams
  75. {
  76. get { return _FavoriteTeams; }
  77. }
  78. /// <summary>
  79. ///
  80. /// </summary>
  81. public List<IdName> FavoriteAthletes
  82. {
  83. get { return _FavoriteAthletes; }
  84. }
  85. /// <summary>
  86. ///
  87. /// </summary>
  88. public List<UserSports> Sports
  89. {
  90. get { return _UserSports; }
  91. }
  92. /// <summary>
  93. ///
  94. /// </summary>
  95. public List<IdName> Languages
  96. {
  97. get { return _Languages; }
  98. }
  99. /// <summary>
  100. ///
  101. /// </summary>
  102. public List<IdName> InspirationalPeople
  103. {
  104. get { return _InspirationalPeople; }
  105. }
  106. /// <summary>
  107. ///
  108. /// </summary>
  109. public List<String> InterestedIn
  110. {
  111. get { return _InterestedIn; }
  112. }
  113. /// <summary>
  114. ///
  115. /// </summary>
  116. public String ThirdPartyID { get; set; }
  117. /// <summary>
  118. ///
  119. /// </summary>
  120. public Double? TimeZone { get; set; }
  121. /// <summary>
  122. ///
  123. /// </summary>
  124. public DateTimeOffset? UpdatedTime { get; set; }
  125. /// <summary>
  126. ///
  127. /// </summary>
  128. public Boolean? Verified { get; set; }
  129. /// <summary>
  130. ///
  131. /// </summary>
  132. public String Bio { get; set; }
  133. /// <summary>
  134. ///
  135. /// </summary>
  136. public DateTime? Birthday { get; set; }
  137. /// <summary>
  138. ///
  139. /// </summary>
  140. public String EMail { get; set; }
  141. /// <summary>
  142. ///
  143. /// </summary>
  144. public UserWork Work { get; set; }
  145. /// <summary>
  146. ///
  147. /// </summary>
  148. public UserEducation Education { get; set; }
  149. /// <summary>
  150. ///
  151. /// </summary>
  152. public List<User> Friends
  153. {
  154. get { return _Friends; }
  155. }
  156. /// <summary>
  157. ///
  158. /// </summary>
  159. public List<Album> Albums
  160. {
  161. get { return _Albums; }
  162. }
  163. /// <summary>
  164. ///
  165. /// </summary>
  166. public List<Book> Books
  167. {
  168. get { return _Books; }
  169. }
  170. /// <summary>
  171. ///
  172. /// </summary>
  173. public List<Movie> Movies
  174. {
  175. get { return _Movies; }
  176. }
  177. /// <summary>
  178. ///
  179. /// </summary>
  180. public List<Music> MusicList
  181. {
  182. get { return _MusicList; }
  183. }
  184. /// <summary>
  185. ///
  186. /// </summary>
  187. public List<Television> Televisions
  188. {
  189. get { return _Televisions; }
  190. }
  191. /// <summary>
  192. ///
  193. /// </summary>
  194. public String ProfileImageUrl
  195. {
  196. get { return GetProfileImageUrl(this.ID); }
  197. }
  198. /// <summary>
  199. ///
  200. /// </summary>
  201. public User()
  202. {
  203. }
  204. /// <summary>
  205. ///
  206. /// </summary>
  207. /// <param name="jsonText"></param>
  208. public User(String jsonText)
  209. {
  210. this.SetProperty(jsonText);
  211. }
  212. /// <summary>
  213. ///
  214. /// </summary>
  215. /// <param name="userID"></param>
  216. /// <returns></returns>
  217. public static String GetProfileImageUrl(String userID)
  218. {
  219. return String.Format("http://graph.facebook.com/{0}/picture", userID);
  220. }
  221. /// <summary>
  222. ///
  223. /// </summary>
  224. /// <param name="jsonText"></param>
  225. public override void SetProperty(String jsonText)
  226. {
  227. var d = this.SetData(jsonText);
  228. this.ID = d.ToString("id");
  229. this.Name = d.ToString("name");
  230. this.FirstName = d.ToString("first_name");
  231. this.MiddleName = d.ToString("middle_name");
  232. this.LastName = d.ToString("last_name");
  233. this.Gender = d.ToString("gender");
  234. this.Locale = d.ToString("locale");
  235. this.Link = d.ToString("link");
  236. this.UserName = d.ToString("username");
  237. this.ThirdPartyID = d.ToString("third_party_id");
  238. this.TimeZone = d.ToDouble("timezone");
  239. this.UpdatedTime = d.ToDateTimeOffset("updated_time");
  240. this.Verified = d.ToBoolean("verified");
  241. this.Bio = d.ToString("bio");
  242. this.Birthday = d.ToDateTime("birthday");
  243. this.EMail = d.ToString("email");
  244. if (d.ContainsKey("hometown") == true)
  245. {
  246. this.HomeTown = new IdName(d["hometown"].ToString());
  247. }
  248. if (d.ContainsKey("location") == true)
  249. {
  250. this.Location = new IdName(d["location"].ToString());
  251. }
  252. if (d.ContainsKey("friends") == true)
  253. {
  254. foreach (var s in FacebookClient.CreateJsonTextList(d, "friends"))
  255. {
  256. this.Friends.Add(new User(s));
  257. }
  258. }
  259. if (d.ContainsKey("albums") == true)
  260. {
  261. foreach (var s in FacebookClient.CreateJsonTextList(d, "albums", "data"))
  262. {
  263. this.Albums.Add(new Album(s));
  264. }
  265. }
  266. if (d.ContainsKey("books") == true)
  267. {
  268. foreach (var s in FacebookClient.CreateJsonTextList(d, "books"))
  269. {
  270. this.Books.Add(new Book(s));
  271. }
  272. }
  273. if (d.ContainsKey("movies") == true)
  274. {
  275. foreach (var s in FacebookClient.CreateJsonTextList(d, "movies"))
  276. {
  277. this.Movies.Add(new Movie(s));
  278. }
  279. }
  280. if (d.ContainsKey("music") == true)
  281. {
  282. foreach (var s in FacebookClient.CreateJsonTextList(d, "music"))
  283. {
  284. this.MusicList.Add(new Music(s));
  285. }
  286. }
  287. if (d.ContainsKey("television") == true)
  288. {
  289. foreach (var s in FacebookClient.CreateJsonTextList(d, "television"))
  290. {
  291. this.Televisions.Add(new Television(s));
  292. }
  293. }
  294. if (d.ContainsKey("sports") == true)
  295. {
  296. foreach (var s in FacebookClient.CreateJsonTextList(d, "sports"))
  297. {
  298. this.Sports.Add(new UserSports(s));
  299. }
  300. }
  301. if (d.ContainsKey("favorite_teams") == true)
  302. {
  303. foreach (var s in FacebookClient.CreateJsonTextList(d, "favorite_teams"))
  304. {
  305. this.FavoriteTeams.Add(new IdName(s));
  306. }
  307. }
  308. if (d.ContainsKey("favorite_athletes") == true)
  309. {
  310. foreach (var s in FacebookClient.CreateJsonTextList(d, "favorite_athletes"))
  311. {
  312. this.FavoriteAthletes.Add(new IdName(s));
  313. }
  314. }
  315. if (d.ContainsKey("interested_in") == true)
  316. {
  317. foreach (var s in FacebookClient.CreateTextList(d, "interested_in"))
  318. {
  319. this.InterestedIn.Add(s);
  320. }
  321. }
  322. if (d.ContainsKey("languages") == true)
  323. {
  324. foreach (var s in FacebookClient.CreateJsonTextList(d, "languages"))
  325. {
  326. this.Languages.Add(new IdName(s));
  327. }
  328. }
  329. if (d.ContainsKey("inspirational_people") == true)
  330. {
  331. foreach (var s in FacebookClient.CreateJsonTextList(d, "inspirational_people"))
  332. {
  333. this.InspirationalPeople.Add(new IdName(s));
  334. }
  335. }
  336. if (d.ContainsKey("work") == true)
  337. {
  338. this.Work = new UserWork(d["work"].ToString());
  339. }
  340. else
  341. {
  342. this.Work = new UserWork();
  343. }
  344. if (d.ContainsKey("education") == true)
  345. {
  346. this.Education = new UserEducation(d["education"].ToString());
  347. }
  348. else
  349. {
  350. this.Education = new UserEducation();
  351. }
  352. }
  353. }
  354. }