예제 #1
0
        JsonResult IDriver.Filter(string target, string query)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);

            target = this.DecodeTarget(target, lroot.Directory.RelPath);
            List <DirInfo> filesFormWebFav = client.GetDirectories(target, true);
            List <DirInfo> directories     = filesFormWebFav.FindAll(d => d.IsDirectory);
            DirInfo        targetDirInfo   = directories[0];
            DirInfo        parentDirInfo   = this.GetParent(targetDirInfo);

            targetDirInfo.HasSubDirectories = filesFormWebFav != null && directories != null && directories.Count > 1;

            OpenResponseBase answer = new OpenResponseBase(DTOBase.Create(targetDirInfo, parentDirInfo, lroot));

            if (filesFormWebFav != null)
            {
                filesFormWebFav.Remove(targetDirInfo);
                foreach (DirInfo dirInfo in filesFormWebFav)
                {
                    if (!Filter(dirInfo, query))
                    {
                        continue;
                    }

                    answer.Files.Add(DTOBase.Create(dirInfo, targetDirInfo, lroot));
                }
            }
            var r = Json(answer);

            return(r);
        }
예제 #2
0
        JsonResult IDriver.Rename(string target, string name)
        {
            string     oldTarget = target;
            WebDavRoot lroot     = this.GetRoot(target);

            target = this.GetCorectTarget(target);
            target = this.DecodeTarget(target);
            DirInfo oldDirInfo = client.GetInfo(target);

            if (oldDirInfo == null)
            {
                throw new ElFinderFileNotExists();
            }
            DirInfo parent = this.GetParent(oldDirInfo);

            client.Rename(target, parent.RelPath + name);
            DirInfo newDirInfo = client.GetInfo(parent.RelPath + name);

            if (newDirInfo == null)
            {
                return(Error.Message("Невозможно переименовать файл. Задано некорректное имя."));
            }
            ReplaceResponse answer = new ReplaceResponse();

            answer.Removed.Add(oldTarget);
            answer.Added.Add(DTOBase.Create(newDirInfo, parent, lroot));
            return(Json(answer));
        }
예제 #3
0
        JsonResult IDriver.Open(string target, bool tree)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);

            target = this.DecodeTarget(target, lroot.Directory.RelPath);
            List <DirInfo> filesFormWebFav = client.GetDirectories(target, true);
            List <DirInfo> directories     = filesFormWebFav.FindAll(d => d.IsDirectory);
            DirInfo        targetDirInfo   = directories[0];
            DirInfo        parentDirInfo   = this.GetParent(targetDirInfo);

            targetDirInfo.HasSubDirectories = filesFormWebFav != null && directories != null && directories.Count > 1;

            OpenResponseBase answer = new OpenResponseBase(DTOBase.Create(targetDirInfo, parentDirInfo, lroot));

            if (filesFormWebFav != null)
            {
                filesFormWebFav.Remove(targetDirInfo);
                foreach (DirInfo dirInfo in filesFormWebFav)
                {
                    dirInfo.HasSubDirectories = IsConstainsChild(dirInfo);
                    answer.Files.Add(DTOBase.Create(dirInfo, targetDirInfo, lroot));
                }
            }
            //HttpContext.Current.Session[RetTarget] = answer.CurrentWorkingDirectory.Hash;
            return(Json(answer));
        }
예제 #4
0
        JsonResult IDriver.MakeDir(string target, string name)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);
            target = this.DecodeTarget(target);
            client.CreateDirectory(target + name);
            DirInfo dirInfo = client.GetInfo(target + name);
            DirInfo parent  = this.GetParent(dirInfo);

            return(Json(new AddResponse(dirInfo, parent, lroot)));
        }
