Example #1
0
        /// <summary>
        /// 根据文件MD5获取文件信息
        /// </summary>
        /// <param name="md5"></param>
        /// <param name="inf"></param>
        /// <returns></returns>
        public bool exist_file(string md5, ref xdb_files inf)
        {
            if (string.IsNullOrEmpty(md5))
            {
                return(false);
            }

            bool          ret = false;
            StringBuilder sb  = new StringBuilder();

            sb.Append("select top 1 ");
            sb.Append(" f_id");
            sb.Append(",f_uid");
            sb.Append(",f_nameLoc");
            sb.Append(",f_nameSvr");
            sb.Append(",f_pathLoc");
            sb.Append(",f_pathSvr");
            sb.Append(",f_pathRel");
            sb.Append(",f_md5");
            sb.Append(",f_lenLoc");
            sb.Append(",f_sizeLoc");
            sb.Append(",f_pos");
            sb.Append(",f_lenSvr");
            sb.Append(",f_perSvr");
            sb.Append(",f_complete");
            sb.Append(",f_time");
            sb.Append(",f_deleted");
            sb.Append(" from cloud2_files where f_md5=@f_md5 order by f_perSvr desc");

            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sb.ToString());

            db.AddString(ref cmd, "@f_md5", md5, 40);
            DbDataReader r = db.ExecuteReader(cmd);

            if (r.Read())
            {
                inf.idSvr    = r.GetInt32(0);
                inf.uid      = r.GetInt32(1);
                inf.nameLoc  = r.GetString(2);
                inf.nameSvr  = r.GetString(3);
                inf.pathLoc  = r.GetString(4);
                inf.pathSvr  = r.GetString(5);
                inf.pathRel  = r.GetString(6);
                inf.md5      = md5;
                inf.lenLoc   = r.GetInt64(8);
                inf.sizeLoc  = r.GetString(9);
                inf.FilePos  = r.GetInt64(10);
                inf.lenSvr   = r.GetInt64(11);
                inf.perSvr   = r.GetString(12);
                inf.complete = r.GetBoolean(13);
                inf.time     = r.GetDateTime(14);
                inf.deleted  = r.GetBoolean(15);
                ret          = true;
            }
            r.Close();
            return(ret);
        }
Example #2
0
        /// <summary>
        /// 根据文件ID获取文件信息
        /// </summary>
        /// <param name="f_id"></param>
        /// <returns></returns>
        public bool GetFileInfByFid(int f_id, ref xdb_files inf)
        {
            bool          ret = false;
            StringBuilder sb  = new StringBuilder();

            sb.Append("select top 1 ");
            sb.Append("f_uid");
            sb.Append(",f_nameLoc");
            sb.Append(",f_nameSvr");
            sb.Append(",f_pathLoc");
            sb.Append(",f_pathSvr");
            sb.Append(",f_pathRel");
            sb.Append(",f_md5");
            sb.Append(",f_lenLoc");
            sb.Append(",f_sizeLoc");
            sb.Append(",f_pos");
            sb.Append(",f_lenSvr");
            sb.Append(",f_perSvr");
            sb.Append(",f_complete");
            sb.Append(",f_time");
            sb.Append(",f_deleted");
            sb.Append(" from cloud2_files where f_id=@f_id");

            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sb.ToString());

            db.AddInt(ref cmd, "@f_id", f_id);
            DbDataReader r = db.ExecuteReader(cmd);

            if (r.Read())
            {
                inf.idSvr    = f_id;
                inf.uid      = r.GetInt32(0);
                inf.nameLoc  = r.GetString(1);
                inf.nameSvr  = r.GetString(2);
                inf.pathLoc  = r.GetString(3);
                inf.pathSvr  = r.GetString(4);
                inf.pathRel  = r.IsDBNull(5) ? string.Empty : r.GetString(5);
                inf.md5      = r.GetString(6);
                inf.lenLoc   = r.GetInt64(7);
                inf.sizeLoc  = r.GetString(8);
                inf.FilePos  = r.GetInt64(9);
                inf.lenSvr   = r.GetInt64(10);
                inf.perSvr   = r.GetString(11);
                inf.complete = r.GetBoolean(12);
                inf.time     = r.GetDateTime(13);
                inf.deleted  = r.GetBoolean(14);
                ret          = true;
            }
            r.Close();
            return(ret);
        }
Example #3
0
        /// <summary>
        /// 根据文件idSvr信息,更新文件数据表中对应项的MD5。
        /// </summary>
        /// <param name="inf"></param>
        public void UpdateMD5(ref xdb_files inf)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("update cloud2_files set ");
            sb.Append(" f_md5 = @f_md5 ");
            sb.Append(" where f_id=@f_id ");

            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sb.ToString());

            db.AddString(ref cmd, "@f_md5", inf.md5, 40);
            db.AddInt(ref cmd, "@f_id", inf.idSvr);
            db.ExecuteNonQuery(cmd);
        }
Example #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string folderStr = Request.Form["folder"];
            string uidTxt    = Request.Form["uid"];
            int    uid       = int.Parse(uidTxt);

            if (string.IsNullOrEmpty(folderStr))
            {
                return;
            }
            folderStr = HttpUtility.UrlDecode(folderStr);

            //文件夹ID,文件夹对象
            Hashtable tbFolders  = new Hashtable();
            JArray    arrFolders = new JArray();
            JArray    arrFiles   = new JArray();

            JObject   jsonObj = JObject.Parse(folderStr);
            FolderInf fdroot  = JsonConvert.DeserializeObject <FolderInf>(folderStr);

            fdroot.pathRel = fdroot.nameLoc;           //相对路径

            fdroot.m_idSvr = DBFolder.Add(ref fdroot); //添加到数据库
            fdroot.idFile  = DBFile.Add(ref fdroot);   //向文件表添加一条数据
            tbFolders.Add(0, fdroot);                  //提供给子文件夹使用

            //解析文件夹
            if (jsonObj["folders"] != null)
            {
                JArray jar = JArray.Parse(jsonObj["folders"].ToString());
                for (int i = 0, l = jar.Count; i < l; ++i)
                {
                    folderStr = jar[i].ToString();//把每一个元素转化为JObject对象
                    FolderInf folder = JsonConvert.DeserializeObject <FolderInf>(folderStr);
                    folder.uid     = uid;
                    folder.pidRoot = fdroot.idSvr;
                    //查找父级文件夹
                    FolderInf fdParent = (FolderInf)tbFolders[folder.m_pidLoc];
                    folder.pathRel  = Path.Combine(fdParent.pathRel, folder.nameLoc);
                    folder.m_pidSvr = fdParent.m_idSvr;
                    folder.m_idSvr  = DBFolder.Add(ref folder);//添加到数据库
                    tbFolders.Add(folder.m_idLoc, folder);
                    arrFolders.Add(JToken.FromObject(folder));
                }
            }

            DBFile    db      = new DBFile();
            xdb_files f_exist = new xdb_files();

            //解析文件
            if (jsonObj["files"] != null)
            {
                JArray jar = JArray.Parse(jsonObj["files"].ToString());
                for (int i = 0, l = jar.Count; i < l; ++i)
                {
                    folderStr = jar[i].ToString();//把每一个元素转化为JObject对象
                    FileInf   fileSvr = JsonConvert.DeserializeObject <FileInf>(folderStr);
                    FolderInf folder  = (FolderInf)tbFolders[fileSvr.pidLoc];
                    fileSvr.uid     = uid;
                    fileSvr.pidRoot = fdroot.m_idSvr;
                    fileSvr.pidSvr  = folder.idSvr;
                    fileSvr.nameSvr = fileSvr.md5 + Path.GetExtension(fileSvr.pathLoc).ToLower();
                    //生成文件路径
                    var pb = new PathCloudBuilder();
                    fileSvr.pathSvr = pb.genFile(fileSvr.uid, fileSvr.md5, fileSvr.nameLoc);

                    //存在相同文件
                    if (db.exist_file(fileSvr.md5, ref f_exist))
                    {
                        fileSvr.lenSvr   = f_exist.lenSvr;
                        fileSvr.perSvr   = f_exist.perSvr;
                        fileSvr.pathSvr  = f_exist.pathSvr;
                        fileSvr.pathRel  = f_exist.pathRel;
                        fileSvr.postPos  = f_exist.FilePos;
                        fileSvr.complete = f_exist.complete;
                        fileSvr.nameSvr  = f_exist.nameSvr;
                    }
                    fileSvr.idSvr = DBFile.Add(ref fileSvr);//将信息添加到数据库
                    arrFiles.Add(JToken.FromObject(fileSvr));
                }
            }

            //转换为JSON
            JObject obj = (JObject)JToken.FromObject(fdroot);

            obj["folders"]  = arrFolders;
            obj["files"]    = arrFiles;
            obj["complete"] = false;

            string json = obj.ToString();

            json = HttpUtility.UrlEncode(json);
            //UrlEncode会将空格解析成+号,
            json = json.Replace("+", "%20");
            Response.Write(json);
        }
