示例#1
0
        public ActionResult Download(string name, string path)
        {
            var file = new BlobFile2(User.Identity.Name, path + name);
            if (file.Exists() && !file.IsDirectory())
            {

                if (name != null)
                {
                    Response.StatusCode = 200;
                    Response.ContentType = file.ContentType();
                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + name);
                    file.GetBlob().DownloadToStream(Response.OutputStream);
                }
                else
                {
                    DateTime dt;
                    if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out dt) && (file.LastModified() - DateTime.SpecifyKind(dt.ToUniversalTime(), DateTimeKind.Utc)).TotalSeconds < 1.0)
                    {
                        Response.StatusCode = 304;
                        return new EmptyResult();
                    }
                    Response.Cache.SetCacheability(HttpCacheability.Public);
                    Response.Cache.SetValidUntilExpires(true);
                    Response.Cache.SetMaxAge(TimeSpan.FromSeconds(300));
                    Response.Expires = 300;
                    Response.ContentType = file.Properties().ContentType;
                    file.GetBlob().DownloadToStream(Response.OutputStream);
                }
            }
            else
            {
                Response.StatusCode = 404;
            }
            return new EmptyResult();
        }
示例#2
0
        public ActionResult Thumb(string path)
        {
            var file = new BlobFile2(User.Identity.Name, path);
            if (file.Exists() && !file.IsDirectory())
            {

                DateTime dt;
                if (DateTime.TryParse(Request.Headers["If-Modified-Since"], out dt) && (file.LastModified() - DateTime.SpecifyKind(dt.ToUniversalTime(), DateTimeKind.Utc)).TotalSeconds < 1.0)
                {
                    Response.StatusCode = 304;
                    return new EmptyResult();
                }
                Response.Cache.SetCacheability(HttpCacheability.Public);
                Response.Cache.SetValidUntilExpires(true);
                Response.Cache.SetMaxAge(TimeSpan.FromSeconds(300));
                Response.Expires = 300;
                Response.ContentType = MimeMapping.GetMimeMapping(path);

                Image image = Image.FromStream(file.GetBlob().OpenRead());
                new Bitmap(image, new Size(200, (int)(image.Height*200.0/image.Width))).Save(Response.OutputStream, image.RawFormat);
            }
            else
            {
                Response.StatusCode = 404;
            }
            return new EmptyResult();
        }
示例#3
0
 public JsonResult Dir(Dictionary<string, string> env, string[] args)
 {
     var blobFile = new BlobFile2(User.Identity.Name, env["path"]);
     var sb = new StringBuilder();
     foreach (var s in blobFile.ListFiles())
     {
         sb.Append(String.Format("{0}\t{1}\t{2}\t{3}\n", s.Path().Name(), s.IsDirectory() ? "D" : "-", s.Length(), s.LastModified()));
     }
     return SuccessWrapper(sb.ToString());
 }
示例#4
0
 public ActionResult Download(Dictionary<string, string> env, string[] args)
 {
     var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
     if (file.Exists())
     {
         return SuccessWrapper("");
     }
     else
     {
         return Error("File Not Exist");
     }
 }
示例#5
0
 public JsonResult Cd(Dictionary<string, string> env, string[] args)
 {
     if (args.Length > 0)
     {
         var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
         if (file.IsDirectory())
         {
             return SuccessWrapper(env["path"] + args[0] + "/");
         }
         else
         {
             return Error("Directory \"" + args[0] + "\" doesn't exist.");
         }
     }
     return Error("Usage: cd [directory]");
 }
示例#6
0
 //
 // GET: /Photo/
 public ActionResult Index()
 {
     const string type = "image/*";
     try
     {
         var file = new BlobFile2(User.Identity.Name, "/");
         var list = file.AllFiles();
         var regex = new Regex("^" + Regex.Escape(type).Replace(@"\*", ".*").Replace(@"\?", ".") + "$",
             RegexOptions.IgnoreCase);
         var data = list.Where(m => regex.IsMatch(m.ContentType())).Select(m => m.Path().Path());
         ViewData["images"] = data;
     }
     catch (Exception ex)
     {
         ViewData["images"] = null;
     }
     return View();
 }
示例#7
0
 public JsonResult Cp(Dictionary<string, string> env, string[] args)
 {
     if (args.Length > 1)
     {
         var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
         if (file.Exists())
         {
             try
             {
                 return SuccessWrapper(String.Format("{0} file(s) copied.", file.Copy(env["path"] + args[1])));
             }
             catch (FileExistsException ex)
             {
                 return Error(args[1] + " Already Exists");
             }
         }
         return Error(args[0] + " Not Exists");
     }
     return Error("Usage: mv [file1] [file2]");
 }
示例#8
0
        public int Copy(string p)
        {
            if (_path.Contains(p)) throw new Exception("You can't copy a directory into itself");
            var target = new BlobFile2(_username, p);
            if (target.Exists())
            {
                if (target.IsDirectory())
                {
                    p += "/" + Path().Name();
                }
                else
                {
                    target.ValidateFileNotExist();
                }
            }

            new BlobFile2(_username, p).ValidateFileNotExist();

            var operations = new TableBatchOperation();
            var path = new FilePath(p);
            if (IsDirectory())
            {
                foreach (FileEntity i in FileTable.ExecuteQuery(PrefixQuery()))
                {
                    var n = new FileEntity()
                    {
                        ContentType = i.ContentType,
                        Key = Guid.NewGuid().ToString("N"),
                        LastModified = DateTime.UtcNow,
                        Length = i.Length,
                        Path = i.Path.Replace(_path.Path(), path.Path()),
                        PartitionKey = i.PartitionKey,
                        Parent = i.Parent.Replace(_path.Path(), path.Path()),
                        RowKey = DateTime.UtcNow.Ticks.ToString("D") + _rnd.Next(1000, 9999).ToString("D"),
                        Type = i.Type
                    };
                    operations.Add(TableOperation.Insert(n));
                    if (i.Type != FileEntity.Directory)
                        _container.GetBlockBlobReference(n.Key)
                            .StartCopyFromBlob(_container.GetBlockBlobReference(i.Key));
                }
            }

            var m = new FileEntity()
            {
                ContentType = _entity.ContentType,
                Key = Guid.NewGuid().ToString("D"),
                LastModified = DateTime.UtcNow,
                Length = _entity.Length,
                Path = path.Path(),
                PartitionKey = _entity.PartitionKey,
                Parent = path.BasePath(),
                RowKey = DateTime.UtcNow.Ticks.ToString("N") + _rnd.Next(1000, 9999).ToString("D"),
                Type = _entity.Type

            };
            if (!IsDirectory())
            {
                _container.GetBlockBlobReference(m.Key).StartCopyFromBlob(GetBlob());
            }
            operations.Add(TableOperation.Insert(m));
            FileTable.ExecuteBatch(operations);
            return operations.Count;
        }
示例#9
0
        public int Move(string p)
        {
            if (_path.Contains(p)) throw new Exception("You can't move a directory into itself");
            var target = new BlobFile2(_username, p);
            if (target.Exists())
            {
                if (target.IsDirectory())
                {
                    p += "/" + Path().Name();
                }
                else
                {
                    target.ValidateFileNotExist();
                }
            }
            new BlobFile2(_username, p).ValidateFileNotExist();

            var operations = new TableBatchOperation();
            var path = new FilePath(p);
            if (IsDirectory())
            {
                foreach (FileEntity i in FileTable.ExecuteQuery(PrefixQuery()))
                {
                    i.Path = i.Path.Replace(_path.Path(), path.Path());
                    i.Parent = i.Parent.Replace(_path.Path(), path.Path());
                    operations.Add(TableOperation.Replace(i));
                }
            }
            _entity.Path = path.Path();
            _entity.Parent = path.BasePath();
            operations.Add(TableOperation.Replace(_entity));
            this._path = path;
            FileTable.ExecuteBatch(operations);
            return operations.Count;
        }
示例#10
0
 public ActionResult UpdateText(String content, string name, string path)
 {
     try
     {
         var f = new BlobFile2(User.Identity.Name, path + "/" + name);
         var stream = new MemoryStream();
         var writer = new StreamWriter(stream);
         writer.Write(content);
         writer.Flush();
         stream.Position = 0;
         f.GetBlob().UploadFromStream(stream);
         return Json(new { code = 0 });
     }
     catch (Exception ex)
     {
         return Json(new { code = 1, data = ex.Message });
     }
 }
示例#11
0
        public ActionResult Index(string path = "/")
        {
            var file = new BlobFile2(User.Identity.Name, path);
            ViewData["files"] = file.ListFiles();

            var paths = path.Split('/').ToList();

            if (paths[paths.Count() - 1] == "")
            {
                paths.RemoveAt(paths.Count() - 1);
            }
            paths.RemoveAt(0);
            ViewData["paths"] = paths;
            ViewData["path"] = path;
            return View();
        }
示例#12
0
 public ActionResult FileListByType(string type)
 {
     try
     {
         var file = new BlobFile2(User.Identity.Name, "/");
         var list = file.AllFiles();
         var regex = new Regex("^" + Regex.Escape(type).Replace(@"\*", ".*").Replace(@"\?", ".") + "$",
             RegexOptions.IgnoreCase);
         var data = list.Where(delegate(BlobFile2 m)
         {
             return regex.IsMatch(m.ContentType()
                 );
         }).Select(m => m.Path().Path());
         return Json(new { code = 0, data = data }, JsonRequestBehavior.AllowGet);
     }
     catch (Exception ex)
     {
         return Json(new { code = 1 }, JsonRequestBehavior.AllowGet);
     }
 }
示例#13
0
 public ActionResult Upload(HttpPostedFileBase file, string path, string[] args)
 {
     if (args.Length > 0)
     {
         var blob = new BlobFile2(User.Identity.Name, path + args[0]);
         if (blob.Exists()) return Error("File \"" + args[0] + "\" already exists.");
         try
         {
             blob.CreateFile(file.InputStream);
             return SuccessWrapper("Upload successfully");
         }
         catch (Exception ex)
         {
             return Error("Upload file failed");
         }
     }
     return Error("Usage: upload [filename]");
 }
示例#14
0
 public ActionResult Touch(Dictionary<string, string> env, string[] args)
 {
     var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
     if (!file.Exists())
     {
         file.CreateEmptyFile();
         return SuccessWrapper(String.Format("File \"{0}\" Created", args[0]));
     }
     return SuccessWrapper(String.Format("File \"{0}\" Updated", args[0]));
 }
示例#15
0
 public JsonResult Rm(Dictionary<string, string> env, string[] args)
 {
     if (args.Length > 0)
     {
         var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
         if (file.Exists())
         {
             return SuccessWrapper(String.Format("{0} file(s) deleted.", file.Delete()));
         }
         return Error("File Not Exist");
     }
     return Error("Usage: rm [file]");
 }
示例#16
0
 public JsonResult Mkdir(Dictionary<string, string> env, string[] args)
 {
     if (args.Length > 0)
     {
         var file = new BlobFile2(User.Identity.Name, env["path"] + args[0]);
         if (file.Exists())
         {
             return Error("Directory \"" + args[0] + "\" already exists.");
         }
         else
         {
             file.CreateDirectory();
             return SuccessWrapper(String.Format("Directory \"{0}\" Created", args[0]));
         }
     }
     return Error("Usage: mkdir [directory]");
 }