Пример #1
0
        /// <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);
            }
        }
Пример #2
0
        /// <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);
            }
        }
Пример #3
0
        /// <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);
            }
        }
Пример #4
0
        /// <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);
        }
Пример #5
0
        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 = "链接失败!";
            }
        }
Пример #6
0
        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("保存登陆信息失败!!!");
            }
        }
Пример #7
0
        private static void WriteConnection(ConnectConfig config)
        {
            var data = LoadingConnection.GetConnectionQuery(config);

            if (data == null || data.Count <= 0)
            {
                LoadingConnection.SetConnection(config);
            }
        }
Пример #8
0
        /// <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));
        }
Пример #9
0
        /// <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);
        }
Пример #10
0
        /// <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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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();
                }
            }
        }
Пример #13
0
        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);
        }
Пример #14
0
        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;
            }
        }
Пример #15
0
        /// <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);
        }
Пример #16
0
        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);
        }
Пример #17
0
        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();
        }
Пример #18
0
 public ConnectionFactory(IOptions <ConnectConfig> connConfig)
 {
     _connConfig = connConfig.Value;
 }
Пример #19
0
        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();
        }
Пример #20
0
        /// <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);
        }
Пример #21
0
        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();
        }
Пример #22
0
 public static void configChange(ConnectConfig tempconfig)
 {
     useConfig = tempconfig;
 }