Beispiel #1
0
        static public FolderInf GetInf(string fid)
        {
            FolderInf inf = new FolderInf();

            GetInf(ref inf, fid);
            return(inf);
        }
Beispiel #2
0
        /// <summary>
        /// 添加一个文件夹上传任务
        /// 更新记录:
        ///     2016-03-30 返回cloud2_files.f_id
        /// </summary>
        /// <param name="fd"></param>
        /// <returns></returns>
        static public int Add(ref FolderInf fd)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("insert into cloud2_files(");
            sb.Append(" f_nameLoc");
            sb.Append(",f_fdTask");
            sb.Append(",f_fdID");
            sb.Append(",f_lenLoc");
            sb.Append(",f_sizeLoc");
            //param
            sb.Append(") values(");
            sb.Append("@f_nameLoc");
            sb.Append(",1");
            sb.Append(",@f_fdID");
            sb.Append(",@fd_lenLoc");
            sb.Append(",@fd_sizeLoc");
            sb.Append(");");
            //获取新插入ID
            sb.Append("SELECT @@IDENTITY");

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

            db.AddString(ref cmd, "@f_nameLoc", fd.nameLoc, 255);
            db.AddInt(ref cmd, "@f_fdID", fd.idSvr);
            db.AddInt64(ref cmd, "@fd_lenLoc", fd.lenLoc);
            db.AddString(ref cmd, "@fd_sizeLoc", fd.size, 10);
            object f_id = db.ExecuteScalar(cmd);

            return(Convert.ToInt32(f_id));
        }
Beispiel #3
0
        /// <summary>
        /// 获取文件夹JSON数据
        /// </summary>
        /// <param name="fid"></param>
        /// <param name="root"></param>
        /// <returns></returns>
        public static string GetFolderData(int fid, ref FolderInf root)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("select ");
            sb.Append("fd_name");
            sb.Append(",fd_length");
            sb.Append(",fd_size");
            sb.Append(",fd_pid");
            sb.Append(",fd_pathLoc");
            sb.Append(",fd_pathSvr");
            sb.Append(",fd_folders");
            sb.Append(",fd_files");
            sb.Append(",fd_filesComplete");
            sb.Append(" from cloud2_folders");
            sb.Append(" where fd_id=@fd_id and fd_complete=1;");

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

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

            //FolderInf root = new FolderInf();
            if (r.Read())
            {
                root.m_name        = r.GetString(0);
                root.m_lenLoc      = r.GetInt64(1);
                root.m_size        = r.GetString(2);
                root.m_pidSvr      = r.GetInt32(3);
                root.m_idSvr       = fid;
                root.m_pathLoc     = r.GetString(4);
                root.m_pathSvr     = r.GetString(5);
                root.foldersCount  = r.GetInt32(6);
                root.filesCount    = r.GetInt32(7);
                root.filesComplete = r.GetInt32(8);
            }
            r.Close();

            //单独取已上传长度
            root.lenSvr = DBFolder.GetLenPosted(fid);

            //取文件信息
            JArray        files = new JArray();
            List <string> ids   = new List <string>();

            DBFile.GetCompletes(fid, ref files, ref ids);

            JObject obj = (JObject)JToken.FromObject(root);

            obj["files"]  = files;
            obj["length"] = root.m_lenLoc;
            obj["ids"]    = string.Join(",", ids.ToArray());//
            return(obj.ToString());
        }
Beispiel #4
0
        /// <summary>
        /// 向数据库添加一条记录
        /// </summary>
        /// <param name="inf"></param>
        /// <returns></returns>
        static public int Add(ref FolderInf inf)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("insert into cloud2_folders(");
            sb.Append("fd_name");
            sb.Append(",fd_pid");
            sb.Append(",fd_uid");
            sb.Append(",fd_length");
            sb.Append(",fd_size");
            sb.Append(",fd_pathLoc");
            sb.Append(",fd_pathSvr");
            sb.Append(",fd_folders");
            sb.Append(",fd_files");
            sb.Append(",fd_pidRoot");
            sb.Append(",fd_pathRel");

            sb.Append(") values(");
            sb.Append("@fd_name");
            sb.Append(",@pid");
            sb.Append(",@uid");
            sb.Append(",@length");
            sb.Append(",@size");
            sb.Append(",@pathLoc");
            sb.Append(",@pathSvr");
            sb.Append(",@folders");
            sb.Append(",@files");
            sb.Append(",@pidRoot");
            sb.Append(",@pathRel");
            sb.Append(");");
            //
            sb.Append("SELECT @@IDENTITY");

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

            db.AddString(ref cmd, "@fd_name", inf.nameLoc, 50);
            db.AddInt(ref cmd, "@pid", inf.pidSvr);
            db.AddInt(ref cmd, "@uid", inf.uid);
            db.AddInt64(ref cmd, "@length", inf.lenLoc);
            db.AddString(ref cmd, "@size", inf.size, 50);
            db.AddString(ref cmd, "@pathLoc", inf.m_pathLoc, 255);
            db.AddString(ref cmd, "@pathSvr", inf.m_pathSvr, 255);
            db.AddInt(ref cmd, "@folders", inf.foldersCount);
            db.AddInt(ref cmd, "@files", inf.filesCount);
            db.AddInt(ref cmd, "@pidRoot", inf.pidRoot);         //为下载控件提供支持
            db.AddString(ref cmd, "@pathRel", inf.pathRel, 255); //为下载控件提供支持

            //获取新插入的ID
            object fid = db.ExecuteScalar(cmd);

            return(Convert.ToInt32(fid));
        }
