コード例 #1
0
ファイル: cacheimpl.cs プロジェクト: skyformat99/socketpro
    private static string InitializeCache(string host, string mysqlConn, CMySqlCachePeer cachePeer = null)
    {
        Dictionary <string, string> mapTables = GetDataTableMap(host);

        if (mapTables.Count == 0)
        {
            return("Host not set for quering cache data");
        }
        string          errMsg = "";
        MySqlConnection conn   = null;

        try
        {
            DataSet ds = new DataSet(host);
            conn = new MySqlConnection(mysqlConn);
            conn.Open();
            foreach (var p in mapTables)
            {
                string tableName = p.Key;
                string sql       = "select * from " + p.Key;
                if (p.Value != null && p.Value.Length > 0)
                {
                    sql += (" where " + p.Value);
                }
                MySqlDataAdapter adapter = new MySqlDataAdapter(new MySqlCommand(sql, conn));
                adapter.Fill(ds, tableName);
                if (cachePeer != null)
                {
                    uint res = cachePeer.SendResult(idQuerying);
                    if (res == CSocketPeer.REQUEST_CANCELED || res == CSocketPeer.SOCKET_NOT_FOUND)
                    {
                        throw new Exception("Connection disconnected or message canceled");
                    }
                }
            }
            m_mapHostDS[host] = ds;
        }
        catch (Exception ex)
        {
            errMsg = ex.Message;
        }
        finally
        {
            if (conn != null && conn.State != ConnectionState.Closed)
            {
                conn.Close();
            }
        }
        return(errMsg);
    }
コード例 #2
0
ファイル: Program.cs プロジェクト: skyformat99/socketpro
    static void Main(string[] args)
    {
        CMySqlCachePeer.CCacheSource source = new CMySqlCachePeer.CCacheSource("root", "Smash123");

        //server cache contains five tables (city, language, store, category, and staff) of MySql sample database sakila
        source.TableFilter["sakila.city"]     = "";
        source.TableFilter["sakila.language"] = "";
        source.TableFilter["sakila.store"]    = "";
        source.TableFilter["sakila.category"] = "";
        source.TableFilter["sakila.staff"]    = "";

        const string mysql_host = "ws-yye-1";
        //query all the above five tables into cache on one given MySql server located at ws-yye-1
        string errMsg = CMySqlCachePeer.InitializeCache(mysql_host, source);

        if (errMsg != null && errMsg.Length > 0)
        {
            Console.WriteLine(errMsg);
        }
        else
        {
#if DEBUG
            Console.WriteLine("Real-time server cache initialized from MySql server " + mysql_host);
            //query a datatable from cache
            DataTable dt = CMySqlCachePeer.Get(mysql_host, "sakila.staff");
            //query a subset of records from cache
            dt = CMySqlCachePeer.Get(mysql_host, "sakila.city", "city_id >= 10 and city_id <= 19", "city_id");
#endif
        }
        using (CMySocketProServer MySocketProServer = new CMySocketProServer())
        {
            if (!MySocketProServer.Run(20901))
            {
                Console.WriteLine("Error code = " + CSocketProServer.LastSocketError.ToString());
            }
            Console.WriteLine("Input a line to close the application ......");
            Console.ReadLine();
        }
    }
コード例 #3
0
ファイル: cacheimpl.cs プロジェクト: udaparts/socketpro
 private static string InitializeCache(string host, string mysqlConn, CMySqlCachePeer cachePeer = null)
 {
     Dictionary<string, string> mapTables = GetDataTableMap(host);
     if (mapTables.Count == 0)
         return "Host not set for quering cache data";
     string errMsg = "";
     MySqlConnection conn = null;
     try
     {
         DataSet ds = new DataSet(host);
         conn = new MySqlConnection(mysqlConn);
         conn.Open();
         foreach (var p in mapTables)
         {
             string tableName = p.Key;
             string sql = "select * from " + p.Key;
             if (p.Value != null && p.Value.Length > 0)
             {
                 sql += (" where " + p.Value);
             }
             MySqlDataAdapter adapter = new MySqlDataAdapter(new MySqlCommand(sql, conn));
             adapter.Fill(ds, tableName);
             if (cachePeer != null)
             {
                 uint res = cachePeer.SendResult(idQuerying);
                 if (res == CSocketPeer.REQUEST_CANCELED || res == CSocketPeer.SOCKET_NOT_FOUND)
                 {
                     throw new Exception("Connection disconnected or message canceled");
                 }
             }
         }
         m_mapHostDS[host] = ds;
     }
     catch (Exception ex)
     {
         errMsg = ex.Message;
     }
     finally
     {
         if (conn != null && conn.State != ConnectionState.Closed)
             conn.Close();
     }
     return errMsg;
 }