public async Task <AddFolderResult> AddFolderAsync(string path) { AddFolderResult result = await this.folderRepository.AddFolderAsync(path); this.FoldersChanged(this, new EventArgs()); return(result); }
public async Task <AddFolderResult> AddFolderAsync(string path) { AddFolderResult result = AddFolderResult.Success; await Task.Run(() => { try { using (var conn = this.factory.GetConnection()) { try { if (!conn.Table <Folder>().Select((f) => f).ToList().Select((f) => f.SafePath).Contains(path.ToSafePath())) { conn.Insert(new Folder { Path = path, SafePath = path.ToSafePath(), ShowInCollection = 1 }); LogClient.Info("Added the Folder {0}", path); } else { LogClient.Info("Didn't add the Folder {0} because it is already in the database", path); result = AddFolderResult.Duplicate; } } catch (Exception ex) { LogClient.Error("Could not add the Folder {0}. Exception: {1}", path, ex.Message); result = AddFolderResult.Error; } } } catch (Exception ex) { LogClient.Error("Could not connect to the database. Exception: {0}", ex.Message); } }); return(result); }
public async Task <AddFolderResult> AddFolderAsync(Folder folder) { AddFolderResult result = AddFolderResult.Success; await Task.Run(() => { try { using (var conn = this.factory.GetConnection()) { try { if (!conn.Table <Folder>().Select((t) => t.Path.ToLower()).ToList().Contains(folder.Path.ToLower())) { conn.Insert(folder); LogClient.Instance.Logger.Info("Added the Folder {0}", folder.Path); } else { LogClient.Instance.Logger.Info("Didn't add the Folder {0} because it is already in the database", folder.Path); result = AddFolderResult.Duplicate; } } catch (Exception ex) { LogClient.Instance.Logger.Error("Could not add the Folder {0}. Exception: {1}", folder.Path, ex.Message); result = AddFolderResult.Error; } } } catch (Exception ex) { LogClient.Instance.Logger.Error("Could not connect to the database. Exception: {0}", ex.Message); } }); return(result); }
private async void AddFolder() { LogClient.Info("Adding a folder to the collection."); var dlg = new WPFFolderBrowserDialog(); if ((bool)dlg.ShowDialog()) { try { this.IsLoadingFolders = true; AddFolderResult result = AddFolderResult.Error; // Initial value // First, check if the folder's content is accessible. If not, don't add the folder. if (FileOperations.IsDirectoryContentAccessible(dlg.FileName)) { result = await this.foldersService.AddFolderAsync(dlg.FileName); } else { result = AddFolderResult.Inaccessible; } this.IsLoadingFolders = false; switch (result) { case AddFolderResult.Success: this.indexingService.OnFoldersChanged(); this.GetFoldersAsync(); break; case AddFolderResult.Error: this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetString("Language_Error"), ResourceUtils.GetString("Language_Error_Adding_Folder"), ResourceUtils.GetString("Language_Ok"), true, ResourceUtils.GetString("Language_Log_File")); break; case AddFolderResult.Duplicate: this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetString("Language_Already_Exists"), ResourceUtils.GetString("Language_Folder_Already_In_Collection"), ResourceUtils.GetString("Language_Ok"), false, ""); break; case AddFolderResult.Inaccessible: this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetString("Language_Error"), ResourceUtils.GetString("Language_Folder_Could_Not_Be_Added_Check_Permissions").Replace("{foldername}", dlg.FileName), ResourceUtils.GetString("Language_Ok"), false, ""); break; } } catch (Exception ex) { LogClient.Error("Exception: {0}", ex.Message); this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetString("Language_Error"), ResourceUtils.GetString("Language_Error_Adding_Folder"), ResourceUtils.GetString("Language_Ok"), true, ResourceUtils.GetString("Language_Log_File")); } finally { this.IsLoadingFolders = false; } } }
private async void AddFolder() { LogClient.Info("Adding a folder to the collection."); var dlg = new WPFFolderBrowserDialog(); if ((bool)dlg.ShowDialog()) { try { this.IsLoadingFolders = true; AddFolderResult result = await this.folderRepository.AddFolderAsync(dlg.FileName); this.IsLoadingFolders = false; switch (result) { case AddFolderResult.Success: await this.indexingService.AddFolderWatcherAsync(dlg.FileName); this.GetFoldersAsync(); break; case AddFolderResult.Error: this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetStringResource("Language_Error"), ResourceUtils.GetStringResource("Language_Error_Adding_Folder"), ResourceUtils.GetStringResource("Language_Ok"), true, ResourceUtils.GetStringResource("Language_Log_File")); break; case AddFolderResult.Duplicate: this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetStringResource("Language_Already_Exists"), ResourceUtils.GetStringResource("Language_Folder_Already_In_Collection"), ResourceUtils.GetStringResource("Language_Ok"), false, ""); break; } } catch (Exception ex) { LogClient.Error("Exception: {0}", ex.Message); this.dialogService.ShowNotification( 0xe711, 16, ResourceUtils.GetStringResource("Language_Error"), ResourceUtils.GetStringResource("Language_Error_Adding_Folder"), ResourceUtils.GetStringResource("Language_Ok"), true, ResourceUtils.GetStringResource("Language_Log_File")); } finally { this.IsLoadingFolders = false; } } }
public async Task <AddFolderResult> AddFolderAsync(string path) { AddFolderResult result = await this.folderRepository.AddFolderAsync(path); return(result); }