Exemplo n.º 1
0
 /// <summary>
 /// Initialize cache with given database server name and cache source information
 /// </summary>
 /// <param name="host">A database server name</param>
 /// <param name="source">A structure for cache source information</param>
 /// <returns>Error message</returns>
 public static string InitializeCache(string host, CCacheSource source)
 {
     host = GetIPAddress(host);
     lock (m_cs)
     {
         m_mapHostTables[host] = source;
         return(InitializeCache(host, source.GetConnectionString(host)));
     }
 }
Exemplo n.º 2
0
    private string GetMySqlConnectionString(out string host)
    {
        host = GetPeerName();
        if (!m_mapHostTables.ContainsKey(host))
        {
            return(string.Format("server={0};port={1};uid={2};pwd={3}", host, 3306, "", ""));
        }
        CCacheSource source = m_mapHostTables[host];

        return(source.GetConnectionString(host));
    }
Exemplo n.º 3
0
    private static void HandleCache(string ipAddr, string tableName, string filter, SocketProAdapter.UDB.tagUpdateEvent et)
    {
        lock (m_cs)
        {
            if (!m_mapHostDS.ContainsKey(ipAddr) || !m_mapHostTables.ContainsKey(ipAddr))
            {
#if DEBUG
                Console.WriteLine("Host <{0}> not registerred at real-time cache server!!!", ipAddr);
#endif
                return;
            }
            DataSet ds = m_mapHostDS[ipAddr];
            if (!ds.Tables.Contains(tableName))
            {
#if DEBUG
                Console.WriteLine("Table <{0}> not registerred at real-time cache server!!!", tableName);
#endif
                return;
            }
            DataTable dt = ds.Tables[tableName];
            switch (et)
            {
            case SocketProAdapter.UDB.tagUpdateEvent.ueInsert:
            case SocketProAdapter.UDB.tagUpdateEvent.ueUpdate:
                do
                {
                    MySqlConnection conn = null;
                    IDataReader     dr   = null;
                    try
                    {
                        CCacheSource source = m_mapHostTables[ipAddr];
                        string       s      = source.GetConnectionString(ipAddr);
                        conn = new MySqlConnection(s);
                        conn.Open();
                        string     sql = "select * from " + tableName + " where " + filter;
                        IDbCommand cmd = new MySqlCommand(sql, conn);
                        dr = cmd.ExecuteReader();
                        var rows = dt.Select(filter);
                        foreach (var row in rows)
                        {
                            row.Delete();
                        }
                        dt.AcceptChanges();
                        dt.Load(dr);
                        dt.AcceptChanges();
                        dr.Close();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                    finally
                    {
                        if (dr != null)
                        {
                            dr.Close();
                        }
                        if (conn != null)
                        {
                            conn.Close();
                        }
                    }
                } while (false);
                break;

            case SocketProAdapter.UDB.tagUpdateEvent.ueDelete:
            {
                var rows = dt.Select(filter);
                foreach (var row in rows)
                {
                    row.Delete();
                }
                dt.AcceptChanges();
            }
            break;

            default:
                Console.WriteLine("Unsupported event type " + et);
                break;
            }
        }
    }
Exemplo n.º 4
0
 /// <summary>
 /// Initialize cache with given database server name and cache source information
 /// </summary>
 /// <param name="host">A database server name</param>
 /// <param name="source">A structure for cache source information</param>
 /// <returns>Error message</returns>
 public static string InitializeCache(string host, CCacheSource source)
 {
     host = GetIPAddress(host);
     lock (m_cs)
     {
         m_mapHostTables[host] = source;
         return InitializeCache(host, source.GetConnectionString(host));
     }
 }