Example #5
0
        /// <summary>
        /// 增加一条数据,并返回新增数据的ID
        /// 在ajax_create_fid.aspx中调用
        /// 文件名称,本地路径,远程路径,相对路径都使用原始字符串。
        /// d:\soft\QQ2012.exe
        /// </summary>
        public int Add(ref xdb_files model)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("insert into cloud2_files(");
            sb.Append(" f_sizeLoc");
            sb.Append(",f_pos");
            sb.Append(",f_lenSvr");
            sb.Append(",f_perSvr");
            sb.Append(",f_complete");
            sb.Append(",f_time");
            sb.Append(",f_deleted");
            sb.Append(",f_fdChild");
            sb.Append(",f_uid");
            sb.Append(",f_nameLoc");
            sb.Append(",f_nameSvr");
            sb.Append(",f_pathLoc");
            sb.Append(",f_pathSvr");
            sb.Append(",f_pathRel");
            sb.Append(",f_md5");
            sb.Append(",f_lenLoc");

            sb.Append(") values (");

            sb.Append(" @f_sizeLoc");
            sb.Append(",@f_pos");
            sb.Append(",@f_lenSvr");
            sb.Append(",@f_perSvr");
            sb.Append(",@f_complete");
            sb.Append(",@f_time");
            sb.Append(",@f_deleted");
            sb.Append(",@f_fdChild");
            sb.Append(",@f_uid");
            sb.Append(",@f_nameLoc");
            sb.Append(",@f_nameSvr");
            sb.Append(",@f_pathLoc");
            sb.Append(",@f_pathSvr");
            sb.Append(",@f_pathRel");
            sb.Append(",@f_md5");
            sb.Append(",@f_lenLoc");
            sb.Append(") ;");
            //获取新插入ID
            sb.Append("SELECT @@IDENTITY");

            DbHelper  db  = new DbHelper();
            DbCommand cmd = db.GetCommand(sb.ToString());

            db.AddString(ref cmd, "@f_sizeLoc", model.sizeLoc, 10);
            db.AddInt64(ref cmd, "@f_pos", model.FilePos);
            db.AddInt64(ref cmd, "@f_lenSvr", model.lenSvr);
            db.AddString(ref cmd, "@f_perSvr", model.perSvr, 6);
            db.AddInBool(cmd, "@f_complete", model.complete);
            db.AddDate(ref cmd, "@f_time", model.time);
            db.AddInBool(cmd, "@f_deleted", false);
            db.AddInBool(cmd, "@f_fdChild", model.f_fdChild);
            db.AddInt(ref cmd, "@f_uid", model.uid);
            db.AddString(ref cmd, "@f_nameLoc", model.nameLoc, 255);
            db.AddString(ref cmd, "@f_nameSvr", model.nameSvr, 255);
            db.AddString(ref cmd, "@f_pathLoc", model.pathLoc, 255);
            db.AddString(ref cmd, "@f_pathSvr", model.pathSvr, 255);
            db.AddString(ref cmd, "@f_pathRel", model.pathRel, 255);
            db.AddString(ref cmd, "@f_md5", model.md5, 40);
            db.AddInt64(ref cmd, "@f_lenLoc", model.lenLoc);

            //db.ExecuteNonQuery(cmd);

            //cmd.Parameters.Clear();
            //cmd.CommandText = "SELECT @@IDENTITY";
            object f_id = db.ExecuteScalar(cmd);

            return(Convert.ToInt32(f_id));
        }
Example #6
0
        /// <summary>
        /// 获取所有已经上传完的文件
        /// </summary>
        /// <param name="f_uid"></param>
        /// <returns></returns>
        static public string GetAllComplete(int f_uid)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("select ");
            sb.Append(" f_id");
            sb.Append(",f_fdTask");
            sb.Append(",f_fdID");
            sb.Append(",f_nameLoc");
            sb.Append(",f_pathLoc");
            sb.Append(",f_md5");
            sb.Append(",f_lenLoc");
            sb.Append(",f_sizeLoc");
            sb.Append(",f_pos");
            sb.Append(",f_lenSvr");
            sb.Append(",f_perSvr");
            sb.Append(",f_complete");
            sb.Append(",f_pathSvr");
            sb.Append(",fd_size");
            sb.Append(" from cloud2_files as f left join cloud2_folders as fd");
            sb.Append(" on f.f_fdID = fd.fd_id");
            sb.Append(" where f.f_deleted=0 and f.f_fdChild=0 and f.f_complete=1");

            JArray    arrFiles = new JArray();
            DbHelper  db       = new DbHelper();
            DbCommand cmd      = db.GetCommand(sb.ToString());

            db.AddInt(ref cmd, "@f_uid", f_uid);
            DbDataReader r = db.ExecuteReader(cmd);

            while (r.Read())
            {
                xdb_files f = new xdb_files();
                f.idSvr    = r.GetInt32(0);
                f.f_fdTask = r.GetBoolean(1);
                f.f_fdID   = r.GetInt32(2);
                f.nameLoc  = r.IsDBNull(3) ? string.Empty : r.GetString(3);
                f.pathLoc  = r.IsDBNull(4) ? string.Empty : r.GetString(4);
                f.md5      = r.IsDBNull(5) ? string.Empty : r.GetString(5);
                f.lenLoc   = r.GetInt64(6);
                f.sizeLoc  = r.IsDBNull(7) ? string.Empty : r.GetString(7);
                //是文件夹
                if (f.f_fdTask)
                {
                    f.sizeLoc = r.IsDBNull(13) ? string.Empty : r.GetString(13);
                }
                f.FilePos  = r.GetInt64(8);
                f.lenSvr   = r.GetInt64(9);
                f.perSvr   = r.IsDBNull(10) ? string.Empty : r.GetString(10);
                f.complete = r.IsDBNull(11) ? false : r.GetBoolean(11);
                f.pathSvr  = r.IsDBNull(12) ? string.Empty : r.GetString(12);//fix(2015-03-19):文件无法续传

                arrFiles.Add((JObject)JToken.FromObject(f));
            }
            r.Close();

            //JArray arrFiles = new JArray();
            //foreach (xdb_files f in files)
            //{
            //    //是文件夹任务=>取文件夹JSON
            //    if (f.f_fdTask)
            //    {
            //        FolderInf fd = new FolderInf();
            //        f.fd_json = DBFolder.GetFilesUnComplete(f.f_fdID, ref fd);
            //        float pdPer = 0;
            //        long lenPosted = DBFolder.GetLenPosted(f.f_fdID);
            //        fd.lenPosted = lenPosted.ToString();
            //        f.f_lenSvr = lenPosted;//给客户端使用。
            //        long len = long.Parse(fd.length);
            //        if (lenPosted > 0 && len > 0)
            //        {
            //            pdPer = (float)Math.Round(((lenPosted * 1.0f) / len * 1.0f) * 100.0f, 2);
            //        }
            //        f.idSvr = f.f_fdID;//将文件ID改为文件夹的ID,客户端续传文件夹时将会使用这个ID。
            //        f.f_perSvr = pdPer.ToString() + "%";
            //        f.f_sizeLoc = fd.size;
            //    }
            //    arrFiles.Add((JObject)JToken.FromObject(f));
            //}
            return(arrFiles.ToString());
        }
