public virtual void ConnectionEvent(ConnType connectionState) { if (E_Connection != null) { E_Connection(this, new ConnectionEventArgs(connectionState, "", _id)); } }
private void SayConnected() { _conn = ConnType.Connected; lblRegisterStatus.Text = "Connected"; btnConnect.Text = "Disconnect"; btnReciever.Enabled = true; }
protected void RunConnectionEvent(ConnType connType, String msg, int id) { if (E_Connection != null) { E_Connection(this, new ConnectionEventArgs(connType, msg, id)); } }
protected DBServer(string conn, ConnType type) { if (type == ConnType.ConnName) { if (string.IsNullOrEmpty(conn)) { if (string.IsNullOrEmpty(DefaultConnStr)) { throw new Exception("默认构造为使用配置文件ConnectionStrings的第一个结点,现在没给出"); } else { ConnStr = DefaultConnStr; } } else { ConnStr = System.Configuration.ConfigurationManager.ConnectionStrings[conn].ConnectionString; } } else if (type == ConnType.ConnString) { ConnStr = conn; } else { throw new Exception("什么?出错了!无此ConnType"); } }
protected void ConnectionEvent(ConnType conn) { if (E_Connection != null) { E_Connection(this, new ConnectionEventArgs(conn)); } }
public ConnectionEventArgs(ConnType connType, String comment = "", int id = -1) : base() { this.id = id; this.connType = connType; this.comment = comment; }
public async static Task <int> BulkTransaction(string connectionString, ConnType type, string query, List <object> bulkList, bool isStoredProc = false) { var affected = 0; using (var conn = GetOpenConnection(connectionString, type)) { using (var transaction = conn.BeginTransaction()) { try { foreach (var item in bulkList) { affected = +await conn.ExecuteAsync(query, item, transaction, null, CommandType.StoredProcedure); } transaction.Commit(); } catch (Exception ex) { throw ex; } } } return(affected); }
public void UpdateConnType() { var up = conns[DirectionInt.UP] != null; var down = conns[DirectionInt.DONW] != null; var left = conns[DirectionInt.LEFT] != null; var right = conns[DirectionInt.RIGHT] != null; int connCount = (up ? 1 : 0) + (down ? 1 : 0) + (left ? 1 : 0) + (right ? 1 : 0); if (connCount > 2) { connType = ConnType.Multi; } else if ((up && down) || (left && right)) { connType = ConnType.Straight; } else { connType = ConnType.Corner; } #if UNITY_EDITOR if (go != null) { go.name += " conn=" + connCount + " type=" + connType.ToString(); } #endif }
protected override void ConnectionEvent(ConnType conn) { if (ConnectionEventOccured != null) { ConnectionEventOccured(_id, new ConnectionEventArgs(conn, "", _id)); } }
/// <summary> /// Attempt a UDP socket connection to the given host over the given port /// </summary> /// <param name="hostName">The name of the host</param> /// <param name="hostPort">The port number to connect</param> /// <param name="listenPort">The port number to lissen</param> /// <param name="async"></param> /// <returns></returns> public static bool ConnectUdp(string hostName, int hostPort, int listenPort, bool async = true) { _hostIP = hostName; _hostPort = hostPort; _localPort = listenPort; string result = string.Empty; _connType = ConnType.Udp; if (listenPort >= 0) { IPEndPoint ep = new IPEndPoint(IPAddress.Any, listenPort); _udpClientLisener = new UdpClient(ep); _udpClientLisener.BeginReceive(new AsyncCallback(ReadCallbackUdp), ep); } else { _udpClientLisener = new UdpClient(); } if (hostPort >= 0 && hostName != "") { _udpClientSender = new UdpClient(); _udpClientSender.Connect(hostName, hostPort); } return(true); }
public static void InicializarConns(ConnType connType) { if (connType == ConnType.LOCALDB) { // TODO - Establecer ligacao Connection = new SqlConnector(); } }
public async static Task <int> ExecuteAsync(string connectionString, ConnType type, string query, object parmObject, bool isStoredProc = false) { using (var conn = GetOpenConnection(connectionString, type)) { return(isStoredProc ? await conn.ExecuteAsync(query, parmObject, commandType : CommandType.StoredProcedure) : await conn.ExecuteAsync(query, parmObject)); } }
public TcpClientBase() { _client = null; _isEndLoop = true; _funcRunInRecvLoop = null; _connState = ConnType.Disconnected; errBuffer = new byte[] { 1, 2, 3, 4, 5, 6 }; }
/// <summary> /// 상태가 변할 경우 이벤트를 내려줌..같은 상태를 호출할 경우 아무 일도 하지 않음.. /// </summary> /// <param name="conn"></param> public void ConnectionEvent(ConnType conn) { /* * if (_connectionState != conn) //상태가 달라질때만 호출.. * { * _connectionState = conn; * RunConnectionEvent(conn, "", _threadId); * }*/ _connectionState = conn; RunConnectionEvent(conn, "", _threadId); }
/// <summary> /// 상태가 변할 경우 이벤트를 내려줌..같은 상태를 호출할 경우 아무 일도 하지 않음.. /// </summary> /// <param name="conn"></param> public void ConnectionEvent(ConnType conn) { if (_connectionState != conn) //상태가 달라질때만 호출.. { _connectionState = conn; if (E_Connection != null) { E_Connection(this, new ConnectionEventArgs(conn)); } } }
public void Rotate() { rotation = (Direction)((int)(rotation + 1) % 4); SideType tempSide = side[3]; ConnType tempConnType = connectionType[3]; for (int i = 3; i > 0; i--) { side[i] = side[i - 1]; connectionType[i] = connectionType[i - 1]; } side[0] = tempSide; connectionType[0] = tempConnType; }
public string GetConnString(ConnType connType) { switch (connType) { case ConnType.Dev: return "Data Source=SRV_SAFIR_OLDEV ;User Id=SFRADM;Password=sfrAdev3;"; case ConnType.Int: return "Data Source=SRV_SAFIR_OLINT ;User Id=SFRADM;Password=sfrAint3;"; case ConnType.Uat: return "Data Source=SRV_SAFIR_OLUAT;User Id=SFRRW;Password=sfrWuat1;"; case ConnType.Prod: return String.Format("Data Source=SAFIR_114;User Id={0};Password={1};", DbUser, DbPass); default: throw new ArgumentOutOfRangeException(nameof(connType), connType, null); } }
static void DeleteFunction(FitnessAppFYPLAB.StrengthInsertRead StrengthFunctions, FitnessAppFYPLAB.CardioInsertRead CardioFunctions, FitnessAppFYPLAB.BalanceInsertRead BalanceFunctions, FitnessAppFYPLAB.CreateFunction SynthesizeTables, SQLiteConnection sqlite_conn_strength, SQLiteConnection sqlite_conn_cardio, SQLiteConnection sqlite_conn_balance, ref string ChooseTable, ref int Choice1, ref int Choice2, ref int Choice3, ref int Choice4) { SQLiteConnection ConnType = null; if (Choice1 == 1) { ConnType = sqlite_conn_strength; SynthesizeTables.CreateTable(sqlite_conn_strength); StrengthFunctions.ReadDataStrength(sqlite_conn_strength, ref ChooseTable, ref Choice2, ref Choice3, ref Choice4); } if (Choice1 == 2) { ConnType = sqlite_conn_cardio; SynthesizeTables.CreateTable(sqlite_conn_cardio); CardioFunctions.ReadDataCardio(sqlite_conn_cardio, ref ChooseTable, ref Choice2, ref Choice3, ref Choice4); } if (Choice1 == 3) { ConnType = sqlite_conn_balance; SynthesizeTables.CreateTable(sqlite_conn_balance); BalanceFunctions.ReadDataBalance(sqlite_conn_balance, ref ChooseTable, ref Choice2, ref Choice3, ref Choice4); } Console.Write("Please enter the number in the Index column to delete the workout: "); int ToDelete = ReadInt32(Console.ReadLine()); string DeleteQuery = "DELETE FROM " + ChooseTable + " WHERE PK = " + ToDelete; SQLiteCommand DelQuery; DelQuery = ConnType.CreateCommand(); DelQuery.CommandText = DeleteQuery; DelQuery.CommandType = System.Data.CommandType.Text; DelQuery.ExecuteNonQuery(); }
private void SayDisconnected() { _conn = ConnType.Notconnected; lblRegisterStatus.Text = "Not Connected"; btnConnect.Text = "Connect"; lblStatus.Text = "On Hook"; btnReciever.Text = "Lift Reciever"; lblDisplay.Text = ""; _recieverLifted = false; DisableAll(); _timer.Stop(); _mySocket.Shutdown(SocketShutdown.Both); _mySocket.Close(); _mySocket = null; }
/// <summary> /// Attempt a TCP socket connection to the given host over the given port /// </summary> /// <param name="hostName">The name of the host</param> /// <param name="portNumber">The port number to connect</param> public static bool ConnectTcp(string hostName, int portNumber, bool async = true) { string result = string.Empty; _connType = ConnType.TcpClient; _tcpClient = new TcpClient(); if (async) { _tcpClient.BeginConnect(hostName, portNumber, new AsyncCallback(ConnectCallback), _tcpClient); } else { _tcpClient.Connect(hostName, portNumber); } return(true); }
public void setStateInvoke(ConnType connType) { lock (this) { if (connType == ConnType.Connected) { this.pic.BackgroundImage = _onImage; } else if (connType == ConnType.Connecting) { this.pic.BackgroundImage = _midImage; } else { this.pic.BackgroundImage = _offImage; } } }
/// <summary> /// Attempt a TCP socket connection to the given host over the given port /// </summary> /// <param name="portNumber">The port number to connect</param> public static bool CreateTcp(int portNumber, bool async = true) { string result = string.Empty; _connType = ConnType.TcpServer; _tcpServer = new TcpListener(portNumber); if (async) { _tcpServer.Start(1); // Max connections _tcpServer.BeginAcceptTcpClient(new AsyncCallback(ConnectCallbackServer), _tcpServer); } else { _tcpServer.AcceptTcpClient(); } return(true); }
public void U_SetState(ConnType connType) { if (this.InvokeRequired) { On2Pressed onPressed = new On2Pressed(U_SetState); this.Invoke(onPressed, new object[] { connType }); } else { lock (this) { this.U_ImageIndex = (int)connType; //this.pic.Location = new Point((this.Width - this.pic.Width) / 2, (this.Height - this.pic.Height) / 2); this.pic.Refresh(); } } //this.pic.Refresh(); }
public IDbConnection GetDbConnection(ConnType connType = ConnType.Write) { IDbConnection dbConnection = null; switch (connType) { case ConnType.Read: int iRdm = Rdm.Next(0, 2000) % mySqlConnOptions.Read.Length; dbConnection = new MySqlConnection(mySqlConnOptions.Read[iRdm]); Console.WriteLine(iRdm); break; case ConnType.Write: dbConnection = new MySqlConnection(mySqlConnOptions.Write); break; default: break; } return(dbConnection); }
public void SetState(ConnType connType) { if (_state != connType) { _state = connType; if (this.InvokeRequired) { On2Pressed onPressed = new On2Pressed(setStateInvoke); try { this.Invoke(onPressed, new object[] { connType }); } catch { } } else { setStateInvoke(connType); } } //this.pic.Refresh(); }
private void afterConnection() { if (_client != null && _client.Connected) { Console.WriteLine("now connected to server (" + _server + ":" + _port + ")"); _sh = new StreamHandler(_encoding); _sh.setStreamTimeout(_readTimeout, _writeTimeout); _sh.setStream(_client.GetStream(), _client.Client); //_loopThread.Abort(); //_loopThread.Join(); _isEndLoop = false; _loopThread = new Thread(new ThreadStart(clientLoop)); _loopThread.Start(); _connState = ConnType.Connected; BeginAClient(); } }
public void disconnect() { //_loopThread.Abort(); _isEndLoop = true; _client.Close(); _client = null; _loopThread.Join(1000); if (_loopThread != null && _loopThread.ThreadState == ThreadState.Running) { FinishAClient(); afterDisconnected(); Thread tt = _loopThread; _loopThread = null; tt.Abort(); } _loopThread = null; Console.WriteLine("now disconnected from server (" + _server + ":" + _port + ")"); _connState = ConnType.Disconnected; Console.WriteLine("client loop end..."); }
protected void ConnectionEvent(ConnType conn, int id) { if (E_Connection != null) { E_Connection(this, new ConnectionEventArgs(conn, "", id)); if (conn == ConnType.Connected)//접속이 되었다면, 해당 id와 함게 conn을 보냄. { int conns = 0; int connects = 0; for (int i = 0; i < _client.Length; i++) { if (_client[i] != null) { conns++; if (_client != null && _client[i].Client != null) { if (_client[i].Client.Connected == true) { connects++; } } } } if (connects == 0) { E_Connection(this, new ConnectionEventArgs(ConnType.Disconnected, "모두연결됨.", -1)); } else if (conns == connects) { E_Connection(this, new ConnectionEventArgs(ConnType.Connected, "연결안됨", -1)); } else { E_Connection(this, new ConnectionEventArgs(ConnType.Connecting, "일부만 연결됨", -1)); } } } }
public static IDbConnection GetOpenConnection(string connectionString, ConnType type) { if (string.IsNullOrWhiteSpace(connectionString)) { throw new Exception(string.Format("Failed to get {0} connection, connectionString is null or empty.", type)); } IDbConnection connection; switch (type) { case ConnType.MySql: connection = new MySqlConnection(connectionString); break; case ConnType.Sql: default: connection = null; break; } connection.Open(); return(connection); }
protected void ConnectionEvent(ConnType conn, int id) { RunConnectionEvent(conn, "", id); if (conn == ConnType.Connected)//접속이 되었다면, 해당 id와 함게 conn을 보냄. { int conns = 0; int connects = 0; for (int i = 0; _client != null && i < _client.Length; i++) { if (_client[i] != null) { conns++; if (_client[i].Client != null) { if (_client[i].Client.Connected == true) { connects++; } } } } OnConnected(this, connects, conns); } }
public bool SaveConnConfig(string fileName, string serverName, bool isIntegrate, string userId, string password, string dbName, string handleTypeName, ICryptConnection cryptObj, out string errMsg) { try { if (!IsSuccess) { errMsg = ErrMessage; return(false); } if (ItsNode == null) { errMsg = "未绑定到XML节点"; return(false); } if (ConnType.Equals("nhibernate", StringComparison.OrdinalIgnoreCase)) { ConnConfigAnalyzer.SaveFactory(fileName, ItsNode, serverName, isIntegrate, userId, password, dbName, handleTypeName, cryptObj); } else if (ConnType.Equals("common.database", StringComparison.OrdinalIgnoreCase)) { ConnConfigAnalyzer.SaveSection(fileName, ConnConfigName, serverName, isIntegrate, userId, password, dbName, handleTypeName, cryptObj); } else { errMsg = "不支持的数据库连接类型 - " + ConnType; return(false); } errMsg = ""; return(true); } catch (Exception ex) { errMsg = ex.Message; return(false); } }
private void SetLayout(ConnType connType, int status) { List<Control> oper = null; if (connType == ConnType.Source) { oper = srcControls; srcStatus = status; } else if (connType == ConnType.Target) { oper = trgControls; trgStatus = status; } else { oper = compControls; } switch (status) { case 0: oper[0].Enabled = true; oper[1].Enabled = true; oper[2].Enabled = !((CheckBox)oper[1]).Checked; oper[3].Enabled = !((CheckBox)oper[1]).Checked; oper[4].Enabled = false; oper[5].Enabled = true; oper[6].Enabled = false; oper[7].Enabled = false; oper[8].Enabled = false; compControls[0].Enabled = false; compControls[1].Enabled = false; break; case 1: oper[0].Enabled = false; oper[1].Enabled = false; oper[2].Enabled = false; oper[3].Enabled = false; oper[4].Enabled = true; oper[5].Enabled = true; oper[6].Enabled = false; oper[7].Enabled = true; oper[8].Enabled = false; compControls[0].Enabled = false; compControls[1].Enabled = false; break; case 2: oper[0].Enabled = false; oper[1].Enabled = false; oper[2].Enabled = false; oper[3].Enabled = false; oper[4].Enabled = false; oper[5].Enabled = false; oper[6].Enabled = true; oper[7].Enabled = true; oper[8].Enabled = true; compControls[0].Enabled = false; compControls[1].Enabled = false; break; case 5: oper[0].Enabled = true; //srcControls[6].Enabled = false; //srcControls[7].Enabled = false; //srcControls[8].Enabled = false; //trgControls[6].Enabled = false; //trgControls[7].Enabled = false; //trgControls[8].Enabled = false; break; case 6: oper[1].Enabled = true; break; default: break; } if (srcStatus == 2 && trgStatus == 2) { compControls[0].Enabled = true; } else { compControls[0].Enabled = false; } }
private void BindDataSource(ComboBox comboBoxBind, ConnType connType, string type) { string target_table = ""; string sql = (type == DB) ? RETRIEVE_DATABASES_SQL : RETRIEVE_TABLES_SQL; if (connType == ConnType.Source) { target_table = (type == DB) ? SRC_DBLIST_TABLE : SRC_TABLIST_TABLE; } else if (connType == ConnType.Target) { target_table = (type == DB) ? TRG_DBLIST_TABLE : TRG_TABLIST_TABLE; } ExecuteSQL(sql, connType, dsGlobal, target_table); comboBoxBind.DisplayMember = COL_NAME; comboBoxBind.ValueMember = COL_NAME; comboBoxBind.DataSource = dsGlobal.Tables[target_table]; }
private void CloseConnection(ConnType connType) { if (connections[(int)connType] != null && connections[(int)connType].State == ConnectionState.Open) connections[(int)connType].Close(); }
private DataTable ExecuteSQL(string sql, ConnType connType) { DataSet ds = new DataSet(); ExecuteSQL(sql, connType, ds, "tmp"); return ds.Tables[0]; }
private void NewConnection(ConnType type, string connStr) { SqlConnection conn = connections[(int)type]; if (conn != null && conn.State == ConnectionState.Open) { conn.Close(); } conn = new SqlConnection(connStr); connections[(int)type] = conn; try { conn.Open(); } catch (SqlException ex) { throw ex; } catch (Exception ex) { throw ex; } }
private SqlDataReader GetDataReader(string sql, ConnType connType) { SqlCommand comm = new SqlCommand(sql, connections[(int)connType]); comm.CommandTimeout = 0; SqlDataReader dr = comm.ExecuteReader(); return dr; }
private SqlDataAdapter GetDataAdapter(string sql, ConnType connType) { SqlCommand comm = new SqlCommand(sql, connections[(int)connType]); comm.CommandTimeout = 0; SqlDataAdapter da = new SqlDataAdapter(comm); return da; }
private void ExecuteSQL(string sql, ConnType connType, DataSet ds, string tabname) { if (sql == null || sql.Length == 0 || connections[(int)connType] == null || connections[(int)connType].State != ConnectionState.Open || ds == null || tabname == null || tabname.Length == 0) return; if (ds.Tables.Contains(tabname)) { DataRelation dr; for(int i = 0; i < ds.Relations.Count;) { dr = ds.Relations[i]; if (tabname.Equals(dr.ParentTable.TableName) || tabname.Equals(dr.ChildTable.TableName)) { ds.Relations.Remove(dr); continue; } i++; } ds.Tables.Remove(tabname); } SqlDataAdapter daSource = GetDataAdapter(sql, connType); daSource.Fill(ds, tabname); }