Exemplo n.º 1
0
        public ActionResult ViewFilesFromFolder(string folder, int mID)
        {
            try
            {
                SetModuleId(mID);
                var directory     = new DirectoryInfo(Request.MapPath(folder));
                var folderContent = new FolderContent();

                foreach (var f in directory.GetFiles())
                {
                    folderContent.Files.Add(new Files
                    {
                        fullName = string.Format("{0}/{1}", folder, f.Name),
                        name     = f.Name,
                        folder   = folder
                    });
                }

                foreach (var f in directory.GetDirectories())
                {
                    folderContent.Folders.Add(new Files
                    {
                        fullName = string.Format("{0}/{1}", folder, f.Name),
                        name     = f.Name,
                        folder   = folder
                    });
                }

                return(View("FilesView", folderContent));
            }
            catch (Exception)
            {
                return(View("FolderDoesntExist"));
            }
        }
 private void CopyFolder(FolderContent source, DirectoryInfo dest)
 {
     foreach (var file in source.Files)
     {
         CopyFile(source.Folder, file, dest);
     }
 }
Exemplo n.º 3
0
 private void CopyFolder(FolderContent source, DirectoryInfo dest)
 {
     foreach (var file in source.Files)
     {
         CopyFile(source.Folder, file, dest);
     }
 }
Exemplo n.º 4
0
        private async Task Copy(string path, FolderContent content, bool postDelete)
        {
            var filesToCopy = new List <(File File, S3Object S3Object, string DestinationKey)>();

            foreach (var folder in content.Folders)
            {
                var originalPath = new CloudPath(folder.Path, folder.Name);

                var newFolderKey         = $"{GetAbsolutePath(path)}/{folder.Name}";
                var destinationFolderKey = await GetNewDirectoryPathIfExists(newFolderKey, newFolderKey);

                var folderKey = GetAbsolutePath(originalPath.TargetPath);

                var files = await GetInnerFolderFiles(folderKey);

                filesToCopy.AddRange(files.Select(x => (x.File, x.S3Object, $"{destinationFolderKey}{x.S3Object.Key.Substring(folderKey.Length)}")));
            }

            if (content.Files.Any())
            {
                var response = await ListContainerObjects(GetAbsolutePath(path));

                filesToCopy.AddRange(content.Files.Select(x => (x, new S3Object {
                    Key = GetAbsolutePath(x.Path)
                }, GetNewFilePathIfExists(response.S3Objects.Select(x => x.Key), $"{GetAbsolutePath(path)}/{x.Name}", $"{GetAbsolutePath(path)}/{x.Name}"))));
            }

            await CopyFile(filesToCopy, postDelete);
        }
Exemplo n.º 5
0
        private async Task Copy(string path, FolderContent content, bool postDelete)
        {
            foreach (var folder in content.Folders)
            {
                var deleted      = 0;
                var originalPath = new CloudPath(folder.Path, folder.Name);

                var absolutePath = $"{GetAbsolutePath(path)}/{folder.Name}";
                var toDirectory  = GetNewDirectoryPathIfExists(absolutePath, absolutePath);

                Directory.CreateDirectory(toDirectory);

                var directory        = GetAbsolutePath(originalPath.TargetPath);
                var directoryContent = GetInnerFolderFiles(directory);

                foreach (var fileTuple in directoryContent)
                {
                    Directory.CreateDirectory($"{toDirectory}{fileTuple.FileInfo.DirectoryName.Substring(directory.Length)}");
                    var toPath = $"{toDirectory}{fileTuple.FileInfo.FullName.Substring(directory.Length)}";
                    await Task.Run(() =>
                    {
                        if (postDelete)
                        {
                            System.IO.File.Move(fileTuple.FileInfo.FullName, toPath);
                        }
                        else
                        {
                            System.IO.File.Copy(fileTuple.FileInfo.FullName, toPath);
                        }

                        deleted++;
                    });
                }

                if (postDelete && deleted == directoryContent.Count)
                {
                    Directory.Delete(directory, true);
                }
            }

            foreach (var file in content.Files)
            {
                var cloudPath = new CloudPath(file.Path, file.Name);
                var filePath  = GetAbsolutePath(cloudPath.TargetPath);
                var toPath    = GetNewFilePathIfExists($"{GetAbsolutePath(path)}/{file.Name}", $"{GetAbsolutePath(path)}/{file.Name}");

                await Task.Run(() =>
                {
                    if (postDelete)
                    {
                        System.IO.File.Move(filePath, toPath);
                    }
                    else
                    {
                        System.IO.File.Copy(filePath, toPath);
                    }
                });
            }
        }