Example #7
0
        /// <summary>
        /// 获取所有文件和文件夹列表,不包含子文件夹,包含已上传完的和未上传完的
        /// </summary>
        /// <param name="f_uid"></param>
        /// <returns></returns>
        static public string GetAll(int f_uid)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("select ");
            sb.Append("f_id");
            sb.Append(",f_fdTask");
            sb.Append(",f_fdID");
            sb.Append(",f_nameLoc");
            sb.Append(",f_pathLoc");
            sb.Append(",f_md5");
            sb.Append(",f_lenLoc");
            sb.Append(",f_sizeLoc");
            sb.Append(",f_pos");
            sb.Append(",f_lenSvr");
            sb.Append(",f_perSvr");
            sb.Append(",f_complete");
            sb.Append(" from cloud2_files where f_uid=@f_uid and f_deleted=0 and f_fdChild=0;");

            List <xdb_files> files = new List <xdb_files>();
            DbHelper         db    = new DbHelper();
            DbCommand        cmd   = db.GetCommand(sb.ToString());

            db.AddInt(ref cmd, "@f_uid", f_uid);
            DbDataReader r = db.ExecuteReader(cmd);

            while (r.Read())
            {
                xdb_files f = new xdb_files();
                f.uid      = f_uid;
                f.idSvr    = r.GetInt32(0);
                f.f_fdTask = r.GetBoolean(1);
                f.f_fdID   = r.GetInt32(2);
                f.nameLoc  = r.IsDBNull(3) ? string.Empty : r.GetString(3);
                f.pathLoc  = r.IsDBNull(4) ? string.Empty : r.GetString(4);
                f.md5      = r.IsDBNull(5) ? string.Empty : r.GetString(5);
                f.lenLoc   = r.GetInt64(6);
                f.sizeLoc  = r.IsDBNull(7) ? string.Empty : r.GetString(7);
                f.FilePos  = r.GetInt64(8);
                f.lenSvr   = r.GetInt64(9);
                f.perSvr   = r.IsDBNull(10) ? string.Empty : r.GetString(10);
                f.complete = r.IsDBNull(11) ? false : r.GetBoolean(11);

                files.Add(f);
            }
            r.Close();

            JArray arrFiles = new JArray();

            foreach (xdb_files f in files)
            {
                //是文件夹任务=>取文件夹JSON
                if (f.f_fdTask)
                {
                    FolderInf fd = new FolderInf();
                    f.fd_json = DBFolder.GetFilesUnComplete(f.f_fdID, ref fd);
                    float pdPer     = 0;
                    long  lenPosted = DBFolder.GetLenPosted(f.f_fdID);
                    fd.lenSvr = lenPosted;
                    f.lenSvr  = lenPosted;//给客户端使用。
                    long len = fd.lenLoc;
                    if (lenPosted > 0 && len > 0)
                    {
                        pdPer = (float)Math.Round(((lenPosted * 1.0f) / len * 1.0f) * 100.0f, 2);
                    }
                    f.idSvr   = f.f_fdID;//将文件ID改为文件夹的ID,客户端续传文件夹时将会使用这个ID。
                    f.perSvr  = pdPer.ToString() + "%";
                    f.sizeLoc = fd.size;
                }
                arrFiles.Add((JObject)JToken.FromObject(f));
            }
            return(arrFiles.ToString());
        }
Example #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string md5      = Request.QueryString["md5"];
            string uid      = Request.QueryString["uid"];
            string lenLoc   = Request.QueryString["lenLoc"];
            string sizeLoc  = Request.QueryString["sizeLoc"];
            string callback = Request.QueryString["callback"];                           //jsonp参数
            //客户端使用的是encodeURIComponent编码,
            string      pathLoc = HttpUtility.UrlDecode(Request.QueryString["pathLoc"]); //utf-8解码
            string      cloud   = Request.QueryString["cloud"];                          //云配置信息
            CloudConfig cc      = new CloudConfig();

            if (!string.IsNullOrEmpty(cloud))
            {
                cc = JsonConvert.DeserializeObject <CloudConfig>(cloud);
            }

            //参数为空
            if (string.IsNullOrEmpty(md5) ||
                string.IsNullOrEmpty(uid) ||
                string.IsNullOrEmpty(sizeLoc))
            {
                Response.Write(callback + "({\"value\":null})");
                return;
            }

            xdb_files fileSvr = new xdb_files();

            fileSvr.f_fdChild = false;
            fileSvr.uid       = int.Parse(uid);//将当前文件UID设置为当前用户UID
            fileSvr.nameLoc   = Path.GetFileName(pathLoc);
            fileSvr.pathLoc   = pathLoc;
            fileSvr.lenLoc    = Convert.ToInt64(lenLoc);
            fileSvr.sizeLoc   = sizeLoc;
            fileSvr.deleted   = false;
            fileSvr.md5       = md5;
            fileSvr.nameSvr   = md5 + Path.GetExtension(pathLoc).ToLower();

            //所有单个文件均以md5方式存储
            var pb = new PathCloudBuilder();

            pb.m_url        = cc.fileUrl;
            fileSvr.pathSvr = pb.genFile(fileSvr.uid, ref fileSvr);

            //数据库存在相同文件
            DBFile    db        = new DBFile();
            xdb_files fileExist = new xdb_files();

            if (db.exist_file(md5, ref fileExist))
            {
                fileSvr.pathSvr  = fileExist.pathSvr;
                fileSvr.perSvr   = fileExist.perSvr;
                fileSvr.lenSvr   = fileExist.lenSvr;
                fileSvr.complete = fileExist.complete;
                fileSvr.idSvr    = db.Add(ref fileSvr);
            }//数据库不存在相同文件
            else
            {
                fileSvr.idSvr = db.Add(ref fileSvr);
            }
            string jv = JsonConvert.SerializeObject(fileSvr);

            jv = HttpUtility.UrlEncode(jv);
            jv = jv.Replace("+", "%20");
            string json = callback + "({\"value\":\"" + jv + "\"})";//返回jsonp格式数据。

            Response.Write(json);
        }