📄 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, (IntPtr) 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.get_Item(key);
node.Text = text;
node.Nodes.Clear();
node.ImageIndex = imageIndex;
node.SelectedImageIndex = imageIndex;
List<DetectResult>.Enumerator enumerator = details.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
DetectResult result = enumerator.get_Current();
node.Nodes.Add("1", result.Desscription, this.GetImageIndex(result.Status), this.GetImageIndex(result.Status));
}
}
finally
{
enumerator.Dispose();
}
node.Expand();
}
}
private void DeteachEventHandler()
{
this._curAction.OnDetectFinished -= new EventHandler<DetectEventArgs>(this, (IntPtr) 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 input = Imps.Client.Core.FixedClientSetting.Instance.TestConnectionUrl;
try
{
Match match = Regex.Match(input, "//[^/]{0,}");
if (match.Success)
{
string[] textArray = match.Value.ToString().Substring(2).Split(new char[] { ':' });
int num = 80;
if (textArray.Length > 1)
{
int.TryParse(textArray[1], ref num);
}
this.data.ServerDnsName.Add(textArray[0]);
this.data.Servers.Add(textArray[0], num);
}
}
catch
{
}
}
private void InitDetectTree()
{
DetectAction action2;
DetectAction action = new DetectAction();
for (NetworkDetectStage nextStage = action.NextStage; nextStage != NetworkDetectStage.Finished; nextStage = action2.NextStage)
{
action2 = this.GetAction(nextStage);
this.tvDetect.Nodes.Add(nextStage.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();
this.tvDetect.Dock = DockStyle.Fill;
this.tvDetect.ImageIndex = 0;
this.tvDetect.ImageList = this.il;
this.tvDetect.Location = new System.Drawing.Point(0, 0);
this.tvDetect.Name = "tvDetect";
this.tvDetect.SelectedImageIndex = 0;
this.tvDetect.Size = new Size(0x193, 0x139);
this.tvDetect.TabIndex = 0;
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.AutoSizeToImage = false;
this.btnClose.BackColor = Color.Transparent;
this.btnClose.BackgroundImageDisable = null;
this.btnClose.BackgroundImageDown = null;
this.btnClose.BackgroundImageHover = null;
this.btnClose.ChangeSkin = true;
this.btnClose.DialogResult = DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(0x148, 0x13f);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new Size(0x4b, 0x19);
this.btnClose.TabIndex = 3;
this.btnClose.Text = "关闭";
this.btnClose.set_UseVisualStyleBackColor(false);
this.btnClose.Click += new EventHandler(this.btnClose_Click);
this.btnRestartDetect.AutoSizeToImage = false;
this.btnRestartDetect.BackColor = Color.Transparent;
this.btnRestartDetect.BackgroundImageDisable = null;
this.btnRestartDetect.BackgroundImageDown = null;
this.btnRestartDetect.BackgroundImageHover = null;
this.btnRestartDetect.ChangeSkin = true;
this.btnRestartDetect.Location = new System.Drawing.Point(0xf7, 0x13f);
this.btnRestartDetect.Name = "btnRestartDetect";
this.btnRestartDetect.Size = new Size(0x4b, 0x19);
this.btnRestartDetect.TabIndex = 2;
this.btnRestartDetect.Text = "重新诊断";
this.btnRestartDetect.set_UseVisualStyleBackColor(false);
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.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new Size(0x193, 0x139);
this.panel1.TabIndex = 3;
this.pb.Location = new System.Drawing.Point(3, 0x13d);
this.pb.Name = "pb";
this.pb.Size = new Size(0xe7, 0x19);
this.pb.set_Style(2);
this.pb.TabIndex = 1;
this.pb.Visible = false;
base.set_AutoScaleDimensions(new SizeF(6f, 13f));
base.set_AutoScaleMode(1);
base.ClientSize = new Size(0x1a8, 0x19d);
base.Controls.Add(this.panel1);
base.Controls.Add(this.btnRestartDetect);
base.Controls.Add(this.btnClose);
base.DisplayLocation = new System.Drawing.Point(0x12, 0x26);
base.DisplaySize = new Size(0x19f, 0x19d);
base.FormBorderStyle = FormBorderStyle.FixedSingle;
base.Icon = (Icon) manager.GetObject("$this.Icon");
base.MinimizeBox = false;
base.Name = "NetworkDetectForm";
base.set_Padding(new Padding(6, 0x22, 0x13, 9));
base.ShowInTaskbar = false;
base.StartPosition = FormStartPosition.CenterScreen;
base.Text = "网络诊断";
base.Load += new EventHandler(this.NetworkDetectForm_Load);
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 + -