Exemplo n.º 1
0
        /// <summary>
        /// upload file
        /// 上传文件
        /// </summary>
        /// <param name="FilePath"></param>
        /// <param name="GridFSName"></param>
        /// <returns></returns>
        public String UploadFile(String FilePath, String GridFSName = "")
        {
            if (System.IO.File.Exists(FilePath) == false)
            {
                throw new Exception("file path not found");
            }

            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            String s = _database.UploadFile(_databasename, FilePath, GridFSName);

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(s);
        }
Exemplo n.º 2
0
        /// <summary>
        /// delete data by key value
        /// 删除指定条件数据
        /// </summary>
        /// <returns></returns>
        public int ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }

            Int32 count = 0;

            if (filterDefinition != null)
            {
                count = _database.DeleteData(_databasename, _TableName, filterDefinition);
            }
            else
            {
                count = _database.DeleteData(_databasename, _TableName);
            }

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(count);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Start Transaction
        /// 开始事务
        /// </summary>
        public void StartTransaction()
        {
            if (database.CheckStatus() == false)
            {
                throw new Exception("Database not open,call Open()");
            }

            database.StartTransaction();
        }
Exemplo n.º 4
0
        /// <summary>
        /// get all database name
        /// </summary>
        /// <returns></returns>
        public List <String> GetDatabaseName()
        {
            List <String> s = new List <String>();

            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }

            s = _database.GetDatabaseName();

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(s);
        }
Exemplo n.º 5
0
 /// <summary>
 /// check connect status
 /// 检查数据库连接
 /// </summary>
 /// <returns></returns>
 public Boolean Status()
 {
     try
     {
         //数据库连接
         if (_database.CheckStatus() == false)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// insert new data
        /// 插入新数据
        /// </summary>
        public void ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            _database.InsertData(_databasename, _TableName, MongoDB.Bson.Serialization.BsonSerializer.Deserialize <BsonDocument>(MongoDBOP.HashtableToJson(htData)));

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return;
        }
Exemplo n.º 7
0
        /// <summary>
        /// update new data
        /// 更新数据
        /// </summary>
        /// <returns></returns>
        public Int32 ExecuteCommand()
        {
            //数据库连接
            if (_connectionConfig.IsAutoCloseConnection == false)
            {
                if (_database.CheckStatus() == false)
                {
                    throw new Exception("databse connect not open");
                }
            }
            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Open();
            }
            Int32 count = _database.UpdateData(_databasename, _TableName, filterDefinition, htData);

            if (_connectionConfig.IsAutoCloseConnection == true)
            {
                _database.Close();
            }

            return(count);
        }