Exemple #1
0
        public int Call(AbstractDBQuery query, DBCallback callback = null)
        {
            int dbIndex = GetDBIndex();

            DBMngLst[dbIndex].Call(query, callback);
            return(dbIndex);
        }
        public int Call(AbstractDBOperater query, DBCallback callback = null)
        {
            int dbIndex = GetDBIndex();

            _dbManagerList[dbIndex].Call(query, callback);
            return(dbIndex);
        }
Exemple #3
0
        /// <summary>
        ///执行存储过程或sql的datareader,自动创建conn,自动关闭conn
        /// </summary>
        /// <param name="text">sql 或proc</param>
        /// <param name="type">sql 或存储过程</param>
        /// <param name="param">参数</param>
        /// <param name="callback">代理方法</param>
        /// <returns>object基本类型</returns>
        public object ExecuteRead(string text, CommandType type, DbParam[] param, DBCallback callback)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }
            if (null == callback)
            {
                throw new ArgumentNullException("callback");
            }

            object returns;

            using (DbCommand cmd = this.CreateCommand(text, type))
            {
                cmd.CommandType = type;
                if (param != null)
                {
                    cmd.CommandType = param[0].sqlType == SqlType.Sql ? CommandType.Text : CommandType.StoredProcedure;
                    IDataParameter[] iparam = this.ConvertParams(param);
                    cmd.Parameters.AddRange(iparam);
                }
                returns = this.DoExecuteRead(cmd, callback);
            }

            return(returns);
        }
Exemple #4
0
    void getSessionKey(object obj)
    {
        lock (singletonLock)
        {
            try
            {
                Action <DBCallback> callback         = (Action <DBCallback>)obj;
                string sessionKey                    = "";
                IEnumerable <SessionTable> dataTable = connection.Table <SessionTable>();
                foreach (SessionTable item in dataTable)
                {
                    sessionKey = Encryption.Decrypt(item.SessionKey);
                    break;
                }

                DBCallback dbCallback = new DBCallback();
                dbCallback.Data = sessionKey;
                dbCallback.completedCallback = callback;
                DBCallbackDispatcher.Singleton.requests.Enqueue(dbCallback);
            }
            catch (Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }
    }
Exemple #5
0
        ///
        ///执行DataReader 返回object 支持conn 需代理调用
        ///

        #region public object ExecuteReadConn(string sqltext, DbConnection conn,DBCallback callback)

        /// <summary>
        /// 执行datareader,参数sql语句 和 delegate返回调用,不关闭conn
        /// </summary>
        /// <param name="sqltext">sql语句</param>
        /// <param name="conn">数据库连接对象</param>
        /// <param name="callback"> delegate 方法</param>
        /// <returns>object类型,基本类型</returns>
        public object ExecuteReadConn(string sqltext, DbConnection conn, DBCallback callback)
        {
            if (string.IsNullOrEmpty(sqltext))
            {
                throw new ArgumentNullException("sqltext");
            }

            if (null == callback)
            {
                throw new ArgumentNullException("callback");
            }
            return(this.ExecuteReadConn(sqltext, CommandType.Text, null, conn, callback));
        }
Exemple #6
0
        /// <summary>
        ///执行存储过程或sql的datareader,自动创建conn,自动关闭conn
        /// </summary>
        /// <param name="text">proc</param>
        /// <param name="param">参数</param>
        /// <param name="callback">代理方法</param>
        /// <returns>object基本类型</returns>
        public object ExecuteRead(string text, DbParam[] param, DBCallback callback)
        {
            if (string.IsNullOrEmpty(text))
            {
                throw new ArgumentNullException("text");
            }
            if (null == callback)
            {
                throw new ArgumentNullException("callback");
            }

            return(this.ExecuteRead(text, CommandType.StoredProcedure, param, callback));
        }
Exemple #7
0
        /// <summary>
        /// 具体执行类,不关闭conn
        /// </summary>
        /// <param name="cmd">cmd对象</param>
        /// <param name="callback">代理方法</param>
        /// <returns>object对象</returns>
        /// <remarks> </remarks>
        protected virtual object DoExecuteReadConn(DbCommand cmd, DBCallback callback)
        {
            object       returns = null;
            DbDataReader reader  = null;

            //处理sql或存储过程名
            dealCMD(cmd);
            //
            if (cmd.Connection.State == ConnectionState.Closed)
            {
                cmd.Connection.Open();
            }
            reader  = cmd.ExecuteReader();
            returns = callback(reader);
            return(returns);
        }
Exemple #8
0
        /// <summary>
        /// 通过cmd执行datareader,不关闭conn
        /// </summary>
        /// <param name="cmd">cmd对象</param>
        /// <param name="callback">代理方法</param>
        /// <returns>object对象</returns>
        public object ExecuteReadConn(DbCommand cmd, DBCallback callback)
        {
            if (cmd == null)
            {
                throw new ArgumentNullException("cmd");
            }

            if (cmd.Connection == null)
            {
                throw new ArgumentNullException("cmd.Connection");
            }

            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }
            object returns = this.DoExecuteReadConn(cmd, callback);

            return(returns);
        }