예제 #5
0
        JsonResult IDriver.Duplicate(IEnumerable <string> targets)
        {
            AddResponse response = new AddResponse();

            foreach (string target in targets)
            {
                WebDavRoot lroot = this.GetRoot(target);
                string     ext = "", path = "", nameWithoutExt = "";
                string     targetDecrypted = this.DecodeTarget(this.GetCorectTarget(target));
                DirInfo    targetInfo      = client.GetInfo(targetDecrypted);
                if (targetInfo == null)
                {
                    throw new ElFinderFileNotExists();
                }
                string destinationFileName;
                if (targetInfo.IsDirectory && targetDecrypted.EndsWith("/"))
                {
                    destinationFileName = targetDecrypted.Substring(0, targetDecrypted.Length - 1) + " (1)";
                }
                else
                {
                    path                = targetDecrypted.Replace(targetInfo.DisplayName, "");
                    ext                 = Path.GetExtension(targetInfo.DisplayName);
                    nameWithoutExt      = targetInfo.DisplayName.Replace(ext, "");
                    destinationFileName = string.Format("{0}{1} (1){2}", path, nameWithoutExt, ext);
                }

                DirInfo destInfo = client.GetInfo(destinationFileName);
                int     i        = 2;
                while (destInfo != null)
                {
                    if (targetInfo.IsDirectory && targetDecrypted.EndsWith("/"))
                    {
                        destinationFileName = string.Format("{0} ({1})", targetDecrypted.Substring(0, targetDecrypted.Length - 1), i);
                    }
                    else
                    {
                        destinationFileName = string.Format("{0}{1} ({3}){2}", path, nameWithoutExt, ext, i);
                    }

                    destInfo = client.GetInfo(destinationFileName);
                    i++;
                }

                client.Copy(targetDecrypted, destinationFileName);
                destInfo = client.GetInfo(destinationFileName);
                DirInfo parent = this.GetParent(destInfo);
                response.Added.Add(DTOBase.Create(destInfo, parent, lroot));
            }

            return(Json(response));
        }
예제 #6
0
        JsonResult IDriver.MakeFile(string target, string name)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);
            string decodedTarget = this.DecodeTarget(target);

            byte[] content = new byte[0];
            client.Upload(decodedTarget + name, content);
            DirInfo fileInfo = client.GetInfo(decodedTarget + name);
            DirInfo parent   = this.GetParent(fileInfo);

            return(Json(new AddResponse(fileInfo, parent, lroot)));
        }
예제 #7
0
        JsonResult IDriver.Rotate(string target, int degree)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);
            string decodedTarget = this.DecodeTarget(target);
            WebDavPicturesEditor pictureEditor = new WebDav.WebDavPicturesEditor(client);

            pictureEditor.Rotate(decodedTarget, degree);
            DirInfo         targetInfo = client.GetInfo(decodedTarget);
            DirInfo         parentInfo = this.GetParent(targetInfo);
            ChangedResponse response   = new ChangedResponse();

            response.Changed.Add((FileDTO)DTOBase.Create(targetInfo, parentInfo, lroot));
            return(Json(response));
        }
예제 #8
0
        JsonResult IDriver.Parents(string target)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);

            target = this.DecodeTarget(target);
            TreeResponse answer  = new TreeResponse();
            DirInfo      dirInfo = client.GetInfo(target);

            if (dirInfo == null)
            {
                throw new ElFinderFileNotExists();
            }
            DirInfo parent = this.GetParent(dirInfo);

            if (parent == null)
            {
                answer.Tree.Add(DTOBase.Create(dirInfo, null, lroot));
            }
            else
            {
                List <DirInfo> directories = client.GetDirectories(parent.RelPath);
                foreach (DirInfo d in directories)
                {
                    if (!d.IsDirectory)
                    {
                        continue;
                    }

                    answer.Tree.Add(DTOBase.Create(d, parent, lroot));
                }

                while (parent.FullPath != lroot.Directory.FullPath)
                {
                    var thisParent = (client.GetInfo(parent.getDir()));
                    //parent = (client.GetInfo(parent.getDir()));
                    answer.Tree.Add(DTOBase.Create(parent, thisParent, lroot));
                    parent = thisParent;
                }
            }
            return(Json(answer));
        }
