Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }