📄 sipctunnelaction.cs
字号:
namespace Imps.Client.Core
{
using Imps.Client.Base;
using System;
using System.Threading;
public sealed class SipCTunnelAction : LoginAction
{
private const int CONNECT_TIMEOUT = 0x2bf20;
private bool connectionBroken;
private const string errorMessage = "连接自适应过程中发生错误";
private string tagHost;
private int tagPort;
private AutoResetEvent waitConn;
public SipCTunnelAction(User user, ILoginListner listener) : base(user, listener)
{
}
public override void Cancel()
{
}
public override void Clear()
{
ISipConnection sipConnection = base.User.SipConnection;
if (sipConnection != null)
{
sipConnection.StateChanged -= new EventHandler<StateChangedEventArgs>(this, (IntPtr) this.SipConnection_StateChanged);
sipConnection.ConnectFailed -= new EventHandler<FailedEventArgs>(this, (IntPtr) this.SipConnection_ConnectFailed);
}
base.User.SipConnection = null;
}
public override void Dispose()
{
}
public override bool Execute()
{
bool flag = false;
try
{
base.NotifyMessage("开始连接自适应");
base.User.SipConnection = ConnectionFactory.CreateSipConnection(base.User);
base.User.SipConnection.StateChanged += new EventHandler<StateChangedEventArgs>(this, (IntPtr) this.SipConnection_StateChanged);
base.User.SipConnection.ConnectFailed += new EventHandler<FailedEventArgs>(this, (IntPtr) this.SipConnection_ConnectFailed);
if (this.waitConn == null)
{
this.waitConn = new AutoResetEvent(false);
}
ThreadPool.QueueUserWorkItem(new WaitCallback(this.InnerExecute), base.User);
if (this.waitConn.WaitOne(this.TimeOut, true))
{
flag = (base.User.SipConnection != null) && (base.User.SipConnection.State == ConnectionState.Connected);
}
else
{
base.NotifyLoginFailed("连接自适应过程中发生错误", ExceptionType.CommonException, null);
}
base.NotifyMessage("连接自适应结束");
}
catch (ThreadAbortException exception)
{
base.NotifyWarning("连接自适应过程中发生错误", exception);
}
catch (Exception exception2)
{
base.NotifyLoginFailed("连接自适应过程中发生错误", ExceptionType.CommonException, exception2);
}
return flag;
}
private void Init(User curUser)
{
string sipcProxy = curUser.Configuration.SystemSetting.ServerUriSetting.SipcProxy;
if (string.IsNullOrEmpty(sipcProxy))
{
throw new NullReferenceException("sipc proxy address should not be null!");
}
string[] textArray = sipcProxy.Split(new char[] { ':' });
if (textArray.Length < 2)
{
throw new Exception(string.Format("sipc proxy adress is invalid: {0}", sipcProxy));
}
this.tagHost = textArray[0];
int.TryParse(textArray[1], ref this.tagPort);
}
public void InnerExecute(object state)
{
try
{
User curUser = state as User;
this.Init(curUser);
curUser.SipConnection.Connect(this.tagHost, this.tagPort);
}
catch (Exception exception)
{
base.NotifyLoginFailed("连接自适应过程中发生错误", ExceptionType.CommonException, exception);
this.waitConn.Set();
}
}
private void SipConnection_ConnectFailed(object sender, FailedEventArgs e)
{
try
{
base.NotifyLoginFailed("连接自适应过程中发生错误", ExceptionType.CommonException, e.FailedException);
this.waitConn.Set();
}
catch (Exception exception)
{
base.NotifyException("连接自适应过程中发生错误", exception);
}
}
private void SipConnection_StateChanged(object sender, StateChangedEventArgs e)
{
try
{
if (e.OldState == ConnectionState.Connected)
{
this.connectionBroken = true;
}
if (e.NewState == ConnectionState.Connected)
{
this.waitConn.Set();
}
}
catch (Exception exception)
{
base.NotifyException("连接自适应过程中发生错误", exception);
}
}
internal bool ConnectionBroken
{
get
{
return this.connectionBroken;
}
}
public override bool LocalCacheHit
{
get
{
return false;
}
}
public override Imps.Client.Core.LoginStage LoginStage
{
get
{
return Imps.Client.Core.LoginStage.ConnectToSipc;
}
}
public override int TimeOut
{
get
{
return 0x2bf20;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -