Last active
September 30, 2016 22:44
-
-
Save pornganizer/036378dc775515941953b83baa4deaca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<FolderVm> GetFolderVms<TItemVm>(ObservableCollection<FolderVm> folders, ObservableCollection<TItemVm> potentialMatches) where TItemVm : IItemVm | |
{ | |
var matchingFolders = new List<FolderVm>(); | |
foreach (var folder in folders) | |
{ | |
var directoryName = new DirectoryInfo(folder.Header).Name; | |
var matchingWebsite = potentialMatches.FirstOrDefault(x => string.Equals(x.Header, directoryName, StringComparison.CurrentCultureIgnoreCase)); | |
if (matchingWebsite != null) | |
matchingFolders.Add(folder); | |
matchingFolders.AddRange(GetFolderVms(folder.Folders, potentialMatches)); | |
} | |
return matchingFolders; | |
} | |
private void Organize(object obj) | |
{ | |
var moveActions = new Stack<KeyValuePair<string, Func<List<FolderVm>>>>(); | |
moveActions.Push(new KeyValuePair<string, Func<List<FolderVm>>>("MoveByCategory", () => | |
{ | |
return GetFolderVms(FoldersVm.Instance.Items, Categories); | |
})); | |
moveActions.Push(new KeyValuePair<string, Func<List<FolderVm>>>("MoveByStar", () => | |
{ | |
return GetFolderVms(FoldersVm.Instance.Items, Stars); | |
})); | |
moveActions.Push(new KeyValuePair<string, Func<List<FolderVm>>>("MoveByWebsite", () => | |
{ | |
return GetFolderVms(FoldersVm.Instance.Items, Websites); | |
})); | |
while (moveActions.Count > 0) | |
{ | |
var moveAction = moveActions.Pop(); | |
var folders = moveAction.Value.Invoke(); | |
var folder = folders.FirstOrDefault(); | |
if (folder != null) | |
{ | |
var newPath = System.IO.Path.Combine(folder.Header, Header) + System.IO.Path.GetExtension(Path); | |
try | |
{ | |
if (Path != newPath) | |
{ | |
FileSystem.MoveFile(Path, newPath, UIOption.AllDialogs); | |
Path = newPath; | |
} | |
} | |
catch (Exception) | |
{ | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment