protected void Page_Load(object sender, EventArgs e) { string md5 = Request.QueryString["md5"]; string uid = Request.QueryString["uid"]; string fid = Request.QueryString["idSvr"]; string cbk = Request.QueryString["callback"]; string fd_idSvr = Request.QueryString["fd_idSvr"]; //返回值。1表示成功 int ret = 0; if (string.IsNullOrEmpty(md5) || string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(fid)) { }//参数不为空 else { DBFile db = new DBFile(); db.UploadComplete(md5); ret = 1; } //更新文件夹已上传文件数 if (!string.IsNullOrEmpty(fd_idSvr)) { DBFolder.child_complete(int.Parse(fd_idSvr)); } Response.Write(cbk + "(" + ret + ")");//必须返回jsonp格式数据 }
/// <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()); }
/// <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()); }
protected void Page_Load(object sender, EventArgs e) { string fid = Request.QueryString["fid"]; string uid = Request.QueryString["uid"]; string callback = Request.QueryString["callback"]; int ret = 0; if (string.IsNullOrEmpty(fid) || string.IsNullOrEmpty(uid)) { }//参数不为空 else { DBFile db = new DBFile(); DBFolder.Remove(int.Parse(fid), int.Parse(uid)); ret = 1; } Response.Write(callback + "(" + ret + ")");//返回jsonp格式数据 }
protected void Page_Load(object sender, EventArgs e) { string fid = Request.QueryString["fid"]; string uid = Request.QueryString["uid"]; string callback = Request.QueryString["callback"]; int ret = 0; if (string.IsNullOrEmpty(fid) || string.IsNullOrEmpty(uid)) { }//参数不为空 else { DBFile db = new DBFile(); db.Delete(Convert.ToInt32(uid), Convert.ToInt32(fid)); ret = 1; } Response.Write(callback + "(" + ret + ")");//返回jsonp格式数据 }
/// <summary> /// 以JSON格式列出所有文件() /// 注意,输出的文件路径会进行UrlEncode编码 /// 客户端需要进行UrlDecode解码 /// </summary> protected void Page_Load(object sender, EventArgs e) { string uid = Request.QueryString["uid"]; string cbk = Request.QueryString["callback"];//jsonp if (!string.IsNullOrEmpty(uid)) { string json = DBFile.GetAllUnComplete2(int.Parse(uid)); if (!string.IsNullOrEmpty(json)) { System.Diagnostics.Debug.WriteLine(json); json = HttpUtility.UrlEncode(json); //UrlEncode会将空格解析成+号 json = json.Replace("+", "%20"); Response.Write(cbk + "({\"value\":\"" + json + "\"})"); return; } } Response.Write(cbk + "({\"value\":null})"); }
protected void Page_Load(object sender, EventArgs e) { string id_file = Request.QueryString["id_file"]; string id_fd = Request.QueryString["id_folder"]; string uid = Request.QueryString["uid"]; string callback = Request.QueryString["callback"]; int ret = 0; if (string.IsNullOrEmpty(id_fd) || string.IsNullOrEmpty(uid)) { } else { DBFolder.Complete(int.Parse(id_fd), int.Parse(uid)); DBFile.fd_complete(int.Parse(id_file)); ret = 1; } Response.Write(callback + "(" + ret + ")"); }
protected void Page_Load(object sender, EventArgs e) { string uid = Request.QueryString["uid"]; string idSvr = Request.QueryString["idSvr"]; string md5 = Request.QueryString["md5"]; string perSvr = Request.QueryString["perSvr"]; //文件百分比 string lenSvr = Request.QueryString["lenSvr"]; //已传大小 string lenLoc = Request.QueryString["lenLoc"]; //本地文件大小 string cbk = Request.QueryString["callback"]; //参数为空 if (string.IsNullOrEmpty(lenLoc) || string.IsNullOrEmpty(uid) || string.IsNullOrEmpty(idSvr) || string.IsNullOrEmpty(md5) ) { XDebug.Output("lenLoc", lenLoc); XDebug.Output("uid", uid); XDebug.Output("idSvr", idSvr); XDebug.Output("md5", md5); Response.Write(cbk + "({\"value\":null,\"des\":\"param is null\"})"); return; } XDebug.Output("lenLoc", lenLoc); XDebug.Output("uid", uid); XDebug.Output("idSvr", idSvr); XDebug.Output("lenSvr", lenSvr); XDebug.Output("perSvr", perSvr); DBFile db = new DBFile(); db.UpdateProgress(Convert.ToInt32(uid), Convert.ToInt32(idSvr), 0, Convert.ToInt64(lenSvr), perSvr); Response.Write(cbk + "({\"value\":true})"); }
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); }
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); }
protected void Page_Load(object sender, EventArgs e) { DBFile.Clear(); DBFolder.Clear(); }
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); }