Exemplo n.º 6
0
        private void folders_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var    FolderContent = new FolderContent();
            string FolderTag     = ((System.Windows.FrameworkElement)folders.SelectedItem).Tag.ToString();

            MoveModel.SetDestinationDirectory(FolderTag);
            SelectedFolderContain.ItemsSource = FolderContent.GetAllFiles(FolderTag);
        }
Exemplo n.º 7
0
        public FolderContent GetContent(string folder)
        {
            var content = new FolderContent
            {
                Folders = Directory.EnumerateDirectories(folder),
                Files   = Directory.EnumerateFiles(folder)
            };

            return(content);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Deserialize fields from a FastTransferStream.
        /// </summary>
        /// <param name="stream">A FastTransferStream.</param>
        public override void Deserialize(FastTransferStream stream)
        {
            if (stream.ReadMarker(StartMarker))
            {
                this.folderContent = new FolderContent(stream);
                if (stream.ReadMarker(EndMarker))
                {
                    return;
                }
            }

            AdapterHelper.Site.Assert.Fail("The stream cannot be deserialized successfully.");
        }
Exemplo n.º 9
0
        /// <summary>
        /// Deserialize fields from a FastTransferStream.
        /// </summary>
        /// <param name="stream">A FastTransferStream.</param>
        public override void Deserialize(FastTransferStream stream)
        {
            if (stream.ReadMarker(StartMarker))
            {
                this.folderContent = new FolderContent(stream);
                if (stream.ReadMarker(EndMarker))
                {
                    return;
                }
            }

            AdapterHelper.Site.Assert.Fail("The stream cannot be deserialized successfully.");
        }  
Exemplo n.º 10
0
        private static FolderContent FolderMapperHelper(Folder folder)
        {
            var files   = folder.Files.Select(x => new FileViewModel(x)).ToList();
            var folders = new List <FolderContent>();

            foreach (var f in folder.Folders)
            {
                folders.Add(FolderMapperHelper(f));
            }

            var fc = new FolderContent(folder, files, folders);

            return(fc);
        }
Exemplo n.º 11
0
        private async void AsbServerPath_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            sinServerPathValid.Symbol = Symbol.Help;

            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput ||
                args.Reason == AutoSuggestionBoxTextChangeReason.ProgrammaticChange)
            {
                string actualParentPath;
                string folderName = string.IsNullOrWhiteSpace(sender.Text) ?
                                    string.Empty : Path.GetFileName(sender.Text);
                string searchKey  = folderName.ToLower();
                string parentPath = string.IsNullOrWhiteSpace(sender.Text) ?
                                    string.Empty : Utils.GetParentPath(sender.Text).TrimEnd(Path.DirectorySeparatorChar);
                FolderContent content = folderPaths.TryGetValue(parentPath, out actualParentPath) ?
                                        await edit.Api.FolderContent(folderPaths[parentPath]) : null;

                if (content?.Folders != null)
                {
                    foreach (FolderItem folder in content.Folders)
                    {
                        folderPaths[content.Path.GetChildPathParts(folder).GetNamePath().TrimEnd(Path.DirectorySeparatorChar)] = folder.Path;
                    }

                    FolderItem currentFolder;
                    if (folderName.Length == 0)
                    {
                        edit.Sync.ServerPath = content.Path;
                    }
                    else if (content.Folders.TryFirst(f => f.Name == folderName, out currentFolder) ||
                             content.Folders.TrySingle(f => f.Name.ToLower() == searchKey, out currentFolder))
                    {
                        edit.Sync.ServerPath = content.Path.GetChildPathParts(currentFolder).ToArray();
                    }

                    sender.ItemsSource = string.IsNullOrWhiteSpace(searchKey) ?
                                         content.Folders : content.Folders.Where(f => f.Name.ToLower().Contains(searchKey));
                }
                else
                {
                    sender.ItemsSource   = null;
                    edit.Sync.ServerPath = content?.Path;
                }
            }

            string actualPath;
            string namePath = sender.Text.TrimEnd(Path.DirectorySeparatorChar);
            bool   exists   = folderPaths.TryGetValue(namePath, out actualPath) && await edit.Api.FolderExists(actualPath);

            sinServerPathValid.Symbol = exists ? Symbol.Accept : Symbol.Dislike;
        }
