protected void Application_Start(object sender, System.EventArgs e) { //suppose sp_config.json inside C:\Program Files\IIS Express //CSpConfig config = SpManager.SetConfig(false, //@"D:\cyetest\socketpro\samples\web_two\web_two\sp_config.json"); Master = SpManager.GetPool("masterdb") as CSqlMasterPool <CMysql, CDataSet>; CMysql handler = Master.Seek(); if (handler != null) //create a test database { string sql = @"CREATE DATABASE IF NOT EXISTS mysample character set utf8 collate utf8_general_ci;USE mysample;CREATE TABLE IF NOT EXISTS COMPANY(ID BIGINT PRIMARY KEY NOT NULL,Name CHAR(64)NOT NULL);CREATE TABLE IF NOT EXISTS EMPLOYEE(EMPLOYEEID BIGINT PRIMARY KEY AUTO_INCREMENT, CompanyId BIGINT NOT NULL,Name NCHAR(64)NOT NULL,JoinDate DATETIME(6) DEFAULT NULL,FOREIGN KEY(CompanyId)REFERENCES COMPANY(id));USE sakila; INSERT INTO mysample.COMPANY(ID,Name)VALUES(1,'Google Inc.'), (2,'Microsoft Inc.'),(3,'Amazon Inc.')"; handler.Execute(sql); } Cache = Master.Cache; Slave = SpManager.GetPool("slavedb0") as CSqlMasterPool <CMysql, CDataSet> .CSlavePool; Master_No_Backup = SpManager.GetPool("db_no_backup") as CSqlMasterPool <CMysql, CDataSet> .CSlavePool; }
static void Main(string[] args) { CSpConfig config = SpManager.SetConfig(true, @"c:\cyetest\socketpro\samples\stream_system\sp_config.json"); CYourServer.Master = SpManager.GetPool("masterdb") as CSqlMasterPool <CMysql, CDataSet>; CYourServer.Slave = SpManager.GetPool("slavedb0") as CSqlMasterPool <CMysql, CDataSet> .CSlavePool; CDataSet Cache = CYourServer.Master.Cache; using (CYourServer server = new CYourServer(2)) { //Cache is ready for use now List <KeyValuePair <string, string> > v0 = Cache.DBTablePair; if (v0.Count == 0) { Console.WriteLine("There is no table cached"); } else { Console.WriteLine("Table cached:"); foreach (KeyValuePair <string, string> p in v0) { Console.WriteLine("DB name = {0}, table name = {1}", p.Key, p.Value); } DataColumn[] keys = Cache.FindKeys(v0[0].Key, v0[0].Value); foreach (DataColumn dc in keys) { Console.WriteLine("Key ordinal = {0}, key column name = {1}", dc.Ordinal, dc.ColumnName); } } DataTable tbl = Cache.Find("sakila", "actor", "actor_id >= 1 and actor_id <= 10"); CYourServer.CreateTestDB(); Console.WriteLine(); //test certificate and private key files are located at the directory ../socketpro/bin #if WIN32_64 //or load cert and private key from windows system cert store server.UseSSL("C:\\cyetest\\socketpro\\bin\\intermediate.pfx", "", "mypassword"); #else //non-windows platforms server.UseSSL("intermediate.cert.pem", "intermediate.key.pem", "mypassword"); #endif //start listening socket with standard TLSv1.x security if (!server.Run(20911)) { Console.WriteLine("Error happens with error message = " + CSocketProServer.ErrorMessage); } Console.WriteLine("Press any key to shut down the application ......"); Console.ReadLine(); CYourServer.Slave.ShutdownPool(); CYourServer.Master.ShutdownPool(); } }