예제 #9
0
        /// <summary>
        /// Добавление корня для отоброжение в elFinder
        /// </summary>
        /// <param name="folder">путь к папке относительно серверной папки пользователя</param>
        /// <param name="alias">имя отображаемое в elFinder</param>
        public void AddRootFolder(string folder, string alias = null)
        {
            DirInfo dirInfo = client.GetInfo(string.Format("{0}/{1}", clientRootDirInfo.RelPath, folder));

            if (dirInfo == null)
            {
                return;
            }

            WebDavRoot item = new WebDavRoot(dirInfo)
            {
                Alias = alias
            };

            item.Directory.HasSubDirectories = IsConstainsChild(item.Directory);
            item.VolumeId = VolumePrefix + this.roots.Count + "_";
            item.DTO      = DTOBase.Create(item.Directory, item);
            this.roots.Add(item);
        }
예제 #10
0
        JsonResult IDriver.Upload(string target, System.Web.HttpFileCollectionBase targets, bool addWithNewIndex)
        {
            string     dest  = this.DecodeTarget(this.GetCorectTarget(target));
            WebDavRoot lroot = this.GetRoot(target);

            if (lroot.Directory.DisplayName == Recived)
            {
                dest  = Upload + "/";
                lroot = this.roots.FirstOrDefault(x => x.Directory.DisplayName == Upload);
            }
            AddResponse response  = new AddResponse();
            DirInfo     destInfo  = client.GetInfo(dest);
            JsonResult  errorResp = Error.Message("Connector.WebDavDriver: Ошибка сервиса. Невозможно загрузить файл. Некорректное имя файла!");

            for (int i = 0; i < targets.AllKeys.Length; i++)
            {
                HttpPostedFileBase file = targets[i];
                if (file == null)
                {
                    return(errorResp);
                }
                string name = file.FileName;

                if (file.FileName.Contains("#"))
                {
                    name = file.FileName.Replace("#", "");
                }
                if (addWithNewIndex)
                {
                    name = GetCorrectDestinationFileName(destInfo.RelPath + name);
                }
                client.Upload(dest + Path.GetFileName(name), file.InputStream);
                DirInfo fileInfo = client.GetInfo(dest + Path.GetFileName(name));
                if (fileInfo == null)
                {
                    return(errorResp);
                }
                response.Added.Add((FileDTO)DTOBase.Create(fileInfo, destInfo, lroot));
            }

            return(Json(response));
        }
예제 #11
0
        JsonResult IDriver.Put(string target, string content)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);
            string          decodedTarget = this.DecodeTarget(target);
            ChangedResponse answer        = new ChangedResponse();

            client.Upload(decodedTarget, Encoding.Default.GetBytes(content));
            DirInfo targetInfo = client.GetInfo(decodedTarget);

            if (targetInfo == null)
            {
                throw new ElFinderFileNotExists();
            }
            DirInfo parent = this.GetParent(targetInfo);

            answer.Changed.Add((FileDTO)DTOBase.Create(targetInfo, parent, lroot));
            return(Json(answer));
        }
예제 #12
0
        JsonResult IDriver.Paste(string source, string dest, IEnumerable <string> targets, bool isCut, IList <int> dublicateIndexes = null)
        {
            ReplaceResponse response      = new ReplaceResponse();
            string          destDecrypted = this.DecodeTarget(this.GetCorectTarget(dest));
            DirInfo         destInfo      = client.GetInfo(destDecrypted);
            int             ind           = 0;

            foreach (string target in targets)
            {
                WebDavRoot lroot           = this.GetRoot(dest);
                string     targetDecrypted = this.DecodeTarget(this.GetCorectTarget(target));
                DirInfo    targetInfo      = client.GetInfo(targetDecrypted);
                if (targetInfo == null)
                {
                    throw new ElFinderFileNotExists();
                }
                if (isCut)
                {
                    response.Removed.Add(this.GetCorectTarget(target));
                    client.Move(targetDecrypted, destDecrypted + targetInfo.DisplayName);
                    targetInfo = client.GetInfo(destInfo.RelPath + targetInfo.DisplayName);
                    response.Added.Add(DTOBase.Create(targetInfo, destInfo, lroot));
                }
                else
                {
                    string destinationFileName = dublicateIndexes != null && dublicateIndexes.Contains(ind)
                        ? GetCorrectDestinationFileName(destInfo.RelPath + targetInfo.DisplayName)
                        : destInfo.RelPath + targetInfo.DisplayName;

                    client.Copy(targetDecrypted, destinationFileName);
                    targetInfo = client.GetInfo(destinationFileName);
                    DirInfo parent = this.GetParent(targetInfo);
                    response.Added.Add(DTOBase.Create(targetInfo, parent, lroot));
                }
                ind++;
            }

            return(Json(response));
        }
