📄 ssnetworkcontrol.cs
字号:
private int ParsePort(string port)
{
int num;
if (((port != null) && (port.Trim() != string.Empty)) && int.TryParse(port, out num))
{
return num;
}
return 0;
}
private void ReadIeHttpProxyTimer_Tick(object sender, EventArgs e)
{
this.UpdateJustTime();
}
private void SetControlsText()
{
this.gbConnStatus.Text = StringTable.NetworkSettingOption.ConnectionStatus;
this.chkConnLog.Text = StringTable.NetworkSettingOption.SaveConnectionLog;
this.ctlExamine.Text = StringTable.NetworkSettingOption.ConnectionDetect;
this.gbNetworkConfig.Text = StringTable.NetworkSettingOption.ConnectionSetting;
this.chkUseDirect.Text = StringTable.NetworkSettingOption.TcpDirectly;
this.lbDirectly.Text = StringTable.NetworkSettingOption.PromptTcpSetting;
this.btnTestTcp.Text = StringTable.NetworkSettingOption.Test;
this.chkUseSocks.Text = StringTable.NetworkSettingOption.SocksProxy;
this.lbSocksServer.Text = StringTable.NetworkSettingOption.ServerUrl;
this.lbSocksPort.Text = StringTable.NetworkSettingOption.ServerPort;
this.lbSocksUser.Text = StringTable.NetworkSettingOption.ServerUserName;
this.lbSocksPassword.Text = StringTable.NetworkSettingOption.ServerPassword;
this.btnTestSocks.Text = StringTable.NetworkSettingOption.Test;
this.chkUseHttpProxy.Text = StringTable.NetworkSettingOption.HttpProxy;
this.ctlHttpProxyType.Items.Add(new UseHttpProxyTypeItem(UseHttpProxyType.UseIeProxySetting));
this.ctlHttpProxyType.Items.Add(new UseHttpProxyTypeItem(UseHttpProxyType.UseManualProxySetting));
this.ctlHttpProxyType.SelectedIndex = 0;
this.ctlPromptHttpSetting.Text = StringTable.NetworkSettingOption.PromptUseIeProxySetting;
this.lbHttpProxyServer.Text = StringTable.NetworkSettingOption.ServerUrl;
this.lbHttpProxyPort.Text = StringTable.NetworkSettingOption.ServerPort;
this.lbHttpUser.Text = StringTable.NetworkSettingOption.ServerUserName;
this.lbHttpPassword.Text = StringTable.NetworkSettingOption.ServerPassword;
this.ctlConnectionType.Text = string.Empty;
}
private void SetLimitation()
{
ControlHelper.SetAcceptDigitOnly(this.txtHttpProxyPort, true);
ControlHelper.SetAcceptDigitOnly(this.txtSocksPort, true);
ControlHelper.SetAcceptPasswordChar(this.txtSocksPassword, true);
ControlHelper.SetAcceptPasswordChar(this.txtHttpProxyPassword, true);
ControlHelper.ForceControlImeHangul(this.txtHttpProxyUserName);
ControlHelper.ForceControlImeHangul(this.txtSocksUserName);
}
private void SsNetworkControl_Disposed(object sender, EventArgs e)
{
this.StopTimer();
}
private void SsNetworkControl_Load(object sender, EventArgs e)
{
this.pbConnStatus.Image = ImpsResources.GetImage("Images.conn.png");
base.Disposed += new EventHandler(this.SsNetworkControl_Disposed);
}
private void StartTimer()
{
if (this.MyTimer == null)
{
this.MyTimer = new System.Windows.Forms.Timer();
this.MyTimer.Interval = 0x3e8;
this.MyTimer.Tick += new EventHandler(this.ReadIeHttpProxyTimer_Tick);
this.MyTimer.Start();
}
}
private void StopTimer()
{
if (this.MyTimer != null)
{
this.MyTimer.Dispose();
this.MyTimer = null;
}
}
private void SupportHttpProxyInputBox()
{
this.txtHttpProxyServerAdress.Enabled = this.CurrentUseHttpProxyType == UseHttpProxyType.UseManualProxySetting;
this.txtHttpProxyPort.Enabled = this.CurrentUseHttpProxyType == UseHttpProxyType.UseManualProxySetting;
this.txtHttpProxyUserName.Enabled = this.chkUseHttpProxy.Checked;
this.txtHttpProxyPassword.Enabled = this.chkUseHttpProxy.Checked;
this.btnTestHttpProxy.Enabled = this.chkUseHttpProxy.Checked;
this.ctlHttpProxyType.Enabled = this.chkUseHttpProxy.Checked;
}
private void SupportSocksProxyInputBoxes()
{
this.txtSockServerAddress.Enabled = this.chkUseSocks.Checked;
this.txtSocksPort.Enabled = this.chkUseSocks.Checked;
this.txtSocksUserName.Enabled = this.chkUseSocks.Checked;
this.txtSocksPassword.Enabled = this.chkUseSocks.Checked;
this.btnTestSocks.Enabled = this.chkUseSocks.Checked && (this.txtSockServerAddress.Text.Trim() != string.Empty);
}
private void SupportTcpInputBoxes()
{
this.btnTestTcp.Enabled = this.chkUseDirect.Checked;
}
private void TestConnection(ConnectionType connectionType)
{
TestConnect tf = new TestConnect();
tf.Shown += delegate {
IConnectionConfigation configation = this.CloneConfigation();
ThreadPool.QueueUserWorkItem(delegate {
ConnectionFactory.TestConnection(new TestConnectionCallBack(tf.ShowMsg), configation, connectionType);
});
};
tf.ShowDialog();
}
private void txtHttpProxyPort_Leave(object sender, EventArgs e)
{
string port = this.txtHttpProxyPort.Text.Trim().TrimStart(new char[] { '0', '-' });
if (!this.CheckPort(port))
{
port = string.IsNullOrEmpty(this.txtHttpProxyServerAdress.Text.Trim()) ? string.Empty : 80.ToString();
}
this.txtHttpProxyPort.Text = port;
}
private void txtHttpProxyServerAdress_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtHttpProxyServerAdress.Text.Trim()) && string.IsNullOrEmpty(this.txtHttpProxyPort.Text.Trim()))
{
this.txtHttpProxyPort.Text = 80.ToString();
}
}
private void txtHttpProxyServerAdress_TextChanged(object sender, EventArgs e)
{
this.btnTestHttpProxy.Enabled = this.chkUseHttpProxy.Checked;
}
private void txtSockServerAddress_Leave(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.txtSockServerAddress.Text.Trim()) && string.IsNullOrEmpty(this.txtSocksPort.Text.Trim()))
{
this.txtSocksPort.Text = 0x438.ToString();
}
}
private void txtSockServerAddress_TextChanged(object sender, EventArgs e)
{
this.btnTestSocks.Enabled = (this.txtSockServerAddress.Text.Trim() != string.Empty) && this.chkUseSocks.Checked;
}
private void txtSocksPort_Leave(object sender, EventArgs e)
{
string port = this.txtSocksPort.Text.Trim().TrimStart(new char[] { '0', '-' });
if (!this.CheckPort(port))
{
port = string.IsNullOrEmpty(this.txtSockServerAddress.Text.Trim()) ? string.Empty : 0x438.ToString();
}
this.txtSocksPort.Text = port;
}
public override bool UpdateData(bool update)
{
Imps.Client.Core.NetworkSetting networkSetting = this.CurrentUser.Configuration.UserSetting.NetworkSetting;
if (update)
{
if (!this.CheckUserInput())
{
return false;
}
networkSetting.BeginUpdate();
networkSetting.SaveLog = this.chkConnLog.Checked;
networkSetting.SocksProxy.ServerUri = this.txtSockServerAddress.Text.Trim();
networkSetting.SocksProxy.ServerPort = this.ParsePort(this.txtSocksPort.Text);
networkSetting.SocksProxy.UserName = this.txtSocksUserName.Text.Trim();
networkSetting.SocksProxy.Password = this.txtSocksPassword.Text;
networkSetting.HttpProxy.ServerUri = this.txtHttpProxyServerAdress.Text.Trim();
networkSetting.HttpProxy.ServerPort = this.ParsePort(this.txtHttpProxyPort.Text);
networkSetting.HttpProxy.UserName = this.txtHttpProxyUserName.Text.Trim();
networkSetting.HttpProxy.Password = this.txtHttpProxyPassword.Text;
networkSetting.UseDirect = this.chkUseDirect.Checked;
networkSetting.UseSocksProxy = this.chkUseSocks.Checked;
networkSetting.UseHttpProxy = this.chkUseHttpProxy.Checked;
networkSetting.UseIeProxy = this.CurrentUseHttpProxyType == UseHttpProxyType.UseIeProxySetting;
networkSetting.EndUpdate();
}
else
{
this.chkConnLog.Checked = networkSetting.SaveLog;
this.txtSockServerAddress.Text = networkSetting.SocksProxy.ServerUri;
this.txtSocksPort.Text = (networkSetting.SocksProxy.ServerPort == 0) ? "" : networkSetting.SocksProxy.ServerPort.ToString();
this.txtSocksPassword.Text = networkSetting.SocksProxy.Password;
this.txtSocksUserName.Text = networkSetting.SocksProxy.UserName;
this.btnTestSocks.Enabled = this.txtSockServerAddress.Text.Trim() != string.Empty;
this.txtHttpProxyServerAdress.Text = networkSetting.HttpProxy.ServerUri;
this.txtHttpProxyPort.Text = (networkSetting.HttpProxy.ServerPort == 0) ? "" : networkSetting.HttpProxy.ServerPort.ToString();
this.txtHttpProxyPassword.Text = networkSetting.HttpProxy.Password;
this.txtHttpProxyUserName.Text = networkSetting.HttpProxy.UserName;
this.bkHttpProxyServerAddress = networkSetting.HttpProxy.ServerUri;
this.bkHttpProxyPort = networkSetting.HttpProxy.ServerPort.ToString();
this.chkUseDirect.Checked = networkSetting.UseDirect;
this.chkUseSocks.Checked = networkSetting.UseSocksProxy;
this.chkUseHttpProxy.Checked = networkSetting.UseHttpProxy;
this.CurrentUseHttpProxyType = networkSetting.UseIeProxy ? UseHttpProxyType.UseIeProxySetting : UseHttpProxyType.UseManualProxySetting;
this.SupportSocksProxyInputBoxes();
this.SupportHttpProxyInputBox();
this.ctlExamine.Enabled = this._frameworkWnd.AccountManager.CurrentUser.Status != UserAccountStatus.Logon;
this.UpdateJustTime();
this.StartTimer();
}
base.Modified = false;
return true;
}
private void UpdateJustTime()
{
if (this.CurrentUseHttpProxyType == UseHttpProxyType.UseIeProxySetting)
{
string str;
int? nullable;
if (IeConfig.ReadIeHttpProxySetting(out str, out nullable))
{
this.txtHttpProxyServerAdress.Text = str ?? string.Empty;
this.txtHttpProxyPort.Text = !nullable.HasValue ? string.Empty : nullable.ToString();
}
else
{
this.txtHttpProxyServerAdress.Text = string.Empty;
this.txtHttpProxyPort.Text = "";
}
}
if ((this.CurrentUser.SipConnection != null) && (this.CurrentUser.SipConnection.State == ConnectionState.Connected))
{
this.ctlConnectionType.Text = this.CurrentUser.SipConnection.ToString();
}
else
{
this.ctlConnectionType.Text = StringTable.ClientCommLayerString.NoConnection;
}
}
private UseHttpProxyType CurrentUseHttpProxyType
{
get
{
return ((UseHttpProxyTypeItem) this.ctlHttpProxyType.SelectedItem).ProxyType;
}
set
{
foreach (UseHttpProxyTypeItem item in this.ctlHttpProxyType.Items)
{
if (item.ProxyType == value)
{
this.ctlHttpProxyType.SelectedItem = item;
if (value == UseHttpProxyType.UseIeProxySetting)
{
this.UpdateJustTime();
}
break;
}
}
}
}
private Imps.Client.Core.User CurrentUser
{
get
{
return this._frameworkWnd.AccountManager.CurrentUser;
}
}
public string HttpProxyHost
{
get
{
return this.txtHttpProxyServerAdress.Text.Trim();
}
}
public string HttpProxyPassword
{
get
{
return this.txtHttpProxyPassword.Text;
}
}
public int HttpProxyPort
{
get
{
int num;
if (int.TryParse(this.txtHttpProxyPort.Text, out num))
{
return num;
}
return 0;
}
}
public string HttpProxyUserName
{
get
{
return this.txtHttpProxyUserName.Text.Trim();
}
}
public string SocksProxyHost
{
get
{
return this.txtSockServerAddress.Text;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -