PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/MSR.LST.ConferenceXP/CXPClient/frmStopLight.cs

#
C# | 326 lines | 242 code | 43 blank | 41 comment | 16 complexity | 33b856c2117def39d7f1e2cfb7e09d94 MD5 | raw file
Possible License(s): Apache-2.0, MPL-2.0-no-copyleft-exception
  1. using System;
  2. using System.Configuration;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Globalization;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. using MSR.LST.Net.Rtp;
  10. namespace MSR.LST.ConferenceXP
  11. {
  12. public class frmStopLight : System.Windows.Forms.Form
  13. {
  14. #region Windows Form Designer generated code
  15. private System.Windows.Forms.MenuItem menuStoplightDetails;
  16. private System.Windows.Forms.ContextMenu contextMenu;
  17. private System.Windows.Forms.NotifyIcon stoplightNotify;
  18. private System.Windows.Forms.RichTextBox txtStatus;
  19. private System.Windows.Forms.Label lblDescription;
  20. private System.Windows.Forms.MenuItem menuStoplightExit;
  21. private System.Windows.Forms.PictureBox pictureBox1;
  22. private System.Windows.Forms.LinkLabel linkLabel1;
  23. private System.ComponentModel.IContainer components;
  24. /// <summary>
  25. /// Required method for Designer support - do not modify
  26. /// the contents of this method with the code editor.
  27. /// </summary>
  28. [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1303")]
  29. private void InitializeComponent()
  30. {
  31. this.components = new System.ComponentModel.Container();
  32. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(frmStopLight));
  33. this.stoplightNotify = new System.Windows.Forms.NotifyIcon(this.components);
  34. this.contextMenu = new System.Windows.Forms.ContextMenu();
  35. this.menuStoplightDetails = new System.Windows.Forms.MenuItem();
  36. this.menuStoplightExit = new System.Windows.Forms.MenuItem();
  37. this.lblDescription = new System.Windows.Forms.Label();
  38. this.txtStatus = new System.Windows.Forms.RichTextBox();
  39. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  40. this.linkLabel1 = new System.Windows.Forms.LinkLabel();
  41. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  42. this.SuspendLayout();
  43. //
  44. // stoplightNotify
  45. //
  46. this.stoplightNotify.ContextMenu = this.contextMenu;
  47. this.stoplightNotify.Icon = ((System.Drawing.Icon)(resources.GetObject("stoplightNotify.Icon")));
  48. this.stoplightNotify.Text = "Testing network connection";
  49. this.stoplightNotify.Visible = true;
  50. this.stoplightNotify.Click += new System.EventHandler(this.stoplightNotify_Click);
  51. this.stoplightNotify.DoubleClick += new System.EventHandler(this.stoplightNotify_DoubleClick);
  52. //
  53. // contextMenu
  54. //
  55. this.contextMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
  56. this.menuStoplightDetails,
  57. this.menuStoplightExit});
  58. //
  59. // menuStoplightDetails
  60. //
  61. this.menuStoplightDetails.Index = 0;
  62. this.menuStoplightDetails.Text = "Open";
  63. this.menuStoplightDetails.Click += new System.EventHandler(this.menuStoplightDetails_Click);
  64. //
  65. // menuStoplightExit
  66. //
  67. this.menuStoplightExit.Index = 1;
  68. this.menuStoplightExit.Text = "Exit";
  69. this.menuStoplightExit.Click += new System.EventHandler(this.menuStoplightExit_Click);
  70. //
  71. // lblDescription
  72. //
  73. this.lblDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
  74. | System.Windows.Forms.AnchorStyles.Right)));
  75. this.lblDescription.FlatStyle = System.Windows.Forms.FlatStyle.System;
  76. this.lblDescription.Location = new System.Drawing.Point(16, 16);
  77. this.lblDescription.Name = "lblDescription";
  78. this.lblDescription.Size = new System.Drawing.Size(452, 52);
  79. this.lblDescription.TabIndex = 1;
  80. this.lblDescription.Text = "This utility detects whether your computer is connected to Internet2 " +
  81. "and to a multicast network. If your computer is not connected to a multicast network, you " +
  82. "can participate in ConferenceXP conferences over unicast or by using the ConferenceXP " +
  83. "Reflector Service.";
  84. //
  85. // txtStatus
  86. //
  87. this.txtStatus.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
  88. | System.Windows.Forms.AnchorStyles.Left)
  89. | System.Windows.Forms.AnchorStyles.Right)));
  90. this.txtStatus.BackColor = System.Drawing.SystemColors.Window;
  91. this.txtStatus.Location = new System.Drawing.Point(16, 110);
  92. this.txtStatus.Name = "txtStatus";
  93. this.txtStatus.ReadOnly = true;
  94. this.txtStatus.Size = new System.Drawing.Size(508, 370);
  95. this.txtStatus.TabIndex = 2;
  96. this.txtStatus.Text = "Determining status...";
  97. this.txtStatus.WordWrap = false;
  98. //
  99. // pictureBox1
  100. //
  101. this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
  102. this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  103. this.pictureBox1.Location = new System.Drawing.Point(476, 16);
  104. this.pictureBox1.Name = "pictureBox1";
  105. this.pictureBox1.Size = new System.Drawing.Size(48, 48);
  106. this.pictureBox1.TabIndex = 4;
  107. this.pictureBox1.TabStop = false;
  108. //
  109. // linkLabel1
  110. //
  111. this.linkLabel1.FlatStyle = System.Windows.Forms.FlatStyle.System;
  112. this.linkLabel1.Location = new System.Drawing.Point(14, 80);
  113. this.linkLabel1.Name = "linkLabel1";
  114. this.linkLabel1.Size = new System.Drawing.Size(216, 25);
  115. this.linkLabel1.TabIndex = 5;
  116. this.linkLabel1.TabStop = true;
  117. this.linkLabel1.Text = "About Internet2 and Multicast Connectivity";
  118. this.linkLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  119. this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
  120. //
  121. // frmStopLight
  122. //
  123. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  124. this.ClientSize = new System.Drawing.Size(540, 488);
  125. this.Controls.Add(this.linkLabel1);
  126. this.Controls.Add(this.pictureBox1);
  127. this.Controls.Add(this.txtStatus);
  128. this.Controls.Add(this.lblDescription);
  129. this.Font = UIFont.FormFont;
  130. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  131. this.MinimumSize = new System.Drawing.Size(420, 400);
  132. this.Name = "frmStopLight";
  133. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  134. this.Text = "Connectivity Detector";
  135. this.Resize += new System.EventHandler(this.frmStopLight_Resize);
  136. this.Load += new System.EventHandler(this.frmStopLight_Load);
  137. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  138. this.ResumeLayout(false);
  139. }
  140. /// <summary>
  141. /// Clean up any resources being used.
  142. /// </summary>
  143. protected override void Dispose( bool disposing )
  144. {
  145. if( disposing )
  146. {
  147. // Dispose detector before components, since detector updates UI
  148. if (detector != null)
  149. {
  150. detector.Dispose();
  151. detector = null;
  152. }
  153. if (components != null)
  154. {
  155. components.Dispose();
  156. }
  157. }
  158. base.Dispose( disposing );
  159. }
  160. #endregion
  161. #region Members
  162. // private ConnectivityDetector detector = null;
  163. private DateTime startTime;
  164. private Icon redLight = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MSR.LST.ConferenceXP.RedLight.ico"));
  165. private Icon greenLight = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MSR.LST.ConferenceXP.GreenLight.ico"));
  166. private Icon yellowLight = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MSR.LST.ConferenceXP.YellowLight.ico"));
  167. private Icon whiteLight = new Icon(Assembly.GetExecutingAssembly().GetManifestResourceStream("MSR.LST.ConferenceXP.WhiteLight.ico"));
  168. private delegate void GuiUpdateHandler(bool networkReceiveDetected,
  169. bool networkSendDetected, bool wellKnownHostDetected, string details);
  170. private GuiUpdateHandler updateGui;
  171. #endregion
  172. #region Constructor
  173. public frmStopLight()
  174. {
  175. InitializeComponent();
  176. // detector = new ConnectivityDetector();
  177. // detector.Connectivity += new ConnectivityDetector.ConnectivityEventHandler(ConnectivityEvent);
  178. startTime = DateTime.Now;
  179. updateGui = new GuiUpdateHandler(UpdateGui);
  180. }
  181. #endregion Constructor
  182. #region Private
  183. private void ConnectivityEvent(bool networkReceiveDetected, bool networkSendDetected,
  184. bool wellKnownHostDetected, string details)
  185. {
  186. if (this.InvokeRequired)
  187. {
  188. this.Invoke(updateGui, networkReceiveDetected, networkSendDetected,
  189. wellKnownHostDetected, details);
  190. }
  191. else
  192. {
  193. UpdateGui(networkReceiveDetected, networkSendDetected,
  194. wellKnownHostDetected, details);
  195. }
  196. }
  197. private void UpdateGui(bool networkReceiveDetected, bool networkSendDetected,
  198. bool wellKnownHostDetected, string details)
  199. {
  200. TimeSpan uptime = DateTime.Now.Subtract(startTime);
  201. bool multicastFunctional = networkReceiveDetected && networkSendDetected;
  202. bool i2Functional = multicastFunctional && wellKnownHostDetected;
  203. // ---------------------------------------------------------
  204. // Tooltips have to be less than 64 characters, be succinct!
  205. // ---------------------------------------------------------
  206. if (i2Functional)
  207. {
  208. stoplightNotify.Icon = greenLight;
  209. stoplightNotify.Text = Strings.Internet2Functional;
  210. }
  211. else if (multicastFunctional)
  212. {
  213. stoplightNotify.Icon = greenLight;
  214. stoplightNotify.Text = Strings.MulticastFunctional;
  215. }
  216. else if (networkReceiveDetected)
  217. {
  218. stoplightNotify.Icon = yellowLight;
  219. stoplightNotify.Text = Strings.ReceiveOnlyNotification;
  220. }
  221. else
  222. {
  223. if (uptime.Minutes > 2)
  224. {
  225. stoplightNotify.Icon = redLight;
  226. stoplightNotify.Text = Strings.MulticastNonfunctional;
  227. }
  228. }
  229. txtStatus.Text = string.Format(CultureInfo.CurrentCulture, Strings.MulticastIPStatus + "\n\n",
  230. detector.MulticastIPAddress.ToString(CultureInfo.InvariantCulture), networkReceiveDetected,
  231. networkSendDetected, multicastFunctional, i2Functional, uptime.Minutes,
  232. uptime.Seconds.ToString("00", CultureInfo.InvariantCulture), details);
  233. }
  234. #region Menu Handlers
  235. private void menuStoplightDetails_Click(object sender, System.EventArgs e)
  236. {
  237. this.WindowState = FormWindowState.Normal;
  238. this.Show();
  239. }
  240. private void menuStoplightExit_Click(object sender, System.EventArgs e)
  241. {
  242. Hide();
  243. Dispose();
  244. }
  245. #endregion
  246. private void stoplightNotify_Click(object sender, System.EventArgs e)
  247. {
  248. this.WindowState = FormWindowState.Normal;
  249. this.Show();
  250. }
  251. private void stoplightNotify_DoubleClick(object sender, System.EventArgs e)
  252. {
  253. this.WindowState = FormWindowState.Normal;
  254. this.Show();
  255. }
  256. private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
  257. {
  258. Process.Start(FMain.helpurlConnectivity);
  259. }
  260. #endregion Private
  261. private void frmStopLight_Resize(object sender, EventArgs e)
  262. {
  263. if (this.WindowState == System.Windows.Forms.FormWindowState.Minimized)
  264. {
  265. this.WindowState = System.Windows.Forms.FormWindowState.Normal;
  266. this.Hide();
  267. }
  268. }
  269. private void frmStopLight_Load(object sender, EventArgs e)
  270. {
  271. this.lblDescription.Font = UIFont.StringFont;
  272. this.txtStatus.Font = UIFont.StringFont;
  273. this.linkLabel1.Font = UIFont.StringFont;
  274. this.stoplightNotify.Text = Strings.TestingNetworkConnection;
  275. this.menuStoplightDetails.Text = Strings.Open;
  276. this.menuStoplightExit.Text = Strings.Exit;
  277. this.lblDescription.Text = Strings.ThisUtilityDetects;
  278. this.txtStatus.Text = Strings.DeterminingStatus;
  279. this.linkLabel1.Text = Strings.AboutInternet2AndMulticast;
  280. this.Text = Strings.ConnectivityDetector;
  281. }
  282. }
  283. }