/// <summary> /// Mysql /// </summary> /// <param name="config"></param> /// <returns></returns> private static bool GetConnectionMysql(ConnectConfig config) { try { //string connStr = string.Format(Consts.MysqlConnectionStr, config.DataSource, config.Port, config.UserID, config.PassWord, config.DataBase); //ConnectionMysql = new MySqlConnection(connStr); //if (ConnectionMysql.State != ConnectionState.Open) //{ // ConnectionMysql.Open(); //} //if (ConnectionMysql.State == ConnectionState.Open) //{ // DataBase = config.DataBase; // DataSource = config.DataSource; // DataType = DataTypes.MYSQL; // ConnectionMysql.Close(); // return true; //} return(false); } catch (Exception e) { return(false); } }
/// <summary> /// SqlServer /// </summary> /// <param name="config"></param> /// <returns></returns> private static bool GetConnectionSql(ConnectConfig config) { try { string connStr = string.Format(Consts.Connection.SqlConnectionStr, config.DataSource, config.UserID, config.PassWord); var conn = new SqlConnection(connStr); if (conn.State != ConnectionState.Open) { conn.Open(); } if (conn.State == ConnectionState.Open) { conn.Close(); return(true); } return(false); } catch { return(false); } }
/// <summary> /// Oracle /// </summary> /// <param name="config"></param> /// <returns></returns> private static bool GetConnectionOracle(ConnectConfig config) { try { string connStr = string.Format(Consts.Connection.OracleConnectionStr, config.UserID, config.PassWord, config.DataSource, config.Port, config.DataBase); var conn = new OracleConnection(connStr); if (conn.State != ConnectionState.Open) { conn.Open(); } if (conn.State == ConnectionState.Open) { conn.Close(); return(true); } return(false); } catch (Exception e) { return(false); } }
/// <summary> /// 获取数据库链接 /// </summary> /// <param name="config"></param> /// <returns></returns> public static bool GetConnection(ConnectConfig config) { bool bRet = false; switch (config.DataType) { case DataTypes.SQLSERVER: bRet = GetConnectionSql(config); break; case DataTypes.ORACLE: bRet = GetConnectionOracle(config); break; case DataTypes.MYSQL: bRet = GetConnectionMysql(config); break; default: break; } if (bRet) { WriteConnection(config); } return(bRet); }
private void Button_Test(object sender, RoutedEventArgs e) { var errMSG = LoginCheck(); if (!string.IsNullOrEmpty(errMSG)) { ErrorMessage.Text = errMSG; return; } var config = new ConnectConfig(); config.ConnectionName = ConnectionName.Text; config.DataBase = DataBase.Text; config.DataType = _dataType; config.DataSource = DatabaseAddress.Text; config.UserID = LoginName.Text; config.PassWord = PassWord.Password; config.Port = Port.Text; if (BaseUnity.GetConnection(config)) { ErrorMessage.Text = "链接成功!"; } else { ErrorMessage.Text = "链接失败!"; } }
public static bool SetConnection(ConnectConfig configData) { StreamWriter writer = null; try { if (ConnectionList == null) { ConnectionList = new List <ConnectConfig>(); } string config = "./Connection.txt"; if (!File.Exists(config)) { var file = File.Create(config); file.Close(); } writer = new StreamWriter(config, true, Encoding.UTF8); configData.Id = "N" + GuidExtend.NewId(); writer.WriteLine(JsonConvert.SerializeObject(configData)); writer.Close(); return(true); } catch (Exception e) { throw new Exception("保存登陆信息失败!!!"); } }
private static void WriteConnection(ConnectConfig config) { var data = LoadingConnection.GetConnectionQuery(config); if (data == null || data.Count <= 0) { LoadingConnection.SetConnection(config); } }
/// <summary> /// Constructor of client and serializer /// </summary> /// <param name="InternalClientInfo"></param> public MqttClient(ConnectConfig config) { _config = config; //建立MqttClient物件 _client = new MqttFactory().CreateMqttClient() as MQTTnet.Client.MqttClient; _client.Disconnected += MqttClient_Disconnected; _mqttStatus = MqttBrokerConnectionStatus.DisConnected; _mqttClientRunningThread = new Thread(new ThreadStart(mqttClientRunningProcess)); }
/// <summary> /// //Delete (Another Datasource) /// </summary> /// <param name="stateName"></param> /// <param name="parameterObject"></param> /// <param name="datasourceCode"></param> /// <returns></returns> public object QueryForDelete(string stateName, object parameterObject, ConnectConfig tempConfig) { objresult = null; Logs.configChange(tempConfig); objresult = QueryForDeleteCore(stateName, parameterObject, Properties.Settings.Default.RES_DB_INS_DEFAULT); Logs.configChange(Logs.DefaultConfig); return(objresult); }
/// <summary> /// //Select List (Another Datasource) /// </summary> /// <param name="statementName"></param> /// <param name="parameterObject"></param> /// <param name="datasourceCode"></param> /// <returns></returns> public ArrayList QueryForList(string statementName, object parameterObject, ConnectConfig tempConfig) { objresult = null; Logs.configChange(tempConfig); objresult = QueryForListCore(statementName, parameterObject, Properties.Settings.Default.RES_DB_INS_DEFAULT); Logs.configChange(Logs.DefaultConfig); return((ArrayList)objresult); }
public static ConnectConfig GetConnectionById(string id, out string connStr) { var config = new ConnectConfig(); connStr = string.Empty; try { if (ConnectionList == null) { throw new Exception("初始化失败!!!"); } config = ConnectionList.Where(s => s.Id == id).FirstOrDefault(); switch (config.DataType) { case DataTypes.SQLSERVER: connStr = string.Format(Consts.Connection.SqlConnectionStr, config.DataSource, config.UserID, config.PassWord); break; case DataTypes.ORACLE: connStr = string.Format(Consts.Connection.OracleConnectionStr, config.UserID, config.PassWord, config.DataSource, config.Port, config.DataBase); break; case DataTypes.MYSQL: //connStr = string.Format(Consts.MysqlConnectionStr, config.DataSource, config.Port, config.UserID, config.PassWord, config.DataBase); break; default: break; } } catch { throw new Exception("初始化失败!!!"); } if (string.IsNullOrEmpty(connStr)) { throw new Exception("初始化失败!!!"); } return(config); }
public static List <ConnectConfig> GetConnectionList() { StreamReader reader = null; try { if (ConnectionList == null) { ConnectionList = new List <ConnectConfig>(); } string config = "./Connection.txt"; if (!File.Exists(config)) { var file = File.Create(config); file.Close(); return(ConnectionList); } reader = new StreamReader(config, Encoding.UTF8); string line = string.Empty; while (!string.IsNullOrEmpty(line = reader.ReadLine())) { ConnectConfig connectionStr = JsonConvert.DeserializeObject <ConnectConfig>(line); ConnectionList.Add(connectionStr); } return(ConnectionList); } catch (Exception e) { throw (new Exception("初始化失败!!!")); } finally { if (reader != null) { reader.Close(); } } }
public static ConnectConfig GetConnectionInfo(ConnectConfig config) { var connection = new ConnectConfig(); try { if (ConnectionList == null) { return(connection); } connection = ConnectionList.Where(s => s.DataSource == config.DataSource && s.DataType == config.DataType && s.UserID == config.UserID).FirstOrDefault(); } catch { throw new Exception("初始化失败!!!"); } return(connection); }
private static void GetConnectionString() { string pathConfigFile = ""; try { var appSettings = ConfigurationManager.AppSettings; pathConfigFile = appSettings[APP_KEY_CONFIF_FILE_NAME]; } catch (Exception e) { Console.WriteLine(e.Message); } if (!String.IsNullOrEmpty(pathConfigFile)) { ConnectConfig cs = new ConnectConfig("fsmonitor", pathConfigFile); CBUtilsConnectionString = cs.ConnectionParametrs; } }
/// <summary> /// permet de se connecter a Deezer, retourne true si la connection reussi et /// false sinon /// </summary> /// <returns></returns> public override bool Connect() { var connectConfig = new ConnectConfig() { ccAppId = "180202", product_id = "DeezerWrapper", product_build_id = "00001", ccUserProfilePath = GetDeezerTempFolder(), ccConnectEventCb = OnConnect }; var connect = new Connect(connectConfig); connect.Start(); connect.SetAccessToken("fr49mph7tV4KY3ukISkFHQysRpdCEbzb958dB320pM15OpFsQs"); connect.ConnectOfflineMode(); m_player = new Player(connect, null); m_player.SongChanged += Player_SongChanged; m_player.Start(OnPlayerEvent); return(true); }
public static List <ConnectConfig> GetConnectionQuery(ConnectConfig config) { List <ConnectConfig> connection = new List <ConnectConfig>(); try { if (ConnectionList == null) { return(connection); } connection = ConnectionList; if (!string.IsNullOrEmpty(config.DataSource)) { connection = connection.Where(s => s.DataSource.Contains(config.DataSource)).ToList(); } if (!string.IsNullOrEmpty(config.UserID)) { connection = connection.Where(s => s.UserID.Contains(config.UserID)).ToList(); } if (config.DataType != null) { connection = connection.Where(s => s.DataType == config.DataType).ToList(); } if (config.PassWord != null) { connection = connection.Where(s => s.PassWord == config.PassWord).ToList(); } } catch { throw new Exception("系统错误!!!"); } return(connection); }
public static void Main(string[] args) { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddYamlFile("appsettings.yaml"); Configuration = builder.Build(); _ = ushort.TryParse(Configuration["MaxConnections"], out MaxConnections); _ = bool.TryParse(Configuration["WhiteList"], out WhiteList); ServerConfig = Configuration.GetSection("Server").Get <ConnectConfig>(); NatConfig = Configuration.GetSection("Nat").Get <ConnectConfig>(); QueryConfig = Configuration.GetSection("Query").Get <QueryConfig>(); ConnectionString = Configuration["DataBase:ConnectionString"]; NoFind = Configuration["Message:NotFind"]; IsEnd = Configuration["Message:IsEnd"]; StateContext stateContext = new StateContext(MaxConnections, ushort.MaxValue); stateContext.Init(); IPEndPoint serverIP = new IPEndPoint(IPAddress.Any, ServerConfig.Port); stateContext.Start(serverIP); int CursorTop, OnPlayer = 0; Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); #if DEBUG #endif #if !DEBUG while (true) { Console.Clear(); Console.WriteLine("##########实时统计##########"); Console.SetCursorPosition(0, 3); //将光标至于当前行的开始位置 Console.WriteLine("##########在线玩家##########"); Console.SetCursorPosition(0, 1); //将光标至于当前行的开始位置 uint TotalBytesSend = Interlocked.Exchange(ref stateContext.TotalBytesSend, 0); uint TotalBytesRead = Interlocked.Exchange(ref stateContext.TotalBytesRead, 0); int Top = Console.CursorTop;//记录当前光标位置 ClearCurrentConsoleLine(); Console.WriteLine("当前上行速率:" + TotalBytesSend); ClearCurrentConsoleLine(); Console.WriteLine("当前下行速率:" + TotalBytesRead); Console.SetCursorPosition(0, 4); int temp = stateContext.Online.Count; if (OnPlayer > temp) { for (int i = 0; i < OnPlayer - temp; i++) { ClearCurrentConsoleLine(4 + temp + i); } } OnPlayer = temp; // 开始打印玩家列表 try { foreach (var token in stateContext.Online) { CursorTop = Console.CursorTop; Console.Write(new string(' ', Console.WindowWidth)); //用空格将当前行填满,相当于清除当前行 Console.SetCursorPosition(0, Console.CursorTop); //将光标至于当前行的开始位置 Console.WriteLine($"玩家ID : {token.Key} 登录时间:{token.Value.ConnectDateTime} 到期时间:{token.Value.EndTime}"); } } catch (Exception ex) { log.Error(ex.Message); } Console.SetCursorPosition(0, 5);//将光标恢复至开始时的位置 Thread.Sleep(1000); } #endif Console.ReadLine(); }
public ConnectionFactory(IOptions <ConnectConfig> connConfig) { _connConfig = connConfig.Value; }
static void Main(string[] args) { var playlist = "dzmedia:///playlist/1490558021"; var station = "dzradio:///radio-30781"; var stream = args.Length > 0 ? args[0] : playlist; var connectConfig = new ConnectConfig() { ccAppId = "180202", product_id = "DeezerWrapper", product_build_id = "00001", ccUserProfilePath = GetDeezerTempFolder(), ccConnectEventCb = OnConnect }; var connect = new Connect(connectConfig); connect.Start(); connect.SetAccessToken("fr49mph7tV4KY3ukISkFHQysRpdCEbzb958dB320pM15OpFsQs"); connect.ConnectOfflineMode(); var version = connect.GetSdkVersion(); var deviceId = connect.GetDeviceId(); Console.WriteLine($"SDK Version: {version}"); Console.WriteLine($"Device Id: {deviceId}"); Thread.Sleep(5000); var player = new Player(connect, null); player.SongChanged += Player_SongChanged; player.Start(OnPlayerEvent); player.SetRepeatMode(QUEUELIST_REPEAT_MODE.DZ_QUEUELIST_REPEAT_MODE_ALL); player.LoadStream(stream); player.Play(); string line; while ((line = Console.ReadLine()) != "Q") { switch (line) { case "P": player.Pause(); break; case "R": player.Resume(); break; case "N": player.Next(); break; case "L": Console.WriteLine("Enter station"); var radio = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(radio)) { player.LoadStream(radio); player.Play(); } break; default: break; } } player.Dispose(); connect.Dispose(); }
/// <summary> /// //Select One Line (Another Datasource) /// </summary> /// <param name="statementName"></param> /// <param name="parameterObject"></param> /// <param name="datasourceCode"></param> /// <returns></returns> public static Hashtable QueryForOneline(string statementName, object parameterObject, ConnectConfig tempConfig) { objresult = null; Logs.configChange(tempConfig); objresult = QueryForOnelineCore(statementName, parameterObject, Properties.Settings.Default.RES_DB_INS_DEFAULT); Logs.configChange(Logs.DefaultConfig); return((Hashtable)objresult); }
static void Main(string[] args) { var stream = args.Length > 0 ? args.First() : "dzradio:///radio-30781"; var connectConfig = new ConnectConfig() { ccAppId = "240702", product_id = "SmartHousePlayer", product_build_id = "00001", ccUserProfilePath = GetDeezerTempFolder(), ccConnectEventCb = OnConnect }; var connect = new Connect(connectConfig); connect.Start(); connect.SetAccessToken("frEbzdJCyceSNydCNyOiAxo4QNim17VrFf3iq9MEDONAAzOcCm"); connect.ConnectOfflineMode(); Thread.Sleep(5000); var player = new Player(connect, null); player.Start(OnPlayerEvent); player.SetRepeatMode(QUEUELIST_REPEAT_MODE.DZ_QUEUELIST_REPEAT_MODE_ALL); player.LoadStream(stream); player.Play(); var line = string.Empty; while ((line = Console.ReadLine()) != "Q") { switch (line) { case "P": player.Pause(); break; case "R": player.Resume(); break; case "N": player.Next(); break; case "B": player.Previous(); break; case "L": Console.WriteLine("Enter station"); var radio = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(radio)) { player.LoadStream(radio); player.Play(); } break; default: break; } } player.Dispose(); connect.Dispose(); }
public static void configChange(ConnectConfig tempconfig) { useConfig = tempconfig; }