PageRenderTime 31ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/NodeXL/GraphDataProviders/Dialogs/Twitter/TwitterGetUserNetwork/TwitterGetUserNetworkDialog.cs

#
C# | 374 lines | 166 code | 67 blank | 141 comment | 8 complexity | 5eac33e3983f4c3233e7961ea1dfaba1 MD5 | raw file
  1. // Copyright (c) Microsoft Corporation. All rights reserved.
  2. using System;
  3. using System.Windows.Forms;
  4. using System.ComponentModel;
  5. using System.Diagnostics;
  6. using Microsoft.SocialNetworkLib;
  7. namespace Microsoft.NodeXL.GraphDataProviders.Twitter
  8. {
  9. //*****************************************************************************
  10. // Class: TwitterGetUserNetworkDialog
  11. //
  12. /// <summary>
  13. /// Gets the network of people followed by a Twitter user or people whom a
  14. /// Twitter user follows.
  15. /// </summary>
  16. ///
  17. /// <remarks>
  18. /// Call <see cref="Form.ShowDialog()" /> to show the dialog. If it returns
  19. /// DialogResult.OK, get the network from the <see
  20. /// cref="GraphDataProviderDialogBase.Results" /> property.
  21. /// </remarks>
  22. //*****************************************************************************
  23. public partial class TwitterGetUserNetworkDialog :
  24. TwitterGraphDataProviderDialogBase
  25. {
  26. //*************************************************************************
  27. // Constructor: TwitterGetUserNetworkDialog()
  28. //
  29. /// <summary>
  30. /// Initializes a new instance of the <see
  31. /// cref="TwitterGetUserNetworkDialog" /> class.
  32. /// </summary>
  33. //*************************************************************************
  34. public TwitterGetUserNetworkDialog()
  35. :
  36. base ( new TwitterUserNetworkAnalyzer() )
  37. {
  38. InitializeComponent();
  39. InitializeTwitterAuthorizationManager(usrTwitterAuthorization);
  40. // m_sScreenNameToAnalyze
  41. // m_bIncludeFollowedVertices
  42. // m_bIncludeFollowerVertices
  43. // m_bIncludeFollowedFollowerEdges
  44. // m_bIncludeRepliesToEdges
  45. // m_bIncludeMentionsEdges
  46. // m_eNetworkLevel
  47. // m_bIncludeLatestStatuses
  48. // m_iMaximumPeoplePerRequest
  49. DoDataExchange(false);
  50. AssertValid();
  51. }
  52. //*************************************************************************
  53. // Property: ToolStripStatusLabel
  54. //
  55. /// <summary>
  56. /// Gets the dialog's ToolStripStatusLabel control.
  57. /// </summary>
  58. ///
  59. /// <value>
  60. /// The dialog's ToolStripStatusLabel control, or null if the dialog
  61. /// doesn't have one. The default is null.
  62. /// </value>
  63. ///
  64. /// <remarks>
  65. /// If the derived dialog overrides this property and returns a non-null
  66. /// ToolStripStatusLabel control, the control's text will automatically get
  67. /// updated when the HttpNetworkAnalyzer fires a ProgressChanged event.
  68. /// </remarks>
  69. //*************************************************************************
  70. protected override ToolStripStatusLabel
  71. ToolStripStatusLabel
  72. {
  73. get
  74. {
  75. AssertValid();
  76. return (this.slStatusLabel);
  77. }
  78. }
  79. //*************************************************************************
  80. // Method: DoDataExchange()
  81. //
  82. /// <summary>
  83. /// Transfers data between the dialog's fields and its controls.
  84. /// </summary>
  85. ///
  86. /// <param name="bFromControls">
  87. /// true to transfer data from the dialog's controls to its fields, false
  88. /// for the other direction.
  89. /// </param>
  90. ///
  91. /// <returns>
  92. /// true if the transfer was successful.
  93. /// </returns>
  94. //*************************************************************************
  95. protected override Boolean
  96. DoDataExchange
  97. (
  98. Boolean bFromControls
  99. )
  100. {
  101. if (bFromControls)
  102. {
  103. // Validate the controls.
  104. if ( !ValidateRequiredTextBox(txbScreenNameToAnalyze,
  105. "Enter the screen name of a Twitter user.",
  106. out m_sScreenNameToAnalyze) )
  107. {
  108. return (false);
  109. }
  110. m_bIncludeFollowedVertices = m_bIncludeFollowerVertices = false;
  111. if (radIncludeFollowedVertices.Checked)
  112. {
  113. m_bIncludeFollowedVertices = true;
  114. }
  115. else if (radIncludeFollowerVertices.Checked)
  116. {
  117. m_bIncludeFollowerVertices = true;
  118. }
  119. else
  120. {
  121. m_bIncludeFollowedVertices = m_bIncludeFollowerVertices = true;
  122. }
  123. m_bIncludeFollowedFollowerEdges =
  124. chkIncludeFollowedFollowerEdges.Checked;
  125. m_bIncludeRepliesToEdges = chkIncludeRepliesToEdges.Checked;
  126. m_bIncludeMentionsEdges = chkIncludeMentionsEdges.Checked;
  127. m_eNetworkLevel = usrNetworkLevel.Level;
  128. m_bIncludeLatestStatuses = chkIncludeLatestStatuses.Checked;
  129. m_iMaximumPeoplePerRequest = usrLimitToN.N;
  130. }
  131. else
  132. {
  133. txbScreenNameToAnalyze.Text = m_sScreenNameToAnalyze;
  134. if (m_bIncludeFollowedVertices)
  135. {
  136. if (m_bIncludeFollowerVertices)
  137. {
  138. radIncludeFollowedAndFollower.Checked = true;
  139. }
  140. else
  141. {
  142. radIncludeFollowedVertices.Checked = true;
  143. }
  144. }
  145. else
  146. {
  147. radIncludeFollowerVertices.Checked = true;
  148. }
  149. chkIncludeFollowedFollowerEdges.Checked =
  150. m_bIncludeFollowedFollowerEdges;
  151. chkIncludeRepliesToEdges.Checked = m_bIncludeRepliesToEdges;
  152. chkIncludeMentionsEdges.Checked = m_bIncludeMentionsEdges;
  153. usrNetworkLevel.Level = m_eNetworkLevel;
  154. chkIncludeLatestStatuses.Checked = m_bIncludeLatestStatuses;
  155. usrLimitToN.N = m_iMaximumPeoplePerRequest;
  156. EnableControls();
  157. }
  158. return (true);
  159. }
  160. //*************************************************************************
  161. // Method: StartAnalysis()
  162. //
  163. /// <summary>
  164. /// Starts the Twitter analysis.
  165. /// </summary>
  166. ///
  167. /// <remarks>
  168. /// It's assumed that DoDataExchange(true) was called and succeeded.
  169. /// </remarks>
  170. //*************************************************************************
  171. protected override void
  172. StartAnalysis()
  173. {
  174. AssertValid();
  175. m_oGraphMLXmlDocument = null;
  176. Debug.Assert(m_oHttpNetworkAnalyzer is TwitterUserNetworkAnalyzer);
  177. TwitterUserNetworkAnalyzer.WhatToInclude eWhatToInclude =
  178. (m_bIncludeFollowedVertices ?
  179. TwitterUserNetworkAnalyzer.WhatToInclude.FollowedVertices : 0)
  180. |
  181. (m_bIncludeFollowerVertices ?
  182. TwitterUserNetworkAnalyzer.WhatToInclude.FollowerVertices : 0)
  183. |
  184. (m_bIncludeLatestStatuses ?
  185. TwitterUserNetworkAnalyzer.WhatToInclude.LatestStatuses : 0)
  186. |
  187. (m_bIncludeFollowedFollowerEdges ?
  188. TwitterUserNetworkAnalyzer.WhatToInclude.FollowedFollowerEdges
  189. : 0)
  190. |
  191. (m_bIncludeRepliesToEdges ?
  192. TwitterUserNetworkAnalyzer.WhatToInclude.RepliesToEdges : 0)
  193. |
  194. (m_bIncludeMentionsEdges ?
  195. TwitterUserNetworkAnalyzer.WhatToInclude.MentionsEdges : 0)
  196. ;
  197. ( (TwitterUserNetworkAnalyzer)m_oHttpNetworkAnalyzer ).
  198. GetNetworkAsync(m_sScreenNameToAnalyze, eWhatToInclude,
  199. m_eNetworkLevel, m_iMaximumPeoplePerRequest);
  200. }
  201. //*************************************************************************
  202. // Method: EnableControls()
  203. //
  204. /// <summary>
  205. /// Enables or disables the dialog's controls.
  206. /// </summary>
  207. //*************************************************************************
  208. protected override void
  209. EnableControls()
  210. {
  211. AssertValid();
  212. Boolean bIsBusy = m_oHttpNetworkAnalyzer.IsBusy;
  213. EnableControls(!bIsBusy, pnlUserInputs);
  214. btnOK.Enabled = !bIsBusy;
  215. this.UseWaitCursor = bIsBusy;
  216. }
  217. //*************************************************************************
  218. // Method: OnEmptyGraph()
  219. //
  220. /// <summary>
  221. /// Handles the case where a graph was successfully obtained by is empty.
  222. /// </summary>
  223. //*************************************************************************
  224. protected override void
  225. OnEmptyGraph()
  226. {
  227. AssertValid();
  228. this.ShowInformation("There are no people in that network.");
  229. txbScreenNameToAnalyze.Focus();
  230. }
  231. //*************************************************************************
  232. // Method: btnOK_Click()
  233. //
  234. /// <summary>
  235. /// Handles the Click event on the btnOK button.
  236. /// </summary>
  237. ///
  238. /// <param name="sender">
  239. /// Standard event argument.
  240. /// </param>
  241. ///
  242. /// <param name="e">
  243. /// Standard event argument.
  244. /// </param>
  245. //*************************************************************************
  246. protected void
  247. btnOK_Click
  248. (
  249. object sender,
  250. EventArgs e
  251. )
  252. {
  253. AssertValid();
  254. OnOKClick();
  255. }
  256. //*************************************************************************
  257. // Method: AssertValid()
  258. //
  259. /// <summary>
  260. /// Asserts if the object is in an invalid state. Debug-only.
  261. /// </summary>
  262. //*************************************************************************
  263. // [Conditional("DEBUG")]
  264. public override void
  265. AssertValid()
  266. {
  267. base.AssertValid();
  268. Debug.Assert(m_sScreenNameToAnalyze != null);
  269. // m_bIncludeFollowedVertices
  270. // m_bIncludeFollowerVertices
  271. // m_bIncludeFollowedFollowerEdges
  272. // m_bIncludeRepliesToEdges
  273. // m_bIncludeMentionsEdges
  274. // m_eNetworkLevel
  275. // m_bIncludeLatestStatuses
  276. Debug.Assert(m_iMaximumPeoplePerRequest > 0);
  277. }
  278. //*************************************************************************
  279. // Protected fields
  280. //*************************************************************************
  281. // These are static so that the dialog's controls will retain their values
  282. // between dialog invocations. Most NodeXL dialogs persist control values
  283. // via ApplicationSettingsBase, but this plugin does not have access to
  284. // that and so it resorts to static fields.
  285. /// The screen name of the Twitter user whose network should be analyzed.
  286. protected static String m_sScreenNameToAnalyze = "bob";
  287. /// true to include a vertex for each person followed by the user.
  288. protected static Boolean m_bIncludeFollowedVertices = true;
  289. /// true to include a vertex for each person following the user.
  290. protected static Boolean m_bIncludeFollowerVertices = false;
  291. /// true to include an edge for each followed/following relationship.
  292. protected static Boolean m_bIncludeFollowedFollowerEdges = true;
  293. /// true to include an edge from person A to person B if person A's latest
  294. /// tweet is a reply to person B.
  295. protected static Boolean m_bIncludeRepliesToEdges = false;
  296. /// true to include an edge from person A to person B if person A's latest
  297. /// tweet is mentions person B.
  298. protected static Boolean m_bIncludeMentionsEdges = false;
  299. /// Network level to include.
  300. protected static NetworkLevel m_eNetworkLevel = NetworkLevel.One;
  301. /// true to include each user's latest status.
  302. protected static Boolean m_bIncludeLatestStatuses;
  303. /// Maximum number of people to request for each query, or Int32.MaxValue
  304. /// for no limit.
  305. protected static Int32 m_iMaximumPeoplePerRequest = Int32.MaxValue;
  306. }
  307. }