Ejemplo n.º 1
0
        /// <summary>
        /// 修改图片数据
        /// </summary>
        /// <param name="groupName">数据库组</param>
        /// <param name="collection">集合</param>
        /// <param name="file">文件对象</param>
        /// <returns></returns>
        public bool UpdateImg(string groupName, string collection, SunFile file)
        {
            SunMongoClient clent;

            if (!MongoDbServer.GetClentByGroupName(groupName, out clent))
            {
                throw new Exception("数据库群组名不存在");
            }
            var server         = clent.GetServer();
            var origDatabase   = server.GetDatabase(MUpload.originalImgDatabase);//原图数据库
            var origCollection = origDatabase.GetCollection <SunFile>(collection);

            return(origCollection.Save <SunFile>(file).Ok);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// 获取图片数据
 /// </summary>
 /// <param name="groupName">数据库组名</param>
 /// <param name="collection">文件所在的集合</param>
 /// <param name="id">文件id</param>
 /// <returns></returns>
 public static SunFile GetImg(string groupName = null, string collection = null, string id = null)
 {
     try
     {
         SunMongoClient clent;
         if (!MongoDbServer.GetClentByGroupName(groupName, out clent))
         {
             throw new Exception("数据库群组名不存在");
         }
         var server         = clent.GetServer();
         var origDatabase   = server.GetDatabase(MUpload.originalImgDatabase);//原图数据库
         var origCollection = origDatabase.GetCollection <SunFile>(collection);
         return(origCollection.FindOne(Query <SunFile> .EQ(f => f.Id, id)));
     }
     catch
     {
         throw new Exception("文件不存在");
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 删除文件
 /// </summary>
 /// <param name="dbGroupName">文件数据库组</param>
 /// <param name="collection">文件集合</param>
 /// <param name="id">文件ID</param>
 /// <returns></returns>
 public static bool DeleteFile(string dbGroupName, string collection, string id)
 {
     try
     {
         SunMongoClient clent;
         if (!MongoDbServer.GetClentByGroupName(dbGroupName, out clent))
         {
             throw new Exception("数据库群组名不存在");
         }
         var server         = clent.GetServer();
         var origDatabase   = server.GetDatabase(MUpload.originalImgDatabase);                                 //原图数据库
         var origCollection = origDatabase.GetCollection <SunFile>(collection);
         var editCollection = server.GetDatabase(MUpload.editImgDatabase).GetCollection <SunFile>(collection); //缩略图数据库
         origCollection.Remove(Query <SunFile> .EQ(f => f.Id, id));
         editCollection.Remove(Query <SunFile> .Matches(f => f.Id, @"^\w+" + id + "$"));
         return(true);
     }
     catch
     {
         return(false);
     }
 }