Exemplo n.º 12
0
        public async Task BulkDelete(FolderContent content)
        {
            var trashFileKeys = new List <string>();

            foreach (var folder in content.Folders)
            {
                trashFileKeys.AddRange(await GetTrashFolderContentKeys(folder.DeletedName));
            }

            trashFileKeys.AddRange(content.Files.Select(x => x.DeletedName));

            var keys = new List <Guid>();

            keys.AddRange(content.Folders.Select(x => Guid.Parse(x.DeletedName.Remove(x.DeletedName.LastIndexOf("/")).Split("/").Last())));
            keys.AddRange(content.Files.Select(x => Guid.Parse(x.DeletedName.Split("/").Last())));

            await DeleteFiles(trashFileKeys);
        }
Exemplo n.º 13
0
        public async Task BulkDelete(FolderContent content)
        {
            var keys = new List <Guid>();

            foreach (var folder in content.Folders)
            {
                var cloudPath = new CloudPath(folder.Path, folder.DeletedName);
                keys.AddRange(content.Folders.Select(x => Guid.Parse(cloudPath.TargetPath)));
                await DeleteFolder(cloudPath.TargetPath);
            }

            foreach (var file in content.Files)
            {
                var cloudPath = new CloudPath(file.Path, file.DeletedName);
                keys.AddRange(content.Folders.Select(x => Guid.Parse(cloudPath.TargetPath)));
                await DeleteFile(cloudPath.TargetPath);
            }
        }
Exemplo n.º 14
0
        private void isFileSelected(object sender, RoutedEventArgs e)
        {
            CheckBox checkBox    = sender as CheckBox;
            var      dataContext = (Application.Models.FileProperties)checkBox.DataContext;
            string   filePath    = dataContext.CheckboxName;
            string   fileName    = dataContext.FileName;

            MoveModel.File           = $"{fileName}.txt";
            MoveModel.SourceFileName = filePath;
            CopyFile.IsEnabled       = true;
            MoveFile.IsEnabled       = true;
            paths[0]  = filePath;
            ischecked = true;
            FolderContent.CheckIfEncryptable(filePath, Encrypt);
            if (dataContext.Extension == ".txt")
            {
                Open.Visibility = Visibility.Visible;
            }
            FolderContent.ListPathManipulation(filePath, checkBox, Zip);
            FolderContent.CheckIfCompressable(Zip.PathList, Compress);
            //FolderContent.CheckIfCompressable(Zip.PathList, Compress);
        }
Exemplo n.º 15
0
        public string GetFileHotLink(string FolderID, string FileName)
        {
            string HotLink = string.Empty;

            FolderContent content = ListFolderContent(FolderID);

            if (content != null)
            {
                for (int idx = 0; idx < content.Files.Count; idx++)
                {
                    if (content.Files[idx].name.ToLower() == FileName.ToLower())
                    {
                        HotLink = content.Files[idx].source;
                    }
                }

                return(HotLink);
            }
            else
            {
                throw new FileNotFoundException("No such file/folder found");
            }
        }
Exemplo n.º 16
0
 private void LoadMobile(DeviceScreenDimensions screenDimensions)
 {
     // Desktop Browser Detected
     if (screenDimensions.Height == 0 && screenDimensions.Width == 0)
     {
         var mobileNavigation = FolderContent.FindControl("MobileNavigation");
         if (mobileNavigation != null)
         {
             mobileNavigation.Visible = false;
             nav.Value = "desktop";
         }
     }
     // Mobile Browser Detected
     else
     {
         this.form1.Attributes.Add("class", "mobile clear");
         var desktopNavigation = FolderContent.FindControl("FolderNavigationControl");
         if (desktopNavigation != null)
         {
             desktopNavigation.Visible = false;
             nav.Value = "mobile";
         }
     }
 }
Exemplo n.º 17
0
 public async Task Move(string path, FolderContent content)
 {
     await Copy(path, content, true);
 }
Exemplo n.º 18
0
 public async Task Copy(string path, FolderContent content)
 {
     await Copy(path, content, false);
 }
Exemplo n.º 19
0
 public static FileSystemItem FromFolderContent(FolderContent folder)
 {
     return(new FileSystemItem(false, folder.Path.LastOrDefault().Name, null,
                               folder.Path.ToPath(), folder.Path, folder.Permission));
 }