Exemple #1
0
 protected void Delete(object sender, EventArgs e)
 {
     if (!CurrentUser.OperateFiles)
     {
         Response.StatusCode = 401;
         return;
     }
     foreach (var path in SelectedPaths)
     {
         FileHelper.Delete(path);
     }
     Response.Redirect(Request.RawUrl);
 }
Exemple #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Clear();
            Response.ContentType = "application/xml";
            var result = new XElement("result");
            var path   = RouteData.GetRelativePath();

            try
            {
                switch (RouteData.GetRouteString("Action").ToLower())
                {
                case "list":
                    if (!Request.GetUser().Browse)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    List(path, result);
                    break;

                case "createdirectory":
                    if (!Request.GetUser().OperateFiles)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    FileHelper.CreateDirectory(path);
                    break;

                case "copy":
                    if (!Request.GetUser().OperateFiles)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    FileHelper.Copy(path, Request.QueryString["Target"].UrlDecode());
                    break;

                case "move":
                    if (!Request.GetUser().OperateFiles)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    FileHelper.Move(path, Request.QueryString["Target"].UrlDecode());
                    break;

                case "delete":
                    if (!Request.GetUser().OperateFiles)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    FileHelper.Delete(path);
                    break;

                case "details":
                    if (!Request.GetUser().Browse)
                    {
                        Response.StatusCode = 401;
                        return;
                    }
                    Details(path, result);
                    break;

                case "niguan":
                    NiGuan(path, result);
                    Response.Write(result.ToString());
                    return;

                case "codecs":
                    Codecs(result);
                    break;

                default:
                    throw new FormatException("无法识别的 Action!");
                }
                result.SetAttributeValue("status", "ok");
            }
            catch (Exception exc)
            {
                result.SetAttributeValue("status", "error");
                result.SetAttributeValue("message", exc.GetMessage());
            }
            Response.Write(result.ToString());
        }
Exemple #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var upload = Request.HttpMethod == "POST";

            if (upload && !Request.GetUser().OperateFiles)
            {
                Response.StatusCode = 401;
                return;
            }
            var    data = upload ? Request.Form : Request.QueryString;
            string id = data["resumableIdentifier"], path = FileHelper.Combine
                                                                (RouteData.GetRelativePath(), data["resumableRelativePath"].ToValidPath(false)),
                   filePath = FileHelper.GetFilePath(path), dataPath = FileHelper.GetDataFilePath(path),
                   state = FileHelper.GetState(dataPath);

            Directory.CreateDirectory(Path.GetDirectoryName(filePath));
            Directory.CreateDirectory(Path.GetDirectoryName(dataPath));
            if (state != TaskType.UploadTask || state == TaskType.UploadTask && new UploadTask(path).Identifier != id)
            {
                FileHelper.Delete(path);
                File.WriteAllBytes(filePath, new byte[0]);
                try
                {
                    new UploadTask(path, id, int.Parse(data["resumableTotalChunks"]),
                                   long.Parse(data["resumableTotalSize"])).Save();
                }
                catch (IOException) { } // another save in progress
            }
            var index = int.Parse(data["resumableChunkNumber"]) - 1;

            if (upload)
            {
                string basePath = FileHelper.GetDataPath(path), partSuffix = ".part" + index,
                       partPath = basePath + ".incomplete" + partSuffix;
                try
                {
                    using (var output = new FileStream(partPath, FileMode.Create, FileAccess.Write, FileShare.Read))
                        Request.Files[Request.Files.AllKeys.Single()].InputStream.CopyTo(output);
                    File.Move(partPath, basePath + ".complete" + partSuffix);
                }
                catch
                {
                    FileHelper.DeleteWithRetries(partPath); // delete imcomplete file
                }
                var task = new UploadTask(path);
                if (task.FinishedParts != task.TotalParts)
                {
                    return;
                }
                using (var output = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
                    for (var i = 0; i < task.TotalParts; ++i)
                    {
                        using (var input = new FileStream(
                                   partPath = FileHelper.GetDataPath(path + ".complete.part" + i),
                                   FileMode.Open, FileAccess.Read, FileShare.Read)) input.CopyTo(output);
                        FileHelper.DeleteWithRetries(partPath);
                    }
                task.Finish();
            }
            else
            {
                Response.StatusCode = File.Exists(FileHelper.GetDataPath(path + ".complete.part" + index))
                                           ? 200 : 204;  // test
            }
        }