Ejemplo n.º 1
0
        public HttpResponseMessage GetObject(string path)
        {
            var bucket   = this.GetBucket();
            var fullPath = FileConfig.MapPath(bucket, path);

            FsEntity fs = new FsEntity();

            if (File.Exists(fullPath))
            {
                var info = new FileInfo(fullPath);
                fs.FullPath       = path.FixFilePath();
                fs.Length         = info.Length;
                fs.Name           = info.Name;
                fs.ObjectType     = ObjectType.File;
                fs.LastUpdateTime = File.GetLastWriteTime(fullPath);
            }
            else if (Directory.Exists(fullPath))
            {
                var info = new DirectoryInfo(fullPath);
                fs.FullPath       = fullPath.FixDirPath();
                fs.Name           = info.Name;
                fs.ObjectType     = ObjectType.Dir;
                fs.LastUpdateTime = Directory.GetLastWriteTime(fullPath);
            }
            return(this.ApiResult(ApiStatusCodes.Success, fs));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage CreateFolder(string path)
        {
            var bucket   = this.GetBucket();
            var fullPath = FileConfig.MapPath(bucket, path);

            try
            {
                if (!Directory.Exists(fullPath))
                {
                    Directory.CreateDirectory(fullPath);
                }

                if (Directory.Exists(fullPath))
                {
                    FsEntity fs   = new FsEntity();
                    var      info = new DirectoryInfo(fullPath);
                    fs.FullPath       = path.UrlCombine(info.Name);
                    fs.Name           = info.Name;
                    fs.ObjectType     = ObjectType.Dir;
                    fs.LastUpdateTime = Directory.GetLastWriteTime(fullPath);
                    return(this.ApiResult(ApiStatusCodes.Success, fs));
                }
                return(this.ApiResult(ApiStatusCodes.Success));
            }
            catch (Exception e)
            {
                return(this.ApiResult(ApiStatusCodes.NormalError, e.Message));
            }
        }
Ejemplo n.º 3
0
        public HttpResponseMessage CreateFile(string path)
        {
            var bucket   = this.GetBucket();
            var fullPath = FileConfig.MapPath(bucket, path);

            try
            {
                if (!File.Exists(fullPath))
                {
                    var dir = Path.GetDirectoryName(fullPath);
                    if (!Directory.Exists(dir))
                    {
                        Directory.CreateDirectory(dir);
                    }
                    using (var stream = File.Create(fullPath))
                    {
                        stream.Write(new byte[] { }, 0, 0);
                    }
                }

                if (File.Exists(fullPath))
                {
                    FsEntity fs   = new FsEntity();
                    var      info = new FileInfo(fullPath);
                    fs.FullPath       = path.UrlCombine(info.Name);
                    fs.Length         = info.Length;
                    fs.Name           = info.Name;
                    fs.ObjectType     = ObjectType.File;
                    fs.LastUpdateTime = File.GetLastWriteTime(fullPath);
                    return(this.ApiResult(ApiStatusCodes.Success, fs));
                }
                return(this.ApiResult(ApiStatusCodes.Success));
            }
            catch (Exception e)
            {
                return(this.ApiResult(ApiStatusCodes.NormalError, e.Message));
            }
        }