Esempio n. 1
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();
        }
Esempio n. 2
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();
        }
Esempio n. 3
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]");
 }
Esempio n. 4
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;
        }
Esempio n. 5
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;
        }