private async Task <IEnumerable <SystemItem> > AddFileSystemItems(IEnumerable <string> paths) { var enumerable = paths.ToList(); var returnList = new List <SystemItem>(); if (enumerable.All(path => path != FolderPath)) { if (enumerable.All(fileName => fileName.StartsWith(FolderPath))) { foreach (var path in enumerable) { var source = path.Substring(FolderPath.Length + 1); var destination = path.Substring(FolderPath.Length + 1); if (File.Exists(path)) { returnList.Add(FileSystemItem.Create(source, destination)); } else if (Directory.Exists(path)) { returnList.Add(FolderSystemItem.Create(source, destination)); } } } else { await DialogCoordinator.Instance.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory."); } } else { await DialogCoordinator.Instance.ShowMessageAsync(this, "Error", "You can't add root project path."); } return(returnList); }
protected void AddFolders(ObservableCollection <SystemItem> itemSource, List <string> paths) { var folders = paths; if (folders == null) { _folderBrowserDialog.CheckFolderExists = true; _folderBrowserDialog.ShowDialog(); if (!string.IsNullOrWhiteSpace(_folderBrowserDialog.SelectedPath)) { folders = new List <string> { _folderBrowserDialog.SelectedPath } } ; _folderBrowserDialog.Reset(); } if (folders == null) { return; } if (folders.All(folderName => folderName.StartsWith(FolderPath))) { foreach (var folder in folders) { var directory = folder.Substring(FolderPath.Length + 1); var destination = folder.Substring(FolderPath.Length + 1); itemSource.Add(FolderSystemItem.Create(directory, destination)); } } else { _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait(); //TODO: Localize } }
private List <SystemItem> AddFileSystemItems(List <string> paths) { if (paths == null) { return(null); } var returnList = new List <SystemItem>(); var filesAndFolders = paths; if (filesAndFolders.Any(path => path == FolderPath)) { _dialogCoordinator.ShowMessageAsync(this, "Error", "You can't add root project path.").Wait(); //TODO: Localize } else { if (filesAndFolders.All(fileName => fileName.StartsWith(FolderPath))) { foreach (var path in filesAndFolders) { var source = path.Substring(FolderPath.Length + 1); var destination = path.Substring(FolderPath.Length + 1); SystemItem item; if (File.Exists(path)) { item = FileSystemItem.Create(source, destination); } else { if (Directory.Exists(path)) { item = FolderSystemItem.Create(source, destination); } else { throw new NotImplementedException(); } } returnList.Add(item); } } else { _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait(); //TODO: Localize } } return(returnList); }
protected void TryAddFolders(ObservableCollection <SystemItem> itemSource, List <string> paths) { if (itemSource == null) { throw new ArgumentNullException(nameof(itemSource)); } if (paths == null) { using (var folderBrowserDialog = new FolderBrowserDialog()) { if (folderBrowserDialog.ShowDialog() == DialogResult.OK && Directory.Exists(folderBrowserDialog.SelectedPath)) { paths = new List <string> { folderBrowserDialog.SelectedPath } } ; } } if (paths == null) { return; } if (paths.All(folderName => folderName.StartsWith(FolderPath))) { foreach (var folder in paths) { var directory = folder.Substring(FolderPath.Length + 1); var destination = folder.Substring(FolderPath.Length + 1); itemSource.Add(FolderSystemItem.Create(directory, destination)); } } else { _dialogCoordinator.ShowMessageAsync(this, "Error", "Allowed to add files and folders only from the project directory.").Wait(); } }