/// <summary> /// Connect /// </summary> private void DoConnect() { Init(); this.Cursor = Cursors.WaitCursor; if (IsTreeList) { ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.WaitCursor; } if (IsCancel) { if (connStatus != null) { if (connStatus.Connection != null) { connStatus.Connection.Cancel(); } else if (connStatus.Login != null) { connStatus.Login.Cancel(); } connStatus = null; ControlService.DashboardTree.DashboardTreeList.FocusedNode.ImageIndex = 1; ActionHelper.OnDisconnected(true); ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; } return; } ConnectionExceptionAction.IsCancel = false; IPEndPoint endPoint = null; IPEndPoint proxyEndPoint = null; endPoint = new IPEndPoint(IPAddress.Parse(Current.LoginInfomation.IpAddress), Current.LoginInfomation.Port); Current.Controller.Connection.FtpUser.Account = Current.LoginInfomation.ConnectionUserName; Current.Controller.Connection.FtpUser.NoSecurityPWD = Pwd;// Current.LoginInfomation.ConnectionPassword; TcpUFEConnection tcpConn = Current.Controller.Connection as TcpUFEConnection; if (tcpConn != null) { var connParams = new TcpConnectionParams(endPoint, proxyEndPoint, Current.LoginInfomation.ProxyType, Current.LoginInfomation.PorxyUserName, Current.LoginInfomation.PorxyPassword); tcpConn.Params = connParams; } ProWrite.UI.Controls.Actions.UFE.Responses.UFEResponseService.Init(Current); ActionHelper.OnCancelConnect(); DataGate.Log.Info("Start connect."); IFtpManager ftpMgr = Current.Controller.Connection.FtpManager; //Connect task ftpOpenTask = Task.Create(p => { try { //Connect ftp Log.Info("Start connect ftp"); ftpMgr.Open(); if (ftpOpenTask.IsCanceled) { Log.Info("Cancel connect ftp"); return; } picCommunication.InvokeProperty("Image", Resources.Resource.GetImage(Resources.Resource.Images.Pass)); Log.Info("Connect ftp successful."); ftpMgr.IsConnected = true; } catch (Exception ex) { DataGate.Log.Error("Connect ftp failed."); if (!ftpOpenTask.IsCanceled) { this.InvokeMethod(delegate { picError.Visible = true; lblError.Visible = true; this.btnRetry.Enabled = true; this.Cursor = Cursors.Default; ftpMgr.IsConnected = false; SocketException inner = ex.InnerException as SocketException; if (inner != null && inner.SocketErrorCode == SocketError.TimedOut) { } else { this.lblError.Text = "Sorry,connection failed,please check your user name or password."; } ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; }); } return; } connStatus = new ConnectionEntity(); if (ftpOpenTask.IsCanceled) { return; } //Start connect connStatus.Connection = Current.Controller.Connection.OpenAsync(p2 => { ControlService.DashboardTree.Cursor = Cursors.Default; if (ftpOpenTask.IsCanceled) { return; } if (p2.IsSuccessed) { DataGate.Log.Info("Connect successed."); picNetWork.Image = Resources.Resource.GetImage(Resources.Resource.Images.Pass); Thread.Sleep(100); picConnection.Image = Resources.Resource.GetImage(Resources.Resource.Images.Pass); Thread.Sleep(200); if (ftpOpenTask.IsCanceled) { return; } //Start login DoLogin(Current, Current.LoginInfomation.Password); } else { if (ftpOpenTask.IsCanceled) { return; } DataGate.Log.Error("Connect failed."); picError.Visible = true; lblError.Visible = true; //picError.Image = Resources.Resource.GetImage(Resources.Resource.Images.Baffle); this.btnRetry.Enabled = true; this.Cursor = Cursors.Default; connStatus = null; //_isCancelConnect = false; if (!IsCancel) { new ConnectionExceptionAction(p2.Exception).Perform(); } ActionHelper.OnDisconnected(true); ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; } }); }); }
/// <summary> /// Connect /// </summary> private void DoConnect() { if (connStatus != null) { return; } if (isUseProxy && ddlProxyType.SelectedIndex != 0) { if (txtProxyIpAdd.Text.Trim() == "") { MsgBox.Warning("Sorry,the proxy IP address can't be empty"); return; } if (this.txtProxyPortNo.Text.Trim() == "") { MsgBox.Warning("Sorry,the proxy port number can't be empty"); return; } } Cursor = Cursors.WaitCursor; ConnectionExceptionAction.IsCancel = false; IsDisconnection = false; DashboardTree._currentSign = Current; IPEndPoint endPoint = null; IPEndPoint proxyEndPoint = null; LoginInfo info = new LoginInfo(); if (Current.Template.Sign.AutoLogin || Current.LoginInfomation.CanSave || Current.LoginInfomation.CanSaveLoginInfo) { info = CloneManager.Clone <LoginInfo>(Current.LoginInfomation); } if (chkStorePWD.Checked) { info.CanSave = true; } else { info.CanSave = false; } info.IpAddress = txtConnectIpAddress.Text.Trim(); info.Port = Convert.ToInt32(txtConnectPortNo.Text); info.ConnectionUserName = txtServerName.Text.Trim(); info.ConnectionPassword = txtConnectPWD.Text.Trim(); Current.LoginInfomation.ConnectionUserName = txtServerName.Text.Trim(); Current.LoginInfomation.ConnectionPassword = txtConnectPWD.Text.Trim(); endPoint = new IPEndPoint(IPAddress.Parse(info.IpAddress), info.Port); if (isUseProxy && ddlProxyType.SelectedIndex != 0) { info.PorxyUserName = txtProxyUserName.Text; info.ProxyPort = Convert.ToInt32(txtProxyPortNo.Text); info.PorxyAddress = txtProxyIpAdd.Text; info.ProxyType = (ProxyTypes)Enum.Parse(typeof(ProxyTypes), ddlProxyType.SelectedItem.ToString()); info.PorxyPassword = txtProxyPWD.Text; proxyEndPoint = new IPEndPoint(IPAddress.Parse(this.txtProxyIpAdd.Text), Convert.ToInt32(this.txtProxyPortNo.Text)); } else { info.ProxyType = ProxyTypes.None; } Current.LoginInfomation = info; Current.Controller.Connection.FtpUser.Account = info.ConnectionUserName; Current.Controller.Connection.FtpUser.NoSecurityPWD = info.ConnectionPassword; TcpUFEConnection tcpConn = Current.Controller.Connection as TcpUFEConnection; if (tcpConn != null) { var connParams = new TcpConnectionParams(endPoint, proxyEndPoint, info.ProxyType, info.PorxyUserName, info.PorxyPassword); tcpConn.Params = connParams; } ProWrite.UI.Controls.Actions.UFE.Responses.UFEResponseService.Init(Current); this.Hide(); ConnectionProgress progress = new ConnectionProgress(Current, false, info.ConnectionPassword); progress.ShowModalDialog(); if (!chkStorePWD.Checked) { Current.LoginInfomation.ConnectionPassword = ""; } if (progress.Result) { LiveImageAction liveImageAction = new LiveImageAction(); liveImageAction.Sign = Current; liveImageAction.Perform(); StatusAction statusAction = new StatusAction(false); statusAction.Sign = Current; statusAction.Perform(); GetStatusAction getStatus = new GetStatusAction(); getStatus.sign = Current; getStatus.Perform(); LogViewAction logviewAction = new LogViewAction(); logviewAction.sign = Current; logviewAction.Perform(); if (Current.IsWebCam) { IsConnectWebCam = true; } UpdateSignInfo(); } else { ActionHelper.OnDisconnected(false); this.Show(); this.Cursor = Cursors.Default; } }
private void DoConnect() { this.lblError.Visible = false; this.picError.Visible = false; this.btnRetry.Enabled = false; this.Cursor = Cursors.WaitCursor; if (IsTreeList) { ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.WaitCursor; } if (IsCancel) { if (connStatus != null) { if (connStatus.Connection != null) { connStatus.Connection.Cancel(); } else if (connStatus.Login != null) { connStatus.Login.Cancel(); } connStatus = null; ControlService.DashboardTree.DashboardTreeList.FocusedNode.ImageIndex = 1; ActionHelper.OnDisconnected(true); ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; } return; } //SignInfo Current = ControlService.SignCombo.Current; ConnectionExceptionAction.IsCancel = false; IPEndPoint endPoint = null; IPEndPoint proxyEndPoint = null; endPoint = new IPEndPoint(IPAddress.Parse(Current.LoginInfomation.IpAddress), Current.LoginInfomation.Port); Current.Controller.Connection.FtpUser.Account = Current.LoginInfomation.ConnectionUserName; Current.Controller.Connection.FtpUser.NoSecurityPWD = Current.LoginInfomation.ConnectionPassword; TcpUFEConnection tcpConn = Current.Controller.Connection as TcpUFEConnection; if (tcpConn != null) { var connParams = new TcpConnectionParams(endPoint, proxyEndPoint, Current.LoginInfomation.ProxyType, Current.LoginInfomation.PorxyUserName, Current.LoginInfomation.PorxyPassword); tcpConn.Params = connParams; } ProWrite.UI.Controls.Actions.UFE.Responses.UFEResponseService.Init(Current); ActionHelper.OnCancelConnect(); IFtpManager ftpMgr = Current.Controller.Connection.FtpManager; try { ftpMgr.Open(); picCommunication.Image = Resources.Resource.GetImage(Resources.Resource.Images.Pass); Thread.Sleep(200); ftpMgr.IsConnected = true; } catch (Exception ex) { picError.Visible = true; lblError.Visible = true; this.btnRetry.Enabled = true; this.Cursor = Cursors.Default; //picError.Image = Resources.Resource.GetImage(Resources.Resource.Images.Baffle); ftpMgr.IsConnected = false; SocketException inner = ex.InnerException as SocketException; if (inner != null && inner.SocketErrorCode == SocketError.TimedOut) { //MsgBox.Warning("Unable to connect ¨C connection timed out after multiple attempts"); } else { //MsgBox.Warning("Sorry,connection failed,please check your user name or password."); } ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; return; } connStatus = new ConnectionEntity(); connStatus.Connection = Current.Controller.Connection.OpenAsync(p => { ControlService.DashboardTree.Cursor = Cursors.Default; if (p.IsSuccessed) { picNetWork.Image = Resources.Resource.GetImage(Resources.Resource.Images.Pass); Thread.Sleep(100); picConnection.Image = Resources.Resource.GetImage(Resources.Resource.Images.Pass); Thread.Sleep(200); DoLogin(Current, Current.LoginInfomation.Password); } else { picError.Visible = true; lblError.Visible = true; //picError.Image = Resources.Resource.GetImage(Resources.Resource.Images.Baffle); this.btnRetry.Enabled = true; this.Cursor = Cursors.Default; connStatus = null; //_isCancelConnect = false; if (!IsCancel) { new ConnectionExceptionAction(p.Exception).Perform(); } ActionHelper.OnDisconnected(true); ControlService.DashboardTree.DashboardTreeList.Cursor = Cursors.Default; } }); }