Exemple #9
0
    void getLevels(object obj)
    {
        try
        {
            Action <DBCallback>           callback  = (Action <DBCallback>)obj;
            Dictionary <int, LevelEntity> levels    = new Dictionary <int, LevelEntity> ();
            IEnumerable <LevelTable>      dataTable = connection.Table <LevelTable>();
            foreach (LevelTable item in dataTable)
            {
                LevelEntity levelEntity   = new LevelEntity();
                string      levelDecrypt  = Encryption.Decrypt(item.Level);
                string      scoreDecrypt  = Encryption.Decrypt(item.Score);
                string      rateDecrypt   = Encryption.Decrypt(item.Rate);
                string      replayDecrypt = Encryption.Decrypt(item.Replay);

                try {
                    levelEntity.Level  = Convert.ToInt32(levelDecrypt);
                    levelEntity.Score  = Convert.ToInt32(scoreDecrypt);
                    levelEntity.Rate   = Convert.ToInt32(rateDecrypt);
                    levelEntity.Replay = Convert.ToInt32(replayDecrypt);

                    // Add Score Entity to Score List
                    levels[levelEntity.Level] = levelEntity;
                } catch (Exception ex) {
                    Debug.LogException(ex);
                }
            }
            Debug.LogWarning("getLevels");
            DBCallback dbCallback = new DBCallback();
            dbCallback.Data = levels;
            dbCallback.completedCallback = callback;
            DBCallbackDispatcher.Singleton.requests.Enqueue(dbCallback);
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
    }
Exemple #10
0
    void getAccount(object obj)
    {
        lock (singletonLock)
        {
            try
            {
                Action <DBCallback>       callback      = (Action <DBCallback>)obj;
                AccountEntity             accountEntity = new AccountEntity();
                IEnumerable <AcountTable> dataTable     = connection.Table <AcountTable>();
                foreach (AcountTable item in dataTable)
                {
                    string userId      = Encryption.Decrypt(item.UserId);
                    string userName    = Encryption.Decrypt(item.UserName);
                    string password    = Encryption.Decrypt(item.Password);
                    string accountType = Encryption.Decrypt(item.AccountType);

                    try {
                        accountEntity.UserId      = userId;
                        accountEntity.UserName    = userName;
                        accountEntity.Password    = password;
                        accountEntity.AccountType = accountType;
                    } catch (Exception ex) {
                        Debug.LogException(ex);
                    }
                    break;
                }

                DBCallback dbCallback = new DBCallback();
                dbCallback.Data = accountEntity;
                dbCallback.completedCallback = callback;
                DBCallbackDispatcher.Singleton.requests.Enqueue(dbCallback);
            }
            catch (Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }
    }
Exemple #11
0
        /// <summary>
        /// 具体执行类,自动创建conn,自动关闭conn
        /// </summary>
        /// <param name="cmd">cmd对象</param>
        /// <param name="callback">代理方法</param>
        /// <returns>object对象</returns>
        /// <remarks> </remarks>
        protected virtual object DoExecuteRead(DbCommand cmd, DBCallback callback)
        {
            object       returns = null;
            DbDataReader reader  = null;
            bool         opened  = false;

            try
            {
                //处理sql语句
                dealCMD(cmd);
                //
                if (cmd.Connection.State == ConnectionState.Closed)
                {
                    cmd.Connection.Open();
                    opened = true;
                }
                reader  = cmd.ExecuteReader();
                returns = callback(reader);
            }
            catch (Exception ex)
            {
                this.HandleExecutionError(ex);
            }
            finally
            {
                if (null != reader)
                {
                    reader.Dispose();
                }

                if (opened)
                {
                    cmd.Connection.Close();
                }
            }

            return(returns);
        }
Exemple #12
0
        public int Call(AbstractDBQuery query, int forceIndex, DBCallback callback = null)
        {
            int dbIndex = 0;

            if (forceIndex > 0 && forceIndex < DBMngLst.Count)
            {
                DBMngLst[forceIndex].Call(query, callback);
                m_dbCallCountList[forceIndex]++;
            }
            else
            {
                DBMngLst[0].Call(query, callback);
                m_dbCallCountList[0]++;
            }
            if (!m_dbCallNameList.ContainsKey(query.ToString()))
            {
                m_dbCallNameList.Add(query.ToString(), 1);
            }
            else
            {
                m_dbCallNameList[query.ToString()]++;
            }
            return(dbIndex);
        }
        public int Call(AbstractDBOperater query, int force_index, DBCallback callback = null)
        {
            int dbIndex = 0;

            if (force_index > 0 && force_index < _dbManagerList.Count)
            {
                _dbManagerList[force_index].Call(query, callback);
                DBCallCountList[force_index]++;
            }
            else
            {
                _dbManagerList[0].Call(query, callback);
                DBCallCountList[0]++;
            }
            if (DBCallNameList.ContainsKey(query.ToString()) == false)
            {
                DBCallNameList.Add(query.ToString(), 1);
            }
            else
            {
                DBCallNameList[query.ToString()]++;
            }
            return(dbIndex);
        }
Exemple #14
0
    void getFriends(object obj)
    {
        lock (singletonLock)
        {
            try
            {
                Action <DBCallback> callback = (Action <DBCallback>)obj;

                List <FriendEntity>       friends   = new List <FriendEntity>();
                IEnumerable <FriendTable> dataTable = connection.Table <FriendTable>();

                foreach (FriendTable item in dataTable)
                {
                    FriendEntity friend = new FriendEntity();
                    friend.UserId = item.UserId;
                    friend.Name   = item.DisplayName;
                    friend.Avatar = item.Avatar;
                    friend.Gender = item.Gender;
                    friend.Level  = item.Level;
                    friend.Score  = item.Score;
                    friend.FBId   = item.FbId;

                    friends.Add(friend);
                }
                DBCallback dbCallback = new DBCallback();
                dbCallback.Data = friends;
                dbCallback.completedCallback = callback;
                DBCallbackDispatcher.Singleton.requests.Enqueue(dbCallback);
                Debug.Log("Completed: " + friends.Count);
            }
            catch (Exception ex)
            {
                Debug.LogWarning(ex.Message);
            }
        }
    }
Exemple #15
0
        public void Call(AbstractDBQuery query, string tableName = DBProxyDefault.DefaultTableName, DBOperateType type = DBProxyDefault.DefaultOperateType, DBCallback callback = null)
        {
            DBManagerPool dbPool = GetDbByTable(tableName, type);

            if (dbPool == null)
            {
                LOG.Warn("db call {0} failed:can not find table{1} type {2} db", query.GetCmd(), tableName, type.ToString());
                return;
            }
            dbPool.Call(query, callback);
        }
Exemple #16
0
 public void Call(AbstractDBQuery query, DBCallback callback = null)
 {
     query.OnCall(callback);
     AddDBQuery(query);
 }
Exemple #17
0
 public void OnCall(DBCallback callback)
 {
     m_Callback = callback;
 }
 public void Call(AbstractDBOperater query, DBCallback callback = null)
 {
     query.OnCall(callback);
     Add(query);
 }
Exemple #19
0
        public void Call(AbstractDBOperater query, int index, string table_name = DBProxyDefault.DefaultTableName, DBOperateType type = DBProxyDefault.DefaultOperateType, DBCallback callback = null)
        {
            DBWorkPool dbPool = GetDbByTable(table_name, type);

            if (dbPool == null)
            {
                Log.Error("db call {0} failed: can not find table {1} type {2} db", query.GetCmd(), table_name, type.ToString());
                return;
            }
            dbPool.Call(query, index, callback);
        }