예제 #13
0
        JsonResult IDriver.Tree(string target)
        {
            WebDavRoot lroot = this.GetRoot(target);

            target = this.GetCorectTarget(target);

            target = this.DecodeTarget(target);
            TreeResponse   answer      = new TreeResponse();
            List <DirInfo> directories = client.GetDirectories(target, true);

            for (int i = 1; i < directories.Count; i++)
            {
                if (!directories[i].IsDirectory)
                {
                    continue;
                }

                directories[i].HasSubDirectories = IsConstainsChild(directories[i]);
                answer.Tree.Add(DTOBase.Create(directories[i], directories[0], lroot));
            }

            return(Json(answer));
        }
예제 #14
0
        JsonResult IDriver.Init(string retTarget, string isModal, bool initReceivedFolder)
        {
            //if (HttpContext.Current.Session[RetTarget]!=null && !ReferenceEquals(HttpContext.Current.Session[RetTarget], ""))
            //{
            //    return ((IDriver)this).Open(HttpContext.Current.Session[RetTarget].ToString(),false);
            //}
            WebDavRoot lroot = !initReceivedFolder?
                               this.roots.FirstOrDefault(x => x.Directory.DisplayName == Upload) :
                                   this.roots.FirstOrDefault(x => x.Directory.DisplayName == Recived);

            if (lroot == null)
            {
                throw new ArgumentNullException(string.Format("Не найдена ожидаемая папка({0} или {1})", Upload, Recived));
            }


            string mytarget = lroot.Directory.RelPath;

            if (!string.IsNullOrEmpty(retTarget))
            {
                lroot    = GetRoot(retTarget);
                mytarget = GetCorectTarget(retTarget);
                mytarget = DecodeTarget(mytarget);
            }
            List <DirInfo> filesFormWebFav = client.GetDirectories(mytarget, true);

            if (filesFormWebFav == null)
            {
                return(null);
            }

            List <DirInfo> directories = filesFormWebFav.FindAll(d => d.IsDirectory);

            DirInfo targetDirInfo = directories[0];

            //var parent = getParent(targetDirInfo);
            targetDirInfo.HasSubDirectories = filesFormWebFav != null && directories != null && directories.Count > 1;

            Options options = new Options
            {
                Path          = mytarget,
                ThumbnailsUrl = "Thumbnails/"
            };

            var curDir = lroot.DTO;

            if (!string.IsNullOrEmpty(retTarget))
            {
                DirInfo parentDirInfo = this.GetParent(targetDirInfo);
                curDir = DTOBase.Create(targetDirInfo, parentDirInfo, lroot);
            }
            //curDir = lroot.DTO;

            InitResponse answer = new InitResponse(curDir, options);

            if (filesFormWebFav != null)
            {
                filesFormWebFav.Remove(targetDirInfo);
                foreach (DirInfo dirInfo in filesFormWebFav)
                {
                    dirInfo.HasSubDirectories = IsConstainsChild(dirInfo);
                    answer.Files.Add(DTOBase.Create(dirInfo, targetDirInfo, lroot));
                }
            }


            foreach (WebDavRoot item in this.roots)
            {
                answer.Files.Add(item.DTO);
            }



            List <DTOBase> filteredFiles = new List <DTOBase>();

            foreach (DTOBase dtoBase in answer.Files)
            {
                string fileName = (dtoBase.Name);
                string ext      = Path.GetExtension(fileName);
                if (isModal != "1")
                {
                    //поиск по неподписан и не зашифрован
                    if (ext != ".sig" && ext != ".enc")
                    {
                        filteredFiles.Add(dtoBase);
                    }
                    //filteredFiles.Add(dtoBase);
                }
                else
                {
                    filteredFiles.Add(dtoBase);
                }
            }
            answer.Files.Clear();
            answer.Files.AddRange(filteredFiles);
            //var answer1 = new InitResponse(answer.Files[0], options);
            //answer1.Files.AddRange(answer.Files);


            return(Json(answer));
        }