/// <summary> /// 在指定时间内尝试连接指定主机上的指定端口。 (默认端口:80,默认链接超时:5000毫秒) /// </summary> /// <param name= "hostname ">要连接到的远程主机的 DNS 名。</param> /// <param name= "port ">要连接到的远程主机的端口号。 </param> /// <param name= "millisecondsTimeout ">要等待的毫秒数,或 -1 表示无限期等待。</param> /// <returns>已连接的一个 TcpClient 实例。</returns> public static TcpClient Connect(string hostname, int?port, int?millisecondsTimeout) { ConnectorState cs = new ConnectorState(); cs.Hostname = hostname; cs.Port = port ?? 80; ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectThreaded), cs); if (cs.Completed.WaitOne(millisecondsTimeout ?? 5000, false)) { if (cs.TcpClient != null) { return(cs.TcpClient); } return(null); //throw cs.Exception; } else { cs.Abort(); return(null); //throw new SocketException(11001); // cannot connect } }
/// <summary> /// Sets the state of the connector space object /// </summary> /// <param name="connectorState">The state to set the connector to</param> public void SetConnectorState(ConnectorState connectorState) { string result = ws.SetConnectorState(this.MAID.ToMmsGuid(), this.ID.ToMmsGuid(), (CONNECTORSTATE)connectorState); SyncServer.ThrowExceptionOnReturnError(result); this.Refresh(); }
private static void ConnectThreaded(object state) { ConnectorState cs = (ConnectorState)state; cs.Thread = Thread.CurrentThread; try { TcpClient tc = new TcpClient(cs.Hostname, cs.Port); if (cs.Aborted) { try { tc.GetStream().Close(); } catch { } try { tc.Close(); } catch { } } else { cs.TcpClient = tc; cs.Completed.Set(); } } catch (Exception e) { cs.Exception = e; cs.Completed.Set(); } }
void OnStateChangedProc(int state, byte[] resultdata) { ConnectorResult result = convertConnectorResult(resultdata); ConnectorState s = (ConnectorState)state; ADebug.Log("OnStateChangedProc state: " + s + " " + result.ToString()); if (s == ConnectorState.Reconnected && result.IsSuccess()) { Connected = true; } else { Connected = false; } if (StateChangedEvent != null) { try { StateChangedEvent(s, result); } catch (Exception ex) { ADebug.LogException(ex); } } }
private void SetSimConnectControls(ConnectorState state, string statusMessage) { lblSimStatus.Text = statusMessage; switch (state) { case ConnectorState.Connected: lblSimStatus.ForeColor = Color.Green; buttonSimConnect.Text = "Disconnect from SimConnect"; break; case ConnectorState.Connecting: lblSimStatus.ForeColor = Color.Black; buttonSimConnect.Text = "Disconnect from SimConnect"; break; case ConnectorState.Disconnected: lblSimStatus.ForeColor = Color.Black; buttonSimConnect.Text = "Connect to SimConnect"; break; case ConnectorState.Retrying: lblSimStatus.ForeColor = Color.Red; buttonSimConnect.Text = "Disconnect from SimConnect"; lblSimStatus.Text += "... Retrying"; break; } lblSimStatus.Invalidate(); buttonSimConnect.Invalidate(); }
public CSObjectEnumerator GetDisconnectors(ConnectorState state) { string type; switch (state) { case ConnectorState.Normal: type = "normal"; break; case ConnectorState.Explicit: type = "explicit"; break; case ConnectorState.Filtered: type = "stay"; break; default: throw new InvalidOperationException("Unknown connector type"); } string searchText = $"<criteria><connector>false</connector><connector-state>{type}</connector-state></criteria>"; return(this.ExportConnectorSpace(searchText)); }
/// <inheritdoc/> public override void OnBeforeDebugAdjustablesUpdate() { _dbgOldConnectorState = connectorState; if (connectorState == ConnectorState.Deployed) { _dbgOldCableLength = currentCableLength; SaveConnectorModelPosAndRot(); _dbgOldConnectorPosAndRot = persistedConnectorPosAndRot; SetConnectorState(ConnectorState.Locked); } base.OnBeforeDebugAdjustablesUpdate(); }
/// <summary> /// Loads the settings. /// </summary> /// <returns></returns> private ConnectorState LoadState() { string settingFilePath = ConfigurationManager.GetInstance().GetStateFilePath(); if (File.Exists(settingFilePath) == false) { return(new ConnectorState()); } ConnectorState configuration = SerializationManager.ReadSettings <ConnectorState>(settingFilePath); return(configuration); }
public async ValueTask OpenAsync(string host, string database, string userName, string password, CancellationToken cancellationToken) { m_connectorState = ConnectorState.Connecting; var socketTask = ConnectAsync(host); var socket = socketTask.IsCompletedSuccessfully ? socketTask.Result : await socketTask.ConfigureAwait(false); var sendBufferBytes = m_arrayPool.Rent(512); var receiveBufferBytes = m_arrayPool.Rent(512); try { var sendBuffer = new Memory <byte>(sendBufferBytes); var receiveBuffer = new Memory <byte>(sendBufferBytes); var sender = new SocketSender(socket); var sendStartupMessageTask = SendStartupMessage(sender, sendBuffer, database, userName, cancellationToken); if (!sendStartupMessageTask.IsCompletedSuccessfully) { await sendStartupMessageTask.ConfigureAwait(false); } var receiver = new SocketReceiver(socket); var processStartupMessageResponseTask = ProcessStartupMessageResponse(sender, sendBuffer, receiver, receiveBuffer, userName, password, cancellationToken); if (!processStartupMessageResponseTask.IsCompletedSuccessfully) { await processStartupMessageResponseTask.ConfigureAwait(false); } m_connectorState = ConnectorState.ReadyForQuery; m_connectionInfo = new ConnectionInfo(); m_connectionInfo.Host = host; m_connectionInfo.Database = database; m_connectionInfo.UserName = userName; m_connectionInfo.Password = password; m_socket = socket; } finally { m_arrayPool.Return(sendBufferBytes); m_arrayPool.Return(receiveBufferBytes); } }
public void Disconnect() { if (State != ConnectorState.Disconnected) { State = ConnectorState.Disconnecting; try { Disconnecting(); Disconnected(_connectParamsWhereConnect); } catch { } finally { State = ConnectorState.Disconnected; } } }
public void Unlock(bool justUnlocked, string sourceLevel) { this.sourceLevel = sourceLevel; if (justUnlocked) { state = ConnectorState.JustUnlocked; } else { state = ConnectorState.PreviouslyUnlocked; if (DestinationNode != null) { DestinationNode.Unlock(sourceLevel); } } animator.SetInteger("State", (int)state); }
//--------------------------------------------------------------------- public void Connect(TConnectorConnectParams connectParams) { if (IsConnected) { throw new InvalidOperationException(); } if (connectParams == null) { throw new ArgumentNullException(nameof(connectParams)); } _connectParamsWhereConnect = connectParams; State = ConnectorState.Connecting; Connecting(connectParams); Connected(connectParams); State = ConnectorState.Connected; }
/// <summary> /// 在指定时间内尝试连接指定主机上的指定端口。 (默认端口:80,默认链接超时:5000毫秒) /// </summary> /// <param name= "hostname ">要连接到的远程主机的 DNS 名。</param> /// <param name= "port ">要连接到的远程主机的端口号。 </param> /// <param name= "millisecondsTimeout ">要等待的毫秒数,或 -1 表示无限期等待。</param> /// <returns>已连接的一个 TcpClient 实例。</returns> public static TcpClient Connect(string hostname, int? port, int? millisecondsTimeout) { ConnectorState cs = new ConnectorState(); cs.Hostname = hostname; cs.Port = port ?? 80; ThreadPool.QueueUserWorkItem(new WaitCallback(ConnectThreaded), cs); if (cs.Completed.WaitOne(millisecondsTimeout ?? 5000, false)) { if (cs.TcpClient != null) return cs.TcpClient; return null; //throw cs.Exception; } else { cs.Abort(); return null; //throw new SocketException(11001); // cannot connect } }
private void SetForeflightControls(ConnectorState state) { if (ConnectorState.Connected == state) { lblForeFlightStatus.Text = "ForeFlight Sender started."; lblForeFlightStatus.ForeColor = Color.Green; tbForeflightIP.Enabled = false; cbForeflightConnectType.Enabled = false; buttonForeflight.Text = "Stop Foreflight Sender"; } else { buttonForeflight.Text = "Start ForeFlight Sender"; lblForeFlightStatus.Text = "ForeFlight Sender stopped."; lblForeFlightStatus.ForeColor = Color.Black; tbForeflightIP.Enabled = true; cbForeflightConnectType.Enabled = true; } lblForeFlightStatus.Invalidate(); tbForeflightIP.Invalidate(); cbForeflightConnectType.Invalidate(); buttonForeflight.Invalidate(); }
public void Break() { connectorState = ConnectorState.Banned; }
protected void ChangeState(ConnectorState newState) { AssertNotDisposed(); CurrentState = newState; }
public Connector(IDbConnection connection) { _state = ConnectorState.可用; _connection = connection; }
/// <summary> /// Sets the connector state of a specified connector /// </summary> /// <param name="id">The ID of the connector space object</param> /// <param name="maid">The ID of the management agent containing the connector space object</param> /// <param name="connectorState">The state of the connector to set</param> public static void SetConnectorState(Guid id, Guid maid, ConnectorState connectorState) { CSObject.ws.SetConnectorState(maid.ToMmsGuid(), id.ToMmsGuid(), (CONNECTORSTATE)connectorState); }
public CellConnector(Cell first, Cell second, Line2D segment, ConnectorState connectorState = ConnectorState.Unlinked) { this.first = first; this.second = second; this.segment = segment; this.connectorState = connectorState; }
protected void OnStateChange(ConnectorState newState) { m_state = newState; ConnectorStateHandler handler = StateChanged; if (handler != null) handler(this, m_state); }
public PgConnector(ArrayPool <byte> arrayPool) { m_arrayPool = arrayPool; m_connectorState = ConnectorState.Disconnected; }
public void Connect() { connectorState = ConnectorState.Linked; }
public void Disconnect() { connectorState = ConnectorState.Unlinked; }
internal NpgsqlOperationInProgressException(ConnectorState state) : base($"The connection is already in state '{state}'") { }
public void SetState(ConnectorState state) { _state = state; }
/// <summary>Changes the connector state</summary> /// <remarks> /// It's a convenience method. The caller can change the state of the connector state machine /// instead. /// </remarks> /// <param name="newState">The new state.</param> /// <seealso cref="connectorStateMachine"/> /// <seealso cref="connectorState"/> protected void SetConnectorState(ConnectorState newState) { connectorStateMachine.currentState = newState; }
public void Dispose() { _state = ConnectorState.可用; }
private void changeStateTo(ConnectorState state) { connectionState = state; Debug.Log(TAG + "New state: " + connectionState); }
public ConnectorState UpdateConnectorState(ConnectorState state) { throw new NotImplementedException(); }