Beispiel #5
0
        /// <summary>
        /// 根据文件夹ID获取文件夹信息和未上传完的文件列表,转为JSON格式。
        /// 说明:
        /// </summary>
        /// <param name="fid"></param>
        /// <returns></returns>
        static public string GetFilesUnComplete(int fid, ref FolderInf fd)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("select ");
            sb.Append("fd_name");
            sb.Append(",fd_length");
            sb.Append(",fd_size");
            sb.Append(",fd_pid");
            sb.Append(",fd_pathLoc");
            sb.Append(",fd_pathSvr");
            sb.Append(",fd_folders");
            sb.Append(",fd_files");
            sb.Append(",fd_filesComplete");
            sb.Append(" from cloud2_folders where fd_id=@fd_id;");

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

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

            //FolderInf root = new FolderInf();
            if (r.Read())
            {
                fd.m_name        = r.GetString(0);
                fd.m_lenLoc      = r.GetInt64(1);
                fd.m_size        = r.GetString(2);
                fd.m_pidSvr      = r.GetInt32(3);
                fd.m_idSvr       = fid;
                fd.idFile        = fid;//将文件夹与文件关联
                fd.m_pathLoc     = r.GetString(4);
                fd.m_pathSvr     = r.GetString(5);
                fd.foldersCount  = r.GetInt32(6);
                fd.filesCount    = r.GetInt32(7);
                fd.filesComplete = r.GetInt32(8);
            }
            r.Close();

            //单独取已上传长度
            //fd.lenPosted = DBFolder.GetLenPosted(fid).ToString();

            //取文件信息
            JArray files = new JArray();

            DBFile.GetUnCompletes(fid, ref files);

            JObject obj = (JObject)JToken.FromObject(fd);

            obj["files"] = files;
            return(obj.ToString());
        }
Beispiel #6
0
        /// <summary>
        /// 根据文件夹ID填充文件夹信息
        /// </summary>
        /// <param name="inf"></param>
        /// <param name="fid"></param>
        static public bool GetInf(ref FolderInf inf, string fid)
        {
            bool          ret = false;
            StringBuilder sb  = new StringBuilder();

            sb.Append("select ");
            sb.Append(" fd_name");
            sb.Append(",fd_length");
            sb.Append(",fd_size");
            sb.Append(",fd_pid");
            sb.Append(",fd_pathLoc");
            sb.Append(",fd_pathSvr");
            sb.Append(",fd_folders");
            sb.Append(",fd_files");
            sb.Append(",fd_filesComplete");
            sb.Append(" from cloud2_folders where fd_id=@fd_id;");

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

            db.AddInt(ref cmd, "@fd_id", Convert.ToInt32(fid));
            DbDataReader r = db.ExecuteReader(cmd);

            if (r.Read())
            {
                inf.m_name        = r.GetString(0);
                inf.m_lenLoc      = r.GetInt64(1);
                inf.m_size        = r.GetString(2);
                inf.m_pidSvr      = r.GetInt32(3);
                inf.m_idSvr       = int.Parse(fid);
                inf.pathLoc       = r.GetString(4);
                inf.pathSvr       = r.GetString(5);
                inf.foldersCount  = r.GetInt32(6);
                inf.filesCount    = r.GetInt32(7);
                inf.filesComplete = r.GetInt32(8);
                ret = true;
            }
            r.Close();
            return(ret);
        }
Beispiel #7
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);
        }
Beispiel #8
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();

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

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

            PathUuidBuilder pb = new PathUuidBuilder();

            fdroot.pathSvr = pb.genFolder(uid, ref fdroot);
            if (!Directory.Exists(fdroot.pathSvr))
            {
                Directory.CreateDirectory(fdroot.pathSvr);
            }

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

            //解析文件夹
            JArray arrFolders = new JArray();

            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.pathSvr  = Path.Combine(fdParent.pathSvr, folder.nameLoc);
                    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));
                }
            }

            //解析文件
            JArray arrFiles = new JArray();

            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   file  = JsonConvert.DeserializeObject <FileInf>(folderStr);
                    FolderInf pidFd = (FolderInf)tbFolders[file.pidLoc];
                    file.uid     = uid;
                    file.pidRoot = fdroot.m_idSvr;
                    file.pidSvr  = pidFd.idSvr;
                    file.nameSvr = file.nameLoc;
                    //以层级结构存储
                    file.pathSvr = Path.Combine(pidFd.pathSvr, file.nameLoc);
                    file.idSvr   = DBFile.Add(ref file);//将信息添加到数据库
                    arrFiles.Add(JToken.FromObject(file));
                }
            }

            //转换为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);
        }
Beispiel #9
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());
        }