📄 networkdetectform.cs
字号:
namespace Imps.Client.Pc
{
using Imps.Client.CommLayer;
using Imps.Client.CommLayer.NetworkDetect;
using Imps.Client.Core;
using Imps.Client.Pc.BizControls;
using Imps.Client.Pc.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Text.RegularExpressions;
using System.Windows.Forms;
public class NetworkDetectForm : XIMDialog
{
private DetectAction _curAction;
private XButton btnClose;
private XButton btnRestartDetect;
private IContainer components;
private DetectData data;
private ImageList il;
private Panel panel1;
private ProgressBar pb;
private const string RegexServer = "//[^/]{0,}";
private TreeView tvDetect;
public NetworkDetectForm()
{
this.InitializeComponent();
}
private void _curAction_OnDetectFinished(object sender, DetectEventArgs e)
{
DetectAction action = sender as DetectAction;
if (action != null)
{
action.Dispose();
this.DeteachEventHandler();
if (e.Passed)
{
this.ChangeTreeStatus(this._curAction.CurrentStage.ToString(), this._curAction.Description, 1, false, e.Details);
if (this._curAction.NextStage != NetworkDetectStage.Finished)
{
this._curAction = this.GetAction(action.NextStage);
this.AttachEventHandler();
this._curAction.BeginDetectAction();
}
else
{
this.EnableButtons(true);
}
}
else
{
this.ChangeTreeStatus(this._curAction.CurrentStage.ToString(), this._curAction.Description, 2, false, e.Details);
if (this._curAction.CanResume)
{
if (this._curAction.NextStage != NetworkDetectStage.Finished)
{
this._curAction = this.GetAction(action.NextStage);
this.AttachEventHandler();
this._curAction.BeginDetectAction();
}
else
{
this.EnableButtons(true);
}
}
else
{
this.EnableButtons(true);
}
}
}
}
private void AttachEventHandler()
{
this._curAction.OnDetectFinished += new EventHandler<DetectEventArgs>(this._curAction_OnDetectFinished);
}
private void btnClose_Click(object sender, EventArgs e)
{
base.Close();
}
private void btnRestartDetect_Click(object sender, EventArgs e)
{
this.StartDetectAction();
this.EnableButtons(false);
}
private void ChangeTreeStatus(string key, string text, int imageIndex, bool showImg, List<DetectResult> details)
{
if (this.tvDetect.InvokeRequired)
{
ChangeTreeStatusCallBack method = new ChangeTreeStatusCallBack(this.ChangeTreeStatus);
if (base.IsHandleCreated)
{
base.Invoke(method, new object[] { key, text, imageIndex, showImg, details });
}
}
else
{
TreeNode node = this.tvDetect.Nodes[key];
node.Text = text;
node.Nodes.Clear();
node.ImageIndex = imageIndex;
node.SelectedImageIndex = imageIndex;
foreach (DetectResult result in details)
{
node.Nodes.Add("1", result.Desscription, this.GetImageIndex(result.Status), this.GetImageIndex(result.Status));
}
node.Expand();
}
}
private void DeteachEventHandler()
{
this._curAction.OnDetectFinished -= new EventHandler<DetectEventArgs>(this._curAction_OnDetectFinished);
}
protected override void Dispose(bool disposing)
{
if (disposing && (this.components != null))
{
this.components.Dispose();
}
base.Dispose(disposing);
}
private void EnableButtons(bool enable)
{
if (this.btnClose.InvokeRequired)
{
try
{
SetButtonStatusCallback method = new SetButtonStatusCallback(this.EnableButtons);
if (base.IsHandleCreated)
{
base.Invoke(method, new object[] { enable });
}
}
catch (Exception)
{
}
}
else
{
this.btnRestartDetect.Enabled = enable;
this.pb.Visible = !enable;
this.btnClose.Focus();
}
}
private DetectAction GetAction(NetworkDetectStage stage)
{
DetectAction action = new AdapterDetectAction();
switch (stage)
{
case NetworkDetectStage.NetworkAdapter:
action = new AdapterDetectAction();
break;
case NetworkDetectStage.IPEndPoint:
action = new IPDetectAction();
break;
case NetworkDetectStage.GateWay:
action = new GateWayDetectAction();
break;
case NetworkDetectStage.IeOffline:
action = new OfflineDetecAction();
break;
case NetworkDetectStage.Proxy:
action = new ProxyDetectAction();
break;
case NetworkDetectStage.KeyPort:
action = new KeyPortDetectAction();
break;
case NetworkDetectStage.HostFile:
action = new HostFileDetectAction();
break;
case NetworkDetectStage.DNS:
action = new DNSDetecAction();
break;
}
action.DetectData = this.data;
return action;
}
private int GetImageIndex(DetectStatus status)
{
switch (status)
{
case DetectStatus.Passed:
return 1;
case DetectStatus.Failed:
return 2;
case DetectStatus.Suspect:
return 3;
}
return 0;
}
private void InitDetectData()
{
this.data = new DetectData();
string testConnectionUrl = Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl;
try
{
Match match = Regex.Match(testConnectionUrl, "//[^/]{0,}");
if (match.Success)
{
string[] strArray = match.Value.ToString().Substring(2).Split(new char[] { ':' });
int result = 80;
if (strArray.Length > 1)
{
int.TryParse(strArray[1], out result);
}
this.data.ServerDnsName.Add(strArray[0]);
this.data.Servers.Add(strArray[0], result);
}
}
catch
{
}
}
private void InitDetectTree()
{
DetectAction action2;
DetectAction action = new DetectAction();
for (NetworkDetectStage stage = action.NextStage; stage != NetworkDetectStage.Finished; stage = action2.NextStage)
{
action2 = this.GetAction(stage);
this.tvDetect.Nodes.Add(stage.ToString(), action2.Description);
}
}
private void InitializeComponent()
{
this.components = new Container();
ComponentResourceManager manager = new ComponentResourceManager(typeof(NetworkDetectForm));
this.tvDetect = new TreeView();
this.il = new ImageList(this.components);
this.btnClose = new XButton();
this.btnRestartDetect = new XButton();
this.panel1 = new Panel();
this.pb = new ProgressBar();
this.panel1.SuspendLayout();
base.SuspendLayout();
base.menubar.Location = new Point(3, 0x21);
this.tvDetect.Location = new Point(3, 3);
this.tvDetect.Name = "tvDetect";
this.tvDetect.Size = new Size(0x188, 0x133);
this.tvDetect.TabIndex = 0;
this.tvDetect.ImageList = this.il;
this.il.ImageStream = (ImageListStreamer) manager.GetObject("il.ImageStream");
this.il.TransparentColor = Color.Transparent;
this.il.Images.SetKeyName(0, "Init.png");
this.il.Images.SetKeyName(1, "Right.png");
this.il.Images.SetKeyName(2, "");
this.il.Images.SetKeyName(3, "");
this.btnClose.DialogResult = DialogResult.Cancel;
this.btnClose.Location = new Point(0x13f, 0x13d);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new Size(0x4b, 0x19);
this.btnClose.TabIndex = 3;
this.btnClose.Text = "关闭";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new EventHandler(this.btnClose_Click);
this.btnRestartDetect.Location = new Point(0xee, 0x13d);
this.btnRestartDetect.Name = "btnRestartDetect";
this.btnRestartDetect.Size = new Size(0x4b, 0x19);
this.btnRestartDetect.TabIndex = 2;
this.btnRestartDetect.Text = "重新诊断";
this.btnRestartDetect.UseVisualStyleBackColor = true;
this.btnRestartDetect.Click += new EventHandler(this.btnRestartDetect_Click);
this.panel1.BackColor = Color.Transparent;
this.panel1.Controls.Add(this.pb);
this.panel1.Controls.Add(this.tvDetect);
this.panel1.Controls.Add(this.btnRestartDetect);
this.panel1.Controls.Add(this.btnClose);
this.panel1.Dock = DockStyle.Fill;
this.panel1.Location = new Point(6, 0x22);
this.panel1.Name = "panel1";
this.panel1.Size = new Size(0x193, 0x171);
this.panel1.TabIndex = 3;
this.pb.Location = new Point(3, 0x13d);
this.pb.Name = "pb";
this.pb.Size = new Size(0xe7, 0x19);
this.pb.Style = ProgressBarStyle.Marquee;
this.pb.TabIndex = 1;
this.pb.Visible = false;
base.AcceptButton = this.btnRestartDetect;
base.AutoScaleDimensions = new SizeF(6f, 13f);
base.AutoScaleMode = AutoScaleMode.Font;
base.CancelButton = this.btnClose;
base.ClientSize = new Size(0x1ac, 0x19c);
base.Controls.Add(this.panel1);
base.FormBorderStyle = FormBorderStyle.FixedSingle;
base.Icon = (Icon) manager.GetObject("$this.Icon");
base.MinimizeBox = false;
base.Name = "NetworkDetectForm";
base.Padding = new Padding(6, 0x22, 0x13, 9);
base.ShowIcon = false;
base.ShowInTaskbar = false;
base.StartPosition = FormStartPosition.CenterScreen;
base.Text = "网络诊断";
base.Load += new EventHandler(this.NetworkDetectForm_Load);
base.Controls.SetChildIndex(this.panel1, 0);
base.Controls.SetChildIndex(base.menubar, 0);
this.panel1.ResumeLayout(false);
base.ResumeLayout(false);
}
private void NetworkDetectForm_Load(object sender, EventArgs e)
{
this.StartDetectAction();
this.EnableButtons(false);
}
protected override void OnFormClosed(FormClosedEventArgs e)
{
this.DeteachEventHandler();
base.OnFormClosed(e);
}
private void StartDetectAction()
{
this.tvDetect.Nodes.Clear();
this.InitDetectTree();
this.InitDetectData();
this._curAction = this.GetAction(new DetectAction().NextStage);
this.AttachEventHandler();
this._curAction.BeginDetectAction();
}
private delegate void ChangeTreeStatusCallBack(string key, string text, int imageIndex, bool showImg, List<DetectResult> details);
private delegate void SetButtonStatusCallback(bool enable);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -