public void ProcessRequest(HttpContext context)
        {
            var url = context.Request.Path;



            var strkey = context.Request["key"];

            var resolver = DependencyResolver.Resolver;

            using (resolver.BeginResolverScope())
            {
                if (!resolver.Resolve<ICheckAuth>().Checked())
                {
                    sendError(context, "无权限");
                    return;
                }




                using (var dbcontext = new FileManagerContext())
                {

                    var key = resolver.Resolve<IKey>();

                    var fileurl = key.GetFileUrl(strkey);


                    var fileInfo = dbcontext.ElfinderFiles.FirstOrDefault(x => x.Content == strkey);

                    ElfinderFileDto dto = new ElfinderFileDto
                    {
                        Content = fileInfo.Content,
                        FileUrl = fileurl,
                        Height = fileInfo.Height,
                        Id = fileInfo.Id,
                        Hidden = fileInfo.Hidden,
                        Mime = fileInfo.Mime,
                        Locked = fileInfo.Locked,
                        Mtime = fileInfo.Mtime,
                        Name = fileInfo.Name,
                        Parent_id = fileInfo.Parent_id,
                        Read = fileInfo.Read,
                        Size = fileInfo.Size,
                        Width = fileInfo.Width,
                        Write = fileInfo.Write,
                    };


                    string json = JsonConvert.SerializeObject(dto);
                    context.Response.Write(json);

                }


            }


        }
        public void ProcessRequest(HttpContext context)
        {
            var url = context.Request.Path;


            var indexparms = url.LastIndexOf("?");



            var filepath = url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);

            if (filepath.Length < 1)
            {
                context.Response.StatusCode = 404;
                context.Response.StatusDescription = "不存在的文件";
                return;
            }

            var parentid = 1;
            ElfinderFile d = null;

            using (var dbcontext = new FileManagerContext())
            {

                for (int index = 1; index < filepath.Length; index++)
                {
                    var s = filepath[index];
                    d = dbcontext.ElfinderFiles.FirstOrDefault(x => x.Name == s && x.Parent_id == parentid);

                    if (d == null)
                    {
                        context.Response.StatusCode = 404;
                        context.Response.StatusDescription = "不存在的文件";
                        return;
                    }

                    parentid = d.Id;

                }
            }

            var strkey = d.Content;

            var resolver = DependencyResolver.Resolver;

            using (resolver.BeginResolverScope())
            {
                if (!resolver.Resolve<ICheckAuth>().Checked())
                {
                    sendError(context, "无权限");
                    return;
                }

                var key = resolver.Resolve<IKey>();

                var fileurl = key.GetFileUrl(strkey);

                context.Response.Redirect(fileurl);
            }


        }
        private void getSubDirs(string rootDir, string rootDirHash, List<DirectoryModel> subDirs,
            int maxTreeLevel, int level)
        {
            if (level > maxTreeLevel)
                return;

            ElfinderFile[] dirs = null;

            rootDir = DecodeHashToPath(rootDir, false);

            var root = DB.GetModelByHash(rootDir);

            if (root == null)
                return;

            using (var context = new FileManagerContext())
            {

                //int id = int.Parse(rootDir);
                dirs = context.ElfinderFiles.Where(x => x.Parent_id == root.Id && x.IsDelete != true && x.Mime == DIR_NAME).ToArray();
            }


            foreach (ElfinderFile di in dirs)
            {
                string hash = EncodePathToHash(di.Content);

                subDirs.Add(createDirectoryModel(di, hash, rootDirHash));
                getSubDirs(hash, hash, subDirs, maxTreeLevel, level + 1);
            }
        }
        public ObjectModel[] Search(string q)
        {
            using (var context = new FileManagerContext())
            {

                //取前50个吧,取再多也没用
                var list = context.ElfinderFiles.Where(x => x.Name.Contains(q)).Take(50);


                ObjectModel[] objlist = list.ToList().Select(x =>
                    {
                        var parent = DB.GetModel(x.Parent_id);

                        if (x.Mime == DIR_NAME)
                        {
                            return createDirectoryModel(x, EncodePathToHash(x.Content),
                                EncodePathToHash(parent.Content)) as ObjectModel;
                        }
                        else
                        {
                            return createFileModel(x, EncodePathToHash(parent.Content)) as ObjectModel;
                        }
                    }).ToArray();

                return objlist;
            }
        }
        public bool DeleteDirectory(DirectoryModel directoryToRemove)
        {
            if (directoryToRemove == null)
                return false;

            string hash = DecodeHashToPath(directoryToRemove.Hash, false);

            ElfinderFile source = DB.GetModelByHash(hash);
            if (source == null)
                return false;

            using (var context = new FileManagerContext())
            {

                int childcount = context.ElfinderFiles.Count(x => x.Parent_id == source.Id && x.IsDelete != true);
                //子目录不为空
                if (childcount > 0)
                {
                    return false;
                    throw new Exception("所删除目录不为空");
                }
            }

            DB.DeleteModel(source);

            return true;
        }
        public FileModel CreateFile(DirectoryModel inDir, string name)
        {
            if (inDir == null)
                return null;

            string path = DecodeHashToPath(inDir.Hash, false);


            var model = DB.GetModelByHash(path);

            using (var context = new FileManagerContext())
            {
                bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0;
                if (exist)
                    return null;
            }

            try
            {

                var filekey = this._key.CreateFileKey(name);

                this._uploadFile.SaveFile(new byte[0], filekey);

                var createdFile = new ElfinderFile
                {
                    Name = name,
                    Parent_id = model.Id,
                    Mime = name.Substring(name.LastIndexOf('.') + 1),
                    Read = true,
                    Write = true,
                    Width = 0,
                    Content = filekey,
                    Locked = false,
                    Height = 0,
                    Hidden = false,
                    Mtime = DateTime.Now,
                    Size = 0
                };
                using (var context = new FileManagerContext())
                {
                    context.ElfinderFiles.Add(createdFile);
                    context.SaveChanges();
                }

                return createFileModel(createdFile, inDir.Hash);
            }
            catch
            {
                throw new Exception();
                return null;
            }
        }
        public DirectoryModel CreateDirectory(DirectoryModel inDir, string name)
        {
            if (inDir == null)
                return null;

            string path = DecodeHashToPath(inDir.Hash, false);


            var model = DB.GetModelByHash(path);


            using (var context = new FileManagerContext())
            {
                bool exist = context.ElfinderFiles.Count(x => x.Name == name && x.Parent_id == model.Id) > 0;
                if (exist)
                    return null;
            }

            try
            {
                var createdDirectory = new ElfinderFile
                {
                    Name = name,
                    Parent_id = model.Id,// int.Parse(DecodeHashToPath(inDir.Hash, false)),
                    Mime = "directory",
                    Read = true,
                    Write = true,
                    Width = 0,
                    Content = this._key.CreateFileKey("noname"),
                    Locked = false,
                    Height = 0,
                    Hidden = false,
                    Mtime = DateTime.Now,
                    Size = 0
                };
                using (var context = new FileManagerContext())
                {
                    context.ElfinderFiles.Add(createdDirectory);
                    context.SaveChanges();
                }

                return createDirectoryModel(createdDirectory, EncodePathToHash(createdDirectory.Content),
                    inDir.Hash);
            }
            catch
            {
                throw;
            }
        }